Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / [D3D] Matrix concatenation problem (with uniform scaling) Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Dexter

March 14, 2005, 01:18 AM

Hello there!

I've got a huge problem with matrix concatenation: as long as I dont scale my mesh it works nicely but, when I multiply by the scaling matrix, my rotations dont work anymore: rotating by 45 degrees on the Z axis makes go to a wrong position...

That's what i'm thinking about this: when I *JUST* rotate my mesh (when it is at 0,0,0) it seems to rotate about it's most lower vertex (at the origin) ... (ie: a mesh tree rotates about its wooden part ) and not about its *REAL* center. Maybe that's the problem...

But then, how to handle this case?

I tried by translating my mesh to the "logical center" and then rotating it. After this step i simply translate it back to the wanted position but.. just doesnt work.

Sorry for the dumb question, it would be great if someone would point me to any source that could help me out.

Thanks in advance.

dexter

 
Illco

March 14, 2005, 03:00 AM

There are two things important. First: in which order do you apply the transforms? It should be scale, rotate, translate. And second: how is the mesh defined i.e. how are the vertices positioned with respect to the object's local origin? If the vertices are not centered around (0,0,0) then rotation may not be what you expect. Maybe you can post the important parts of the code.

 
Dexter

March 14, 2005, 09:41 AM

Here we go. vCenter is object center computed manually... we dont have mesh center ALWAYS at 0,0,0...

[code]
// -> Let's translate to our origin first (object origin)
D3DXMatrixTranslation(&originMat, vCenter.x, vCenter.y, vCenter.z);

// -> Rotation...
D3DXMatrixRotationYawPitchRoll(&rotMat, m_vRotation.y, m_vRotation.x, m_vRotation.z);

// -> Scale it
D3DXMatrixScaling(&scaleMat, m_fScale, m_fScale, m_fScale);

// -> Final pos
D3DXMatrixTranslation(&transMat, m_vPos.x, m_vPos.y, m_vPos.z);

m_matState = originMat * scaleMat * rotMat * transMat;
[/code]

 
Illco

March 15, 2005, 03:55 AM

Ok. I'm not sure I spotthe problem, but maybe some tips. First, if an object is at (x,y,z) and you want it at the world origin then the translation should be over (-x,-y,-z). You might want to do that for the center, instead of moving the object further away. However, you also might want to try without any origin matrix; I'm not sure what you want it to do.

The YawPitchRoll matrix creation function must be used with care. I'm not sure where your rotation values come from, but note that the rotations this function takes in are in radians, not degrees. Moreover it might be problematic to rotate over anything not in [-pi, pi].

Then there is gimbal lock, which is a problem for any rotation defined as a sequence of rotations over the different axes. Look it up on google or in a book and you'll find some info.

 
Dexter

March 15, 2005, 02:02 PM

Well, doesnt work :|

I simply want my "tree" to rotate about its center, not about its base!

That's driving me crazy :| None has any idea about this?

 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.