Posted by Wuzzeb on 2001-05-26
> Date: Wed, 23 May 2001 08:35:27 -0000
> From: "Angelo Bertolli" <abertoll@xxxxxxx.xxx>
> Subject: 3D rotation
>
>
> I have a math problem. I had been writing a 3D
> asteroids game. But I
> couldn't get the ship to behave the way I wanted. I
> have to keep track of
> the direction the ship is going, and it's
> orientation (I decided to use a
> directional vector and a normal to the ship). Plus
> I have to rotate the
> ship. But I figure if I can get the vectors to
> rotate properly, I can get
> the ship to rotate properly. I found something that
> "rotates about an
> arbitrary vector" to solve the problem of the ship
> roll and pitch (using a
> third vector that I keep track of). Here is the
> transformation I found, but
> it doesn't seem to work properly. Does anyone have
> an ideas?
>
> void vectorRotate(double n[3], double theta, double
> matrix[3][3]) {
> matrix[0][0] = cos(theta) + (1 - cos(theta)) *
> pow(n[0],2);
> matrix[1][0] = (1 - cos(theta)) * n[1] * n[0] -
> sin(theta) * n[2];
> matrix[2][0] = (1 - cos(theta)) * n[2] * n[0] +
> sin(theta) * n[1];
>
> matrix[0][1] = (1 - cos(theta)) * n[0] * n[1] +
> sin(theta) * n[2];
> matrix[1][1] = cos(theta) + (1 - cos(theta)) *
> pow(n[1],2);
> matrix[2][1] = (1 - cos(theta)) * n[2] * n[1] -
> sin(theta) * n[0];
>
> matrix[0][2] = (1 - cos(theta)) * n[0] * n[2] -
> sin(theta) * n[1];
> matrix[1][2] = (1 - cos(theta)) * n[1] * n[3] +
> sin(theta) * n[0];
> matrix[2][2] = cos(theta) + (1 - cos(theta)) *
> pow(n[2],2);
> }
>
> I multiply the vectors by thix matrix to get the new
> vectors.
>
> Angelo
>
>
>
The easiest way to do 3-d rotations is to use
homogeneous coordinates. The homogeneous coordinate
point (x, y, z, w) translates into the Euclidean 3-d
point (x / w, y / w, z / w). This provides easy
scaling of the vector with respect to an arbitray
point.
For more information see
http://www.gamedev.net/reference/list.asp?categoryid=28
and these articles...
http://www.gamedev.net/reference/articles/article1279.asp
http://www.gamedev.net/reference/articles/article695.asp
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/
Previous post | Next post | Timeline | Home