xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
477 stars 171 forks source link

Non-canonical matrix-vector product #540

Open VladislavShirinkinITEM opened 8 months ago

VladislavShirinkinITEM commented 8 months ago

https://github.com/xBimTeam/XbimEssentials/blob/ac8b9092b87ae401d91d53578388b2b746c26852/Xbim.Common/Geometry/XbimVector3D.cs#L188

See for example https://mathinsight.org/matrix_vector_multiplication

andyward commented 8 months ago

Can you be clear about what the issue relates to? If there's an issue it would help to see a failing test case

VladislavShirinkinITEM commented 8 months ago

This relates to integration with other projects, which uses canonical matrix operations. OpenGL and DirectX shaders for example. If we have many transforms we should know that multiplication order is different The case:

  1. M1 - element transform
  2. M2 - model transform
  3. M3 - world transform

multiplication order in GLSL to get screen coords from 3d-space:

u_1 = M_3 \times M_2 \times M_1 \times v

using xBim matrices we'll write

u_2 = v \times M_1 \times M_2 \times M_3

that because of

(M_1 \times M_2)^T = M_2^T \times M_1^T

Difference between u1 and u2 is transposition, but vector is just list of numbers we can't see difference.

andyward commented 8 months ago

Any thoughts @martin1cerny ? This is above my pay grade

I'm unsure of the implications. i.e. what is broken? what is this solution? what will break if we apply a solution? What test cases do we have around this.