I hand built a TriangleFanArray shape, and I want to be able to view it
from below and above. How do I set the normals so I can see it from
above and below? (I tried making two objects, one with normals up and
one with normals down, yet both objects will only be shown if I look
from above them???)
Sample code:
int numOfTriangles = 24;
int format = GeometryArray.TEXTURE_COORDINATE_2 |
GeometryArray.COORDINATES | GeometryArray.NORMALS;
...
int[] fan_counts = { numOfTriangles+2 };
TriangleFanArray trisUp = new TriangleFanArray(numOfTriangles+2,
format, fan_counts);
TriangleFanArray trisDown = new TriangleFanArray(numOfTriangles+2,
format, fan_counts);
...
for(int triangles = 0; triangles <= numOfTriangles; triangles++)
{
...
// Set the vertices
verticesUp[verticeIndex] = x;
verticesUp[verticeIndex+1] = 0;
verticesUp[verticeIndex+2] = z;
verticesDown[verticeIndex] = x;
verticesDown[verticeIndex+1] = 0;
verticesDown[verticeIndex+2] = z;
// Set the normals
normalsUp[verticeIndex] = 0;
normalsUp[verticeIndex+1] = 1;
normalsUp[verticeIndex+2] = 0;
normalsDown[verticeIndex] = 0;
normalsDown[verticeIndex+1] = -1;
normalsDown[verticeIndex+2] = 0;
// Set the texture coords
textureCoords[textureIndex] = (float)(theta2 * .5 + .5);
textureCoords[textureIndex+1] = (float)(theta* .5 + .5);
...
}
// Set the top ring
trisUp.setCoordinates(0, verticesUp);
trisUp.setTextureCoordinates(0,0,textureCoords);
trisUp.setNormals(0,normalsUp);
// Set the bottom ring
trisDown.setCoordinates(0, verticesDown);
trisDown.setTextureCoordinates(0,0,textureCoords);
trisDown.setNormals(0,normalsDown);
topRing = new Shape3D(trisUp, createAppearance(texture));
botRing = new Shape3D(trisDown, createAppearance(texture));
TransformGroup result = new TransformGroup();
result.addChild(topRing);
result.addChild(botRing);
return result;
john - 19 Oct 2004 18:26 GMT
Hi,
Making 2 geometry objects is not the best idea,
it will just waste the memory...
You just want to be able to view front and back faces of your 3d object,
so you can simply specify the culling mode:
Appearance app=new Appearance();
PolygonAttributes polyAttrib = new PolygonAttributes();
// front and back faces are visible with 'CULL_NONE'
polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
app.setPolygonAttributes(polyAttrib);
When creating the Shape3D object, specify the geometry and the
Appearance object (app here).
Best Regards,
John
On Thu, 14 Oct 2004 13:46:23 -0700, bret.lichtenwald wrote :
> I hand built a TriangleFanArray shape, and I want to be able to view it
> from below and above. How do I set the normals so I can see it from
[quoted text clipped - 3 lines]
>
> Sample code:
[SNIP]
> TriangleFanArray trisUp = new TriangleFanArray(numOfTriangles+2,
> format, fan_counts);
> TriangleFanArray trisDown = new TriangleFanArray(numOfTriangles+2,
> format, fan_counts);
[SNIP]