Solved

Moving a mesh

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Ruby, Python, Perl, nodeJS, JavaScript, AJAX, Jscript 2 223
Is an Indie RTS practical? 7 129
RTS client unit selections are stored best where? 1 120
Unity 3D Lighting 1 87
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…
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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