Sign in to follow this  

Converting From Left to Righthanded

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

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 this post


Link to post
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 this post


Link to post
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
////opengl
void 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 direction
var 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
////opengl
void 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=direction
var 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.

Share this post


Link to post
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this