1   /*
2    * Created on 2005-01-06
3    *
4    * TODO To change the template for this generated file go to
5    * Window - Preferences - Java - Code Style - Code Templates
6    */
7   package org.sourceforge.jvb3d.Loader;
8   
9   import javax.media.j3d.PointSound;
10  import javax.vecmath.Point3d;
11  import javax.vecmath.Point3f;
12  import javax.vecmath.Tuple3d;
13  import javax.vecmath.Tuple3f;
14  import javax.vecmath.Vector3f;
15  
16  import com.sun.j3d.utils.geometry.GeometryInfo;
17  
18  import junit.framework.TestCase;
19  
20  /***
21   * @author Develop
22   *
23   * TODO To change the template for this generated type comment go to
24   * Window - Preferences - Java - Code Style - Code Templates
25   */
26  public class SubSurfaceTest extends TestCase {
27  	SubSurface testedSurface = null;
28  	Point3d[] points = null;
29  	SubSurface tested2 = null;
30  	Point3d[] points2 = null;
31  	
32  	protected void setUp() throws Exception {
33  		super.setUp();
34  		points = new Point3d[4];
35  		points[0] = new Point3d(-3, 2, 0);
36  		points[1] = new Point3d(2, 2, 0);
37  		points[2] = new Point3d(2, -1, 0);
38  		points[3] = new Point3d(-3, -1, 0);
39  		testedSurface = new SubSurface(points);
40  		
41  		points2 = new Point3d[4];
42  		points2[0] = new Point3d(-6.456612, 5.947031, 0.000000);
43  		points2[1] = new Point3d(-6.456612, 8.947031, 0.000000);
44  		points2[2] = new Point3d(-6.456612, 8.947031, 2.600000);
45  		points2[3] = new Point3d(-6.456612, 5.947031, 2.600000);
46  		tested2 = new SubSurface(points2);
47  	}
48  	
49  	protected void tearDown() throws Exception {
50  		testedSurface = null;
51  		super.tearDown();
52  	}
53  	
54  	public void testIsInside() {
55  		assertTrue("Punkt (0,0,0) leży na powierzchni", testedSurface.isInside(new Point3d(0,0,0)));
56  		assertTrue("Punkt (-3,0,0) leży na powierzchni", testedSurface.isInside(new Point3d(-3,0,0)));
57  		assertTrue("Punkt (2,-1,0) leży na powierzchni", testedSurface.isInside(new Point3d(2,-1,0)));
58  		assertTrue("Punkt (0,2,0) leży na powierzchni", testedSurface.isInside(new Point3d(0,2,0)));
59  		
60  		assertTrue("Punkt (-4,2,0) nie leży na powierzchni", !testedSurface.isInside(new Point3d(-4,2,0)));
61  		assertTrue("Punkt (-3,3,0) nie leży na powierzchni", !testedSurface.isInside(new Point3d(-3,3,0)));
62  		assertTrue("Punkt (2,2.01,0) nie leży na powierzchni", !testedSurface.isInside(new Point3d(2,2.01,0)));
63  		assertTrue("Punkt (0,-1.1,0) nie leży na powierzchni", !testedSurface.isInside(new Point3d(0,-1.1,0)));
64  	}
65  
66  	public void testCutOpening() {
67  		Point3d[] cutPoints = new Point3d[4];
68  		
69  		cutPoints[0] = new Point3d(-2, 1, 0);
70  		cutPoints[1] = new Point3d(-1, 1, 0);
71  		cutPoints[2] = new Point3d(-1, 0, 0);
72  		cutPoints[3] = new Point3d(-2, 0, 0);
73  		
74  		Point3d cut2[] = new Point3d[4];
75  		
76  		cut2[0] = new Point3d(-6.456612, 6.171031, 0.000000);
77  		cut2[1] = new Point3d(-6.456612, 6.171031, 2.210000);
78  		cut2[2] = new Point3d(-6.456612, 7.238031, 2.210000);
79  		cut2[3] = new Point3d(-6.456612, 7.238031, 0.000000);
80  		
81  		SubSurface[] subsurfaces = tested2.cutOpening(cut2);
82  		
83  		/*for(int i=0; i<4; i++) {
84  			System.out.print(subsurfaces[i].vertices[0]);
85  			System.out.print(subsurfaces[i].vertices[1]);
86  			System.out.print(subsurfaces[i].vertices[2]);
87  			System.out.println(subsurfaces[i].vertices[3]);
88  		}*/
89  	}
90  
91  	public void testCreateBox() {
92  		GeometryInfo[] geometry = testedSurface.createBox();
93  		
94  		GeometryInfo[] geom2 = tested2.createBox();
95  		
96  		/*for(int i=0; i<6; i++) {
97  			System.out.print(geom2[i].getCoordinates()[0]);
98  			System.out.print(geom2[i].getCoordinates()[1]);
99  			System.out.print(geom2[i].getCoordinates()[2]);
100 			System.out.println(geom2[i].getCoordinates()[3]);
101 		}*/
102 		
103 		Point3f[] coords = geometry[0].getCoordinates();
104 		
105 		Point3d[] tempPoints = new Point3d[4];
106 		
107 		for(int i=0; i<4; i++) {
108 			tempPoints[i] = new Point3d(points[i]);
109 			tempPoints[i].z -= SubSurface.wallDefaultWidth;
110 		}
111 		for(int i=0; i<4; i++)
112 			assertTrue("Błąd przedniej powierzchni", tempPoints[i].epsilonEquals(new Point3d(coords[i]), 0.001));
113 		
114 		
115 		for(int i=0; i<4; i++) {
116 			tempPoints[i] = new Point3d(points[i]);
117 			tempPoints[i].z += SubSurface.wallDefaultWidth;
118 		}
119 		
120 		coords = geometry[1].getCoordinates();
121 		for(int i=0; i<4; i++)
122 			assertTrue("Błąd tylniej powierzchni", tempPoints[3-i].epsilonEquals(new Point3d(coords[i]), 0.001));
123 		
124 		Vector3f[] normals = new Vector3f[6];
125 		normals[0] = new Vector3f(0.0f, 0.0f, -1.0f);
126 		normals[1] = new Vector3f(0.0f, 0.0f, 1.0f);
127 		normals[2] = new Vector3f(-1.0f, 0.0f, 0.0f);
128 		normals[3] = new Vector3f(1.0f, 0.0f, 0.0f);
129 		normals[4] = new Vector3f(0.0f, 1.0f, 0.0f);
130 		normals[5] = new Vector3f(0.0f, -1.0f, 0.0f);
131 		
132 		for(int i=0; i<6; i++)
133 			assertTrue("Błędna normalna powierzchni "+i, normals[i].epsilonEquals(geometry[i].getNormals()[0], 0.001f));
134 	}
135 }