/* */ package com.sun.j3d.utils.geometry;
/* */
/* */ import javax.vecmath.Matrix4f;
/* */ import javax.vecmath.Point3f;
/* */ import javax.vecmath.Vector3f;
/* */
/* */ class Project
/* */ {
/* */ static void projectFace(Triangulator triRef, int loopMin, int loopMax)
/* */ {
/* 31 */ Vector3f normal = new Vector3f();
/* 32 */ Vector3f nr = new Vector3f();
/* */
/* 37 */ determineNormal(triRef, triRef.loops[loopMin], normal);
/* 38 */ int j = loopMin + 1;
/* 39 */ if (j < loopMax) {
/* 40 */ for (int i = j; i < loopMax; i++) {
/* 41 */ determineNormal(triRef, triRef.loops[i], nr);
/* 42 */ if (Basic.dotProduct(normal, nr) < 0.0D) {
/* 43 */ Basic.invertVector(nr);
/* */ }
/* 45 */ Basic.vectorAdd(normal, nr, normal);
/* */ }
/* 47 */ double d = Basic.lengthL2(normal);
/* 48 */ if (Numerics.gt(d, 1.0E-008D)) {
/* 49 */ Basic.divScalar(d, normal);
/* */ }
/* */ else
/* */ {
/* 53 */ normal.x = (normal.y = 0.0F);
/* 54 */ normal.z = 1.0F;
/* */ }
/* */
/* */ }
/* */
/* 63 */ projectPoints(triRef, loopMin, loopMax, normal);
/* */ }
/* */
/* */ static void determineNormal(Triangulator triRef, int ind, Vector3f normal)
/* */ {
/* 79 */ int ind1 = ind;
/* 80 */ int i1 = triRef.fetchData(ind1);
/* 81 */ int ind0 = triRef.fetchPrevData(ind1);
/* 82 */ int i0 = triRef.fetchData(ind0);
/* 83 */ int ind2 = triRef.fetchNextData(ind1);
/* 84 */ int i2 = triRef.fetchData(ind2);
/* 85 */ Vector3f pq = new Vector3f();
/* 86 */ Basic.vectorSub(triRef.vertices[i0], triRef.vertices[i1], pq);
/* 87 */ Vector3f pr = new Vector3f();
/* 88 */ Basic.vectorSub(triRef.vertices[i2], triRef.vertices[i1], pr);
/* 89 */ Vector3f nr = new Vector3f();
/* 90 */ Basic.vectorProduct(pq, pr, nr);
/* 91 */ double d = Basic.lengthL2(nr);
/* 92 */ if (Numerics.gt(d, 1.0E-008D)) {
/* 93 */ Basic.divScalar(d, nr);
/* 94 */ normal.set(nr);
/* */ }
/* */ else {
/* 97 */ normal.x = (normal.y = normal.z = 0.0F);
/* */ }
/* */
/* 100 */ pq.set(pr);
/* 101 */ ind1 = ind2;
/* 102 */ ind2 = triRef.fetchNextData(ind1);
/* 103 */ i2 = triRef.fetchData(ind2);
/* 104 */ while (ind1 != ind) {
/* 105 */ Basic.vectorSub(triRef.vertices[i2], triRef.vertices[i1], pr);
/* 106 */ Basic.vectorProduct(pq, pr, nr);
/* 107 */ d = Basic.lengthL2(nr);
/* 108 */ if (Numerics.gt(d, 1.0E-008D)) {
/* 109 */ Basic.divScalar(d, nr);
/* 110 */ if (Basic.dotProduct(normal, nr) < 0.0D) {
/* 111 */ Basic.invertVector(nr);
/* */ }
/* 113 */ Basic.vectorAdd(normal, nr, normal);
/* */ }
/* 115 */ pq.set(pr);
/* 116 */ ind1 = ind2;
/* 117 */ ind2 = triRef.fetchNextData(ind1);
/* 118 */ i2 = triRef.fetchData(ind2);
/* */ }
/* */
/* 121 */ d = Basic.lengthL2(normal);
/* 122 */ if (Numerics.gt(d, 1.0E-008D)) {
/* 123 */ Basic.divScalar(d, normal);
/* */ }
/* */ else
/* */ {
/* 127 */ normal.x = (normal.y = 0.0F); normal.z = 1.0F;
/* */ }
/* */ }
/* */
/* */ static void projectPoints(Triangulator triRef, int i1, int i2, Vector3f n3)
/* */ {
/* 146 */ Matrix4f matrix = new Matrix4f();
/* 147 */ Point3f vtx = new Point3f();
/* */
/* 154 */ Vector3f n1 = new Vector3f();
/* 155 */ Vector3f n2 = new Vector3f();
/* */
/* 160 */ if ((Math.abs(n3.x) > 0.1D) || (Math.abs(n3.y) > 0.1D)) {
/* 161 */ n1.x = (-n3.y);
/* 162 */ n1.y = n3.x;
/* 163 */ n1.z = 0.0F;
/* */ }
/* */ else {
/* 166 */ n1.x = n3.z;
/* 167 */ n1.z = (-n3.x);
/* 168 */ n1.y = 0.0F;
/* */ }
/* 170 */ double d = Basic.lengthL2(n1);
/* 171 */ Basic.divScalar(d, n1);
/* 172 */ Basic.vectorProduct(n1, n3, n2);
/* 173 */ d = Basic.lengthL2(n2);
/* 174 */ Basic.divScalar(d, n2);
/* */
/* 179 */ matrix.m00 = n1.x;
/* 180 */ matrix.m01 = n1.y;
/* 181 */ matrix.m02 = n1.z;
/* 182 */ matrix.m03 = 0.0F;
/* 183 */ matrix.m10 = n2.x;
/* 184 */ matrix.m11 = n2.y;
/* 185 */ matrix.m12 = n2.z;
/* 186 */ matrix.m13 = 0.0F;
/* 187 */ matrix.m20 = n3.x;
/* 188 */ matrix.m21 = n3.y;
/* 189 */ matrix.m22 = n3.z;
/* 190 */ matrix.m23 = 0.0F;
/* 191 */ matrix.m30 = 0.0F;
/* 192 */ matrix.m31 = 0.0F;
/* 193 */ matrix.m32 = 0.0F;
/* 194 */ matrix.m33 = 1.0F;
/* */
/* 201 */ triRef.initPnts(20);
/* 202 */ for (int i = i1; i < i2; i++) {
/* 203 */ int ind = triRef.loops[i];
/* 204 */ int ind1 = ind;
/* 205 */ int j1 = triRef.fetchData(ind1);
/* 206 */ matrix.transform(triRef.vertices[j1], vtx);
/* 207 */ j1 = triRef.storePoint(vtx.x, vtx.y);
/* 208 */ triRef.updateIndex(ind1, j1);
/* 209 */ ind1 = triRef.fetchNextData(ind1);
/* 210 */ j1 = triRef.fetchData(ind1);
/* 211 */ while (ind1 != ind) {
/* 212 */ matrix.transform(triRef.vertices[j1], vtx);
/* 213 */ j1 = triRef.storePoint(vtx.x, vtx.y);
/* 214 */ triRef.updateIndex(ind1, j1);
/* 215 */ ind1 = triRef.fetchNextData(ind1);
/* 216 */ j1 = triRef.fetchData(ind1);
/* */ }
/* */ }
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.utils.geometry.Project
* JD-Core Version: 0.6.2
*/