Hi
How I get the Normal Vector of the tetrahedron create with
TriangleArray.
My class tetrahedron is below:
import javax.media.j3d.*;
import javax.vecmath.*;
class Tetrahedron extends Shape3D {
public Tetrahedron(float x, float y, float z, float s) {
super();
float xsizeMin = -s/2.0f + x;
float xsizeMax = s/2.0f + x;
float ysizeMin = -s/2.0f + y;
float ysizeMax = s/2.0f + y;
float zsizeMin = -s/2.0f + z;
float zsizeMax = s/2.0f + z;
// TriangleArray tetra = new TriangleArray(12,
GeometryArray.COORDINATES);
TriangleArray tetra = new TriangleArray(12,
GeometryArray.COORDINATES |
GeometryArray.COLOR_3 | GeometryArray.NORMALS);
Point3f verts[] = new Point3f[4];
verts[0] = new Point3f(xsizeMax, ysizeMax, zsizeMax);
verts[1] = new Point3f(xsizeMax, ysizeMin, zsizeMin);
verts[2] = new Point3f(xsizeMin, ysizeMin, zsizeMax);
verts[3] = new Point3f(xsizeMin, ysizeMax, zsizeMin);
Point3f pnts[] = new Point3f[12];
pnts[0] = verts[2];
pnts[1] = verts[1];
pnts[2] = verts[0];
pnts[3] = verts[3];
pnts[4] = verts[2];
pnts[5] = verts[0];
pnts[6] = verts[1];
pnts[7] = verts[2];
pnts[8] = verts[3];
pnts[9] = verts[1];
pnts[10] = verts[3];
pnts[11] = verts[0];
tetra.setCoordinates(0, pnts);
//
Color3f colors[] = new Color3f[4];
colors[0] = new Color3f(0.0f, 1.0f, 0.0f);
colors[1] = new Color3f(0.0f, 0.0f, 1.0f);
colors[2] = new Color3f(1.0f, 1.0f, 0.0f);
colors[3] = new Color3f(1.0f, 0.0f, 0.0f);
Color3f clrs[] = new Color3f[12];
clrs[0] = colors[0];
clrs[1] = colors[0];
clrs[2] = colors[0];
clrs[3] = colors[1];
clrs[4] = colors[1];
clrs[5] = colors[1];
clrs[6] = colors[2];
clrs[7] = colors[2];
clrs[8] = colors[2];
clrs[9] = colors[3];
clrs[10] = colors[3];
clrs[11] = colors[3];
tetra.setColors(0, clrs);
//
this.setGeometry(tetra);
this.setAppearance(new Appearance());
}
}
I use the method getNormals:
...
Geometry geo2 = shape2.getGeometry();
GeometryArray gArray2 = (GeometryArray) geo2;
gArray2.getNormals(0, normals);
for (int j=0; j<4; j++){
System.out.println("normal:" + j + " : (" + normals[j*3] + ", "
+ normals[j*3 + 1] + " , " + normals[j*3 + 2] + ")" );
...
The problem is that it print (0.0, 0.0, 0.0);
Where is the error?
I wait the your e-mails.
Haroldo
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".