
Hello everyone. In this image the larger cone is fallling but is oriented toward the cam position (where it is created).
I would like to orient or align a shape (a cone) toward a certain position.
The shape is created at cam position (let's say x:0, y:-10, z:80) facing down with the closed end looking down (i guess this is normal). It should point at (x:0,y:0,z:0);
How do I calculate the rotation along the 3 axis?
I think one should do something like:
Code: Select all
Transform tt = myRigidBody.getWorldTransform(trnsfrm);
tt.setRotation(etoq(0, phi, theta));
myRigidBody.setWorldTransform(tt);
// also the shape is accelerated with setLinearVelocity(linVel);
Code: Select all
Vector3f linVel = new Vector3f(destination.x - initPosition.x, destination.y - initPosition.y, destination.z - initPosition.z);
float theta = atan2(linVel.y,linVel.x); //y
float phi = acos(linVel.z/(float) distance); //z
Here's my function wich transforms 3 angles into a Quat:
Code: Select all
Quat4f etoq (float heading, float attitude, float bank) {
// Assuming the angles are in radians.
float c1 = cos(heading/2);
float s1 = sin(heading/2);
float c2 = cos(attitude/2);
float s2 = sin(attitude/2);
float c3 = cos(bank/2);
float s3 = sin(bank/2);
float c1c2 = c1*c2;
float s1s2 = s1*s2;
float w = c1c2*c3 - s1s2*s3;
float x = c1c2*s3 + s1s2*c3;
float y = s1*c2*c3 + c1*s2*s3;
float z = c1*s2*c3 - s1*c2*s3;
return new Quat4f(x,y,z,w);
}
Any help?
Thanks
GC