urgently : i'm in need help
hello
i'm a girl student in FCI my graduation project is a visualization tool
using java3d
i face a problem and need to help me please
i want to create a cone and let it move from
position to another position and also i want to rotate the cone in the
direction of the second position
i do the move from the position to the second position using
KBRotPosScaleSplinePathInterpolator but i can't rotate the cone head
into the direction of the second point
i use thecode of rotation of objects using transform 3d but it doesn't
work could u help me
this is the code for creating objects and rotating it
for(int i=0;i<count;i++)
{
Transform3D t3d=new Transform3D();
//t3d.set(new Vector3f(0.0f,0.0f,0.0f));
double rotAngle = calcTurn(new Point3d(pos1), new Point3d(pos0));
System.out.println("rotation angle is "+rotAngle);
TransformGroup tg=new TransformGroup(t3d);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Cone c = new Cone(0.05f,.1f, redApp);
doRotateY(rotAngle,tg,t3d);
tg.addChild(c);
KBKeyFrame []KKF1;
KKF1=setupLinearKeyFrames(1,0);
Alpha a1=setupAnimationData(i,(5000*i)/10);
createInterpolators(tg,KKF1,a1);
rootBranchGroup.addChild(tg);
}
i calculate the angle between 2 positions using this function
private double calcTurn(Point3d alienLoc, Point3d touristLoc)
/* Calculate the angle to turn the alien around the
y-axis, so that it is facing towards the tourist.
This angle is relative to the original orientation
facing along +z-axis
*/
{ // printTuple(alienLoc, "alienLoc");
// printTuple(touristLoc, "touristLoc");
double zDiff = touristLoc.z - alienLoc.z;
double xDiff = touristLoc.x - alienLoc.x;
//System.out.println("xDiff: " + df.format(xDiff) +
//"; zDiff: " + df.format(zDiff) );
double turnAngle = 0.0;// the angle to rotate the alien
if (zDiff != 0.0) {
double angle = Math.atan( xDiff/zDiff);
// the angle from alienLoc to touristLoc
// System.out.println("angle: " + df.format(angle));
if ((xDiff > 0) && (zDiff > 0))// some redundancy for clarity
turnAngle = angle;
else if ((xDiff > 0) && (zDiff < 0))
turnAngle = Math.PI + angle;// since angle has neg value
else if ((xDiff < 0) && (zDiff < 0))
turnAngle = Math.PI + angle;
else if ((xDiff < 0) && (zDiff > 0))
turnAngle = angle;// since angle has neg value
}
else {// zDiff == 0.0, which is unlikely with doubles
if (xDiff > 0)
turnAngle = Math.PI/2;
else if (xDiff < 0)
turnAngle = -Math.PI/2;
else// alien and sprite at *exact* same place
turnAngle = 0.0;
}
// System.out.println("turnAngle: " + df.format(turnAngle));
return turnAngle;
} // end of calcAngle()
then do rotation by this function
public void doRotateY(double radians,TransformGroup objectTG, Transform3D t3d)
// Rotate the sprite by radians amount around its y-axis
{
objectTG.getTransform( t3d );
//toRot.setIdentity();
Transform3D toRot=new Transform3D();
toRot.rotY(radians);// overwrite previous rotation
t3d.mul(toRot);
objectTG.setTransform(t3d);
} // end of doRotateY()

