Transforming a quaternion from 3ds max axes to Ogre axes?
-
- Halfling
- Posts: 94
- Joined: Sun Sep 25, 2005 10:25 pm
- Location: Menlo Park, CA
Transforming a quaternion from 3ds max axes to Ogre axes?
I'm trying to convert a PML file exported from 3ds max, and I'm wondering if anyone knows how to convert quaternions from Z-UP axes to Y-UP axes. It's *almost* right if I swap y and z, and negate w, but not quite. Anyone know how to do this?
Thanks
Thanks
-
- Halfling
- Posts: 94
- Joined: Sun Sep 25, 2005 10:25 pm
- Location: Menlo Park, CA
-
- Lich
- Posts: 1742
- Joined: Tue Apr 05, 2005 1:11 pm
- Location: Gosport, South England
- x 1
-
- Gnoblar
- Posts: 13
- Joined: Fri Jul 01, 2005 3:11 pm
- Location: Madrid. Spain
-
- Halfling
- Posts: 94
- Joined: Sun Sep 25, 2005 10:25 pm
- Location: Menlo Park, CA
-
- Lich
- Posts: 1742
- Joined: Tue Apr 05, 2005 1:11 pm
- Location: Gosport, South England
- x 1
-
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 535
Well,, when dealing with 2d on a computer, the screen is x and y. So when going to 3d, it makes sense to keep the x and y axes the same and make the z go into the screen (or out of the screen in ogre's case, but I prefer into).
But in software like autocad and stuff they probably deal with floor plans more, so moving to 3d means extruding upwards, so thats the z axis.
In real life, most positioning is relative to the ground, so the z axis becomes altitude.
At least that's how I always thought about it.
Oh yeah, I was working on a pml to novodex/ogre importer last week too, and got stuck on the quaternions.
Seems I got it right though, but stuffed up something else.
But in software like autocad and stuff they probably deal with floor plans more, so moving to 3d means extruding upwards, so thats the z axis.
In real life, most positioning is relative to the ground, so the z axis becomes altitude.
At least that's how I always thought about it.

Oh yeah, I was working on a pml to novodex/ogre importer last week too, and got stuck on the quaternions.

Seems I got it right though, but stuffed up something else.
-
- Halfling
- Posts: 94
- Joined: Sun Sep 25, 2005 10:25 pm
- Location: Menlo Park, CA
-
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 535
-
- Goblin
- Posts: 292
- Joined: Fri Jul 22, 2005 8:14 pm
- Location: Midwest USA
I get a Quat from an external device (A motion tracker) that has ZUP orientation. I simply swap z and w, negating both and it works fine. Positions have to have some terms swapped as well. Here is a snippet:
Code: Select all
m_vBufferVector[index].z = pFloats[0];
m_vBufferVector[index].x = pFloats[1];
m_vBufferVector[index].y = pFloats[2];
m_qBufferQuat[index].x = pFloats[3];
m_qBufferQuat[index].y = pFloats[4];
m_qBufferQuat[index].w = -pFloats[5];
m_qBufferQuat[index].z = -pFloats[6];
-
- Gnoblar
- Posts: 3
- Joined: Tue Oct 22, 2013 6:04 am
Re: Transforming a quaternion from 3ds max axes to Ogre axes
"just wondering, why do 3d modelling programs use Z up instead of Y up? because i thought Y up was like a standard way axes are done?"
Back before we had these newfangled I/O devices on our desks, where the keyboard sits was a notepad (quadrilateral ruled, of course), and in our hand was a pencil (mechanical, of course, plus plenty of multi-colored pens in our handy pocket protector (i.e. "nerd pack"). And we had a slide-rule attached to our belt, so PI was just "3.14" back in those days...
When you drew the X axis on your paper on the desk in front of you, X was left and right. Then you plotted Y toward the top of the page (away from you) and toward the bottom of the page (toward you). And in the rare cases you needed to model in 3D with pipe-cleaners and/or toothpicks, that Z axis stuck up off your paper. Just like back in math class in the olden days.
With a keyboard where the notepad used to sit, there is nowhere for the drawing surface to go but vertical in front of you...

Actually, the coordinate system in OpenGL and other CG systems makes more sense when you convert it to Euler angles, because the polar axis is up and down where you would expect it to be. Gimbal lock is straight up and straight down, just like when standing on the North Pole and every direction your look is south. Likewise every direction is north when standing on the South Pole. Look at a globe to see where all the longitude lines converge.
Then we have the Razer Hydra with its own different coordinate system (out of the twelve you can choose from), which in that case makes great sense for a hand held controller. Swapping coordinate systems swaps the polar axis, so you need to choose whichever system suits your needs for a given purpose (GL, HMD, controller, or whatever)... Sadly, the Hydra swaps from a LH system to a RH system and some sections of its 3-space coverage (luckily not where you normally use it with the base sitting in front of you on your desk). You can detect the axis swap when all the quaternion elements swap their signs, then swap them back immediately, or do it later by detecting and dealing with whichever coordinate system it seems to be using at that location.
It is a good thing Ogre does not use multiple coordinate systems that you have to keep track of, eh?
EDIT: Hmm... Posting when I should be sleeping again... I think I had my "math coords" swapped. 2D on paper was X to the right, Y away from you toward the top of the paper. But in 3D I believe that changes to something that is not intuitively obvious to me. And whichever coordinate system you use changes depending on whether you are viewing it on a vertical desktop display sitting in front of you and facing you, or on a tablet computer that is on the desktop or table in front of you and facing the ceiling. Then converting between Euler angles and quaternions only makes it harder to envision.
Back before we had these newfangled I/O devices on our desks, where the keyboard sits was a notepad (quadrilateral ruled, of course), and in our hand was a pencil (mechanical, of course, plus plenty of multi-colored pens in our handy pocket protector (i.e. "nerd pack"). And we had a slide-rule attached to our belt, so PI was just "3.14" back in those days...
When you drew the X axis on your paper on the desk in front of you, X was left and right. Then you plotted Y toward the top of the page (away from you) and toward the bottom of the page (toward you). And in the rare cases you needed to model in 3D with pipe-cleaners and/or toothpicks, that Z axis stuck up off your paper. Just like back in math class in the olden days.
With a keyboard where the notepad used to sit, there is nowhere for the drawing surface to go but vertical in front of you...


Actually, the coordinate system in OpenGL and other CG systems makes more sense when you convert it to Euler angles, because the polar axis is up and down where you would expect it to be. Gimbal lock is straight up and straight down, just like when standing on the North Pole and every direction your look is south. Likewise every direction is north when standing on the South Pole. Look at a globe to see where all the longitude lines converge.
Then we have the Razer Hydra with its own different coordinate system (out of the twelve you can choose from), which in that case makes great sense for a hand held controller. Swapping coordinate systems swaps the polar axis, so you need to choose whichever system suits your needs for a given purpose (GL, HMD, controller, or whatever)... Sadly, the Hydra swaps from a LH system to a RH system and some sections of its 3-space coverage (luckily not where you normally use it with the base sitting in front of you on your desk). You can detect the axis swap when all the quaternion elements swap their signs, then swap them back immediately, or do it later by detecting and dealing with whichever coordinate system it seems to be using at that location.
It is a good thing Ogre does not use multiple coordinate systems that you have to keep track of, eh?
EDIT: Hmm... Posting when I should be sleeping again... I think I had my "math coords" swapped. 2D on paper was X to the right, Y away from you toward the top of the paper. But in 3D I believe that changes to something that is not intuitively obvious to me. And whichever coordinate system you use changes depending on whether you are viewing it on a vertical desktop display sitting in front of you and facing you, or on a tablet computer that is on the desktop or table in front of you and facing the ceiling. Then converting between Euler angles and quaternions only makes it harder to envision.
Last edited by geekmaster on Tue Oct 22, 2013 5:45 pm, edited 1 time in total.
-
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 139
Re: Transforming a quaternion from 3ds max axes to Ogre axes
inb4 any Greek prefixes describing what just happened 

-
- Gnoblar
- Posts: 3
- Joined: Tue Oct 22, 2013 6:04 am
Re: Transforming a quaternion from 3ds max axes to Ogre axes
What did "just happen"? I signed up for this forum and posted something I thought would be a useful contribution, in reply to a question. Perhaps I am just adding to the confusion. ???c6burns wrote:inb4 any Greek prefixes describing what just happened
You could stick these stickers on stuff to keep it straight, maybe:

Greek letters? Σκατά?
-
- OGRE Moderator
- Posts: 7157
- Joined: Sun Jan 25, 2004 7:35 am
- Location: Brisbane, Australia
- x 535
Re: Transforming a quaternion from 3ds max axes to Ogre axes
Hey geekmaster. 
You can move the gimbal lock position by changing the euler angle that is in the middle.
But yaw pitch roll order (as local transforms left to right) is probably the most useful (in my opinion anyway), so up/down gimbal lock would be typical.

It depends on the euler angle order. There's 6 combinations of euler angles (when each is used once, not counting the form where you use one axis twice such as yaw pitch yaw), only two of those have gimbal lock as up/down.geekmaster wrote:Gimbal lock is straight up and straight down,
You can move the gimbal lock position by changing the euler angle that is in the middle.
But yaw pitch roll order (as local transforms left to right) is probably the most useful (in my opinion anyway), so up/down gimbal lock would be typical.
-
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 139
Re: Transforming a quaternion from 3ds max axes to Ogre axes
The Greek prefix I was thinking was "necro" ... it's cool though that you probably found this thread by search engine or something and signed up to post something useful
No harm in that, really.

-
- Gnoblar
- Posts: 3
- Joined: Tue Oct 22, 2013 6:04 am
Re: Transforming a quaternion from 3ds max axes to Ogre axes
I did not refer to my notes when I posted my first post here, so of course, I did not get it right... People who hang out here probably have orders of magnitude more thought time in coordinate space transforms that I, when in fact I am rather a noob at this. My experience is talking direct to framebuffers and such (2D) and many other IO devices. But progress is damn slow that way, so I need to adopt some libraries. Ogre3D looks good to me.
Now, how do I access Ogre3D from my native (kernel) mode RasPi code?
I am spending much more time buried in code these days than in any forums. I have more than 10K posts in a few forums in the past couple of years, so I may contribute here if I have something new and useful to contribute when I get "into" ogre3D...
Regarding gimbal lock being "straight up and straight down" I was referring to typically what is found in OpenGL and other CG documents, and in typical code that does Euler conversions. Up and down makes intuitive sense because when you look down beyond straight down (between your knees) you are actually looking 180-degrees in the other direction with 180-degrees roll too (an alternate way to get to the same position), so the other axes flipping 180 at the gimbal lock singularity makes sense when viewed that way. It makes a lot of sense for an HMD.
I have been working with decoding raw USB HID packets for the Oculus Rift tracker and the Razer Hydra. The Hydra has a strange behavior, where it flips between RH and LH coordinates and some areas of its coverage (all the quaternion values flip sign). Thankfully, that is not in the "normal" operating area in front of your desk when positioned as recommended in its docs. And such a large jump can be easily detected and compensated in software, if you are aware of its existence.
I plan to extend the "Baking Pi" USB HID drivers to support the Rift and Hydra in addition to its current keyboard and mouse. It would be nice to squeeze a miminal subset of Ogre3D in there too. Is there a stripped down "micro-ogre" subset I can use, without needing to figure out where to slice out the fat?

Now, how do I access Ogre3D from my native (kernel) mode RasPi code?

I am spending much more time buried in code these days than in any forums. I have more than 10K posts in a few forums in the past couple of years, so I may contribute here if I have something new and useful to contribute when I get "into" ogre3D...
Regarding gimbal lock being "straight up and straight down" I was referring to typically what is found in OpenGL and other CG documents, and in typical code that does Euler conversions. Up and down makes intuitive sense because when you look down beyond straight down (between your knees) you are actually looking 180-degrees in the other direction with 180-degrees roll too (an alternate way to get to the same position), so the other axes flipping 180 at the gimbal lock singularity makes sense when viewed that way. It makes a lot of sense for an HMD.
I have been working with decoding raw USB HID packets for the Oculus Rift tracker and the Razer Hydra. The Hydra has a strange behavior, where it flips between RH and LH coordinates and some areas of its coverage (all the quaternion values flip sign). Thankfully, that is not in the "normal" operating area in front of your desk when positioned as recommended in its docs. And such a large jump can be easily detected and compensated in software, if you are aware of its existence.
I plan to extend the "Baking Pi" USB HID drivers to support the Rift and Hydra in addition to its current keyboard and mouse. It would be nice to squeeze a miminal subset of Ogre3D in there too. Is there a stripped down "micro-ogre" subset I can use, without needing to figure out where to slice out the fat?
