1
Support / How to Rotate Object relative to camera?
« on: November 04, 2007, 10:25:43 pm »
Hi again,
I'm trying to figure out how to rotate an object relative to the X Y axis of the screen space.
This *seemed* at first to almost work, but when I move the camera behind or under the object, I get inverse and / or reverse rotations - so I guess I'm way off here. :-(
Any suggestions?
Thank you,
S.
I'm trying to figure out how to rotate an object relative to the X Y axis of the screen space.
This *seemed* at first to almost work, but when I move the camera behind or under the object, I get inverse and / or reverse rotations - so I guess I'm way off here. :-(
Any suggestions?
Thank you,
S.
Code: [Select]
public SimpleVector rotateRespect2Cam(float rotX, float rotY)
{
SimpleVector dir = theCamera.getDirection();
dir.rotateX(rotX);
dir.rotateY(rotY);
return dir.calcSub(theCamera.getDirection());
}
Code: [Select]
SimpleVector rotate = rotateRespect2Cam(delta.x * -camRotSpeed, delta.y * -camRotSpeed);
object.rotateX(rotate.x); // rx rz ry to avoid gimbal lock.
object.rotateZ(rotate.z);
object.rotateY(rotate.y);