Adding pitch and roll capability to Player/RTSUnit
by Hadi Aggoune · in Torque Game Engine · 08/19/2006 (4:59 am) · 1 replies
Hey everyone. I've been working in torque for a while but my knowledge of 3D graphics math at the moment is limited/rusty. I'm using the RTS Kit and the RTSUnits by default are set to the terrain height and can only rotate around the Z axis (yaw). I've managed to unlock movement in the Z direction (though this did mess up the green selection circle), but I'm stuck as to how to enable the thing to rotate around the X/Y axes. We're using setTransform to do this. RTSUnit uses Player's setTransform and setPosition methods. I found a resource that was incomplete and appears to be buggy/not completely work: http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7778
I wasn't able to get that to work. By default, the methods look like this:
void Player::setTransform(const MatrixF& mat)
{
// This method should never be called on the client.
// This currently converts all rotation in the mat into
// rotations around the z axis.
Point3F pos,vec;
mat.getColumn(1,&vec);
mat.getColumn(3,&pos);
Point3F rot(0,0,-mAtan(-vec.x,vec.y));
setPosition(pos,rot);
setMaskBits(MoveMask | NoWarpMask);
}
void Player::setPosition(const Point3F& pos,const Point3F& rot)
{
MatrixF mat;
if (isMounted()) {
// Use transform from mounted object
MatrixF nmat,zrot;
mMount.object->getMountTransform(mMount.node,&nmat);
zrot.set(EulerF(0, 0, rot.z));
mat.mul(nmat,zrot);
}
else {
mat.set(EulerF(0, 0, rot.z));
mat.setColumn(3,pos);
}
Parent::setTransform(mat);
mRot = rot;
}
At first I tried just calling Parent::setTransform in Player (Which calls the version in sceneObject) but when I did that I lost even my yaw functionality for some reason.
I tried messing with the line: Point3F rot(0,0,-mAtan(-vec.x,vec.y)) in setTransform and mat.set(EulerF(0, 0, rot.z)) in setPosition but was unsure of what really needed to be done here.
So my question is, does anyone know why passing up to the Parent::setTransform wouldn't work here? is there something somewhere else in either Player or RTSUnit that would prohibit this? and if that is the case, any ideas on how to alter Player's current setTransform to enable rotations around X and Y?
I see that all rotations are translated to be rotations around the Z axis, but if this were not the case...I'm not sure what this function would need to do other than call Parent::setTransform.
Any help or ideas are greatly appreciated and I'll be happy to share my final solution for this unit once I get it figured out.
I wasn't able to get that to work. By default, the methods look like this:
void Player::setTransform(const MatrixF& mat)
{
// This method should never be called on the client.
// This currently converts all rotation in the mat into
// rotations around the z axis.
Point3F pos,vec;
mat.getColumn(1,&vec);
mat.getColumn(3,&pos);
Point3F rot(0,0,-mAtan(-vec.x,vec.y));
setPosition(pos,rot);
setMaskBits(MoveMask | NoWarpMask);
}
void Player::setPosition(const Point3F& pos,const Point3F& rot)
{
MatrixF mat;
if (isMounted()) {
// Use transform from mounted object
MatrixF nmat,zrot;
mMount.object->getMountTransform(mMount.node,&nmat);
zrot.set(EulerF(0, 0, rot.z));
mat.mul(nmat,zrot);
}
else {
mat.set(EulerF(0, 0, rot.z));
mat.setColumn(3,pos);
}
Parent::setTransform(mat);
mRot = rot;
}
At first I tried just calling Parent::setTransform in Player (Which calls the version in sceneObject) but when I did that I lost even my yaw functionality for some reason.
I tried messing with the line: Point3F rot(0,0,-mAtan(-vec.x,vec.y)) in setTransform and mat.set(EulerF(0, 0, rot.z)) in setPosition but was unsure of what really needed to be done here.
So my question is, does anyone know why passing up to the Parent::setTransform wouldn't work here? is there something somewhere else in either Player or RTSUnit that would prohibit this? and if that is the case, any ideas on how to alter Player's current setTransform to enable rotations around X and Y?
I see that all rotations are translated to be rotations around the Z axis, but if this were not the case...I'm not sure what this function would need to do other than call Parent::setTransform.
Any help or ideas are greatly appreciated and I'll be happy to share my final solution for this unit once I get it figured out.
Torque Owner Hadi Aggoune
www.garagegames.com/index.php?sec=mg&mod=project&page=view.job&qid=5648
You will be paid. We'd love to hear from you.