Skip to main content
GameDev.net gamedev.net
🔒 Locked

Converting From Left to Righthanded

Started by wioneo Aug 31, 2010 at 11:25 PM 1 replies 1.1k views
Original Post
wioneo
wioneo
I managed to get this function working with a left handed coordinate system, but I am having trouble converting to the default OpenGL system. This function is meant to increment the passed variables based on the passed rotation angles and length offset.
'lengthdir(x,y,z, 10, 0,90,90);'
Assuming an original position of (0,0,0), the new position should be (0,10,0) after the above call.
void lengthdir(float &x,float &y,float &z, float length,float xdir,float ydir,float zdir)//3 angles{	float sinx=sin(d2r*xdir), cosx=cos(d2r*xdir);	float siny=sin(d2r*ydir), cosy=cos(d2r*ydir);	float sinz=sin(d2r*zdir), cosz=cos(d2r*zdir);	float X,Y,Z;	//Xoffset	X=Y=Z=0;	Y=-length*sinx;	Z=length*cosx;	X=Z*siny;	x+=X*cosz-Y*sinz;	//Yoffset	X=Y=Z=0;	Y=-length*sinx;	Z=length*cosx;	X=Z*siny;	y+=Y*cosz+(X*sinz);	//Zoffset	X=Y=Z=0;	z+=length*cosx*cosy;}

There are a few unnecessary/redundant bits, but I like to keep everything obvious until I have it working properly.

As it stands, all 'ydir' values work as expected while 'zdir' is equal to zero, but any change causes problems. I have not tested 'xdir' yet, and inversing the y output did not work.

Any help or advice on this issue would be greatly appreciated.
Zakwayda
Zakwayda
I'm not completely sure what that function is supposed to do, but generally, you don't need to modify geometric functions of this sort based on handedness. The result of a geometric operation such as this one may appear to be inverted if you switch handedness, but the underlying math isn't dependent on handedness and typically shouldn't change.

In any case, OpenGL doesn't have a 'default' handedness; you can set it up to be either left- or right-handed, as you prefer. As such, the most straightforward solution might be simply to stick with a left-handed coordinate system.
wioneo
wioneo
An example use of the function would be calculating the coord offsets of a wrist from an elbow given the length of the forearm and 3 rotational values(very flexible person).

Here are a few examples of how the different versions of similar functions work under the 2 systems...
//////2 angles////openglvoid lengthdir(float &x,float &y,float &z, float length,float hdirection,float vdirection){	float sinv=sin(d2r*vdirection);	x=x+ sinv* cos(d2r*hdirection) *length;	y=y+ sinv* sin(d2r*hdirection) *length;	z=z+ cos(d2r*vdirection) *length;}////gm//arg0=length, arg1=horizontal direction, arg2=vertical directionvar ilen, ihang, ivang;ilen=argument0;ihang=argument1-90;ivang=argument2;X=cos(d2r*ihang)*ilen * cos(d2r*ivang);Y=-sin(d2r*ihang)*ilen * cos(d2r*ivang);Z=-sin(d2r*ivang)*ilen//////1 angle////openglvoid lengthdir(float &x,float &y, float length,float direction)//1 angle{	x=x+(cos(d2r*direction)*length);	y=y+(sin(d2r*direction)*length);	return;}////gm//arg0=length, arg1=directionvar ilen, iang;ilen=argument0;iang=argument1-90;X=cos(d2r*ihang)*ilen;Y=-sin(d2r*ihang)*ilen


As you can see, increasing the number of rotations compounds the differences, and I've just been guessing/checking up to this point. I was hoping that someone knew how to do this properly to save time, but eventually random testing will hopefully work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.