# Vb.net - Dx9 - Translation + Rotation with Meshes problem.

## Recommended Posts

Dean1988    130
hi guys I've recently, the last day or two go into Dx9 with VB.NET (due to job) And i have a problem...possibly. basically, i'm rendering 2 meshes, and i want one to turn on an axis while the other turns on another axis. If i do this

dxClass.dxDevice.Transform.World = Matrix.Translation(-40, 0, 0)
dxMesh1.RenderMesh()

dxClass.dxDevice.Transform.World = Matrix.Translation(40, 0, 0)
dxMesh2.RenderMesh()


Then they both render at different points as i expected. However, if i try this...
'New Line Here!
dxClass.dxDevice.Transform.World = Matrix.Multiply(dxClass.dxDevice.Transform.World, Matrix.RotationYawPitchRoll(Math.PI / 10000, Math.PI / 10000, Math.PI / 10000))
dxClass.dxDevice.Transform.World = Matrix.Translation(-40, 0, 0)
dxMesh1.RenderMesh()

dxClass.dxDevice.Transform.World = Matrix.Translation(40, 0, 0)
dxMesh2.RenderMesh()

The first Mesh doesn't Rotate at all, it just sits there. Now, im sure it does that due to the Translation of me playing it a x:-40, however, how am i supposed to place an object off-center and get it rotating, there obviously has to be a way. I'm not asking for direct code, as that way i wouldn't learn as well, but if possible pointers to the right pages etc. Cheers, Dean

##### Share on other sites
Mushu    1396
Uhh... PI/10000 is going to give you a really small number. I'm guessing it is rotating, just not by a discernable amount.

##### Share on other sites
Dean1988    130
Hi,

But it works great without the Translation.

Cheers,

Dean.

##### Share on other sites
Mushu    1396
I'd assume then that your RawPitchRoll transform is being undone (overwritten) by the translation. Try multiplying in the translation matrix instead of just setting it.

##### Share on other sites
Dean1988    130
Okay,
so i tried this

            dxClass.dxDevice.Transform.World = Matrix.Multiply(dxClass.dxDevice.Transform.World, Matrix.RotationYawPitchRoll(Math.PI / 10000, Math.PI / 10000, Math.PI / 10000))            dxClass.dxDevice.Transform.World = Matrix.Multiply(dxClass.dxDevice.Transform.World, Matrix.Translation(-10, 0, 0))            dxMesh1.RenderMesh()

And, i suppose as you would expect, it flies off the screen, as the X value is being multiplied every time it renders...

Cheers though mate...

Dean

##### Share on other sites
Sr_Guapo    876
You are overwriting the world matrix every time you set the translation. Try to instead multiply the rotaion matrix by the translation (rotate on the left). That will rotate and translate the mesh every frame.

##### Share on other sites
Dean1988    130
Hi

so i tried this.

            dxClass.dxDevice.Transform.World = Matrix.Multiply(Matrix.RotationX(100), Matrix.Translation(-10, 0, 0))              dxMesh1.RenderMesh()

And it's very nearly there, it just set's the rotation the same every time, i chose 100, and it just sits there, which i guess is fair enough.

I assume i neeed to use a variable that i increment every loop?

Cheers,

Dean

##### Share on other sites
Mushu    1396
Its flying off the screen because each pass is cumulative - you'll need to undo the changes you've made to the matrix otherwise they'll keep adding up.

I'm no MDX guru (go unmanaged!) but I'm guessing the call is

Matrix.Identity();

or something similar.

##### Share on other sites
Dean1988    130
Calling

Matrix.Identity to the World just stops ALL rotation, so either im not using it right ( which is probably the case ) or it's not doing what we expect it to do.

And btw, i do intend to move it over to C++ in the end, i only use VB at work, i'm a C++ Programmer outside of work :)

Cheers,

Dean

##### Share on other sites
Mushu    1396
arrr!

dxClass.dxDevice.Transform.World = Matrix.Identity()dxClass.dxDevice.Transform.World = Matrix.Multiply(Matrix.RotationX(100), Matrix.Translation(-10, 0, 0))  dxMesh1.RenderMesh()

^ does that work?

MDX in C++ is, essentially the same as in VB, minus all the language differences [wink] its the same library afaik

##### Share on other sites
Sr_Guapo    876
Quote:
 Original post by Mushuarrr!*** Source Snippet Removed ***^ does that work?MDX in C++ is, essentially the same as in VB, minus all the language differences [wink] its the same library afaik

That should work, but you will have to keep track of the total angle (not the change in the angle).

Yes, MDX will work in c++ but what is the point. Unmanaged isn't too difficult to learn (for me anyways). If you are pretty comfortable in c++ and understand the basics of DX, you should do fine in unmanaged. Really, my only gripes are how it is less organized than managed and how there is no "autocomplete" for the 2^43 different constants.

##### Share on other sites
Dean1988    130
Okay

1) I meant unmanaged :P I just never really have a need to call it unmanaged hehe.

2) That code still keeps it stationary, it's really weird...

I don't understand when you say keep track of it?

Cheers.

Dean.

##### Share on other sites
Mushu    1396
By keep track of the angle, he means store the angle in a variable or something.
// render a mesh at x,y,z rotated by r degrees on the y-axisdxClass.dxDevice.Transform.World = Matrix.Identity()dxClass.dxDevice.Transform.World = Matrix.Multiply(Matrix.RotationY(r*PI/180), Matrix.Translation(x, y, z))  dxMesh1.RenderMesh()// becasuse Matrix.Identity() undos all the previous transforms// you can't rely on it to actually "rotate" anything (ie,// spin). You have to incriment a variable and rotate the object// a little more each pass (ie, increasing r in the above code)

If the code I pasted before (which is essentially the same as above) doesn't work, then we're going to need to see more code. Because (assuming all the MDX functions are right) it does work.

Blah, I'm off to bed (getting late over here :X) Sorry I couldn't be of more help.

##### Share on other sites
Dean1988    130
I thought so :)

I just didn't want to try it, and make myself look even more like a tit :P

Cheers guys, it's working great now.

Dean.