Jump to content
  • Advertisement
Sign in to follow this  
budipro

Float precision problem not over

This topic is 4848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, This is the continuation from my post in http://www.gamedev.net/community/forums/topic.asp?topic_id=330097 After changing my function to convert from geo-coordinate into cartesian into this:
public static Vector3 GetCartesian(AirPoint p)
{
   Vector3 ret = new Vector3();

   double lat_rad = p.m_Lat * m_deg2rad;
   double rad = (m_eqRadius + p.m_Alt) * m_scale;
   double proj = rad * Math.Cos( lat_rad );
   double lon = (p.m_Lng - m_upperleftlon) * m_deg2rad;

   ret.X = (float)(rad * Math.Sin(-lat_rad));
   ret.Z = (float)(proj * Math.Sin(lon) - m_sclThreeQuarterRad);
   ret.Y = (float)(proj * Math.Cos(lon) - m_sclThreeQuarterRad);
		
   return ret;
}
My airplane can fly smoothly. But then I realize that this code works only in a certain area on earth (near the point specified by (0, m_sclThreeQuarterRad, m_sclThreeQuarterRad)). So I decided to change my reference coordinate based on the camera position, which is like this:
public static Vector3 GetCartesian(AirPoint p, VectorD translation)
{
   Vector3 ret = new Vector3();

   double lat_rad = p.m_Lat * m_deg2rad;
   double rad = (m_eqRadius + p.m_Alt) * m_scale;
   double proj = rad * Math.Cos( lat_rad );
   double lon = (p.m_Lng - m_upperleftlon) * m_deg2rad;

   ret.X = (float)(rad * Math.Sin(-lat_rad) + translation.X);
   ret.Z = (float)(proj * Math.Sin(lon) + translation.Z);
   ret.Y = (float)(proj * Math.Cos(lon) + translation.Y);
		
   return ret;
}
With the translation is obtained based on the camera position. Using this way, my airplane is vibrating again. I wonder why. Is there any other idea of changing the world reference coordinate? Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!