I’m not sure if this is worthwhile, but here is a slight modification to Cylinder to make Cone. It’s so minor that I’m just posting it as a diff against Cylinder.
I don’t trust my understanding of the shape data structure (indexes, texturing) enough to do something more difficult like a trapazoid.
-Mike
--- Cylinder.java Thu Apr 22 18:26:53 2004
+++ Cone.java Sun Apr 25 22:27:48 2004
@@ -42,7 +42,7 @@
* @author Mark Powell
* @version $Id: Cylinder.java,v 1.2 2004/04/22 22:26:53 renanse Exp $
*/
-public class Cylinder extends TriMesh {
+public class Cone extends TriMesh {
private int axisSamples;
private int radialSamples;
@@ -49,7 +49,7 @@
private float radius;
private float height;
- public Cylinder(
+ public Cone(
String name,
int axisSamples,
int radialSamples,
@@ -108,6 +108,7 @@
for (int axisCount = 0, i = 0; axisCount < axisSamples; axisCount++) {
float axisFraction = axisCount * inverseAxisLess; // in [0,1]
float z = -halfHeight + height * axisFraction;
+ float computedRadius = radius * axisCount / axisSamples;
// compute center of slice
Vector3f sliceCenter = new Vector3f(0, 0, z);
@@ -120,7 +121,7 @@
float radialFraction = radialCount * inverseRadial; // in [0,1)
Vector3f tempNormal =
new Vector3f(cos[radialCount], sin[radialCount], 0);
- vertex[i] = sliceCenter.add(tempNormal.mult(radius));
+ vertex[i] = sliceCenter.add(tempNormal.mult(computedRadius));
if (true) {
normal[i] = tempNormal;
} else {