Construct a matrix like so, where each vector is one column of the matrix:
[ House's X+ direction | House's Y+ direction | House's Z+ direction | House's position]
The fourth row should be [0, 0, 0, 1]
Since you're in Unreal with its right-handed coordinate system
- x -> right
- y -> back
- z -> up
we can write this as:
$$M = \begin{bmatrix} houseRight.x & -houseForward.x & houseUp.x & housePosition.x\\ houseRight.y & -houseForward.y & houseUp.y & housePosition.y\\ houseRight.z & -houseForward.z & houseUp.z & housePosition.z\\ 0 & 0 & 0 & 1 \end{bmatrix}$$
Multiplying a vector v
with v.w = 1
\$v\$ like this:
$$v = \begin{bmatrix}v.x\\v.y\\v.z\\1\end{bmatrix}$$
by this matrix like sogives us...
$$M v = \begin{bmatrix} houseRight \cdot v.xyz &+& housePosition.x \\ -houseForward \cdot v.xyz &+& housePosition.y \\ houseUp \cdot v.xyz &+& housePosition.z \\ &1& \end{bmatrix}^T$$
...which takes a coordinate v' = M v.xyz
will take a coordinate from house-local coordinates to global coordinates. You can verify that...
When
v = [0, 0, 0, 1]
(the origin), this matrix maps it to the center of the house - thev.w = 1
coordinate gets multiplied by the house position column in the matrix., and the rest get zero'd-outAs we increase
v.x
, the resultv'
moves along the house's X+ (right) direction, and so on for the Y (back) & Z (up)
To convert back from world coordinates to house-local coordinates, take the inverse of this matrix.