Search code examples
c++visual-c++quaternionsglm-math

Determine position in front of quaternion with GLM?


Is there a way to calculate the XYZ position in front of a quaternion (XYZW) rotation, preferably using GLM?

I know the Quat rotation and the Position of the object I want to calculate the position in front of.

I know how to calculate the position in front of a rotation matrix where you have a Front vector, Up vector and Right vector, but in this case I only have XYZW values (where W is always 0, I never see it becomming 1..?)

In very short: The data I have: Quat (X Y Z W) and Position(X Y Z) and I want to calculate PositionInFront(Position, Quat, Distance, &X, &Y, &Z)

How to accomplish this goal?

I tried a cast to 3x3matrix and perform the Up,Right,Front (because a 3x3 matrix cast is these values, right?) calculations but they do not return the correct positions.

Or would it be possible to determine the objects Z Angle? (rotation around world Z / height axis only)


Solution

  • It seemed that there were 2 more quaternion structures for the vehicle which I forgot to use. and those 3 are the complete set needed for the Front,Right,Up calculation formula:

        float offX = 10.0f;
        float offY = 0.0f;
        float offZ = 0.0f;
    
        float x = offX * info.Rotation.Front.x + offY * info.Rotation.Right.x + offZ * info.Rotation.Up.x + info.Pos.x;
        float y = offX * info.Rotation.Front.y + offY * info.Rotation.Right.y + offZ * info.Rotation.Up.y + info.Pos.y;
        float z = offX * info.Rotation.Front.z + offY * info.Rotation.Right.z + offZ * info.Rotation.Up.z + info.Pos.z;
    
        float Angle = (atan2(x-info.Pos.x, y-info.Pos.y) * 180.0f / PI);