17 #ifndef INC_StdMeshMath
18 #define INC_StdMeshMath
42 float x{0},
y{0},
z{0};
56 static_assert((
sizeof(
StdMeshVertex) & 31) == 0,
"StdMeshVertex should be a multiple of 32 bytes");
111 const float*
data()
const {
return &a[0][0]; }
137 const float*
data()
const {
return &a[0][0]; }
184 template<
typename MatrixType>
185 void Translate(MatrixType& mat,
float dx,
float dy,
float dz)
187 static_assert(MatrixType::NColumns >= 4,
"Matrix must have at least 4 columns");
189 for (
int i = 0; i < MatrixType::NRows; ++i)
190 mat(i, 3) += mat(i,0)*dx + mat(i,1)*dy + mat(i,2)*dz;
194 template<
typename MatrixType>
195 void Scale(MatrixType& mat,
float sx,
float sy,
float sz)
197 static_assert(MatrixType::NColumns >= 3,
"Matrix must have at least 3 columns");
199 for (
int i = 0; i < MatrixType::NRows; ++i)
208 template<
typename MatrixType>
209 void Rotate(MatrixType& mat,
float angle,
float x,
float y,
float z)
215 template<
typename MatrixType>
216 void Perspective(MatrixType& mat,
float cot_fovy2,
float aspect,
float nearVal,
float farVal)
218 static_assert(MatrixType::NColumns >= 4,
"Matrix must have at least 4 columns");
220 const float fa = cot_fovy2 / aspect;
221 const float fb = cot_fovy2;
222 const float z1 = (nearVal + farVal) / (nearVal - farVal);
223 const float z2 = 2 * nearVal * farVal / (nearVal - farVal);
225 for (
int i = 0; i < MatrixType::NRows; ++i)
227 const float mat2 = mat(i, 2);
230 mat(i, 2) = mat2 * z1 - mat(i, 3);
231 mat(i, 3) = mat2 *
z2;
StdMeshMatrix operator+(const StdMeshMatrix &lhs, const StdMeshMatrix &rhs)
StdMeshVector & operator-=(StdMeshVector &lhs, const StdMeshVector &rhs)
StdMeshMatrix & operator*=(StdMeshMatrix &lhs, const StdMeshMatrix &rhs)
StdMeshQuaternion & operator+=(StdMeshQuaternion &lhs, const StdMeshQuaternion &rhs)
void Rotate(MatrixType &mat, float angle, float x, float y, float z)
StdMeshQuaternion operator-(const StdMeshQuaternion &rhs)
void Perspective(MatrixType &mat, float cot_fovy2, float aspect, float nearVal, float farVal)
void Scale(MatrixType &mat, float sx, float sy, float sz)
StdMeshMatrix operator*(const StdMeshMatrix &lhs, const StdMeshMatrix &rhs)
StdMeshVector operator/(const StdMeshVector &lhs, const StdMeshVector &rhs)
void Translate(MatrixType &mat, float dx, float dy, float dz)
static StdMeshMatrix Identity()
static StdMeshMatrix Inverse(const StdMeshMatrix &mat)
static StdMeshMatrix Rotate(float angle, float rx, float ry, float rz)
static StdMeshMatrix LookAt(const StdMeshVector &eye, const StdMeshVector ¢er, const StdMeshVector &up)
static StdMeshMatrix Scale(float sx, float sy, float sz)
float & operator()(int i, int j)
static StdMeshMatrix TransformInverse(const StdMeshTransformation &transform)
const float * data() const
static const int NColumns
StdMeshTransformation Decompose() const
float operator()(int i, int j) const
static StdMeshMatrix Translate(float dx, float dy, float dz)
static StdMeshMatrix Transform(const StdMeshTransformation &transform)
float Determinant() const
static StdMeshMatrix Zero()
static StdProjectionMatrix Scale(float sx, float sy, float sz)
static StdMeshMatrix Upper3x4(const StdProjectionMatrix &matrix)
static const int NColumns
float & operator()(int i, int j)
static StdProjectionMatrix Rotate(float angle, float rx, float ry, float rz)
static StdProjectionMatrix Translate(float dx, float dy, float dz)
float operator()(int i, int j) const
static StdProjectionMatrix Identity()
const float * data() const
static StdProjectionMatrix Orthographic(float left, float right, float bottom, float top)
static StdMeshQuaternion Zero()
static StdMeshQuaternion Nlerp(const StdMeshQuaternion &lhs, const StdMeshQuaternion &rhs, float w)
static StdMeshQuaternion AngleAxis(float theta, const StdMeshVector &axis)
static StdMeshVector Zero()
static StdMeshVector UnitScale()
static StdMeshVector Translate(float dx, float dy, float dz)
static StdMeshVector Cross(const StdMeshVector &lhs, const StdMeshVector &rhs)
uint16_t bone_index[MaxBoneWeightCount]
static const size_t MaxBoneWeightCount
float bone_weight[MaxBoneWeightCount]