Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 simulation rotation probleme
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

alienfg
Neophyte

1 Posts

Posted - Jun 11 2005 :  11:30:32 AM  Show Profile  Reply with Quote
In my space game engine i save only 3 degree for the rotation of an object.
Look my function parameter and think you are in an airplane.
The x,y,z paramter is the x,y and z degree for the new rotation
In my class i have these 3 variables too
CurentXDegree as single
CurentYDegree as single
CurentZDegree as single

I want to call this function to rotate the airplane by 40 degree on the X axis of the object, not the world. This example is the same as if you are in airplane at heading 45 and you pull back the stick. The airplane is supposed to "nose up".
This is my probleme, the airplane don't nose up, the airplane rotate by 45 degrees on x axis, but the axis is centered on the world, not my airplane.

Rotation(45,45,0)
Public Sub Rotate(Rx As Single, Ry As Single, Rz As Single)
Dim MatTmp As D3DMATRIX
Dim MatRot As D3DMATRIX


XDegree = XDegree + (Rx * Me.RotXSpeed)
If XDegree >= 360 Then XDegree = XDegree - 360
If XDegree <= 360 Then XDegree = XDegree + 360

YDegree = YDegree + (Ry * Me.RotYSpeed)
If YDegree >= 360 Then YDegree = YDegree - 360
If YDegree <= 360 Then YDegree = YDegree + 360

ZDegree = ZDegree + (Rz * Me.RotZSpeed)
If ZDegree >= 360 Then ZDegree = ZDegree - 360
If ZDegree <= 360 Then ZDegree = ZDegree + 360

D3DXMatrixIdentity MatRot

D3DXMatrixRotationYawPitchRoll MatTmp, Rad(YDegree), Rad(XDegree), Rad(ZDegree)
D3DXMatrixMultiply MatRot, MatTmp, MatRot

D3DDevice.SetTransform D3DTS_WORLD, MatRot
End Sub

I'm on this rotation probleme for the last 3 weeks and i can't figure out how i can rotate an aircraft with local axis.

Thanks for the help

Eric Coleman
Gladiator

USA
811 Posts

Posted - Jun 13 2005 :  1:04:33 PM  Show Profile  Visit Eric Coleman's Homepage  Reply with Quote
As a tip, you can replace those If Then statements with the following code, XDegree = (XDegree + 360) Mod 360.

Your code, as you have it written here, should spin the plane around it's origin and then draw the plane at the origin of the "world".

Typically you would want to add some translation (movement) in your WORLD matrix to that you can actually move the plane.

Typically you would use the following formula for calculating the world matrix for a particular object.

Mw = world matrix
Rm = local rotation matrix
Tm = global translation matrix

Mw = Rm * Tm

You must interpret the translations from Left to Right. First the object is rotated around the origin, generally in the center of the object by the matrix Rm. Then the object is translated (moved) according to Tm.

You can combine matrices (plural of matrix) to create a single matrix that performs all of the operations of the combined matrices.

For example, if you wanted to create a model of the solar system, then you would need at least 3 matrices to render the Earth correctly. Given a sphere where the origin (0,0,0) is in the center inside the sphere, you would need to first rotate the sphere according to the time. The earth rotates at 24 hours a day. So, your first matrix, Rm would do that rotation. The next matrix is to translate it from the center of the solar system to its correct orbital path, which is roughly 93 million miles from the center. This would be the Tm matrix. The next matrix is another "rotation", but since the earth is now 93 million miles away from the center of the "WORLD" in terms of "WORLD coordinates", a rotation matrix will rotate the earth around the WORLD origin, which is still the center of the solar system in this simplified example. The translation matrix, Tm, move the origin from the center of the sphere to 93 million miles way. Rotation matrices always rotate around the origin. The final rotation matrix is our "day" matrix. There are 365 days in a year, so this matrix is calulcated according to the day of the year.

The final world matrix for the planet earth is as follows.

W_earth = Mrot_earth * Tdist_earth * Mrev_earth

For the moon, it would be slightly more complicated. It cycles around the earth every 27 days. I'm not sure how far the moon is from the earth, but it's definatly greater than 0. It also has one day per revolution. The moon's world matrix would look like this:

W_moon = Mrot_moon * Tdist_moon * Mrev_moon * Tdist_earth * Mrev_earth.

The rotation of the earth is left out of this equation because the earth's rotation has nothing to do with the location of the moon. However, the earth's position relative to the center of the solar system does effect the position of the moon because the moon revolves around the earth. The Tdist_moon translation matrix translates the distance the moon is from the earth.

I hope this helps!

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.11 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.