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.

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-&gt;w = float(cos_a);

this-&gt;x = float(sin_a * cos_lat * sin_long);
this-&gt;y = float(sin_a * sin_lat);
this-&gt;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 on other sites
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&gt;=-180 && longitude&lt;=0 ){				float longi=-(longitude+90);		float lati=-latitude;		if( latitude &lt;= 0){		this-&gt;x = float(longi/90);		this-&gt;y = float( lati / 180 );		this-&gt;z = float(1 - ( lati / 180 ) );		this-&gt;w = float(longi/90 * ( lati / 180 ) * 2 );		} else {			this-&gt;x = float(longi/90);			this-&gt;y = float( lati / 180 );			this-&gt;z = float(1 + ( lati / 180 ) );			this-&gt;w = float(longi/90 * ( lati / 180 ) * 2 );		}			}else{		float longi=(longitude-90);			float lati=-latitude;		if(longitude&lt;90){					this-&gt;x = float( 1 + ( longi / 180 ));			this-&gt;y = float( (longi/180) * (lati / 90)  ); 			this-&gt;z = float( longi / 180 );			this-&gt;w = float( ( lati / 90 ) * (1+longi/180 ) );		}else{			this-&gt;x = float( 1 - ( longi / 180 ));			this-&gt;y = float( (longi/180) * (lati / 90) );			this-&gt;z = float( longi / 180 );			this-&gt;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 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.

This topic is now closed to further replies.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 11
• 9
• 9
• 11
• Forum Statistics

• Total Topics
633700
• Total Posts
3013428
×

Important Information

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!