mirror of
https://github.com/bloeys/gglm.git
synced 2025-12-29 13:38:20 +00:00
Quat axis and angle tests
This commit is contained in:
@ -25,3 +25,51 @@ func TestNewQuatAngleAxis(t *testing.T) {
|
|||||||
t.Errorf("Got: %v; Expected: %v", q.String(), ans.String())
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ func (t *TrMat) Scale(v *Vec3) {
|
|||||||
t.Data[2][2] *= v.Data[2]
|
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) {
|
func (t *TrMat) Rotate(rads float32, axis *Vec3) {
|
||||||
|
|
||||||
s := Sin32(rads)
|
s := Sin32(rads)
|
||||||
|
|||||||
Reference in New Issue
Block a user