OVRSharp icon indicating copy to clipboard operation
OVRSharp copied to clipboard

Fix Matrix Transpose

Open LittleFinix opened this issue 4 years ago • 2 comments

The ToHmdMatrix34_t and ToMatrix4x4 methods do not properly transpose their matrices.

Dotnet uses row vectors, whereas ovr uses column vectors. This requires the entire Matrix to be transposed, but the current methods only transpose the last row/column (the translation component).

This isn't noticeable as long as scaling is uniform and rotation only happens along one axis, but does not allow for more complex affine transformations.

This pull request fixes this. However, this is a breaking change, since rotations now happen the other (correct) way around.

LittleFinix avatar Sep 11 '21 10:09 LittleFinix

Here's a demonstration:

There's a 'parent' and a 'local' ('test') overlay. The local overlay's matrix is multiplied with the parent to make their transformation relative to the parent.

The steps in this demo are:

  • move local overlay 25cm to the right
  • rotate local 90deg clockwise
  • rotate parent 45deg counter-clockwise
  • move parent 50cm forward (away)

Here's the version with the previous code: https://user-images.githubusercontent.com/3407997/132946105-52564624-17fd-4f58-8c43-53cea0be6ad8.mp4

And with the new code: https://user-images.githubusercontent.com/3407997/132946109-91ff89db-692b-4d8c-afd6-32f2b66c3159.mp4

Here's the code for the demo, it requires only OVRSharp and .net 6: https://gist.github.com/LittleFinix/92c355efd3f935b2d20ffca2ea4c61c3

LittleFinix avatar Sep 11 '21 11:09 LittleFinix

Thanks for the fix (and the detailed explanation/demo)! I'll test this out sometime this week and release this, maybe with a major version bump due to the breaking change.

tjhorner avatar Sep 13 '21 00:09 tjhorner