Solved

Moving a mesh

Posted on 2003-11-04
5
823 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
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 63 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 62 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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