+ if (points[0].equals(points[1])) continue;
+ if (points[0].equals(points[2])) continue;
+ if (points[1].equals(points[2])) continue;
+ mesh.newT(points[0], points[1], points[2], norm.norm(), 1);
+ }
+ }
+
+ /**
+ * vGetNormal() finds the gradient of the scalar field at a point
+ * This gradient can be used as a very accurate vertx normal for
+ * lighting calculations
+ */
+ static void vGetNormal(SampledField sampledField, GLvector rfNormal, double fX, double fY, double fZ) {
+ rfNormal.fX =
+ sampledField.getSample(new Point(fX-0.01, fY, fZ)) -
+ sampledField.getSample(new Point(fX+0.01, fY, fZ));
+ rfNormal.fY =
+ sampledField.getSample(new Point(fX, fY-0.01, fZ)) -
+ sampledField.getSample(new Point(fX, fY+0.01, fZ));
+ rfNormal.fZ =
+ sampledField.getSample(new Point(fX, fY, fZ-0.01)) -
+ sampledField.getSample(new Point(fX, fY, fZ+0.01));
+ vNormalizeVector(rfNormal, rfNormal);
+ }
+
+ static void vNormalizeVector(GLvector rfVectorResult, GLvector rfVectorSource) {
+ double fOldLength;
+ double fScale;
+
+ fOldLength = Math.sqrt( (rfVectorSource.fX * rfVectorSource.fX) +
+ (rfVectorSource.fY * rfVectorSource.fY) +
+ (rfVectorSource.fZ * rfVectorSource.fZ) );
+
+ if(fOldLength == 0.0) {
+ rfVectorResult.fX = rfVectorSource.fX;
+ rfVectorResult.fY = rfVectorSource.fY;
+ rfVectorResult.fZ = rfVectorSource.fZ;
+ } else {
+ fScale = 1.0/fOldLength;
+ rfVectorResult.fX = rfVectorSource.fX*fScale;
+ rfVectorResult.fY = rfVectorSource.fY*fScale;
+ rfVectorResult.fZ = rfVectorSource.fZ*fScale;