/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Feb 9, 2005 */ package ml.test; import junit.framework.TestCase; import ml.math.Matrix3; import ml.math.Quaternion; import ml.math.Vector3D; /** * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates * * @author gregor */ public class QuaternionTest extends TestCase { public void testEqualsQuaternion() { Quaternion a=new Quaternion(); Quaternion b=new Quaternion(); Quaternion c=new Quaternion(); a.w=1.0; a.x=2.0; a.y=3.0; a.z=4.0; b.w=1.0; b.x=2.0; b.y=3.0; b.z=4.0; c.w=2.0; c.x=2.0; c.y=3.0; c.z=4.0; assertTrue(a.equals(b)); assertTrue(b.equals(a)); assertFalse(a.equals(c)); assertFalse(c.equals(a)); } public void testClone() { Quaternion a=new Quaternion(); a.w=1.0; a.x=2.0; a.y=3.0; a.z=4.0; Quaternion b=a.clone(); assertTrue(b.equals(a)); assertFalse(b==a); } public void testAbs() { Quaternion a=new Quaternion(); a.w=3.0; a.x=0.0; a.y=0.0; a.z=0.0; assertTrue(a.abs()==3.0); } public void testNormalize() { //TODO Implement normalize(). } public void testGetRotationAxis() { //TODO Implement getRotationAxis(). } public void testGetRotationAngle() { //TODO Implement getRotationAngle(). } public void testToRotationMatrix() { Quaternion a=new Quaternion(); Matrix3 b, c; // this quaternion represents a rotation arount the x axis by Pi a.w=0.0; a.x=1.0; a.y=0.0; a.z=0.0; b=new Matrix3(); b=a.toRotationMatrix3(); c=new Matrix3(); for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { c.X[i][j]=0.0; } } c.X[0][0]=1.0; c.X[1][1]=-1.0; c.X[2][2]=-1.0; assertTrue(b.equals(c)); } public void testAdd() { Quaternion a=new Quaternion(); Quaternion b; Quaternion c=new Quaternion(); Quaternion d; a.w=1.0; a.x=1.0; a.y=1.0; a.z=1.0; b=a; c.w=2.0; c.x=2.0; c.y=2.0; c.z=2.0; d=a.add(b); assertTrue(d.equals(c)); } public void testSub() { Quaternion a=new Quaternion(); Quaternion b; Quaternion c=new Quaternion(); Quaternion d; a.w=1.0; a.x=1.0; a.y=1.0; a.z=1.0; b=a; c.w=0.0; c.x=0.0; c.y=0.0; c.z=0.0; d=a.sub(b); assertTrue(d.equals(c)); } public void testMulitplyScalar() { Quaternion a=new Quaternion(); Quaternion b=new Quaternion(); a.w=1.0; a.x=1.0; a.y=1.0; a.z=1.0; b.w=3.0; b.x=3.0; b.y=3.0; b.z=3.0; assertTrue(a.multiply(3).equals(b)); } public void testMultiplyQuaternion() { Quaternion a=new Quaternion(); Quaternion b=new Quaternion(); Quaternion c=new Quaternion(); a.w=1.0; a.x=1.0; a.y=1.0; a.z=1.0; b.w=2.0; b.x=2.0; b.y=2.0; b.z=2.0; c.w=-4.0; c.x=4.0; c.y=4.0; c.z=4.0; assertTrue(a.multiply(b).equals(c)); } public void testDotProduct() { //TODO Implement dotProduct(). } public void testFromAxisAngle() { Quaternion a=new Quaternion(); Quaternion b=new Quaternion(); Vector3D axis=new Vector3D(); double angle; axis.X1=1.0; axis.X2=0.0; axis.X3=0.0; angle=Math.PI/2; a.fromAxisAngle(axis,angle); b.w=Math.cos(angle/2.0); b.x=Math.sin(angle/2); b.y=0.0; b.z=0.0; assertTrue(a.equals(b)); } public void testSlerpTo() { //TODO Implement slerpTo(). } }