forked from oakmound/ofbx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrotationOrder.go
44 lines (40 loc) · 1.07 KB
/
rotationOrder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package ofbx
import (
"github.com/oakmound/oak/v2/alg"
"github.com/oakmound/oak/v2/alg/floatgeom"
)
// RotationOrder determines the dimension order for rotation
type RotationOrder int
// A block of rotation order sets
const (
EulerXYZ RotationOrder = iota
EulerXZY RotationOrder = iota
EulerYZX RotationOrder = iota
EulerYXZ RotationOrder = iota
EulerZXY RotationOrder = iota
EulerZYX RotationOrder = iota
SphericXYZ RotationOrder = iota // Currently unsupported. Treated as EulerXYZ.
)
func (o RotationOrder) rotationMatrix(euler floatgeom.Point3) Matrix {
rx := rotationX(euler.X() * alg.DegToRad)
ry := rotationY(euler.Y() * alg.DegToRad)
rz := rotationZ(euler.Z() * alg.DegToRad)
switch o {
default:
case SphericXYZ:
panic("This should not happen")
case EulerXYZ:
return rz.Mul(ry).Mul(rx)
case EulerXZY:
return ry.Mul(rz).Mul(rx)
case EulerYXZ:
return rz.Mul(rx).Mul(ry)
case EulerYZX:
return rx.Mul(rz).Mul(ry)
case EulerZXY:
return ry.Mul(rx).Mul(rz)
case EulerZYX:
return rx.Mul(ry).Mul(rz)
}
panic("This shouldn't happen either")
}