Anyone have a firm grasp on quats?
by Stephen Zepp · in RTS Starter Kit · 11/25/2004 (6:05 am) · 5 replies
I'm trying to add a bit of an interface change to placing the building--allowing the player to rotate the building about the z-axis prior to actual creation.
This is pretty easy in script, but gets a bit lower level in the code handling, which is where we need to do it, and I can't quite wrap my head around the actual C++ code needed to pull it off. Here's the algorithm:
--calculate angle of rotation based on mouse movement (this part is fine)
--startMat = buildingMarker->getTransform()
--apply the rotation to startMat
--apply the new transform to object: buildingMarker->setTransform(....)
it's the last two steps that I'm having trouble with. Anyone an expert at this stuff before I spend a couple more hours working on it?
This is pretty easy in script, but gets a bit lower level in the code handling, which is where we need to do it, and I can't quite wrap my head around the actual C++ code needed to pull it off. Here's the algorithm:
--calculate angle of rotation based on mouse movement (this part is fine)
--startMat = buildingMarker->getTransform()
--apply the rotation to startMat
--apply the new transform to object: buildingMarker->setTransform(....)
it's the last two steps that I'm having trouble with. Anyone an expert at this stuff before I spend a couple more hours working on it?
#2
For instance, exactly what does AngAxiF .setMatrix do? I finally got it to compile at least, checkin it now--if it works cool, if not, I'll probably be back for more discussion ;)
EDIT: I know I really need to get a book on quats and understand it all, but right now I just want this building to rotate, hehe.
11/25/2004 (6:52 am)
Yeah, that's the direction I'm heading right now--the problem is my lack of knowledge about mixing together the old mat, the AngAxisF, and the new mat. For instance, exactly what does AngAxiF .setMatrix do? I finally got it to compile at least, checkin it now--if it works cool, if not, I'll probably be back for more discussion ;)
EDIT: I know I really need to get a book on quats and understand it all, but right now I just want this building to rotate, hehe.
#3
11/25/2004 (7:05 am)
Ugly, but it works:Point3F pos; const MatrixF& tmat = ((ShapeBase*)mNewBuilding)->getTransform(); tmat.getColumn(3,&pos); AngAxisF aa(tmat); aa.axis.x = 0.f; aa.axis.y = 0.f; aa.axis.z = 1.f; aa.angle = pRotDegrees; MatrixF mat; aa.setMatrix(&mat); mat.setColumn(3,pos); ((ShapeBase*)mNewBuilding)->setTransform(mat);
#4
Here's a gameDev.net article that gives a run down on the rotation schemes:
www.gamedev.net/reference/articles/article1095.asp
11/25/2004 (2:45 pm)
I don't think the rotation system provided to torque script is actually quaternian, I do believe that the AngleAxisF is a different bugger. In any case the xyz describes an arbitrary axis of rotation and A is the rotation amount around that axis. What is interesting is that torque converts the angleAxisF to a quat in order to set the matrix to the quat rotation.Here's a gameDev.net article that gives a run down on the rotation schemes:
www.gamedev.net/reference/articles/article1095.asp
#5
As it turns out, I was able to get it working for my purposes (see my post above). It needs some work (Mostly coordinating the building marker's interaction with the terrain with the actual building's interaction with the terrain, as slightly slanted terrain causes the building to be rotated slightly but NOT the marker), but for tier 1 imp I'm happy with it!
11/25/2004 (2:50 pm)
Well, from the research I did today (which was mediocre, basically grabbing different styles from the codebase itself and seeing what worked, it appears that the rotation schemes have evolved in TGE--you see manual calcuations, Euler rots and then full quat rots, and, as you noted, conversion back and forth between many of the options.As it turns out, I was able to get it working for my purposes (see my post above). It needs some work (Mostly coordinating the building marker's interaction with the terrain with the actual building's interaction with the terrain, as slightly slanted terrain causes the building to be rotated slightly but NOT the marker), but for tier 1 imp I'm happy with it!
Torque 3D Owner Martin "Founder" Hoover
AngAxisF.setMatrix(&newMatrix);
startMat.mul(newMatrix);
I would guess that you would want to set it to a new matrix then multiply them together.