Skip to content

Commit cb1c243

Browse files
committed
[orx-shapes] Fix frame orientation in frames()
1 parent b82ffb9 commit cb1c243

File tree

1 file changed

+11
-2
lines changed
  • orx-shapes/src/commonMain/kotlin/frames

1 file changed

+11
-2
lines changed

orx-shapes/src/commonMain/kotlin/frames/Frames.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ fun frames(positions: List<Vector3>, directions: List<Vector3> = emptyList(), up
3737
val forward = (directions.getOrNull(0) ?: (next - current)).normalized
3838
val right = (forward cross up).normalized
3939
up = ((right cross forward)).normalized
40-
result.add(Matrix44.fromColumnVectors(right.xyz0, up.xyz0, forward.xyz0, current.xyz1))
40+
val frame = Matrix44.fromColumnVectors(right.xyz0, up.xyz0, -forward.xyz0, current.xyz1)
41+
require(frame.determinant in 0.99..1.01) {
42+
"Initial frame determinant (${frame.determinant}) != 1.0"
43+
}
44+
result.add(frame)
4145
}
4246

4347
for (i in 1 until positions.size - 1) {
@@ -55,9 +59,14 @@ fun frames(positions: List<Vector3>, directions: List<Vector3> = emptyList(), up
5559
require(up.length > 0.0) { "`up.length` is zero or NaN in .frames()" }
5660
require(right.length > 0.0) { "`right.length` is zero or NaN in .frames()" }
5761

62+
val orientation = Matrix44.fromColumnVectors(right.xyz0, up.xyz0, -forward.xyz0, Vector4.UNIT_W)
63+
require(orientation.determinant in 0.99..1.01) {
64+
"Orientation determinant ${orientation.determinant} != 1.0"
65+
}
66+
5867
val m = buildTransform {
5968
translate(current)
60-
multiply(Matrix44.fromColumnVectors(right.xyz0, up.xyz0, forward.xyz0, Vector4.UNIT_W))
69+
multiply(orientation)
6170
}
6271

6372
result.add(m)

0 commit comments

Comments
 (0)