[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Moving a mesh

Posted on 2003-11-04
5
Medium Priority
?
828 Views
Last Modified: 2013-12-08
HI, I'm probably going to sound as thick as a TV weather girl asking this one.. but here goes.

I've loaded a mesh into memory and I am rendering it...

I have a rotation and a translation in place for the mesh, and this is fine.

However, when I translate then after rotate the mesh, it is still rotating about it's origin when it loaded (0,0,0) not the new object center... anyone know how I can reset the object center after my translation had taken place:

I create the object center upon loading the mesh, thusly:

hr = D3DXComputeBoundingSphere ( (D3DXVECTOR3*)pVertices, MeshSysMem->GetNumVertices(), D3DXGetFVFVertexSize (MeshSysMem->GetFVF()), &ObjectCenter, &ObjectRadius );

And my translation and rotation matrices are applied thusly:

D3DXMATRIX rot_matrix = Rotate (pitch,roll,yaw);
D3DXMATRIX trans_matrix = Translate (x, y, z);
d3d_device->SetTransform(D3DTS_WORLD, &( trans_matrix * rot_matrix ) );      

But I can not call the ComputeBoundingSphere as the matrices are applied in my render, and the vertices are not to be changed....

Any ideas?

(this question is so inspecific ain't it... sorry).
0
Comment
Question by:xelous
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Author Comment

by:xelous
ID: 9684043
I've worked this out.. I think...

But the points are up for grabs to anyone with a better solution than this one:

D3DXMatrixMultiply( &matWorld, &rot_matrix, &trans_matrix);
d3d_device->SetTransform(D3DTS_WORLD, &matWorld );            

This seems to do the rotation transform around the translation transform.... seems to... going to test it, but as it's half 3 in the morning I'm off to bed.
0
 

Accepted Solution

by:
F4Codec earned 189 total points
ID: 9747021
You've discovered that matrix maths is not commutative!

E.g., Mat1 * Mat2 is not the same as Mat2 * Mat1
If you have a rotation and translation matrix, you have to be careful how you combine them.
There is a left to right rule. The visible effects happen in a left to right order.

so RotationMatrix * TranslationMatrix
will rotate the object about the origin, then translate it to the given place.
However TranslationMatrix * RotationMatrx
will move the object to the given place, then rotate the whole thing around the origin.

In the first case, its like spining the thing around, then moving it somewhere, so it will be at that location pointing in a given direction.
In the second case, you move it there, then the its as though you spin the whole scene around the origin, so it will no longer be at the translated coordinates..

0
 

Assisted Solution

by:andreasrohde
andreasrohde earned 186 total points
ID: 9809284
Hello xelous,

i dont know if this fix your problem, i've done that for a little game i wrote.
to do a 90 degree rotation of my object i get the x,y,z positions from the
current matrix of the object. i think it's m11, m21 and m31 (its long ago).
then i rotate of the object and write back the save settings to
the modified matrix of the object.

its not math, but it works in my case.

by
Andreas

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question