Parabolic paths

How would I use a LineArray to display a parabola (tracing the path of a projectile)

float hAngle = unitAngle;
float velocity = 5;
Point3f[] pointz = new Point3f[] {
  new Point3f(unitLoc.x, unitLoc.y, unitLoc.z),
  new Point3f(unitLoc.x + velocity*(float)Math.sin(hAngle), unitLoc.y + velocity*1 +.5f*-9.8f*1, unitLoc.z+ velocity*(float)Math.cos(hAngle)), 
  new Point3f(unitLoc.x + (float)Math.sin(hAngle), unitLoc.y + velocity*2 +.5f*-9.8f*4, unitLoc.z+ (float)Math.cos(hAngle)), 
  new Point3f(unitLoc.x + (float)Math.sin(hAngle), unitLoc.y + velocity*3 +.5f*-9.8f*9, unitLoc.z+ (float)Math.cos(hAngle)), 
  new Point3f(unitLoc.x +(float)Math.sin(hAngle), unitLoc.y + velocity*4 +.5f*-9.8f*16, unitLoc.z+ (float)Math.cos(hAngle)), 
};

LineArray path = new LineArray(pointz.length, LineArray.COORDINATES);
path.setCoordinates(0, pointz);
Shape3D parabola = new Shape3D(path, new Appearance());
scene.addChild(parabola);
v.renderOnce();
try{
  wait(1000);
} catch (InterruptedException ie) {}
scene.removeChild(parabola);
v.renderOnce();

I tried using this code, but nothing is rendered… any ideas?

You can try to place your calculation code instead of some of shapes in Xith3DLineAttributesTest.java - this test demonstrates use of LineArray and LineAttributes.

Yuri

I had a similar problem so I created a Parabola class that could give me a point along a parabolic path at a given time. At the bottom you can see how I arranged that for display in Xith. Using that, I get a dotted-line parabola.


    parabola = new Parabola(new Point3f(0,0,0), bOffset);
                                                                                                                                                              
    float[] verts = new float[303];
                                                                                                                                                              
    float totalFlightTime = parabola.getFlightTime();
    float increment = totalFlightTime / 100;
    float t = 0.0f;
    for(int i=0; i<verts.length; i+=3) {
      Point3f point = parabola.computePointAtT(t);
                                                                                                                                                              
      verts[i] = point.x;
      verts[i+1] = point.y;
      verts[i+2] = point.z;
      t += increment;
    }
                                                                                                                                                              
    lineAttribs.setLineWidth(lineWidth);
                                                                                                                                                              
    geom = new LineArray(verts.length / 3, LineArray.COORDINATES);
    geom.setCoordinates(0, verts);
    shape.setGeometry(geom);
                                                                                                                                                              
    appearance.setLineAttributes(lineAttribs);
    shape.setAppearance(appearance);

Also, I seem to recall having trouble using Point3f with some type of GeometryArray in the past. When I switched to floats it worked fine.