/** * returns the waypoint at the given index * @param i the index * @return returns the waypoint position */ public Vector3f getWayPoint(int i) { return spline.getControlPoints().get(i); }
/** * returns an iterator on the waypoints collection * @return */ public Iterator<Vector3f> iterator() { return spline.getControlPoints().iterator(); }
/** * return the number of waypoints of this path * @return */ public int getNbWayPoints() { return spline.getControlPoints().size(); }
/** * sets the curve tension * * @param curveTension the tension */ public void setCurveTension(float curveTension) { this.curveTension = curveTension; if(type==SplineType.CatmullRom && !getControlPoints().isEmpty()) { this.computeTotalLength(); } }
/** * remove the waypoint at the given index from the path * @param i the index of the waypoint to remove */ public void removeWayPoint(int i) { removeWayPoint(spline.getControlPoints().get(i)); }
private void createLinearMesh() { float[] array = new float[spline.getControlPoints().size() * 3]; short[] indices = new short[(spline.getControlPoints().size() - 1) * 2]; int i = 0; int cpt = 0; int k; int j = 0; for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { Vector3f vector3f = it.next(); array[i] = vector3f.getX();
private void createCatmullRomMesh(int nbSubSegments) { float[] array = new float[((spline.getControlPoints().size() - 1) * nbSubSegments + 1) * 3]; short[] indices = new short[(spline.getControlPoints().size() - 1) * nbSubSegments * 2]; int i = 0; int cptCP = 0; for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { Vector3f vector3f = it.next(); array[i] = vector3f.x; for (int j = 0; j < (spline.getControlPoints().size() - 1) * nbSubSegments; j++) { k = j; indices[i] = (short) k;
if(spline.getControlPoints() != null && spline.getControlPoints().size() > 0) { if(nbSubSegments == 0) { nbSubSegments = spline.getControlPoints().size() + 1; } else { nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1;
/** * This method interpolates the data for the nurbs curve. * @param u * the u value * @param nurbSpline * the nurbs spline definition * @param store * the resulting point in 3D space */ public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { if (nurbSpline.getType() != SplineType.Nurb) { throw new IllegalArgumentException("Given spline is not of a NURB type!"); } List<Vector3f> controlPoints = nurbSpline.getControlPoints(); float[] weights = nurbSpline.getWeights(); List<Float> knots = nurbSpline.getKnots(); int controlPointAmount = controlPoints.size(); store.set(Vector3f.ZERO); float delimeter = 0; for (int i = 0; i < controlPointAmount; ++i) { float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); store.addLocal(nurbSpline.getControlPoints().get(i) .mult(val)); delimeter += val; } store.divideLocal(delimeter); }
nbSubSegments = 1; int centerPointsAmount = (spline.getControlPoints().size() + 2) / 3; List<Vector3f> controlPoints = spline.getControlPoints(); int lineIndex = 0; for (int i = 0; i < centerPointsAmount - 1; ++i) {
/** * compute the index of the waypoint and the interpolation value according to a distance * returns a vector 2 containing the index in the x field and the interpolation value in the y field * @param distance the distance traveled on this path * @return the waypoint index and the interpolation value in a vector2 */ public Vector2f getWayPointIndexForDistance(float distance, Vector2f store) { float sum = 0; if(spline.getTotalLength() == 0){ store.set(0, 0); return store; } distance = distance % spline.getTotalLength(); int i = 0; for (Float len : spline.getSegmentsLength()) { if (sum + len >= distance) { return new Vector2f((float) i, (distance - sum) / len); } sum += len; i++; } store.set((float) spline.getControlPoints().size() - 1, 1.0f); return store; }
private void attachDebugNode(Node root) { if (debugNode == null) { debugNode = new Node(); Material m = assetManager.loadMaterial("Common/Materials/RedColor.j3m"); for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { Vector3f cp = it.next(); Geometry geo = new Geometry("box", new Box(0.3f, 0.3f, 0.3f)); geo.setLocalTranslation(cp); geo.setMaterial(m); debugNode.attachChild(geo); } switch (spline.getType()) { case CatmullRom: debugNode.attachChild(CreateCatmullRomPath()); break; case Linear: debugNode.attachChild(CreateLinearPath()); break; default: debugNode.attachChild(CreateLinearPath()); break; } root.attachChild(debugNode); } }
/** * returns the waypoint at the given index * @param i the index * @return returns the waypoint position */ public Vector3f getWayPoint(int i) { return spline.getControlPoints().get(i); }
/** * returns an iterator on the waypoints collection * @return */ public Iterator<Vector3f> iterator() { return spline.getControlPoints().iterator(); }
/** * return the number of waypoints of this path * @return */ public int getNbWayPoints() { return spline.getControlPoints().size(); }
/** * sets the curve tension * * @param curveTension the tension */ public void setCurveTension(float curveTension) { this.curveTension = curveTension; if(type==SplineType.CatmullRom && !getControlPoints().isEmpty()) { this.computeTotalLength(); } }
/** * remove the waypoint at the given index from the path * @param i the index of the waypoint to remove */ public void removeWayPoint(int i) { removeWayPoint(spline.getControlPoints().get(i)); }
/** * This method interpolates the data for the nurbs curve. * @param u * the u value * @param nurbSpline * the nurbs spline definition * @param store * the resulting point in 3D space */ public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { if (nurbSpline.getType() != SplineType.Nurb) { throw new IllegalArgumentException("Given spline is not of a NURB type!"); } List<Vector3f> controlPoints = nurbSpline.getControlPoints(); float[] weights = nurbSpline.getWeights(); List<Float> knots = nurbSpline.getKnots(); int controlPointAmount = controlPoints.size(); store.set(Vector3f.ZERO); float delimeter = 0; for (int i = 0; i < controlPointAmount; ++i) { float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); store.addLocal(nurbSpline.getControlPoints().get(i) .mult(val)); delimeter += val; } store.divideLocal(delimeter); }
/** * compute the index of the waypoint and the interpolation value according to a distance * returns a vector 2 containing the index in the x field and the interpolation value in the y field * @param distance the distance traveled on this path * @return the waypoint index and the interpolation value in a vector2 */ public Vector2f getWayPointIndexForDistance(float distance, Vector2f store) { float sum = 0; if(spline.getTotalLength() == 0){ store.set(0, 0); return store; } distance = distance % spline.getTotalLength(); int i = 0; for (Float len : spline.getSegmentsLength()) { if (sum + len >= distance) { return new Vector2f((float) i, (distance - sum) / len); } sum += len; i++; } store.set((float) spline.getControlPoints().size() - 1, 1.0f); return store; }
private void attachDebugNode(Node root) { if (debugNode == null) { debugNode = new Node(); Material m = assetManager.loadMaterial("Common/Materials/RedColor.j3m"); for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { Vector3f cp = it.next(); Geometry geo = new Geometry("box", new Box(0.3f, 0.3f, 0.3f)); geo.setLocalTranslation(cp); geo.setMaterial(m); debugNode.attachChild(geo); } switch (spline.getType()) { case CatmullRom: debugNode.attachChild(CreateCatmullRomPath()); break; case Linear: debugNode.attachChild(CreateLinearPath()); break; default: debugNode.attachChild(CreateLinearPath()); break; } root.attachChild(debugNode); } }