> From: Christopher Currie <[EMAIL PROTECTED]>
> 
> < stuff which shows how Chris sets up an IndexedTriangleStripArray for
>   an elevation grid >
>
>  What I'm confused about is how to set the normals (i.e.,
> IndexedTriangleStripArray.setNormals).

The simple answer is to use the NormalGenerator in the utilities.  Just put your 
primitives into a GeometryInfo and call NormalGenerator.generateNormals() and 
you should be all set.

The normal generator will do the kind of stuff you describe, but in case you 
want to do it yourself:

>   I know how to calculate a normal given two vectors (i.e., cross
> product), and I know that
>   I need a "normals" array that is the same size as the coordinates
> array above, i.e.,
> 
>  float[] normals = new float[3*3*3].

Correct, you will need a normal for each vertex.


>  I guess my first question is: where are the triangle in these two
> strips?  Am I correct in
>  assuming that the first triangle is: v(0) -> v(3) -> v(1)?  The second
> is: v(3) -> v(4) -> v(1),
>  and so on?

Not exactly.  If the indicies in the triangle strip array are 0, 3, 1, 4, then 
the triangles will be {0,3,1}, {3,1,4}, etc.  Note that every other triangle has 
"reverse winding".  That is, for "even" triangles (0, 2, 4) the normal is 
calculated using the normal "counter-clockwise" winding:

        normal = cross(vector(pt1 - pt0) ,vector(pt1 - pt0))
        
        
but for "odd" triangles (1, 3, 5), the normal is calcuated using "clockwise" 
winding:

        normal = cross(vector(pt2 - pt0) ,vector(pt1 - pt0))
> 
>  If so, how would you calculate the normal vector at v(1)?  Is it the
> average of two normal
>  vectors calculated from two triangles that share v(1)?

Yup.  To generate smooth normals, average the the normals of all the triangles 
which are adjacent to the vertex.  For best results, weight the vectors based on 
the area of the triangles (i.e. large triangles have more affect on the averaged 
normal than small triangles).

The other thing to worry about for the general case is when the triangles along 
an edge form a sharp edge or "crease" (think of the edges of a cube).  In this 
case you don't want to average the normals across the crease.  For an elevation 
grid you probably don't want to worry about this, but the NormalGenerator 
supports this.

As I said, it is much easier to just leave this to the NormalGenerator.

Doug Gehringer
Sun Microsystems


=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to