Getting an inconsistancy with mRadToDeg
by Wesley Hopson · in Technical Issues · 09/30/2008 (9:27 pm) · 2 replies
I am getting some wierd numbers out of mDegToRad function which while not horribly off is causing me to end up with values 1 or 2 degrees off what they should be.
really was not clear exactly where to post this it mentions the RTS kit some but only because it was what i was working on the real problem is the mDegToRad function
code i am running it in is two key bindings i setup for the RTS camera that i wanted to control the yaw and pitch with the mouse.
function updateViewPitch(%val)
{
echo("Pitch = " @ %Val);
if ($cursorschroll == 1)
{
Echo("------------------------");
%Angle = $RTSCamera.GetPitchAngle() + -1 * %val * ($cameraFov / 90) * 0.02 * $cameraYawSpeed;
$RTSCamera.SetPitchAngle(%Angle);
Echo("we want set Pitch to " @ %Angle);
Echo("Pitch Angle = " @ $RTSCamera.GetPitchAngle());
Echo("Pitch Rad = " @ mDegToRad(%Angle));
Echo("Converted Pitch = " @ mDegToRad(mRadToDeg(%Angle)));
Echo("------------------------");
}
}
function updateViewYaw(%val)
{
if ($cursorschroll == 1)
{
Echo("------------------------");
%Angle = $RTSCamera.GetYawAngle() + -1 * %val * ($cameraFov / 90) * 0.02 * $cameraYawSpeed;
$RTSCamera.setYawAngle(%Angle);
Echo("we want to set Yaw to " @ %Angle);
Echo("Yaw Angle = " @ $RTSCamera.GetYawAngle());
Echo("Yaw Rad = " @ mDegToRad(%Angle));
Echo("Converted Yaw = " @ mDegToRad(mRadToDeg(%Angle)));
Echo("------------------------");
}
}
I noticed it works fairly well but seems a bit jerky at times in certain places so i went to investigate. I noticed that the SetYaw and pitch functions converted my deg to Radians to calculate with then converted it back to degrees with the get functions. My first instinct was to see if thier was a round off error causing my problems after all you can only approx pi so long so then i woulda just had to increase the size of the variable the radian values were being put in. What i found was a bit more than a simple round off issue. So of the values i was getting from mRadToDeg in some places the result is just wrong.
Small section of my console report for the above code:
Pitch = -8
------------------------
we want set Pitch to 42
Pitch Angle = 50
Pitch Rad = 0.872665
Converted Pitch = 50
------------------------
------------------------
we want to set Yaw to 24
Yaw Angle = 24
Yaw Rad = 0.418879
Converted Yaw = 24
------------------------
Pitch = -9
------------------------
we want set Pitch to 32
Pitch Angle = 41
Pitch Rad = 0.715585
Converted Pitch = 41.0001
------------------------
Pitch = -1
------------------------
we want set Pitch to 39
Pitch Angle = 40
Pitch Rad = 0.698132
Converted Pitch = 40
------------------------
Now taking my calculator for say this one
we want set Pitch to 42
Pitch Angle = 50
Pitch Rad = 0.872665
Converted Pitch = 50
I can tell you that 42 * (pi / 180) should be 0.733038 not 0.872665
I checked the Math section of code and found
inline F32 mDegToRad(F32 d)
{
return((d * M_PI_F) / 180.0f);
}
inline F32 mRadToDeg(F32 r)
{
return((r * 180.0f) / M_PI_F);
}
inline F64 mDegToRad(F64 d)
{
return (d * M_PI) / 180.0;
}
inline F64 mRadToDeg(F64 r)
{
return (r * 180.0) / M_PI;
}
These seem to be correct to me. My best guess is thier is some problem with the M_PI_F or M_PI value being used.
Any idea why it is doing what it is doing or at the least some idea for how to correct for this or work around it would be greatly helpful.
really was not clear exactly where to post this it mentions the RTS kit some but only because it was what i was working on the real problem is the mDegToRad function
code i am running it in is two key bindings i setup for the RTS camera that i wanted to control the yaw and pitch with the mouse.
function updateViewPitch(%val)
{
echo("Pitch = " @ %Val);
if ($cursorschroll == 1)
{
Echo("------------------------");
%Angle = $RTSCamera.GetPitchAngle() + -1 * %val * ($cameraFov / 90) * 0.02 * $cameraYawSpeed;
$RTSCamera.SetPitchAngle(%Angle);
Echo("we want set Pitch to " @ %Angle);
Echo("Pitch Angle = " @ $RTSCamera.GetPitchAngle());
Echo("Pitch Rad = " @ mDegToRad(%Angle));
Echo("Converted Pitch = " @ mDegToRad(mRadToDeg(%Angle)));
Echo("------------------------");
}
}
function updateViewYaw(%val)
{
if ($cursorschroll == 1)
{
Echo("------------------------");
%Angle = $RTSCamera.GetYawAngle() + -1 * %val * ($cameraFov / 90) * 0.02 * $cameraYawSpeed;
$RTSCamera.setYawAngle(%Angle);
Echo("we want to set Yaw to " @ %Angle);
Echo("Yaw Angle = " @ $RTSCamera.GetYawAngle());
Echo("Yaw Rad = " @ mDegToRad(%Angle));
Echo("Converted Yaw = " @ mDegToRad(mRadToDeg(%Angle)));
Echo("------------------------");
}
}
I noticed it works fairly well but seems a bit jerky at times in certain places so i went to investigate. I noticed that the SetYaw and pitch functions converted my deg to Radians to calculate with then converted it back to degrees with the get functions. My first instinct was to see if thier was a round off error causing my problems after all you can only approx pi so long so then i woulda just had to increase the size of the variable the radian values were being put in. What i found was a bit more than a simple round off issue. So of the values i was getting from mRadToDeg in some places the result is just wrong.
Small section of my console report for the above code:
Pitch = -8
------------------------
we want set Pitch to 42
Pitch Angle = 50
Pitch Rad = 0.872665
Converted Pitch = 50
------------------------
------------------------
we want to set Yaw to 24
Yaw Angle = 24
Yaw Rad = 0.418879
Converted Yaw = 24
------------------------
Pitch = -9
------------------------
we want set Pitch to 32
Pitch Angle = 41
Pitch Rad = 0.715585
Converted Pitch = 41.0001
------------------------
Pitch = -1
------------------------
we want set Pitch to 39
Pitch Angle = 40
Pitch Rad = 0.698132
Converted Pitch = 40
------------------------
Now taking my calculator for say this one
we want set Pitch to 42
Pitch Angle = 50
Pitch Rad = 0.872665
Converted Pitch = 50
I can tell you that 42 * (pi / 180) should be 0.733038 not 0.872665
I checked the Math section of code and found
inline F32 mDegToRad(F32 d)
{
return((d * M_PI_F) / 180.0f);
}
inline F32 mRadToDeg(F32 r)
{
return((r * 180.0f) / M_PI_F);
}
inline F64 mDegToRad(F64 d)
{
return (d * M_PI) / 180.0;
}
inline F64 mRadToDeg(F64 r)
{
return (r * 180.0) / M_PI;
}
These seem to be correct to me. My best guess is thier is some problem with the M_PI_F or M_PI value being used.
Any idea why it is doing what it is doing or at the least some idea for how to correct for this or work around it would be greatly helpful.
About the author
#2
Anyway your right this probably should be moved to the private forums i really kinda thought this was in that section already but anyhow i reposted my topic here:
http://www.garagegames.com/mg/forums/result.thread.php?qt=79606
09/30/2008 (11:30 pm)
Ah Thanks i suppose that would make some since. Annoying thing is I am not really sure exactly how information is passed between script and the C++ code. It is somthing i would really like to understand. I have looked at the console methods in the .cc files and looked up the console method on the SDK documentation but i really do not understand certain things about it. (which my questions about it should probably not be discussed in the open forums i am guessing)Anyway your right this probably should be moved to the private forums i really kinda thought this was in that section already but anyhow i reposted my topic here:
http://www.garagegames.com/mg/forums/result.thread.php?qt=79606
Associate Tom Spilman
Sickhead Games
And you probably should move this to the TGE private forums if you get any further into the C++ code.