I
BezierPatch2 is "done", whiteout Savable
But he will not work, I need to make BezierMesh2 (damn hard for me :-o), i will need time to make this one…
Here comes the
//import java.io.IOException;
import com.jme.math.Vector3f;
import com.jme.system.JmeException;
//import com.jme.util.export.InputCapsule;
//import com.jme.util.export.JMEExporter;
//import com.jme.util.export.JMEImporter;
//import com.jme.util.export.OutputCapsule;
//import com.jme.util.export.Savable;
/
* <code>BezierPatch2</code> defines a ixj mesh of control points. The patch
* will be enough to generate a single section of a <code>BezierMesh2</code>.
* The detail level of the patch determines the smoothness of the resultant
* <code>BezierMesh2</code>.
@author Made by: Mark Powell / "Maimed" by: Andreasabe
* @version $Id: BezierPatch2.java,v 1.00 2008/06/xx nca Exp $
*/
public class BezierPatch2 { //implements Savable {
private Vector3f[][] anchors;
private int detailLevel, i, j;
/
* Constructor instantiates a new <code>BezierPatch2</code> with a default
* empty control point mesh and a detail level of zero.
*
* @param i
* the row size
* @param j
* the column size
*/
public BezierPatch2(int i, int j) {
this.i = i;
this.j = j;
anchors = new Vector3f[i][j];
detailLevel = 0;
}
/
* Constructor instantiates a new <code>BezierPatch2</code> with a given
* control point grid and a default detail level of zero.
*
* @param anchors
* the control points that make up the patch.
*/
public BezierPatch2(int i, int j, Vector3f[][] anchors) {
if (anchors.length != i || anchors[0].length != j) {
throw new JmeException("Bezier patch anchors must be ixj.");
}
this.i = i;
this.j = j;
this.anchors = anchors;
detailLevel = 0;
}
/
* Constructor instantiates a new <code>BezierPatch2</code> with a given
* control point grid and a given detail level.
*
* @param anchors
* the control points that make up the patch.
* @param detailLevel
* the detail level of the patch.
*/
public BezierPatch2(int i, int j, Vector3f[][] anchors, int detailLevel) {
if (anchors.length != i || anchors[0].length != j) {
throw new JmeException("Bezier patch anchors must be ixj.");
}
this.i = i;
this.j = j;
this.anchors = anchors;
this.detailLevel = detailLevel;
}
/
*
* <code>setAnchors</code> sets the control anchors of this patch.
*
* @param anchors
* the control anchors of this patch.
*/
public void setAnchors(Vector3f[][] anchors) {
if (anchors.length != i || anchors[0].length != j) {
throw new JmeException("Bezier patch anchors must be ixj.");
}
this.anchors = anchors;
}
/
*
* <code>getAnchors</code> returns the control anchors that make up this
* patch.
*
* @return the control anchors of this patch.
*/
public Vector3f[][] getAnchors() {
return anchors;
}
/
*
* <code>setAnchor</code> sets a single anchor of the patch.
*
* @param i
* the i index (row).
* @param j
* the j index (column).
* @param anchor
* the control anchor for this point.
*/
public void setAnchor(int i, int j, Vector3f anchor) {
if ((i < 0 || i > this.i) || (j < 0 || j > this.j)) {
throw new JmeException("Bezier Patch anchor out of bounds.");
}
anchors[i][j] = anchor;
}
/
*
* <code>getAnchor</code> returns a single control anchor of a given (i,
* j) of the patch.
*
* @param i
* the i index (row).
* @param j
* the j index (column).
* @return the control anchor of the given i,j.
*/
public Vector3f getAnchor(int i, int j) {
if ((i < 0 || i > this.i) || (j < 0 || j > this.j)) {
throw new JmeException("Bezier Patch anchor out of bounds.");
}
return anchors[i][j];
}
/
*
* <code>setDetailLevel</code> sets the detail level of this patch.
*
* @param detailLevel
* the detail level of this patch.
*/
public void setDetailLevel(int detailLevel) {
this.detailLevel = detailLevel;
}
/
*
* <code>getDetailLevel</code> retrieves the detail level of this patch.
*
* @return the detail level of this patch.
*/
public int getDetailLevel() {
return detailLevel;
}
// public void write(JMEExporter e) throws IOException {
// OutputCapsule capsule = e.getCapsule(this);
// capsule.write(anchors, "anchors", new Vector3f[4][4]);
// capsule.write(detailLevel, "detailLevel", 0);
// }
//
// public void read(JMEImporter e) throws IOException {
// InputCapsule capsule = e.getCapsule(this);
// Savable[][] savs = capsule.readSavableArray2D("anchors", new Vector3f[4][4]);
// if (savs != null) {
// for (int i = 0; i < savs.length; i++) {
// for (int j = 0; j < savs[i].length; j++) {
// anchors[i][j] = (Vector3f) savs[i][j];
// }
// }
// }
//
// detailLevel = capsule.readInt("detailLevel", 0);
// }
public Class getClassTag() {
return this.getClass();
}
}
Help me, i don't know what to do.
private Vector3f calcBerstein(float u, Vector3f[] p, int s) {
if (p.length != s) {
throw new JmeException("Point parameter must be the right one.");
}
Vector3f a[] = new Vector3f[s];
a[0] = p[0].mult((float) Math.pow(u, 3));
a[1] = p[1].mult(3 * (float) Math.pow(u, 2) * (1 - u));
a[2] = p[2].mult(3 * u * (float) Math.pow((1 - u), 2));
a[3] = p[3].mult((float) Math.pow((1 - u), 3));
Vector3f b = new Vector3f();
for (int k = 0; k < s; k++) {
b.addLocal(a[k]);
}
return b;
}
this code make all thing work. But this array of Vectors p[].mult and the Math.pow method are killing me... :'(
What seems to be the issue?
My brain and my free time. :’(
I