Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (757) Games in Android Showcase (229) games submitted by our members Games in WIP (844) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 java3d polygon_array  (Read 3027 times) 0 Members and 1 Guest are viewing this topic.
hawkwind

Junior Devvie

Java games rock!

 « Posted 2003-05-11 13:39:36 »

I am confused...perhaps youse guys can help...The code below is from a java3d terrain applet i once saw.  He is setting up his floor terrain as a polygon array, roughly U shaped,  and texturing with a grass image.   What I don't understand is the use of greater than 0 texture coord's.  I thought that these were required to range twixt 0 and 1 and yet this produces a nice ground floor.  Any ideas what is happening here??

Appearance app = new Appearance();
app.setMaterial(new Material());
app.setTexture(texture);
TextureAttributes textureAttributes = new TextureAttributes();
textureAttributes.setTextureMode(TextureAttributes.MODULATE);
app.setTextureAttributes(textureAttributes);

// create geometry
GeometryInfo geom = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
Point3f[] coords = new Point3f[16];
coords[0] =  new Point3f(-12.0f, 1.2f, -35.0f);
coords[1] =  new Point3f(-12.0f, 1.0f, -18.0f);
coords[2] =  new Point3f(-12.0f, 0.0f, -10.0f);
coords[3] =  new Point3f(-12.0f, 0.0f,   0.0f);
coords[4] =  new Point3f( -1.5f, 0.0f,   0.0f);
coords[5] =  new Point3f( -0.5f, 0.0f, -10.0f);
coords[6] =  new Point3f( -0.5f, 1.0f, -18.0f);
coords[7] =  new Point3f(-0.25f, 1.0f, -30.0f);
coords[8] =  new Point3f( 0.25f, 1.0f, -30.0f);
coords[9] =  new Point3f(  0.5f, 1.0f, -18.0f);
coords[10] = new Point3f(  0.5f, 0.0f, -10.0f);
coords[11] = new Point3f(  1.5f, 0.0f,   0.0f);
coords[12] = new Point3f( 12.0f, 0.0f,   0.0f);
coords[13] = new Point3f( 12.0f, 0.0f, -10.0f);
coords[14] = new Point3f( 12.0f, 1.0f, -18.0f);
coords[15] = new Point3f( 12.0f, 1.2f, -35.0f);
geom.setCoordinates(coords);
Point2f[] text = new Point2f[16];
text[0] =  new Point2f(  -6.0f, -17.5f);
text[1] =  new Point2f(  -6.0f,  -9.0f);
text[2] =  new Point2f(  -6.0f,  -5.0f);
text[3] =  new Point2f(  -6.0f,   0.0f);
text[4] =  new Point2f( -0.75f,   0.0f);
text[5] =  new Point2f( -0.25f,  -5.0f);
text[6] =  new Point2f( -0.25f,  -9.0f);
text[7] =  new Point2f(-0.125f, -15.0f);
text[8] =  new Point2f( 0.125f, -15.0f);
text[9] =  new Point2f(  0.25f,  -9.0f);
text[10] = new Point2f(  0.25f,  -5.0f);
text[11] = new Point2f(  0.75f,   0.0f);
text[12] = new Point2f(   6.0f,   0.0f);
text[13] = new Point2f(   6.0f,  -5.0f);
text[14] = new Point2f(   6.0f,  -9.0f);
text[15] = new Point2f(   6.0f, -17.5f);
geom.setTextureCoordinates(text);
// there is only one polygon with 16 vertices
int[] stripCounts = new int[1];
stripCounts[0] = 16;
geom.setStripCounts(stripCounts);
// easy creation of other elements (normal, ...)
new Triangulator().triangulate(geom);
geom.recomputeIndices();
new NormalGenerator(Math.PI).generateNormals(geom);
geom.recomputeIndices();
new Stripifier().stripify(geom);
geom.recomputeIndices();

// create and return shape
Shape3D shape = new Shape3D(geom.getIndexedGeometryArray(), app);
return shape;

pepe

Junior Devvie

Nothing unreal exists

 « Reply #1 - Posted 2003-05-11 15:02:31 »

An image always have coordinates between 0 and 1.
Nevertheless, when you map it, you can use coordinates greater than that, if you want a polygon to show the same texture many times in it.  For example, if you set a polygon with a 0.0 and 2.0 coordinates for two different points, the texture will be repeated two times from its beginning to its end. If you set .5 and 10, it will be repeated 9.5 times, beginning in the middle of the texture.
Did i make it clearer?

------------------------------------------------------
GoSub: java2D gamechmark http://frederic.barachant.com/GoSub/GoSub.jnlp
hawkwind

Junior Devvie

Java games rock!

 « Reply #2 - Posted 2003-05-11 20:07:57 »

i learn