Skip to main content
Adding specific matrix entries & details
Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

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 - the v.w = 1 coordinate gets multiplied by the house position column in the matrix., and the rest get zero'd-out

  • As we increase v.x, the result v' 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.

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]

Multiplying a vector v with v.w = 1 by this matrix like so v' = M v 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 - the v.w = 1 coordinate gets multiplied by the house position column in the matrix.

  • As we increase v.x, the result v' moves along the house's X+ direction, and so on for the Y & Z

To convert back from world coordinates to house-local coordinates, take the inverse of this matrix.

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\$ like this:

$$v = \begin{bmatrix}v.x\\v.y\\v.z\\1\end{bmatrix}$$

by this matrix gives 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.xyz 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 - the v.w = 1 coordinate gets multiplied by the house position column in the matrix, and the rest get zero'd-out

  • As we increase v.x, the result v' 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.

Source Link
DMGregory
  • 136.3k
  • 22
  • 247
  • 373

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]

Multiplying a vector v with v.w = 1 by this matrix like so v' = M v 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 - the v.w = 1 coordinate gets multiplied by the house position column in the matrix.

  • As we increase v.x, the result v' moves along the house's X+ direction, and so on for the Y & Z

To convert back from world coordinates to house-local coordinates, take the inverse of this matrix.