• Create Account

# Rotate model towards given coordinate

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1xikky  Members   -  Reputation: 100

Like
0Likes
Like

Posted 07 March 2012 - 06:31 PM

Hello to GameDev community!

In my game I have a plane model that the user can control and is viewed as 'third person' camera.

Is it possible to turn/rotate the plane model to a Vector3 coordinate, when certain conditions are met?
My problem is how to turn/rotate the plane towards a given coordinate.

Thank you!

### #2NDraskovic  Members   -  Reputation: 190

Like
0Likes
Like

Posted 30 March 2012 - 04:29 AM

I think the best way to do this is to use trigonometry, try to calculate the angle by which you need to rotate your model so it faces the destination you want

### #3dAND3h  Members   -  Reputation: 214

Like
-1Likes
Like

Posted 05 April 2012 - 06:30 PM

Well, first of all, you need the direction you want to turn to.
So, you have a Vector3 Position of the object you want to face.

desiredDirection = ObjectPosition - planePositon ;
//Ok, so you have the direction you want to face, now we need to recalculate our other direction vectors
Right = Vector3.Cross(Up,desiredDirection);
//We need to normalize this
Vector3.Normalize(ref Right, out Right);
//then get the new forward/look Vector
Forwards = Vector3.Cross(Up,Right);
//normalize again
Vector3.Normalize(ref Forwards,out Forwards);
//then we need the new Up vector
Vector3.Cross(Right,Forwards);

//Now comes the fun part. We need an homogenous Matrix to represent this transformation around 3 different axis simultaneously. So it will be a 4d //matrix like so:
Matrix rot = new Matrix(Right.X,Right.Y,Right.Z,0, Up.X, Up.Y, Up.Z, 0, Forwards.X, Forwards.Y, Forwards.Z, 0, 0, 0, 0, 1);

//As you can see, the last dimension has no translation.

//If you then just multiply your world matrix with the matrix you created here, your plane should turn to face your object.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS