diff --git a/gglm/quat_test.go b/gglm/quat_test.go index a08ee51..a518991 100755 --- a/gglm/quat_test.go +++ b/gglm/quat_test.go @@ -25,3 +25,51 @@ func TestNewQuatAngleAxis(t *testing.T) { t.Errorf("Got: %v; Expected: %v", q.String(), ans.String()) } } + +func TestQuatAngle(t *testing.T) { + + a := gglm.NewQuatAngleAxis(180*gglm.Deg2Rad, gglm.NewVec3(0, 1, 0)).Angle() + var ans float32 = 180.0 * gglm.Deg2Rad + + if !gglm.EqF32(a, ans) { + t.Errorf("Got: %v; Expected: %v", a, ans) + } + + a = gglm.NewQuatAngleAxis(90*gglm.Deg2Rad, gglm.NewVec3(1, 1, 0).Normalize()).Angle() + ans = 90 * gglm.Deg2Rad + + if !gglm.EqF32(a, ans) { + t.Errorf("Got: %v; Expected: %v", a, ans) + } + + a = gglm.NewQuatAngleAxis(125*gglm.Deg2Rad, gglm.NewVec3(1, 1, 0).Normalize()).Angle() + ans = 125 * gglm.Deg2Rad + + if !gglm.EqF32(a, ans) { + t.Errorf("Got: %v; Expected: %v", a, ans) + } +} + +func TestQuatAxis(t *testing.T) { + + a := gglm.NewQuatAngleAxis(1, gglm.NewVec3(0, 1, 0)).Axis() + ans := gglm.NewVec3(0, 1, 0) + + if !gglm.EqF32(a.X(), ans.X()) || !gglm.EqF32(a.Y(), ans.Y()) || !gglm.EqF32(a.Z(), ans.Z()) { + t.Errorf("Got: %v; Expected: %v", a.String(), ans.String()) + } + + a = gglm.NewQuatAngleAxis(1, gglm.NewVec3(1, 1, 0).Normalize()).Axis() + ans = gglm.NewVec3(1, 1, 0).Normalize() + + if !gglm.EqF32(a.X(), ans.X()) || !gglm.EqF32(a.Y(), ans.Y()) || !gglm.EqF32(a.Z(), ans.Z()) { + t.Errorf("Got: %v; Expected: %v", a.String(), ans.String()) + } + + a = gglm.NewQuatAngleAxis(1, gglm.NewVec3(67, 46, 32).Normalize()).Axis() + ans = gglm.NewVec3(67, 46, 32).Normalize() + + if !gglm.EqF32(a.X(), ans.X()) || !gglm.EqF32(a.Y(), ans.Y()) || !gglm.EqF32(a.Z(), ans.Z()) { + t.Errorf("Got: %v; Expected: %v", a.String(), ans.String()) + } +} diff --git a/gglm/transform.go b/gglm/transform.go index 82a7c9c..de4ee81 100755 --- a/gglm/transform.go +++ b/gglm/transform.go @@ -27,6 +27,7 @@ func (t *TrMat) Scale(v *Vec3) { t.Data[2][2] *= v.Data[2] } +//Rotate takes a *normalized* axis and angles in radians to rotate around the given axis func (t *TrMat) Rotate(rads float32, axis *Vec3) { s := Sin32(rads)