Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi guys I'm a begginer in DirectX and now I'm writing a small 3D demo app where you have an object and the goal is to rotate this object around X and Y axes with the mouse, this is my code:

VB
device.Transform.World = Matrix.RotationY(0 - _
(Control.MousePosition.X / int3DSpeed))'rotate around Y
device.Transform.World = Matrix.RotationX(0 - _
(Control.MousePosition.Y / int3DSpeed))'rotate around X



The problem is that VB is executing only the first assignment:
VB
device.Transform.World = Matrix.RotationY(0 - _
(Control.MousePosition.X / int3DSpeed))'rotate around Y

and the second one:
VB
device.Transform.World = Matrix.RotationX(0 - _
(Control.MousePosition.Y / int3DSpeed))'rotate around X

is always ignored.

What is wrong with my code, how can I rotate the object on X and Y axes simultaneously?
Posted
Updated 26-Nov-11 10:51am
v2
Comments
LanFanNinja 26-Nov-11 19:42pm    
Check solution below

Let me explain this obvious thing about what happens: you assign two different values to the same object device.Transform.World, one value in first statement, another value in second statement. In this way, only the second statement has effect, the result of first one is lost.

I have no idea why do you feel that the second statement is ignored. In fact, "ignored" is the first one, more exactly, has no effect. I think you just misinterpreted the result of rotation. Remove first statement and check it up.

Nothing is ignored, which you can easily see by running this code fragment under debugger. Please always run you code in question under debugger before making any statements and asking questions.

As to combined transform, it is obtained via matrix multiplication.

—SA
 
Share this answer
 
Try this

VB
device.Transform.World = Matrix.Multiply(Matrix.RotationY(0 - (Control.MousePosition.X / int3DSpeed)), Matrix.RotationX(0 - (Control.MousePosition.Y / int3DSpeed)))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900