# [.net] Positioning objects

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
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]

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 21
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633383
• Total Posts
3011584
• ### Who's Online (See full list)

There are no registered users currently online

×