Hello I need to draw some cylinder on virtual universe. How can I get angle of a cylinder.

Examples: - I have some points (point3f) in virtual universe. Each two points I am
> drawing one line using (LineStripArray). But it’s very difficult to identify
> (visibility) lines in universe.  So I think to change lines with cylinders to get
> perfect identification. But I fail to get angles (with x y z plane). Any idea about
> what can I do or else   any formula to get angles.

I do this in EurekaWorks, but it's not easy.  The problem is that you
need to change the shape of the cylinder when the points change, otherwise
the cylinder will get wider as it gets longer.  So I use geometry by
reference and update the geometry each frame:

  /**
   * Update the coordinates of the Interval cylinder to correspond
   * to the current height and width of the clinder.  We can't use
   * a scale transform for these cylinders because it'd be a non-
   * uniform scale, so we are essentially scaling by-hand.  We're
   * taking a "unit" cylinder (height 1 and width 1) and
   * multiplying each component by the current width and height.
   */
  public void updateData (Geometry geometry)
  {
    float[] coords = ((GeometryArray)geometry).getCoordRefFloat();

    for (int i = 0 ; i < INTERVAL_VERTEX_COUNT * 3 ; i += 3) {
      coords[i + 0] = cylinderPoints[i + 0] * cylinderWidth; // x
      coords[i + 1] = cylinderPoints[i + 1] * cylinderHeight; // y
      coords[i + 2] = cylinderPoints[i + 2] * cylinderWidth; // z
    }
  } // End of updateData

Once you've figured that out, you need to be able to position
the cylinder where you want it.  This involves some math:

  private Vector3f tempVec = new Vector3f();
  private Vector3f crossVec = new Vector3f();
  private static final Vector3f YAXIS = new Vector3f(0, 1, 0);
  private Transform3D tempTrans = new Transform3D();
  private Transform3D tempTrans2 = new Transform3D();
  private AxisAngle4f tempAA = new AxisAngle4f();

  /**
   * Draws interval c from (x0,y0,z0) to (x1,y1,z1).
   * The Java 3D Cylinder utility creates a cylinder on the Y-axis and
   * centered on the origin.
   * I need that cylnder to go from an arbitrary point (x0, y0, z0) to
   * another arbitrary point (x1, y1, z1).<p>
   *
   * To do that, I make the cylinder parallel to the vector
   * (x1-x0, y1-y0, z1-z0), I translate it to the midpoint
   * of the two nodes, and I change its length to the distance
   * between the two nodes.<p>
   *
   * The hard part is getting it parallel to (x1-x0, y1-y0, z1-z0).
   * To do that, I rotate it so it has the correct orientation.<p>
   *
   * The rotation axis is the cross product of (x1-x0, y1-y0, z1-z0)
   * and the Y-axis.  The rotation angle is the inverse cosine of
   * the dot product of those two vectors.<p>
   */
  private void updateInterval(int c, float x0, float y0, float z0,
      float x1, float y1, float z1, float strength, float radius,
      float r, float g, float b)
  {
    // This is the direction vector we want for the cylinder
    tempVec.set(x1-x0, y1-y0, z1-z0);

    // Update geometry of cylinder to current width & length
    cylinderHeight = tempVec.length();
    cylinderWidth = BASE_INTERVAL_WIDTH * radius;
    TriangleStripArray tsa = (TriangleStripArray)intervalGeom.get(c);
    tsa.updateData(this);

    // Update color
    ((Material)intervalMaterial.get(c)).setDiffuseColor(r, g, b);

    // Find axis of rotation
    tempVec.normalize();
    crossVec.cross(YAXIS, tempVec);

    // Find amount of rotation and put into matrix
    tempAA.set(crossVec, (float)Math.acos(YAXIS.dot(tempVec)));
    tempTrans.set(tempAA);

    // Transform to midpoint between two nodes
    tempTrans2.setIdentity();
    tempTrans2.setTranslation(new Vector3f((x1+x0)/2f, (y0+y1)/2f, (z0+z1)/2f));
    tempTrans2.mul(tempTrans);

    // Update transform
    TransformGroup tg = (TransformGroup)intervalTG.get(c);
    tg.setTransform(tempTrans2);
  } // End of updateInterval

-Paul Pantera
 http://www.presidiolabs.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".

Reply via email to