Solved

Moving a mesh

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
3d letters for 3d font rendering 7 996
Network game - UDP safety concerns? 10 264
factorial example challenge 10 90
count8 challlenge 13 116
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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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

12 Experts available now in Live!

Get 1:1 Help Now