Java Reference
In-Depth Information
int knobFaceStripCount[] = new int[1]; // per knob vertex count
int knobVertexCount;
// #(vertices) for knob
int knobStripCount[] = new int[1];
// #(vertices) in strip/strip
// Front facing normals for the knob's faces
Vector3f frontNormal = new Vector3f(0.0f, 0.0f, 1.0f);
Vector3f outNormal = new Vector3f(1.0f, 0.0f, 0.0f);
// Temporary variables for storing coordinates and vectors
Point3f coordinate = new Point3f(0.0f, 0.0f, 0.0f);
Shape3D newShape;
// The angle subtended by a single segment
double segmentAngle = 2.0 * Math.PI/segmentCount;
double tempAngle;
this.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// Construct the knob's front and rear face
knobFaceVertexCount = segmentCount + 2;
knobFaceStripCount[0] = knobFaceVertexCount;
TriangleFanArray frontKnobFace = new TriangleFanArray(knobFaceVertexCount,
GeometryArray.COORDINATES | GeometryArray.NORMALS, knobFaceStripCount);
coordinate.set(0.0f, 0.0f, frontZ);
frontKnobFace.setCoordinate(0, coordinate);
frontKnobFace.setNormal(0, frontNormal);
for(int index = 1; index < segmentCount+2; index++)
{
tempAngle = segmentAngle * (double)index;
coordinate.set(radius * (float)Math.cos(tempAngle), radius * (float)Math.sin(tempAngle), frontZ);
frontKnobFace.setCoordinate(index, coordinate);
frontKnobFace.setNormal(index, frontNormal);
}
TexCoordGeneration tcg = new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR,
TexCoordGeneration.TEXTURE_COORDINATE_2);
frontfacelook.setTexCoordGeneration(tcg);
frontfacelook.setTexture(texture);
newShape = new Shape3D(frontKnobFace, frontfacelook);
PickTool.setCapabilities(newShape, PickTool.INTERSECT_FULL);
this.addChild(newShape);
// Construct knob's outer skin (the cylinder body)
knobVertexCount = 2 * segmentCount + 2;
knobStripCount[0] = knobVertexCount;
TriangleStripArray outerknobFace = new TriangleStripArray(knobVertexCount,
GeometryArray.COORDINATES|GeometryArray.NORMALS, knobStripCount);
outNormal.set(1.0f, 0.0f, 0.0f);
Search WWH ::

Custom Search