Flying Vehicle pitch problem
by Gotland_0001 · in Torque Game Engine · 05/29/2006 (3:35 pm) · 4 replies
I am sitting and reewriting "flyingvehicle.cc", updateForces() function and I have encounterd a problem and I am not getting any brighter so I was hoping someone else can explain this.
What I want to do is to manipulate the players pitch (x-axis rotation) and I have a almost identical code for the Z-axis rotation and it works great.
The problem is that the x-axis is spitting out a lot of strange angles that make no sense at all.
Here is the code...
"m3F_" or "t3F" is the same as a Point3F variable.
"mF32" or "tF32" is F32 variables.
Please help me if you can... I really need to get this finished as soon as possible.
What I want to do is to manipulate the players pitch (x-axis rotation) and I have a almost identical code for the Z-axis rotation and it works great.
The problem is that the x-axis is spitting out a lot of strange angles that make no sense at all.
Here is the code...
"m3F_" or "t3F" is the same as a Point3F variable.
"mF32" or "tF32" is F32 variables.
// Flattening X-axis ===============================
t3F_VerticalPlayerPosition = currPosMat.getPosition();
t3F_VerticalPlayerPosition.x = 0;
t3F_VerticalForwardVector = yv;
//t3F_VerticalForwardVector.x = 0;
//t3F_VerticalForwardVector.normalize();
t3F_VerticalObjectPosition = m3f_towardPosition;
t3F_VerticalObjectPosition.x = 0;
// Subtract the distances ==========================
t3F_VerticalSubtraction = ( t3F_VerticalObjectPosition - t3F_VerticalPlayerPosition );
t3F_VerticalSubtraction.normalize();
// Dot Product of the 2 vectors =====================
tF32_VerticalDotProduct = mDot( t3F_VerticalForwardVector, t3F_VerticalSubtraction );
//Just makes a angle out of it! ===================== TEMPORARY
tF32_VerticalAngle = mRadToDeg(mAcos(tF32_VerticalDotProduct));
// Cross Product ==================================== what side?
t3F_VerticalCrossProduct = mCross( t3F_VerticalForwardVector, t3F_VerticalSubtraction );
if(t3F_VerticalCrossProduct.x < 0)
{
tF32_VerticalAngle = -tF32_VerticalAngle;
}The actual manipulation follows but I know that stuff is working... the bug is somewhere above or something in Torque that I do not know about.Please help me if you can... I really need to get this finished as soon as possible.
#2
I'm also having fun in this class at the moment.
yv is definately correct? Where is it coming from?
05/30/2006 (5:07 am)
Hmmm.I'm also having fun in this class at the moment.
yv is definately correct? Where is it coming from?
#3
I got how to get the YV or ForwardVector from... I think it was how the script gets it from the code.
Well, dug it up from some obscure corner in the code and I think it should be ok.
It is just strange... I have manipulated and hacked this code a lot since I posted it and I can't help to always be a bit annoyed at how the Z-axis influence the angle of the X-axis when I run the EXE.
I noticed that my Z-axis rotation that runs the same code and works also have the same problem but there it is the Roll rotation that influences the rotation... have to figure out how to lock it out somehow.
Still... this little change actually improved the situation a little bit... now I seem to get the correct angles when my players y-axis and the objects y-axis align.
I am asking myself if the trick is to set up your own little forward vector with certain values in it.
05/30/2006 (6:41 am)
Ah, YV is the forward vector from the mRidig.getTransform... bla bla... better to just show the code.MatrixF currPosMat; mRigid.getTransform(&currPosMat); ... Point3F xv,yv,zv; currPosMat.getColumn(1,&yv); //YV is the forward Vector
I got how to get the YV or ForwardVector from... I think it was how the script gets it from the code.
Well, dug it up from some obscure corner in the code and I think it should be ok.
It is just strange... I have manipulated and hacked this code a lot since I posted it and I can't help to always be a bit annoyed at how the Z-axis influence the angle of the X-axis when I run the EXE.
I noticed that my Z-axis rotation that runs the same code and works also have the same problem but there it is the Roll rotation that influences the rotation... have to figure out how to lock it out somehow.
t3F_VerticalForwardVector = yv; t3F_VerticalForwardVector.x = 0; t3F_VerticalForwardVector.y = -1;
Still... this little change actually improved the situation a little bit... now I seem to get the correct angles when my players y-axis and the objects y-axis align.
I am asking myself if the trick is to set up your own little forward vector with certain values in it.
#4
05/30/2006 (11:00 am)
Arrgh... no results... what is wrong... man... looks like another sleepless night again =/
Torque Owner Gotland_0001