Skip to content

Commit

Permalink
kram - simd - add trs and tru calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alecazam committed Sep 28, 2024
1 parent 7f70bc6 commit 2b9d5c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 27 additions & 1 deletion libkram/vectormath/vectormath++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@
//
// col: TRS * TRS * v cameraToWorldTfm * worldToModelTfm * ..
// row: v * SRT * SRT modelToWorldTfm * worldToCameraTfm * ...

//
// TODO: need natvis and lldb formatting of math classes.
//
// TODO: here's a decomp
// https://github.com/erich666/GraphicsGems/blob/master/gemsii/unmatrix.c

//-----------------

Expand Down Expand Up @@ -883,6 +886,29 @@ float4x4 inverse_tru(const float4x4& mtx)
return inverse;
}

float4x4 float4x4_tr(float3 t, quatf r) {
float4x4 m(float4x4::identity());
m[3].xyz = t;
m = m * float4x4m(r);
return m;
}

// TODO: there are faster ways to apply post rot, post scale
float4x4 float4x4_trs(float3 t, quatf r, float3 scale) {
float4x4 m(float4x4::identity());
m[3].xyz = t;
m = m * float4x4m(r);

// TODO: *= not working
m = m * float4x4(float4m(scale,1.0f));
return m;
}

// leaving this in here, since it can be further optimized
float4x4 float4x4_tru(float3 t, quatf r, float scale) {
return float4x4_trs(t, r, float3m(scale));
}

float4x4 inverse_trs(const float4x4& mtx)
{
bool success = false;
Expand Down
4 changes: 4 additions & 0 deletions libkram/vectormath/vectormath++.h
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,10 @@ SIMD_CALL float4x4 float4x4m(float3 axis, float angleInRadians) {
return float4x4m(quatf(axis, angleInRadians));
}

float4x4 float4x4_tr(float3 t, quatf r);
float4x4 float4x4_trs(float3 t, quatf r, float3 scale);
float4x4 float4x4_tru(float3 t, quatf r, float scale);

#endif // SIMD_FLOAT


Expand Down

0 comments on commit 2b9d5c2

Please sign in to comment.