Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have created an object movement path in a 3D authoring application. Then, I exported the path (100 frames) into my custom text file in the form of Euler Angles.

The next point was loading the animation into my game. To make it smoother, I performed linear interpolation between all the animation frames. Because of the interpolation, the object was moving correctly and smoothly, in about 80% of its path. In the remaining 20%, it jumps once to different orientation for a moment. Then, it jumps back, and smoothly finishes remaining of the path.

Do I face Gimbal Lock issue, please? Is there any way of fixing it? My tests have proven, that linear interpolation, which I perform, is correct. However, without linear interpolation, the object does not introduce this smoothness issue. Without interpolation, the object movement is obviously more aliased.

To summarize: Could I kndly ask to confirm that the issue I have here is gimbal lock? Can I ask for practical solution, please? Thank you.

I am adding the animation data. The issue occurs somewhere after frame 80.


Animation Data

The Animation data might help you. It is stored in the format: PosX, PosY, PosZ, RotX, RotY, RotZ, SclX, SclY, SclZ.

#new animation###############
<
no TopRightApproach
np Scene_Root

#begin 100 animation frames
as 100
a 8.984154 9.694528 10009.996094 -180.001068 85.938065 -89.102135 1.000000 1.000000 1.000000
a 8.987644 9.461698 10006.712891 -179.542618 85.955078 -89.218880 1.000000 1.000000 1.000000
a 8.995170 8.773152 9996.920898 -178.195877 86.005127 -89.568436 1.000000 1.000000 1.000000
a 8.998324 7.653935 9980.741211 -176.004623 86.085548 -90.150589 1.000000 1.000000 1.000000
a 8.984107 6.137118 9958.277344 -173.016205 86.192795 -90.968750 1.000000 1.000000 1.000000
a 8.935911 4.263794 9929.640625 -169.279999 86.322464 -92.028351 1.000000 1.000000 1.000000
a 8.834530 2.078479 9894.919922 -164.849365 86.469925 -93.338814 1.000000 1.000000 1.000000
a 8.659353 -0.368791 9854.232422 -159.778748 86.630211 -94.910629 1.000000 1.000000 1.000000
a 8.389198 -3.028332 9807.674805 -154.125946 86.798615 -96.757645 1.000000 1.000000 1.000000
a 8.003077 -5.851116 9755.331055 -147.951019 86.970734 -98.895927 1.000000 1.000000 1.000000
a 7.481458 -8.786425 9697.345703 -141.313080 87.142395 -101.340607 1.000000 1.000000 1.000000
a 6.806078 -11.788560 9633.822266 -134.272385 87.310028 -104.107964 1.000000 1.000000 1.000000
a 5.960865 -14.813670 9564.890625 -126.886299 87.470482 -107.211334 1.000000 1.000000 1.000000
a 4.931985 -17.821638 9490.685547 -119.207855 87.621101 -110.659729 1.000000 1.000000 1.000000
a 3.707599 -20.777081 9411.324219 -111.282890 87.759743 -114.454948 1.000000 1.000000 1.000000
a 2.278911 -23.646814 9326.969727 -103.144257 87.884651 -118.585815 1.000000 1.000000 1.000000
a 0.638988 -26.402788 9237.757813 -94.811073 87.994583 -123.027390 1.000000 1.000000 1.000000
a -1.216847 -29.020498 9143.830078 -86.285469 88.088776 -127.737762 1.000000 1.000000 1.000000
a -3.291077 -31.478796 9045.333984 -77.551552 88.166946 -132.656998 1.000000 1.000000 1.000000
a -5.583939 -33.759590 8942.430664 -68.577599 88.229309 -137.709320 1.000000 1.000000 1.000000
a -8.094282 -35.848312 8835.259766 -59.323414 88.276596 -142.810486 1.000000 1.000000 1.000000
a -10.819101 -37.732933 8723.966797 -49.746075 88.309952 -147.873535 1.000000 1.000000 1.000000
a -13.753524 -39.403763 8608.709961 -39.808613 88.330864 -152.817459 1.000000 1.000000 1.000000
a -16.891382 -40.853546 8489.634766 -29.487383 88.341103 -157.574615 1.000000 1.000000 1.000000
a -20.225103 -42.077068 8366.883789 -18.776186 88.342537 -162.094757 1.000000 1.000000 1.000000
a -23.745558 -43.070892 8240.607422 -7.687020 88.337074 -166.345886 1.000000 1.000000 1.000000
a -27.442255 -43.833294 8110.949707 3.750950 88.326576 -170.313156 1.000000 1.000000 1.000000
a -31.303263 -44.364086 7978.052734 15.494358 88.312828 -173.995956 1.000000 1.000000 1.000000
a -35.315113 -44.664520 7842.061035 27.489048 88.297478 -177.404449 1.000000 1.000000 1.000000
a -39.462746 -44.737206 7703.111328 39.673283 88.282089 -180.556396 1.000000 1.000000 1.000000
a -43.729130 -44.586052 7561.345215 51.980412 88.268150 -183.474457 1.000000 1.000000 1.000000
a -48.095078 -44.216312 7416.899902 64.340660 88.257141 -186.184448 1.000000 1.000000 1.000000
a -52.539017 -43.634575 7269.907227 76.681992 88.250580 -188.714432 1.000000 1.000000 1.000000
a -57.036156 -42.848896 7120.494141 88.930428 88.250122 -191.094437 1.000000 1.000000 1.000000
a -61.557461 -41.869068 6968.793457 101.009323 88.257713 -193.357132 1.000000 1.000000 1.000000
a -66.068169 -40.707054 6814.946777 112.837379 88.275726 -195.539856 1.000000 1.000000 1.000000
a -70.527527 -39.377113 6659.050781 124.323631 88.307304 -197.689606 1.000000 1.000000 1.000000
a -74.883102 -37.897480 6501.245605 135.359741 88.356773 -199.870743 1.000000 1.000000 1.000000
a -79.073669 -36.288589 6341.615723 145.780823 88.423538 -202.204208 1.000000 1.000000 1.000000
a -83.048775 -34.563198 6180.319824 155.424957 88.500549 -204.807938 1.000000 1.000000 1.000000
a -86.761948 -32.734024 6017.475098 164.176315 88.589706 -207.753723 1.000000 1.000000 1.000000
a -90.160110 -30.820969 5853.197266 171.880707 88.693443 -211.151733 1.000000 1.000000 1.000000
a -93.182159 -28.853851 5687.632324 178.311142 88.814514 -215.184875 1.000000 1.000000 1.000000
a -95.760071 -26.874413 5520.888672 183.514175 88.955826 -220.189575 1.000000 1.000000 1.000000
a -97.817413 -24.940729 5353.116211 187.123825 89.119591 -226.856110 1.000000 1.000000 1.000000
a -99.271843 -23.130093 5184.452637 187.359161 89.304878 -236.833206 1.000000 1.000000 1.000000
a -100.037704 -21.542662 5015.049316 179.437531 89.497887 -254.771408 1.000000 1.000000 1.000000
a -100.031853 -20.303196 4845.088379 151.451355 89.629776 -292.446320 1.000000 1.000000 1.000000
a -99.182739 -19.559208 4674.762695 291.944275 90.458984 -161.182373 1.000000 1.000000 1.000000
a -97.442368 -19.473804 4504.315918 273.930450 90.745369 -187.833755 1.000000 1.000000 1.000000
a -94.799210 -20.211189 4334.016113 268.405609 91.116585 -201.273117 1.000000 1.000000 1.000000
a -91.287979 -21.916485 4164.151367 267.106964 91.525215 -209.631729 1.000000 1.000000 1.000000
a -86.987350 -24.667471 3995.015137 267.965698 91.931450 -214.846268 1.000000 1.000000 1.000000
a -81.982269 -28.356201 3826.834717 270.173737 92.298965 -217.592072 1.000000 1.000000 1.000000
a -76.352097 -32.819702 3659.774414 272.429474 92.621109 -219.038483 1.000000 1.000000 1.000000
a -70.173721 -37.898491 3493.952393 274.095367 92.895790 -219.690750 1.000000 1.000000 1.000000
a -63.521225 -43.437111 3329.450684 274.800812 93.122452 -219.787338 1.000000 1.000000 1.000000
a -56.465767 -49.284065 3166.322266 274.642273 93.301178 -219.443222 1.000000 1.000000 1.000000
a -49.076012 -55.291142 3004.602539 273.902985 93.432320 -218.706345 1.000000 1.000000 1.000000
a -41.418377 -61.312618 2844.312744 272.626160 93.516396 -217.581085 1.000000 1.000000 1.000000
a -33.557667 -67.204132 2685.466797 270.890015 93.554153 -216.036774 1.000000 1.000000 1.000000
a -25.557846 -72.821381 2528.081299 268.807770 93.546745 -214.007919 1.000000 1.000000 1.000000
a -17.482519 -78.019058 2372.174316 266.533997 93.496086 -211.387970 1.000000 1.000000 1.000000
a -9.391724 -82.652771 2217.783691 264.253021 93.414352 -208.041183 1.000000 1.000000 1.000000
a -1.305104 -86.605675 2065.017334 262.132111 93.330910 -203.849457 1.000000 1.000000 1.000000
a 6.781445 -89.769653 1914.023193 260.402527 93.255775 -198.631531 1.000000 1.000000 1.000000
a 14.872069 -92.022461 1764.984375 259.315521 93.202789 -192.187439 1.000000 1.000000 1.000000
a 22.971615 -93.223053 1618.113037 259.088806 93.193535 -184.352234 1.000000 1.000000 1.000000
a 31.085062 -93.204956 1473.673706 259.803406 93.260254 -175.099915 1.000000 1.000000 1.000000
a 39.216648 -91.768005 1332.016479 261.265259 93.447968 -164.682587 1.000000 1.000000 1.000000
a 47.368805 -88.667946 1193.618896 262.938171 93.814819 -153.698944 1.000000 1.000000 1.000000
a 55.539368 -83.604195 1059.160889 264.085083 94.432259 -142.955521 1.000000 1.000000 1.000000
a 63.715828 -76.209015 929.650635 264.077515 95.391594 -133.161606 1.000000 1.000000 1.000000
a 71.863411 -66.050301 806.609619 262.599335 96.807785 -124.729851 1.000000 1.000000 1.000000
a 79.806870 -52.886086 691.773071 259.552643 98.523193 -117.801910 1.000000 1.000000 1.000000
a 87.138481 -36.938866 586.204651 255.640915 100.443077 -111.729950 1.000000 1.000000 1.000000
a 93.392937 -18.585585 490.532349 251.516113 102.569275 -105.945999 1.000000 1.000000 1.000000
a 98.084183 1.707072 404.999969 247.688187 104.917473 -100.041023 1.000000 1.000000 1.000000
a 100.718758 23.406570 329.519897 244.617203 107.524292 -93.681702 1.000000 1.000000 1.000000
a 100.808044 45.916389 263.785370 242.749939 110.458992 -86.582306 1.000000 1.000000 1.000000
a 97.899155 68.556969 207.378372 242.493729 113.836517 -78.531448 1.000000 1.000000 1.000000
a 91.653503 90.539482 159.840546 64.095169 62.185379 -249.486740 1.000000 1.000000 1.000000
a 82.035561 110.984665 120.341881 66.671341 58.309464 -239.938141 1.000000 1.000000 1.000000
a 69.303429 128.851440 86.450623 70.901794 55.979618 -228.105255 1.000000 1.000000 1.000000
a 52.973385 141.918472 55.832756 83.709579 55.103844 -205.541702 1.000000 1.000000 1.000000
a 33.546043 142.795471 29.466892 116.969391 46.180241 -154.715836 1.000000 1.000000 1.000000
a 19.857452 129.141251 15.259699 129.680740 25.349024 -120.760765 1.000000 1.000000 1.000000
a 12.343875 112.144974 8.724246 127.029526 14.333036 -108.347511 1.000000 1.000000 1.000000
a 7.821478 95.381325 5.209990 122.078331 8.939495 -102.264587 1.000000 1.000000 1.000000
a 4.932919 79.590408 3.140254 116.943588 5.913023 -98.623123 1.000000 1.000000 1.000000
a 3.046561 65.016060 1.870584 112.077103 4.031883 -96.189346 1.000000 1.000000 1.000000
a 1.816201 51.780125 1.082831 107.615768 2.781020 -94.455673 1.000000 1.000000 1.000000
a 1.027526 39.939304 0.597993 103.613441 1.909752 -93.170593 1.000000 1.000000 1.000000
a 0.540331 29.559338 0.308290 100.096359 1.286182 -92.199020 1.000000 1.000000 1.000000
a 0.255917 20.679609 0.143687 97.080849 0.833416 -91.459457 1.000000 1.000000 1.000000
a 0.103634 13.330984 0.057448 94.579781 0.504789 -90.900986 1.000000 1.000000 1.000000
a 0.032585 7.548802 0.017888 92.605690 0.271279 -90.491302 1.000000 1.000000 1.000000
a 0.006448 3.381170 0.003515 91.172569 0.115071 -90.210548 1.000000 1.000000 1.000000
a 0.000409 0.855556 0.000222 90.297157 0.024915 -90.045868 1.000000 1.000000 1.000000
a 0.000000 0.000000 0.000000 89.999992 0.004890 -90.009010 1.000000 1.000000 1.000000
#end 100 animation frames

>
#end animation
share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

As you've noted, performing linear interpolation of the individual angles composing a set of euler angles (your "rotX, rotY, rotZ" values) does not result in a linear rotation. This is partly because angles don't interpolate linearly to begin with (for example, 179 degrees and -179 degrees are nearly the same angle, but linearly interpolating from one to the other as if they were simple numbers would go the long way around), and partly because euler angles do suffer from gimbal lock, as you mentioned, where the order in which you apply the three rotations affects later rotations in the sequence.

A better way to interpolate these orientations is to convert your euler angles into another representation before interpolating them; quaternions are one extremely popular choice. Rotation matrices are another. These other representations of orientation will interpolate far more successfully than euler angles do.

share|improve this answer
    
+1 - Hi Trevor, thank you very much for your answer. Is it common to perform the Euler Angle to Quaternion conversion during game runtime, or should I export quaternions from my 3d application, and load them straight as quaternions? I am considering performance cost in my question. –  Bunkai.Satori Jun 10 '11 at 3:42
1  
This is a trade-off which will depend upon your specific situation. The performance cost of converting from Euler Angle to Quaternion isn't completely trivial, since it involves a little bit of trigonometry, but quaternions do require 30% more memory to store (four floats, instead of three). I've worked on games which have worked in both ways. It's up to you whether memory or performance is a larger concern for you. (But in general, on PC you don't need to worry much about memory, where that's a much larger concern on consoles) –  Trevor Powell Jun 10 '11 at 4:17
    
+1, thank you very much, Trevor. Good Luck with future games. :-) –  Bunkai.Satori Jun 10 '11 at 4:28
add comment

It looks like your problem lies in your exporter not producing continuous euler data. The discontinuity appears late, when the X and Z swap roles in the orientation, which is what gives you the odd looking interpolation. it's these lines:

a 97.899155 68.556969 207.378372 242.493729 113.836517 -78.531448 1.000000 1.000000 1.000000
a 91.653503 90.539482 159.840546 64.095169 62.185379 -249.486740 1.000000 1.000000 1.000000

you can solve this one of two ways, either make the exporter export continuous eulers (and then allow for euler elements outside the normal range), or interpolate as quaternions rather than as eulers.

You don't need to export as quaternion as the euler to quaternion conversion isn't very expensive, and if you're interpolating over a number of frames you could even cache the quaternions and the information you have to generate to perform the interpolation (information such as which way round to interpolate)

share|improve this answer
    
+1, Hello, and thanks for your good quality answer. Especially, thank you for analyzing my coordinates. I can confirm, that from what I see in practice, those two lines are causing the issue. It is the point, where the game object rapidly changes orientation. So, you confirmed, that the issue I had is Gimal Lock, if I am correct. I have already started implementing quaternion interpolation. It looks like less job than exporting quaternions from 3D application. –  Bunkai.Satori Jun 10 '11 at 14:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.