Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm having problem with locking one object on another. Lets image an turret which always targets flying plane. I come to this solution:

  1. Compute yaw = atan2(z2-z1, x2-x1)
  2. Compute pitch = atan2(y2-y1, z2-z1)
  3. Rotate

What do you think about such method? Is there any "faster" way without using atan2? Can I achieve same effect with just quaternions operations?

share|improve this question
1  
Is this two questions? What are you asking? It looks to me like you asked a question about having a turret face an object, then gave us some unrelated code about orbital motion without even telling us what you want to know about it. –  stephelton May 13 '12 at 21:07
    
like pictures show,I want my origin point to be in the center of orbiting objects not a part of the path just like it is now. –  user1075940 May 14 '12 at 5:57
    
You're still asking two questions... –  stephelton May 14 '12 at 15:10
add comment

1 Answer

up vote 1 down vote accepted

To get an object A to point towards a point B, then it's not difficult.

Vector current_heading = non_rotated_heading_of_object * object->rotation;
Vector target_heading = (target_position - object->position).normalize();
Vector axis = current_heading.cross(target_heading);
float angle = std::acos(current_heading.dot(target_heading));
Quaternion rotation = rotateAngleAxis(axis, angle);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.