Jump to content
  • Advertisement
Sign in to follow this  
Swamii

[.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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!