[.net] Positioning objects

Started by
2 comments, last by DrGUI 18 years, 7 months ago
My little pet project is a Managed DirectX 9-based engine. I'm quite the newbie when it comes to dealing with DirectX directly; this is one of those cases that must have an obvious answer. Let's say I have a model that is rendered like so:
int modelPositionX, modelPositionY, modelPositionZ;
...
device.Transform.World = Matrix.Translation(modelPositionX, modelPositionY, modelPositionZ);
Now, let's say I apply a Matrix.RotationAxis to the Matrix.Translation. If I were to do that, how would I now retrieve the new "position" of the camera? Since the RotationAxis may change exactly where the model is drawn (changing its "position" in 3d space), how would I determine where the new position of the model is? Or, as a newbie, am I approaching this in the wrong way?
------Tech, life, family, faith: Give me a visit.
Advertisement
ok that is quite easy.

Basically you Rotate your world axis with Matrix.RotationAxis and then multiply your translation matrix to that. like Below I exclueded params to keep it simple in look.
device.Transform.World = Matrix.RotationAxis(...) * Matrix.Translation(...);


You should also experiment with Multiplying the Translation matrix by the rotation matrix and see what happens becuase they have different results.

device.Transform.World = Matrix.Translation(...) * Matrix.RotationAxis(...);


As for finding out where the model is currently located. Maybe you should wrap up your model aka mesh or what not into a object where you can store the location of it.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
I think you misunderstand my problem. I know how to rotate my objects, as well as position them. My problem is, once I've rotated my object, how do I find its new position?

Take the following code for instance:

// Position my model and rotate it.int modelPositionX = 10, modelPositionY = 20, modelPositionZ = 30;device.Transform.World = Matrix.Translation(modelPositionX, modelPositionY, modelPositionZ) * Matrix.RotationAxis(...);// Now that I've positioned and rotated my model, how do I find out its new position?modelPositionX = ??????;modelPositionY = ??????;modelPositionZ = ??????;


I've the gut feeling I'm approaching this totally wrong. How do you all position your objects? How do you know where to draw them after rotating them about an external axis point?
------Tech, life, family, faith: Give me a visit.
Hi

I'm not quite sure what you're trying to do; usually objects are rotated and scaled first, which doesn't change their position, then they are translated.

If I've misunderstood you, you can get the translation from the matrix by using:
x = matrix.M41;
y = matrix.M42;
z = matrix.M43;

I'm 95% sure that's right; hope that helped solve your problem [smile]

This topic is closed to new replies.

Advertisement