From f6b533597609f2bb3adb8149bcfec4fc4be9e881 Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Sat, 14 Apr 2012 19:34:19 +0000 Subject: [PATCH] * Formatting and minor changes in Curve, Cylinder, PQTorus git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9303 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/scene/shape/Curve.java | 214 +++++++++--------- .../core/com/jme3/scene/shape/Cylinder.java | 2 + .../core/com/jme3/scene/shape/PQTorus.java | 27 +-- 3 files changed, 124 insertions(+), 119 deletions(-) diff --git a/engine/src/core/com/jme3/scene/shape/Curve.java b/engine/src/core/com/jme3/scene/shape/Curve.java index fbeda5955..dc92f5e8c 100644 --- a/engine/src/core/com/jme3/scene/shape/Curve.java +++ b/engine/src/core/com/jme3/scene/shape/Curve.java @@ -39,11 +39,12 @@ import java.util.Iterator; import java.util.List; /** - * A Curve is a visual, line-based representation of a {@link Spline}. - * The underlying Spline will be sampled N times where N is the number of - * segments as specified in the constructor. Each segment will represent - * one line in the generated mesh. - * + * A + * Curve is a visual, line-based representation of a {@link Spline}. + * The underlying Spline will be sampled N times where N is the number of + * segments as specified in the constructor. Each segment will represent one + * line in the generated mesh. + * * @author Nehon */ public class Curve extends Mesh { @@ -54,13 +55,12 @@ public class Curve extends Mesh { /** * Serialization only. Do not use. */ - public Curve(){ + public Curve() { } - + /** - * Create a curve mesh. - * Use a CatmullRom spline model that does not cycle. - * + * Create a curve mesh. Use a CatmullRom spline model that does not cycle. + * * @param controlPoints the control points to use to create this curve * @param nbSubSegments the number of subsegments between the control points */ @@ -70,7 +70,7 @@ public class Curve extends Mesh { /** * Create a curve mesh from a Spline - * + * * @param spline the spline to use * @param nbSubSegments the number of subsegments between the control points */ @@ -79,17 +79,17 @@ public class Curve extends Mesh { this.spline = spline; switch (spline.getType()) { case CatmullRom: - this.createCatmullRomMesh(nbSubSegments); + this.createCatmullRomMesh(nbSubSegments); break; case Bezier: - this.createBezierMesh(nbSubSegments); - break; + this.createBezierMesh(nbSubSegments); + break; case Nurb: - this.createNurbMesh(nbSubSegments); - break; + this.createNurbMesh(nbSubSegments); + break; case Linear: default: - this.createLinearMesh(); + this.createLinearMesh(); break; } } @@ -122,7 +122,7 @@ public class Curve extends Mesh { } i = 0; - int k = 0; + int k; for (int j = 0; j < (spline.getControlPoints().size() - 1) * nbSubSegments; j++) { k = j; indices[i] = (short) k; @@ -140,100 +140,101 @@ public class Curve extends Mesh { } /** - * This method creates the Bezier path for this curve. - * - * @param nbSubSegments - * amount of subsegments between position control points - */ - private void createBezierMesh(int nbSubSegments) { - if(nbSubSegments==0) { - nbSubSegments = 1; - } - int centerPointsAmount = (spline.getControlPoints().size() + 2) / 3; - - //calculating vertices - float[] array = new float[((centerPointsAmount - 1) * nbSubSegments + 1) * 3]; - int currentControlPoint = 0; - List controlPoints = spline.getControlPoints(); - int lineIndex = 0; - for (int i = 0; i < centerPointsAmount - 1; ++i) { - Vector3f vector3f = controlPoints.get(currentControlPoint); - array[lineIndex++] = vector3f.x; - array[lineIndex++] = vector3f.y; - array[lineIndex++] = vector3f.z; - for (int j = 1; j < nbSubSegments; ++j) { - spline.interpolate((float) j / nbSubSegments, currentControlPoint, temp); - array[lineIndex++] = temp.getX(); - array[lineIndex++] = temp.getY(); - array[lineIndex++] = temp.getZ(); - } - currentControlPoint += 3; - } - Vector3f vector3f = controlPoints.get(currentControlPoint); - array[lineIndex++] = vector3f.x; - array[lineIndex++] = vector3f.y; - array[lineIndex++] = vector3f.z; + * This method creates the Bezier path for this curve. + * + * @param nbSubSegments amount of subsegments between position control + * points + */ + private void createBezierMesh(int nbSubSegments) { + if (nbSubSegments == 0) { + nbSubSegments = 1; + } + int centerPointsAmount = (spline.getControlPoints().size() + 2) / 3; + + //calculating vertices + float[] array = new float[((centerPointsAmount - 1) * nbSubSegments + 1) * 3]; + int currentControlPoint = 0; + List controlPoints = spline.getControlPoints(); + int lineIndex = 0; + for (int i = 0; i < centerPointsAmount - 1; ++i) { + Vector3f vector3f = controlPoints.get(currentControlPoint); + array[lineIndex++] = vector3f.x; + array[lineIndex++] = vector3f.y; + array[lineIndex++] = vector3f.z; + for (int j = 1; j < nbSubSegments; ++j) { + spline.interpolate((float) j / nbSubSegments, currentControlPoint, temp); + array[lineIndex++] = temp.getX(); + array[lineIndex++] = temp.getY(); + array[lineIndex++] = temp.getZ(); + } + currentControlPoint += 3; + } + Vector3f vector3f = controlPoints.get(currentControlPoint); + array[lineIndex++] = vector3f.x; + array[lineIndex++] = vector3f.y; + array[lineIndex++] = vector3f.z; + + //calculating indexes + int i = 0, k; + short[] indices = new short[(centerPointsAmount - 1) * nbSubSegments << 1]; + for (int j = 0; j < (centerPointsAmount - 1) * nbSubSegments; ++j) { + k = j; + indices[i++] = (short) k; + ++k; + indices[i++] = (short) k; + } + + this.setMode(Mesh.Mode.Lines); + this.setBuffer(VertexBuffer.Type.Position, 3, array); + this.setBuffer(VertexBuffer.Type.Index, 2, indices); + this.updateBound(); + this.updateCounts(); + } + + /** + * This method creates the Nurb path for this curve. + * + * @param nbSubSegments amount of subsegments between position control + * points + */ + private void createNurbMesh(int nbSubSegments) { + float minKnot = spline.getMinNurbKnot(); + float maxKnot = spline.getMaxNurbKnot(); + float deltaU = (maxKnot - minKnot) / nbSubSegments; - //calculating indexes - int i = 0, k = 0; - short[] indices = new short[(centerPointsAmount - 1) * nbSubSegments << 1]; - for (int j = 0; j < (centerPointsAmount - 1) * nbSubSegments; ++j) { - k = j; - indices[i++] = (short) k; - ++k; - indices[i++] = (short) k; - } + float[] array = new float[(nbSubSegments + 1) * 3]; - this.setMode(Mesh.Mode.Lines); - this.setBuffer(VertexBuffer.Type.Position, 3, array); - this.setBuffer(VertexBuffer.Type.Index, 2, indices); - this.updateBound(); - this.updateCounts(); - } - - /** - * This method creates the Nurb path for this curve. - * @param nbSubSegments - * amount of subsegments between position control points - */ - private void createNurbMesh(int nbSubSegments) { - float minKnot = spline.getMinNurbKnot(); - float maxKnot = spline.getMaxNurbKnot(); - float deltaU = (maxKnot - minKnot)/nbSubSegments; - - float[] array = new float[(nbSubSegments + 1) * 3]; - - float u = minKnot; - Vector3f interpolationResult = new Vector3f(); - for(int i=0;i it = spline.getControlPoints().iterator(); it.hasNext();) { Vector3f vector3f = it.next(); @@ -260,12 +261,13 @@ public class Curve extends Mesh { this.updateBound(); this.updateCounts(); } - + /** * This method returns the length of the curve. + * * @return the length of the curve */ public float getLength() { - return spline.getTotalLength(); + return spline.getTotalLength(); } } diff --git a/engine/src/core/com/jme3/scene/shape/Cylinder.java b/engine/src/core/com/jme3/scene/shape/Cylinder.java index 85bb970fc..77af227ef 100644 --- a/engine/src/core/com/jme3/scene/shape/Cylinder.java +++ b/engine/src/core/com/jme3/scene/shape/Cylinder.java @@ -392,6 +392,7 @@ public class Cylinder extends Mesh { updateBound(); } + @Override public void read(JmeImporter e) throws IOException { super.read(e); InputCapsule capsule = e.getCapsule(this); @@ -404,6 +405,7 @@ public class Cylinder extends Mesh { inverted = capsule.readBoolean("inverted", false); } + @Override public void write(JmeExporter e) throws IOException { super.write(e); OutputCapsule capsule = e.getCapsule(this); diff --git a/engine/src/core/com/jme3/scene/shape/PQTorus.java b/engine/src/core/com/jme3/scene/shape/PQTorus.java index 26baed788..97901f5e6 100644 --- a/engine/src/core/com/jme3/scene/shape/PQTorus.java +++ b/engine/src/core/com/jme3/scene/shape/PQTorus.java @@ -105,17 +105,6 @@ public class PQTorus extends Mesh { return width; } - public void read(JmeImporter e) throws IOException { - super.read(e); - InputCapsule capsule = e.getCapsule(this); - p = capsule.readFloat("p", 0); - q = capsule.readFloat("q", 0); - radius = capsule.readFloat("radius", 0); - width = capsule.readFloat("width", 0); - steps = capsule.readInt("steps", 0); - radialSamples = capsule.readInt("radialSamples", 0); - } - /** * Rebuilds this torus based on a new set of parameters. * @@ -145,9 +134,9 @@ public class PQTorus extends Mesh { FloatBuffer fnb = createVector3Buffer(vertCount); FloatBuffer ftb = createVector2Buffer(vertCount); - Vector3f pointB = new Vector3f(), T = new Vector3f(), N = new Vector3f(), B = new Vector3f(); + Vector3f pointB, T, N, B; Vector3f tempNorm = new Vector3f(); - float r, x, y, z, theta = 0.0f, beta = 0.0f; + float r, x, y, z, theta = 0.0f, beta; int nvertex = 0; // Move along the length of the pq torus @@ -224,6 +213,18 @@ public class PQTorus extends Mesh { setBuffer(Type.Index, 3, sib); } + @Override + public void read(JmeImporter e) throws IOException { + super.read(e); + InputCapsule capsule = e.getCapsule(this); + p = capsule.readFloat("p", 0); + q = capsule.readFloat("q", 0); + radius = capsule.readFloat("radius", 0); + width = capsule.readFloat("width", 0); + steps = capsule.readInt("steps", 0); + radialSamples = capsule.readInt("radialSamples", 0); + } + @Override public void write(JmeExporter e) throws IOException { super.write(e);