Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Java 3D / October 2004

Tip: Looking for answers? Try searching our database.

Shape 3d and normals

Thread view: 
bret.lichtenwald@gmail.com - 14 Oct 2004 21:46 GMT
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]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.