> From: Rakesh Kotecha <[EMAIL PROTECTED]>
>
> does anyone know how i could easily have a picture (gif files) as a
> billboard without knowing the size... included in a j3d application?
>
> i.e. i just want to create a billboard with the picture on it... (and
> the billoboard sizes itself to the picture being loaded) and include it
> in my scene graph
>
> the only way i can think of doing it is to create a square out of
> polygons and load it as a texture...
>
> and then adding that square to a billboard transform.
You have the right idea, but if you use a square then the image will always get
"squished" from whatever shape it has into the square. For example, if the
picture has the shape of normal 4"x6" photo, if you texture map it onto a square
it will shrink the image along the long side to make it a square.
What you need to do is set up your billboard so that the primitive is a
rectangle with the right aspect ratio for your picture. Take a look at the
example TextureTest/TextureImage.java for how to load the texture. You'll want
to size your polygon with some code like:
TextureLoader texLoad = new TextureLoader(args[0], this);
// get the image size
ImageComponent2D img = texLoad.getImage();
int width = img.getWidth();
int height = img.getHeight();
// get the texture
Texture tex = texLoad.getTexture();
// create the quad. Let's say we want the quad to be 1.0 units tall.
// We want to set the width so that the aspect ratio is preserved:
// xSize/ySize == width/height
// xSize = ySize * width / height
double ySize = 1.0;
double xSize = ySize * width / height
// make a quad with the specified size with the center of the bottom
// edge at 0,0
Point3d quadPts[] = new Point3d[4];
quadPts[0] = new Point3d(-xSize / 2, 0.0, 0.0);
quadPts[1] = new Point3d( xSize / 2, 0.0, 0.0);
quadPts[2] = new Point3d( xSize / 2, ySize, 0.0);
quadPts[3] = new Point3d(-xSize / 2, ySize, 0.0);
// set up the texture coords so that the texture spans the quad
Point2D quadTexCoords = new Point2D[4];
quadTexCoords[0] = new Point2d(0.0, 0.0);
quadTexCoords[1] = new Point2d(1.0, 0.0);
quadTexCoords[2] = new Point2d(1.0, 1.0);
quadTexCoords[3] = new Point2d(0.0, 1.0);
// create the quad
QuadArray quad = new QuadArray(4, QuadArray.COORDINATES |
QuadArray.TEXTURE_COORDINATE_2);
quad.setCoordinates(0, quadPts);
quad.setTextureCoords(0, quadTexCoords);
// Set up an appearance with the texture and either:
// disable lighting
// or
// set up the quad with normals (all (0.0, 0.0, 1.0)) for lighting
Hope this gets you started,
Doug Gehringer
Sun Microsystems
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/