Stride: [Math] Quaternion expects left handed coordinate system

Created on 15 Feb 2019  路  3Comments  路  Source: stride3d/stride

Release Type: Any.

Version: Latest as of the time of writing.

Platform(s): Any.

Describe the bug
Xenko uses a right handed coordinate system(right < 0) while Quaternions expects a left handed one(right > 0), this leads to the issue described below.

What v should logically be equal to, given xenko's coordinate system, is a vector pointing downwards, but it returns a vector pointing upwards instead.

var right = new Vector3(-1f, 0f, 0f);
var forward = new Vector3(0f, 0f, 1f);
var deg90AsRad = 1.570796f;
var cw90Degrees = Quaternion.RotationAxis(right, deg90AsRad);
var v = Vector3.Transform(forward, cw90Degrees);

Well, good luck to whoever decides to fix that one !

bug

Most helpful comment

always fun to propagate knowledge. this topic is one of the most confusing in 3d engines and i never get tired to help anyone with it. happy coding!

All 3 comments

Xenko uses a right handed coordinate system (right < 0) while Quaternions expects a left handed one (right > 0), this leads to the issue described below.

this is technically not the right way to describe handedness. left/right handed is not (only) about the x-axis, it describes how the positive direction of the basis vectors of a coordinate system are related to each other.

the convention in xenko is:
right -> positive x
up -> positive y
forward -> negative z

which is indeed right handed.

image

so this assumption is incorrect:
> var right = new Vector3(-1f, 0f, 0f);

your camera matrix defines how you perceive the coordinate system on screen. e.g. if you look into the opposite direction, the x axis appears to be flipped.

see also slide 13-16 in this presentation:
https://docs.google.com/presentation/d/14rxW-qZ0ZwDIppdc_4uGGYc_Fdm10NbYLMXOKGZ-BCg/

quaternion math is a well defined set of operations and does not care about handedness at all. the calculations (e.g. multiplying a vector with a quaternion) are always the same. only the usage of it might change depending on the coordinate system convention. for example positive angles might be perceived differently in different coordinate systems.

Thank you for clarifying this, I should have know. I got too caught up be my own code to think this through !

always fun to propagate knowledge. this topic is one of the most confusing in 3d engines and i never get tired to help anyone with it. happy coding!

Was this page helpful?
0 / 5 - 0 ratings