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

Started by
12 comments, last by Dean1988 18 years, 8 months ago
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
I''m new,so take it easy.
Advertisement
Uhh... PI/10000 is going to give you a really small number. I'm guessing it is rotating, just not by a discernable amount.
Hi,

But it works great without the Translation.

Cheers,

Dean.
I''m new,so take it easy.
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.
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
I''m new,so take it easy.
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.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
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
I''m new,so take it easy.
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.
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
I''m new,so take it easy.
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

This topic is closed to new replies.

Advertisement