The CatmullRomCurve and BezierCurve classes were creating some unnecessary garbage, this patch fixes that.
If there are no complaints I'll commit this early next week.
Cheers,
Ian.
For some reason, the forums don't show me when files are attached. Can you post the patch in code tags?
Looks good to me. But anyway please check if tests pass if you haven't done so ;).
Here's the patch, and I'll run through all of the tests and post the results in a couple of days.
Index: src/com/jme/curve/CatmullRomCurve.java
===================================================================
--- src/com/jme/curve/CatmullRomCurve.java (revision 4136)
+++ src/com/jme/curve/CatmullRomCurve.java (working copy)
@@ -143,15 +143,12 @@
// calculate tangent
Vector3f point = getPoint(time);
- Vector3f tangent = point.subtract(getPoint(time + precision));
- tangent = tangent.normalize();
+ Vector3f tangent = point.subtract(getPoint(time + precision)).normalizeLocal();
// calculate normal
Vector3f tangent2 = getPoint(time - precision).subtract(point);
- Vector3f normal = tangent.cross(tangent2);
- normal = normal.normalize();
+ Vector3f normal = tangent.cross(tangent2).normalizeLocal();
// calculate binormal
- Vector3f binormal = tangent.cross(normal);
- binormal = binormal.normalize();
+ Vector3f binormal = tangent.cross(normal).normalizeLocal();
// set columns
rotation.setColumn(0, tangent);
rotation.setColumn(1, normal);
@@ -179,14 +176,11 @@
}
Matrix3f rotation = new Matrix3f();
// calculate tangent
- Vector3f tangent = getPoint(time).subtract(getPoint(time + precision));
- tangent = tangent.normalize();
+ Vector3f tangent = getPoint(time).subtract(getPoint(time + precision)).normalizeLocal();
// calculate binormal
- Vector3f binormal = tangent.cross(up);
- binormal = binormal.normalize();
+ Vector3f binormal = tangent.cross(up).normalizeLocal();
// calculate normal
- Vector3f normal = binormal.cross(tangent);
- normal = normal.normalize();
+ Vector3f normal = binormal.cross(tangent).normalizeLocal();
// set columns
rotation.setColumn(0, tangent);
rotation.setColumn(1, normal);
Index: src/com/jme/curve/BezierCurve.java
===================================================================
--- src/com/jme/curve/BezierCurve.java (revision 4136)
+++ src/com/jme/curve/BezierCurve.java (working copy)
@@ -162,15 +162,12 @@
//calculate tangent
Vector3f point = getPoint(time);
- Vector3f tangent = point.subtract(getPoint(time + precision));
- tangent = tangent.normalize();
+ Vector3f tangent = point.subtract(getPoint(time + precision)).normalizeLocal();
//calculate normal
Vector3f tangent2 = getPoint(time - precision).subtract(point);
- Vector3f normal = tangent.cross(tangent2);
- normal = normal.normalize();
+ Vector3f normal = tangent.cross(tangent2).normalizeLocal();
//calculate binormal
- Vector3f binormal = tangent.cross(normal);
- binormal = binormal.normalize();
+ Vector3f binormal = tangent.cross(normal).normalizeLocal();
rotation.setColumn(0, tangent);
rotation.setColumn(1, normal);
@@ -198,16 +195,13 @@
Matrix3f rotation = new Matrix3f();
//calculate tangent
- Vector3f tangent = getPoint(time).subtract(getPoint(time + precision));
- tangent = tangent.normalize();
+ Vector3f tangent = getPoint(time).subtract(getPoint(time + precision)).normalizeLocal();
//calculate binormal
- Vector3f binormal = tangent.cross(up);
- binormal = binormal.normalize();
+ Vector3f binormal = tangent.cross(up).normalizeLocal();
//calculate normal
- Vector3f normal = binormal.cross(tangent);
- normal = normal.normalize();
+ Vector3f normal = binormal.cross(tangent).normalizeLocal();
rotation.setColumn(0, tangent);
rotation.setColumn(1, normal);
It's ok, I tested it.
I felt a bit guilty for asking you to pass tests for something like this.
Both CatmullCurveTest and BezierCurveTest pass. Patch looks fine :).
No problem.
Committed.