| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "eu/base/transform.h" |
| 2 |
|
|
|
| 3 |
|
|
#include <cmath> |
| 4 |
|
|
#include <algorithm> |
| 5 |
|
|
|
| 6 |
|
|
namespace eu |
| 7 |
|
|
{ |
| 8 |
|
|
Transform |
| 9 |
|
✗ |
transform_from_matrix(const m4& m) |
| 10 |
|
|
{ |
| 11 |
|
|
// heavily inspired by DecomposeMatrixToComponents from imguizmo |
| 12 |
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 24 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 24 not taken.
|
✗ |
const auto right = m.get_column(0).to_vec3(0.0f); |
| 13 |
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 25 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 25 not taken.
|
✗ |
const auto up = m.get_column(1).to_vec3(0.0f); |
| 14 |
0/4
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 26 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 26 not taken.
|
✗ |
const auto out = m.get_column(2).to_vec3(0.0f); |
| 15 |
|
|
|
| 16 |
|
|
const auto scale = v3 |
| 17 |
|
|
{ |
| 18 |
|
|
right.get_length(), |
| 19 |
|
|
up.get_length(), |
| 20 |
|
|
out.get_length() |
| 21 |
0/6
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 31 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 31 not taken.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 31 not taken.
|
✗ |
}; |
| 22 |
|
|
|
| 23 |
|
|
// orthonormalize the basis to drop the scale |
| 24 |
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 27 not taken.
|
✗ |
const auto normalized_right = right.get_normalized().value_or(kk::right); |
| 25 |
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 28 not taken.
|
✗ |
const auto normalized_up = up.get_normalized().value_or(kk::up); |
| 26 |
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 29 not taken.
|
✗ |
const auto normalized_out = out.get_normalized().value_or(kk::out); |
| 27 |
|
|
|
| 28 |
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 31 not taken.
|
✗ |
const auto rotation_matrix = m4::from_basis(normalized_right, normalized_up, normalized_out); |
| 29 |
|
|
|
| 30 |
|
|
return |
| 31 |
|
|
{ |
| 32 |
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 31 not taken.
|
✗ |
.position = m.get_translation(), |
| 33 |
0/4
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 30 not taken.
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 30 not taken.
|
✗ |
.rotation = Q::from_rotation_matrix(rotation_matrix).get_normalized(), |
| 34 |
|
|
.scale = scale |
| 35 |
|
✗ |
}; |
| 36 |
|
|
} |
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
m4 |
| 40 |
|
✗ |
matrix_from_transform(const Transform& t) |
| 41 |
|
|
{ |
| 42 |
|
|
// heavily inspired by RecomposeMatrixFromComponents from imguizmo |
| 43 |
|
|
|
| 44 |
|
|
const auto rotation = m4::from_basis |
| 45 |
0/2
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 13 not taken.
|
✗ |
( |
| 46 |
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 13 not taken.
|
✗ |
t.rotation.get_local_right(), |
| 47 |
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 14 not taken.
|
✗ |
t.rotation.get_local_up(), |
| 48 |
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 15 not taken.
|
✗ |
t.rotation.get_local_out() |
| 49 |
|
|
); |
| 50 |
|
|
|
| 51 |
0/8
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 18 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 16 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 16 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 16 not taken.
|
✗ |
return m4::from_translation(t.position) * rotation * m4::from_scale(t.scale); |
| 52 |
|
|
} |
| 53 |
|
|
} |
| 54 |
|
|
|