Jump to content
  • Advertisement
Sign in to follow this  
tiburon

OpenGL left-handed to right-handed conversion

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

Hi all, Newbie question. If the underlying graphics API is OpenGL but I import .X models, is it possible to not convert the left-handed coord to right-handed coord as long as everything is consistent. The model should look the same right, just flipped correct? But would the animation keys be incorrect? p.s. I do transpose the matrices, but I have not negated the axis nor changed the winding order. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
IIRC, you need to do 3 things:
1) Transpose the matrices
2) Negate the Z axis
3) Reverse windings

#3 can be avoided simply by changingwhat GL considers to be the front face. Sure, it's slightly hackish, but it's the easiest solution. The other two are fairly important though, because otherwise your transformations are going to be all messed up (non normalized vectors and all sorts of badness).

Share this post


Link to post
Share on other sites
thanks a lot for the reply Promit.

I've done all those things now, but even without the animation data, I cannot seem to get the model to display correctly. Should I negate the z values in the transfromation matrices also?

Share this post


Link to post
Share on other sites
There is an easy way to convert right handed to left handed in direct3d:
Create a matrix like this:
1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 1

Then D3DXVec3TRansformCorrd() and you get your new vector.
You can also use this matrix to convert matrices (joints,bones,camera).

Share this post


Link to post
Share on other sites
Transpose the matrices? Why?

Switching between left-handed and right-handed involves negating an axis (or swapping Y and Z, as Samurai Jack suggests) and reversing the winding order.

The notation for D3D and OpenGL is different but the order of vectors and matrices in memory is the same.

Share this post


Link to post
Share on other sites
Hey thanks guys, I'll try it out. I think the transpose of the matrix that Promit was refering to is that OpenGL stores the matrices in col major rather than row major as in the DirectX .x files.

> You can also use this matrix to convert matrices (joints,bones,camera).
I'll try swapping the axis for everthing. What about quaternion rotation data? Should I swap them also?

Share this post


Link to post
Share on other sites
Quote:
Original post by tiburon
... I think the transpose of the matrix that Promit was refering to is that OpenGL stores the matrices in col major rather than row major as in the DirectX .x files.


The following matrix in D3D,
    a b c d
e f g h
i j k l
m n o p
is stored as a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p.

The following matrix in OpenGL,
    a e i m
b f j n
c g k o
d h l p
is stored as a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p.

As you can see, the matrix is "transposed" automatically.

Share this post


Link to post
Share on other sites
Quote:
Original post by tiburon
Hi all,
Newbie question. If the underlying graphics API is OpenGL but I import .X models, is it possible to not convert the left-handed coord to right-handed coord as long as everything is consistent. The model should look the same right, just flipped correct? But would the animation keys be incorrect?

p.s. I do transpose the matrices, but I have not negated the axis nor changed the winding order.


Thanks.


Just us a right handed projection matrix and reverse the winding order and you are set. Nothing more to do.

Share this post


Link to post
Share on other sites
> Just us a right handed projection matrix

Just to verify, I changed the projection matrix in Opengl by changing the sign the col(3), row(3), and col(3), row(4), or projMatrix[10], projMatrix[11]. This should give me a right-handed projection matrix rather than a left-handed correct?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!