Jump to content
  • Advertisement
Sign in to follow this  
cbastien

OpenGL quaternion "SpheriqueToQuat"

This topic is 4229 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

Hello everybody ! I'm drawing a sphere in C++/opengl using quaternion to turn around it. But i have difficulties to implement a correct function to transform sperical coordinate (latitude,longitude) to a quaternion First, i do not understand why i need an angle to convert latitude and longitude to a quaternion ( i thought it only was for the up vector ) I used the quaternion faq to make my function
void Quaternion::SpheriqueToQuat(const float latitude, const float longitude, const float angle)
{

double sin_a = sin(angle / 2);
double cos_a = cos(angle / 2);

double sin_lat = sin(latitude);
double cos_lat = cos(latitude);

double sin_long = sin(longitude);
double cos_long = cos(longitude);


this->w = float(cos_a);

this->x = float(sin_a * cos_lat * sin_long);
this->y = float(sin_a * sin_lat);
this->z = float(sin_a * sin_lat * cos_long);

Normalize();

return;
}


The result is really bad : If i put the angle value to 1, latitude to 0 and i increase the longitude with a timer, the resulting movement draw a eight on my sphere instead of turning around the equator.

Thanks in advance for any advice. Sébastien. [Edited by - cbastien on May 16, 2007 4:28:27 AM]

Share this post


Link to post
Share on other sites
Advertisement
here a temporary version i made, it is not really accurate but it works !



void Quaternion::SpheriqueToQuat(const float latitude, const float longitude, const float angle)
{

//this is a temporary version // do NOT work Accurately
if( longitude>=-180 && longitude<=0 ){

float longi=-(longitude+90);
float lati=-latitude;

if( latitude <= 0){
this->x = float(longi/90);
this->y = float( lati / 180 );
this->z = float(1 - ( lati / 180 ) );
this->w = float(longi/90 * ( lati / 180 ) * 2 );
} else {
this->x = float(longi/90);
this->y = float( lati / 180 );
this->z = float(1 + ( lati / 180 ) );
this->w = float(longi/90 * ( lati / 180 ) * 2 );
}
}else{
float longi=(longitude-90);
float lati=-latitude;

if(longitude<90){
this->x = float( 1 + ( longi / 180 ));
this->y = float( (longi/180) * (lati / 90) );
this->z = float( longi / 180 );
this->w = float( ( lati / 90 ) * (1+longi/180 ) );
}else{
this->x = float( 1 - ( longi / 180 ));
this->y = float( (longi/180) * (lati / 90) );
this->z = float( longi / 180 );
this->w = float( ( lati / 90 ) * (1-longi/180 ) );
}
}
}



any advice to help me in a better way to do that ?

[Edited by - cbastien on May 16, 2007 4:41:09 AM]

Share this post


Link to post
Share on other sites

This topic is 4229 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!