Solved

Moving a mesh

Posted on 2003-11-04
5
817 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now