0

I'm trying to implement yaw pitch roll for visualisation camera yaw pitch roll more then 360 degree like in Maya, Blender, Unreal Engine, Unity etc. All this application can show angles in gui more then 360 degree and no have any Gimbal lock problems.

current psevdo code;

Quaternion rotation; //relative (local rotation)
Quaternion parentRotation;
    //it is psevdo code where we calculate delta angle that user generate on current frame by mouse
void SetDeltaWorldRotationFromUserInput(Quaternion value)
{
    SetWorldRotation(value);
}

void SetWorldRotation(Quaternion value)
{
    SetLocalRotation(parentQuaternion.inverted() * value); //get/set local rotation
}

void SetLocalRotation(Quaternion value)
{
    rotation = value; //this we save new local rotation but i want to save somehow more then 360 degree 
    auto eulersForGui = value.toEulers(); //it is current eulers but i want to accumulate and show in gui accumulate rotation. like currentRotation + delta or somehow

    auto deltaEulers = (value * rotation.inverted()).toEulers(); //i can get delta eulers but i can't add it to euelers and don't know what i need to do with this value

}
Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
  • As your question title suggests, accumulation the angles, not the quaternion - you can re-calculate the quaternion when the angles are updated. – meowgoesthedog Jan 25 '19 at 10:34
  • I rotate object around pivot and then recalculate it position relate it parent by invert paren quaternion after that i loose my original angle and in any case eulers can't be simplest added to last eulers – Igor Shumakov Jan 25 '19 at 10:44
  • Don't understand what you mean; why do you need to *re-calculate* the angles if you can just store them? Use the accumulated angles to calculate the local quaternion and multiply it with the parent quaternion to obtain the global transformation. – meowgoesthedog Jan 25 '19 at 10:58
  • I don't know how accumulate eulers. I know that i can't simplest add yaw to yaw. Can you explain it somehow. Thanks for answer anyway – Igor Shumakov Jan 25 '19 at 11:21
  • You **can** accumulate the angles directly based on mouse movements - that's how every game / CAD software does it, but you cannot combine Euler angle transformations by adding them; these are two different concepts. – meowgoesthedog Jan 25 '19 at 11:26
  • It is sound stupid but i don't see difference between angles and eulers. Eulers it is a angles around each axis. What the value CAD etc display on widget? – Igor Shumakov Jan 25 '19 at 11:44
  • There are a variety of representations of rotation in space: A 3x3 matrix, a quaternion, any flavor of Euler (or Brian-Tait) angles, axis-angle, from vector - to vector, and may be more. Most of them can be converted to each other e.g. a 3x3 matrix to Euler angles. In the latter case there might be multiple solutions, so a stable algorithm has to consider to chose one. However, some of these representations are actually orientations and limited to one ful sphere e.g. the 3x3 matrix. These representations cannot turn more than 360°. – Scheff's Cat Jan 25 '19 at 12:13
  • but in maya, blender etc somehow show angles more than 360 – Igor Shumakov Jan 25 '19 at 12:36
  • @IgorShumakov because they do not use Euler angles ... Throw them in thrash where they belong (yes they have their purpose but its usually more pain than worth) use cumulative 4x4 transform matrix instead see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) especially the last links in there with examples of camera and player control ... its always a shame to see a good idea/SW/Game to use Eulers and suffer the bugs due it ... – Spektre Jan 25 '19 at 13:14
  • You might want to check out this website; it has all the information you need about 4x4 affine transformation matrices, how they are represented, how a point can be distinguished from a vector. It shows different forms of the 4x4 transformation matrix such as, translation, scaling, shearing, rotation and after you have an understanding of these, it continues with Euler angles and quaternions and how they are related and their differences. Happy Reading! http://brainvoyager.com/bv/doc/UsersGuide/CoordsAndTransforms/SpatialTransformationMatrices.html – Francis Cugler Jan 25 '19 at 14:13

1 Answers1

0

I had left a link in the comment section to your question. However as a quick answer to your problem I think this quote from that webpage should point you in the right direction:

"A sequence of rotations can be represented by a series of quaternions multiplied together, producing a single resulting quaternion that encodes the combined rotations."

The quote above can refer to either multiple quaternions each rotating around a different axis to get the combined rotation in 3D, or multiple rotations about the same axis that would accumulate to a single rotation that is more than 360 degrees.

Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
  • Yes multiplay matrix or quaternion can rotate more then 360, but after that you get result matrix or quaternion and how after that maya etc show in gui angles more then 360? After any multiplied manipulations you loose information about how many user rotate object 720 or more – Igor Shumakov Jan 25 '19 at 14:52
  • @IgorShumakov Without any code to see what you have tried it is hard to say exactly, but if you have your current position and orientation you can create a temporary copy of that. Then use that copy to do the transformation for the new position. Then you may need another variable like a basic `float`, `double`, `int` etc. that will update and represent your actual rotational value. Remember that your trigonometric functions `sin` & `cos` are circular functions. – Francis Cugler Jan 26 '19 at 00:05
  • Yes you are right. I added the code. No one seems to understand my question. – Igor Shumakov Jan 26 '19 at 11:01