Going between coord systems

Started by
2 comments, last by alvaro 10 years, 2 months ago

I'm using a left handed coordinate system,but,the physics engine I'm using uses a right handed coordinate system. By now,you probably know where I'm going.

I thought that if I always pass my coords unchanged,and convert the ones I get from the physics engine to a left handed sys,there would be no problem,yet there is.

For example:

When I try to create a displacement vector like: get x position from physics engine - old_x position from my engine I just get the right movement,but inversed(moving left will actually get you to right)

So I thought,wouldn't inversing the Z coord I get from the physics engine work? No,It doesn't. Would inversing all the coords I get from the physics engine work? No,Would creating the displacement vector normally(the one that moves inversed),and then just inversing the vector work? NO!

Some ideeas?

Advertisement

There exists several left-handed or right-handed coordinate system. How your coordinate systems are defined?

A general approach for that sort of thing is to create a transform (using 4x4 matrix) to transform one coord system to another. Then use M * (do physics stuff) * M-1

For instance:

Matrix M = transform-from-your-left-hand-to-physics-right-hand;

Matrix InvM = Inverse( M );

Vector physVec = localVec * M;

(do physics engine stuff with physVec)

localVec = physVec * InvM;

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

It is also possible to use the C++ type system to help you. Define a vector type you use for your game and a different one you use to interface with the Physics system. You can provide conversion functions between them, which do the matrix multiplications that Buckeye described. That way you won't forget a conversion somewhere, because your compiler won't let you.

This topic is closed to new replies.

Advertisement