• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
newObjekt

Is this Gimbal Lock at work or do I have a real problem?

12 posts in this topic

Here's a quick video I recorded:

 

http://www.youtube.com/watch?v=mtpaAaAGPTU&feature=youtu.be

 

Currently I am using bullet physics to calculate my RigidBody physics actors. After each bullet step I basically run this code on my RigidBody game actors to get their position and rotation from bullet.

 

      //the variable "physics" is the bullet RigidBody object

        Vector3f c = physics.getCenterOfMassPosition(new Vector3f());
        setLocation(new Vertex(c.x, c.y, c.z + 10));

        Quat4f q = physics.getOrientation(new Quat4f());
        setRotation(MathUtil.convertQuat2Euler3(new Quat(q.x, q.y, q.z, q.w)));

 

Problem A:

I'm currently converting the Quaternion that is returned by the RigidBody to an Euler angle then applying that to the object and rendering.

I'm like 99% sure thats causing gimbal lock. I can rewrite my renderer to use Quat's instead of Euler angles and solve the problem if that is it. It's a lot of work though so I want to confirm that this is the problem.

 

Problem B:

I have to add 10 to the location.z value of the RigidBody for some odd reason. I have no idea why.

 

Thanks :)

0

Share this post


Link to post
Share on other sites

You should be using MotionStates to receive bullet notifications about your objects changing positions.

 

If your engine needs to be fed a 3x3 matrix, you could use the btTransform that bullet sends you though the motion state (see previous link) and call .getBasis() on it to get a 3x3 matrix. That way you won't need to do quaternion<->matrix convertions and you may also benefit from bullet's interpolation extrapolation.

 

I'm not familiar with java, and don't know exacly what's wrong with your current code.

Edited by mdias
2

Share this post


Link to post
Share on other sites

You should be using MotionStates to receive bullet notifications about your objects changing positions.

 

If your engine needs to be fed a 3x3 matrix, you could use the btTransform that bullet sends you though the motion state (see previous link) and call .getBasis() on it to get a 3x3 matrix. That way you won't need to do quaternion<->matrix convertions and you may also benefit from bullet's interpolation extrapolation.

 

I'm not familiar with java, and don't know exacly what's wrong with your current code.

Ah okay. Can MotionStates give me the rotation in Euler angles? 

My engine currently requires that I get object rotations in Euler angles but I can convert the engine to use Quaternions if that will fix the problem I am having with the spastic rotations.

 

With the .getBasis() method I assume the matrix would be:

location.x rotation.x velocity.x

location.y rotation.y velocity.y

location.z rotation.z velocity.z

 

Or something similar?

Edited by newObjekt
0

Share this post


Link to post
Share on other sites

Problem A:

I'm currently converting the Quaternion that is returned by the RigidBody to an Euler angle then applying that to the object and rendering.

I'm like 99% sure thats causing gimbal lock. I can rewrite my renderer to use Quat's instead of Euler angles and solve the problem if that is it. It's a lot of work though so I want to confirm that this is the problem.

 

Problem B:

I have to add 10 to the location.z value of the RigidBody for some odd reason. I have no idea why.

 

Thanks smile.png

This is unlikely gimbal lock and more than likely a simple math problem.  The problem is likely 'related' to gimbal lock but not in the way you might be thinking.  Converting from quat to euler can and should be a perfect operation, there is no orientation which can not be represented in euler, but the way you perform the conversion has to account for the order of rotations which Euler implies, as such as things near various axis' the order of rotations will cause changes in how the Euler angles are represented.  Assuming a fairly normal Euler representation, most will be BPH ordered if I remember correctly.  (Bank, pitch then heading.)  If your engine uses a different order then the conversion of a quat to Euler will likely look correct in 90% of the cases and then do what I see in the video, all of a sudden change.

 

Overall, if you are using Euler for rendering, you have got to change it.  It's just a bag of pissed off cats waiting to bite you.  Euler angles are great for UI representations, pretty much everywhere else, avoid them like the plague.

2

Share this post


Link to post
Share on other sites

 

Problem A:

I'm currently converting the Quaternion that is returned by the RigidBody to an Euler angle then applying that to the object and rendering.

I'm like 99% sure thats causing gimbal lock. I can rewrite my renderer to use Quat's instead of Euler angles and solve the problem if that is it. It's a lot of work though so I want to confirm that this is the problem.

 

Problem B:

I have to add 10 to the location.z value of the RigidBody for some odd reason. I have no idea why.

 

Thanks smile.png

This is unlikely gimbal lock and more than likely a simple math problem.  The problem is likely 'related' to gimbal lock but not in the way you might be thinking.  Converting from quat to euler can and should be a perfect operation, there is no orientation which can not be represented in euler, but the way you perform the conversion has to account for the order of rotations which Euler implies, as such as things near various axis' the order of rotations will cause changes in how the Euler angles are represented.  Assuming a fairly normal Euler representation, most will be BPH ordered if I remember correctly.  (Bank, pitch then heading.)  If your engine uses a different order then the conversion of a quat to Euler will likely look correct in 90% of the cases and then do what I see in the video, all of a sudden change.

 

Overall, if you are using Euler for rendering, you have got to change it.  It's just a bag of pissed off cats waiting to bite you.  Euler angles are great for UI representations, pretty much everywhere else, avoid them like the plague.

 

Yeah, the use of Euler was a choice I made before I had much experience. Won't ever do it again in the future. As it stands just actor rotations use Euler angles. Animations and what not use Quaternions.

 

As for the ordering, I might have it wrong. I will swap them around tomorrow morning when I start working and see if it solves the problem.

 

Looking for an honest opinion, should I just go ahead and rewrite the actors to use quats and call it done? I believe I have a quat slerp fucntion already written for animations (not on linux atm so can't check) so I could pretty easily convert it. It'd take maybe an hour or two to do it.

 

Oh and here's a random question. How much of a speed difference is their between using floats and doubles for graphics and physics. I was considering switching to floats if it's a big enough difference.

Edited by newObjekt
0

Share this post


Link to post
Share on other sites

 

This is unlikely gimbal lock and more than likely a simple math problem.  The problem is likely 'related' to gimbal lock but not in the way you might be Yeah, the use of Euler was a choice I made before I had much experience. Won't ever do it again in the future. As it stands just actor rotations use Euler angles. Animations and what not use Quaternions.

 

As for the ordering, I might have it wrong. I will swap them around tomorrow morning when I start working and see if it solves the problem.

 

Looking for an honest opinion, should I just go ahead and rewrite the actors to use quats and call it done? I believe I have a quat slerp fucntion already written for animations (not on linux atm so can't check) so I could pretty easily convert it. It'd take maybe an hour or two to do it.

 

Oh and here's a random question. How much of a speed difference is their between using floats and doubles for graphics and physics. I was considering switching to floats if it's a big enough difference.

 

Overall, I highly suggest switching to *anything* other than Euler, matrix or quaternion's, your choice.  Of course, at that point you really need to know/understand the math involved as Eulers are fairly easy to visualize (ignoring gimbal lock) where matrix/quats and of course the resulting heavy use of vectors gets much more difficult to visualize as you work.

 

As to the floats versus doubles thing.  CPU performance wise, it makes no difference.  Anytime a x86/64 works on a float it internally converts it to 80bits for the actual work.  On older CPU's you "could" get a bit of a performance benefit to the cycle times by setting the fpu to low precision mode but that is no longer true as I understand it.  So, from the CPU side there is no benefit.  But..  There is a large benefit overall to using 32bit floats in terms of cache and memory which are the slowest bits anymore.  Using a double takes twice as much memory so you have all sorts of reasons the double will be slower: more cache lines in use, less per cache line, more likely to span multiple lines etc and of course more memory movement all over.

 

Memory is pretty much the primary performance hit for most programs.  Reductions of memory read and memory write (cache line level) are the largest possible optimizations anymore in real work.

2

Share this post


Link to post
Share on other sites

 

Overall, I highly suggest switching to *anything* other than Euler, matrix or quaternion's, your choice.  Of course, at that point you really need to know/understand the math involved as Eulers are fairly easy to visualize (ignoring gimbal lock) where matrix/quats and of course the resulting heavy use of vectors gets much more difficult to visualize as you work.

 

As to the floats versus doubles thing.  CPU performance wise, it makes no difference.  Anytime a x86/64 works on a float it internally converts it to 80bits for the actual work.  On older CPU's you "could" get a bit of a performance benefit to the cycle times by setting the fpu to low precision mode but that is no longer true as I understand it.  So, from the CPU side there is no benefit.  But..  There is a large benefit overall to using 32bit floats in terms of cache and memory which are the slowest bits anymore.  Using a double takes twice as much memory so you have all sorts of reasons the double will be slower: more cache lines in use, less per cache line, more likely to span multiple lines etc and of course more memory movement all over.

 

Memory is pretty much the primary performance hit for most programs.  Reductions of memory read and memory write (cache line level) are the largest possible optimizations anymore in real work.

 

 

Alright. I'll make that my project for tomorrow. Out with Euler in with Quat. I understand Quat moderately well as I have worked with it extensively with skinned meshes and animations. It'll be nice to have the whole engine using the same rotation code heh.

 

I'll also make a branch and convert the engine from doubles to floats and see how much of a difference it makes since it sounds like it might have an impact on performance.

 

Thanks for the advice. Cheers.

Edited by newObjekt
0

Share this post


Link to post
Share on other sites

 

I'll also make a branch and convert the engine from doubles to floats and see how much of a difference it makes since it sounds like it might have an impact on performance.

 

 

Keep in mind that this is an "overall" performance item.  It won't likely show up notably unless you really beat on things.  I.e. early engines won't show any notable difference, only when you have a fair sized simulation are you likely to notice the difference in major ways.  Any initial game is likely not to see any benefit, only when your simulation times start eating up notable portions of your frame time does this really make a difference.

1

Share this post


Link to post
Share on other sites

 

 

I'll also make a branch and convert the engine from doubles to floats and see how much of a difference it makes since it sounds like it might have an impact on performance.

 

 

Keep in mind that this is an "overall" performance item.  It won't likely show up notably unless you really beat on things.  I.e. early engines won't show any notable difference, only when you have a fair sized simulation are you likely to notice the difference in major ways.  Any initial game is likely not to see any benefit, only when your simulation times start eating up notable portions of your frame time does this really make a difference.

 

 

Yeah I very well understand that. When I want to stress test something I make the engine load the BSPs of 5 maps at once or spawn in 200 bouncing physics boxes. Etc etc...

Regardless you seem very knowledgeable about this so I'd take your word that it will make a difference either way. :P

0

Share this post


Link to post
Share on other sites

 

You should be using MotionStates to receive bullet notifications about your objects changing positions.

 

If your engine needs to be fed a 3x3 matrix, you could use the btTransform that bullet sends you though the motion state (see previous link) and call .getBasis() on it to get a 3x3 matrix. That way you won't need to do quaternion<->matrix convertions and you may also benefit from bullet's interpolation extrapolation.

 

I'm not familiar with java, and don't know exacly what's wrong with your current code.

Ah okay. Can MotionStates give me the rotation in Euler angles? 

My engine currently requires that I get object rotations in Euler angles but I can convert the engine to use Quaternions if that will fix the problem I am having with the spastic rotations.

 

With the .getBasis() method I assume the matrix would be:

location.x rotation.x velocity.x

location.y rotation.y velocity.y

location.z rotation.z velocity.z

 

Or something similar?

 

 

 

MotionStates will not give you rotation in Euler angles. It will only give you a btTransform which is composed of a btMatrix3x3 (rotation matrix) and a btVector3 (object's translation/position).

The 3x3 matrix is a rotation matrix, it will only describe the rotation of the object. You should study how they work, it's pretty interesting and will probably be useful to you in the long term. Simply put they describe how each axis' coordinate is affected (by the rotation).

Edited by mdias
1

Share this post


Link to post
Share on other sites

Made the changes and problem is solved. Thanks again AllEightUp.

 

http://www.youtube.com/watch?v=r2wrey_U4kg

1

Share this post


Link to post
Share on other sites

 

Made the changes and problem is solved. Thanks again AllEightUp.

 

 

There's a glitch at 0:36

 

http://youtu.be/r2wrey_U4kg?t=34s

 

That's most likely just encoding. When I record my desktop with ffmpeg it tends to skip a few frames every once and a while.

0

Share this post


Link to post
Share on other sites

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  
Followers 0