Sign in to follow this  

Creating rotation matrix through the target point

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, In the game I am creating the enemies should first look at the player before they start to shoot. Also, when the player runs, the enemies should always look at him. I use a 4*4 matrix for the enemy. So when I have the player pos I should be able to rotate that matrix to let them view the player. The rotation will be one on the y-axis. This was my theory:
Quote:
float angle = atanf((Enemy.pos.z - objCamera.mPos.z) / (Enemy.pos.x - objCamera.mPos.x)); Enemy.LocalMatrix[0] = cosf(angle); Enemy.LocalMatrix[2] = sinf(angle); Enemy.LocalMatrix[8] = -sinf(angle); Enemy.LocalMatrix[10] = cosf(angle);
But this only works if the player is in the first quadrant. Is there an easy way to fix this or should I check in which quadrant the player is?

Share this post


Link to post
Share on other sites
Any time you apply a direct-inverse trig function pair, there's a mathematical identity you should probably be using instead.

cos(atan(x)) = sqrt(1 / (1 + x^2)); sin(atan(x)) = sqrt(x^2 / (1 + x^2))

Share this post


Link to post
Share on other sites

This topic is 3779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this