# Converting From Left to Righthanded

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

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

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

• Total Topics
633709
• Total Posts
3013481
×