package torus;
/**
Given list of triangles (each a triple of xyz's) create Java3D object.
A Shape3D object is created containing one array of triangles.
The appearance parameter is just passed through.
Demo for CSE391 course, G. Hart, Sept 2003
*/
import java.lang.Math.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class makeJ3DObj extends javax.media.j3d.Shape3D{
public makeJ3DObj(xyz[][] triList, Appearance app) {
TriangleArray tris = new TriangleArray(3*triList.length,
GeometryArray.COORDINATES | GeometryArray.NORMALS);
for (int i=0; i<triList.length; i++){ // for each given triangle
xyz v0=triList[i][0]; // extract vertices
xyz v1=triList[i][1];
xyz v2=triList[i][2];
// compute outward normal for lighting calculations
xyz norm = xyz.unit(xyz.cross(xyz.minus(v1, v0), xyz.minus(v2, v0)));
// convert points and normals to vecmath format
tris.setCoordinate(3*i+0, new Point3f(v0.x, v0.y, v0.z));
tris.setNormal (3*i+0, new Vector3f(norm.x, norm.y, norm.z));
tris.setCoordinate(3*i+1, new Point3f(v1.x, v1.y, v1.z));
tris.setNormal (3*i+1, new Vector3f(norm.x, norm.y, norm.z));
tris.setCoordinate(3*i+2, new Point3f(v2.x, v2.y, v2.z));
tris.setNormal (3*i+2, new Vector3f(norm.x, norm.y, norm.z));
}
this.setGeometry(tris); // put triangles in this object
this.setAppearance(app); // pass along given appearance
//this.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // allow rotation
}
}