I want to get a quaternion from the latitude and longitude. could any one hell me how to construct the quaternion?
the coordinate frame details:
void latlon_to_xyz(const double lat, const double lon, double &x, double &y, double &z)
{
double theta = 2*pi*(lon + 180.0)/360.0;
double phi = pi*(lat + 90.0)/180.0;
x = -(cos(theta)*sin(phi));
z = -(sin(theta)*sin(phi));
y = -cos(phi);
}
void xyz_to_latlon(const double x, const double y, const double z, double &lat, double &lon)
{
double theta = pi + atan2(z, x);
double phi = acos(-y);
lat = phi/pi*180.0 - 90.0;
lon = theta/(2*pi)*360.0 - 180.0;
}
InputSystem input;
Frustum camera; // preinitialized to initial position and orientation.
void MoveCamera(float dt)
{
float2 spherical = camera.front.ToSphericalCoordinatesNormalized();
if (input.IsKeyDown(Left)) spherical.x -= dt;
if (input.IsKeyDown(Right)) spherical.x += dt;
if (input.IsKeyDown(Up)) spherical.y -= dt;
if (input.IsKeyDown(Down)) spherical.y += dt;
camera.front = float3::FromSphericalCoordinates(spherical.x, spherical.y);
camera.up = float3::unitY;
float3::Orthonormalize(camera.front, camera.up);
// If I wanted a quaternion out of the camera transform, I'd do the following:
Quat q = camera.WorldMatrix().Float3x3Part().ToQuat();
}