PDA

View Full Version : Where to apply scale for transformation matrix



Stuart McDonald
10-08-2009, 02:10 PM
Ok, my maths skills are now apparently zero...I have an "Orientation" class that maintain pos, up and face vectors. It provides the transformation matrix for my objects and has tiltLeft/right, lookUp/Down, etc. I wrote it years ago and haven't touched it since.

I now want to add a scale vector. So to the getTransformationMatrix method I added

Matrix4x4 mT

// The X column (0,1,2,3) is the crossProduct of the
// Up and Facing vectors i.e. the vector which is
// perpendicular to them (the X-axis)
Vector3 vxAxis = crossProduct( vUp, -vFace)
mT[0] = vxAxis[0] * vScale[0]
mT[1] = vxAxis[1]
mT[2] = vxAxis[2]
mT[3] = 0;

// The Y column (4,5,6,7) is the Up vector
mT[4] = vUp[0]
mT[5] = vUp[1] * vScale[1]
mT[6] = vUp[2]
mT[7] = 0;

// The Z column (8,9,10,11) is the Facing vector
mT[8] = vFace[0]
mT[9] = vFace[1]
mT[10] = vFace[2] * vScale[2]
mT[11] = 0

// The Location column (12,13,14,15) is the position
mT[12] = vPos[0]
mT[13] = vPos[1]
mT[14] = vPos[2]
mT[15] = 1;
I was only using this for objects drawn with no rotations (so vUp=0,1,0 and vFace=0,0,-1) and it all worked. The shapes were translated and scaled (these were 2D GUI shapes).

However I just rotated (tiltRight, again 2D GUI shape) an object and it all goes wrong (the shape rotates, but also sort of shrinks, grows, shinks, grows with a period of 90 degrees (so 0,180 it is normal, 90,270 is at it's smallest).

I guess I need to use vScale elsewhere or differently, but where? The other relevant parts are the Orientation tiltRight code that changes the vUp

Matrix4x4 mRot
mRot.loadRotation(degrees, vFace)
vUp.rotate(mRot)and Maxtrix4x4 loadRotation and Vector3 rotate code.

Sorry for a newbie question. Cheers,

Stuart.

Ilian Dinev
10-08-2009, 02:23 PM
You _must_ multiply with a 4x4 scaling-matrix. Here's what it looks like:
http://pyopengl.sourceforge.net/documentation/manual/glScale.3G.html

Stuart McDonald
10-09-2009, 12:17 AM
LOL! I actually thought that's what I'd done. Sheesh, my brain really is turning to mush. Well at least I've re-learned matrix multiplication, wonder how long before I forget again :)

Thanks.