wavelength 1.0.0
Loading...
Searching...
No Matches
transform.h
Go to the documentation of this file.
1#pragma once
2
3#include "math/quaternion.h"
4#include "math/transformops.h"
5#include "math/vector3.h"
6#include "os/prnstream.h"
7
18struct alignas(16) Transform {
19 Vector3 mBasisX; // +0x00
20 Vector3 mBasisY; // +0x10
21 Vector3 mBasisZ; // +0x20
23};
24
26constexpr int kTransformRowCount = 4;
27
29constexpr int kTransformRowFloatCount = 4;
30
40inline void MultiplyPoint(const Transform &xfm, const Vector3 &v, Vector3 &out) {
41 const float fX =
42 xfm.mBasisX.x * v.x + xfm.mBasisY.x * v.y + xfm.mBasisZ.x * v.z + xfm.mTranslation.x;
43 const float fY =
44 xfm.mBasisX.y * v.x + xfm.mBasisY.y * v.y + xfm.mBasisZ.y * v.z + xfm.mTranslation.y;
45 const float fZ =
46 xfm.mBasisX.z * v.x + xfm.mBasisY.z * v.y + xfm.mBasisZ.z * v.z + xfm.mTranslation.z;
47 out.x = fX;
48 out.y = fY;
49 out.z = fZ;
50}
51
61inline void MultiplyVector(const Transform &xfm, const Vector3 &v, Vector3 &out) {
62 const float fX = xfm.mBasisX.x * v.x + xfm.mBasisY.x * v.y + xfm.mBasisZ.x * v.z;
63 const float fY = xfm.mBasisX.y * v.x + xfm.mBasisY.y * v.y + xfm.mBasisZ.y * v.z;
64 const float fZ = xfm.mBasisX.z * v.x + xfm.mBasisY.z * v.y + xfm.mBasisZ.z * v.z;
65 out.x = fX;
66 out.y = fY;
67 out.z = fZ;
68}
69
78inline void Multiply(Transform &out, const Transform &first, const Transform &second) {
79 sceVu0MulAffineMatrixXyz(&out.mBasisX.x, &first.mBasisX.x, &second.mBasisX.x);
80}
81
88inline void Invert(Transform &out, const Transform &xfm) {
89 InversMatrix(&out.mBasisX.x, &xfm.mBasisX.x);
90}
91
99inline void MakeScale(const Transform &xfm, Vector3 &scale) {
100 Mat33ExtractScale(&xfm.mBasisX.x, &scale.x);
101}
102
112PrnStream &operator<<(PrnStream &stream, const Transform &transform);
Text output stream.
Definition prnstream.h:16
void Mat33ExtractScale(const float *pMat3Rows, float *pScale)
Report the scale each basis row carries.
Affine transform stored as three basis rows and a translation row.
Definition transform.h:18
Vector3 mTranslation
Definition transform.h:22
Vector3 mBasisZ
Definition transform.h:21
Vector3 mBasisY
Definition transform.h:20
Vector3 mBasisX
Definition transform.h:19
Three-component vector, padded to a PlayStation 2 quadword.
Definition vector3.h:14
float x
Definition vector3.h:15
float y
Definition vector3.h:16
float z
Definition vector3.h:17
void MultiplyPoint(const Transform &xfm, const Vector3 &v, Vector3 &out)
Transform a point by the basis rows and the translation of a transform.
Definition transform.h:40
constexpr int kTransformRowCount
Rows in a transform held as a bare array, three of the basis and the translation.
Definition transform.h:26
PrnStream & operator<<(PrnStream &stream, const Transform &transform)
Write the four rows of a transform.
void MakeScale(const Transform &xfm, Vector3 &scale)
Report the length of each basis row, negating the third when the basis is left handed,...
Definition transform.h:99
void MultiplyVector(const Transform &xfm, const Vector3 &v, Vector3 &out)
Transform a direction by the basis rows of a transform, without the translation.
Definition transform.h:61
constexpr int kTransformRowFloatCount
Floats in a row of a transform held as a bare array, x, y, z, and padding.
Definition transform.h:29
void Multiply(Transform &out, const Transform &first, const Transform &second)
Concatenate two transforms, applying the second and then the first, with sceVu0MulAffineMatrixXyz().
Definition transform.h:78
void Invert(Transform &out, const Transform &xfm)
Invert a transform whose basis is orthonormal, with InversMatrix().
Definition transform.h:88
void sceVu0MulAffineMatrixXyz(float *pDst, const float *pA, const float *pB)
Multiply two affine transforms in the first three words of every row.
void InversMatrix(float *pDst, const float *pSrc)
Invert a rigid transform.