/* * 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 16, 2005 */ package ml.test; import junit.framework.TestCase; import ml.math.Plane; import ml.math.Ray; 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 PlaneTest extends TestCase { public static void main(String[] args) { junit.awtui.TestRunner.run(PlaneTest.class); } public void testFromPointAndVectors() { Vector3D point=new Vector3D(); Vector3D a=new Vector3D(); Vector3D b=new Vector3D(); Vector3D normal=new Vector3D(); point.X1=0.0; point.X2=1.0; point.X3=0.0; a.X1=1.0; a.X2=0.0; a.X3=0.0; b.X1=0.0; b.X2=0.0; b.X3=1.0; Plane p=new Plane(); p.fromPointAndVectors(point,a,b); normal.X1=0.0; normal.X2=-1.0; normal.X3=0.0; assertTrue(normal.equals(p.normal)); assertTrue(p.distance==1.0); } public void testFromPoints() { Vector3D point1=new Vector3D(); Vector3D point2=new Vector3D(); Vector3D point3=new Vector3D(); Vector3D normal=new Vector3D(); point1.X1=0.0; point1.X2=1.0; point1.X3=0.0; point2.X1=1.0; point2.X2=1.0; point2.X3=0.0; point3.X1=0.0; point3.X2=1.0; point3.X3=1.0; Plane p=new Plane(); p.fromPoints(point1,point2,point3); normal.X1=0.0; normal.X2=-1.0; normal.X3=0.0; assertTrue(normal.equals(p.normal)); assertTrue(p.distance==1.0); } public void testGetIntersectionPoint() { Vector3D point1=new Vector3D(); Vector3D point2=new Vector3D(); Vector3D point3=new Vector3D(); Ray ray=new Ray(); // make plane parallel to xz-plane point1.X1=0.0; point1.X2=1.0; point1.X3=0.0; point2.X1=1.0; point2.X2=1.0; point2.X3=0.0; point3.X1=0.0; point3.X2=1.0; point3.X3=1.0; Plane p=new Plane(); p.fromPoints(point1,point2,point3); ray.start.X1=0.0; ray.start.X2=0.0; ray.start.X3=0.0; ray.direction.X1=0.0; ray.direction.X2=1.0; ray.direction.X3=0.0; Vector3D intersection=p.getIntersectionPoint(ray); assertFalse(intersection==null); if(intersection!=null) { Vector3D result=new Vector3D(); result.X1=0.0; result.X2=1.0; result.X3=0.0; assertTrue(intersection.equals(result)); } // change plane to be at a 45-degree angle point1.X1=0.0; point1.X2=1.0; point1.X3=0.0; point2.X1=1.0; point2.X2=1.0; point2.X3=0.0; point3.X1=0.0; point3.X2=2.0; point3.X3=1.0; p.fromPoints(point1,point2,point3); // move ray start point off center ray.start.X1=0.0; ray.start.X2=0.0; ray.start.X3=1.0; ray.direction.X1=0.0; ray.direction.X2=1.0; ray.direction.X3=0.0; // test again intersection=p.getIntersectionPoint(ray); assertFalse(intersection==null); if(intersection!=null) { Vector3D result=new Vector3D(); result.X1=0.0; result.X2=2.0; result.X3=1.0; assertTrue(intersection.equals(result)); } } }