com.jme3.math.Vector4f Java Examples

The following examples show how to use com.jme3.math.Vector4f. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Surface.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Constructor. Constructs required surface.
 * @param controlPoints space control points
 * @param nurbKnots knots of the surface
 * @param uSegments the amount of U segments
 * @param vSegments the amount of V segments
 * @param basisUFunctionDegree the degree of basis U function
 * @param basisVFunctionDegree the degree of basis V function
 * @param smooth defines if the mesu should be smooth (true) or flat (false)
 */
private Surface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree, boolean smooth) {
    this.validateInputData(controlPoints, nurbKnots, uSegments, vSegments);
    type = SplineType.Nurb;
    this.uSegments = uSegments;
    this.vSegments = vSegments;
    this.controlPoints = controlPoints;
    knots = nurbKnots;
    this.basisUFunctionDegree = basisUFunctionDegree;
    CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[0], basisUFunctionDegree);
    if (nurbKnots[1] != null) {
        this.basisVFunctionDegree = basisVFunctionDegree;
        CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[1], basisVFunctionDegree);
    }

    this.buildSurface(smooth);
}
 
Example #2
Source File: Surface.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method validates the input data. It throws {@link IllegalArgumentException} if
 * the data is invalid.
 * @param controlPoints space control points
 * @param nurbKnots knots of the surface
 * @param uSegments the amount of U segments
 * @param vSegments the amount of V segments
 */
private void validateInputData(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
        int uSegments, int vSegments) {
    int uPointsAmount = controlPoints.get(0).size();
    for (int i = 1; i < controlPoints.size(); ++i) {
        if (controlPoints.get(i).size() != uPointsAmount) {
            throw new IllegalArgumentException("The amount of 'U' control points is invalid!");
        }
    }
    if (uSegments <= 0) {
        throw new IllegalArgumentException("U segments amount should be positive!");
    }
    if (vSegments < 0) {
        throw new IllegalArgumentException("V segments amount cannot be negative!");
    }
    if (nurbKnots.length != 2) {
        throw new IllegalArgumentException("Nurb surface should have two rows of knots!");
    }
    for (int i = 0; i < nurbKnots.length; ++i) {
        for (int j = 0; j < nurbKnots[i].size() - 1; ++j) {
            if (nurbKnots[i].get(j) > nurbKnots[i].get(j + 1)) {
                throw new IllegalArgumentException("The knots' values cannot decrease!");
            }
        }
    }
}
 
Example #3
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Generate a new FloatBuffer using the given array of Vector4 objects. The
 * FloatBuffer will be 4 * data.length long and contain the vector data.
 *
 * @param data
 *            array of Vector4 objects to place into a new FloatBuffer
 * @return a new direct, flipped FloatBuffer, or null if data was null
 */
public static FloatBuffer createFloatBuffer(Vector4f... data) {
    if (data == null) {
        return null;
    }
    FloatBuffer buff = createFloatBuffer(4 * data.length);
    for (int x = 0; x < data.length; x++) {
        if (data[x] != null) {
            buff.put(data[x].getX()).put(data[x].getY()).put(data[x].getZ()).put(data[x].getW());
        } else {
            buff.put(0).put(0).put(0).put(0);
        }
    }
    buff.flip();
    return buff;
}
 
Example #4
Source File: Surface.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Constructor. Constructs required surface.
 * @param controlPoints space control points
 * @param nurbKnots knots of the surface
 * @param uSegments the amount of U segments
 * @param vSegments the amount of V segments
 * @param basisUFunctionDegree the degree of basis U function
 * @param basisVFunctionDegree the degree of basis V function
 */
private Surface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
        int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) {
    this.validateInputData(controlPoints, nurbKnots, uSegments, vSegments);
    this.type = SplineType.Nurb;
    this.uSegments = uSegments;
    this.vSegments = vSegments;
    this.controlPoints = controlPoints;
    this.knots = nurbKnots;
    this.basisUFunctionDegree = basisUFunctionDegree;
    CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[0], basisUFunctionDegree);
    if (nurbKnots[1] != null) {
        this.basisVFunctionDegree = basisVFunctionDegree;
        CurveAndSurfaceMath.prepareNurbsKnots(nurbKnots[1], basisVFunctionDegree);
    }

    this.buildSurface();
}
 
Example #5
Source File: Surface.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This method validates the input data. It throws {@link IllegalArgumentException} if
 * the data is invalid.
 * @param controlPoints space control points
 * @param nurbKnots knots of the surface
 * @param uSegments the amount of U segments
 * @param vSegments the amount of V segments
 */
private void validateInputData(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
        int uSegments, int vSegments) {
    int uPointsAmount = controlPoints.get(0).size();
    for (int i = 1; i < controlPoints.size(); ++i) {
        if (controlPoints.get(i).size() != uPointsAmount) {
            throw new IllegalArgumentException("The amount of 'U' control points is invalid!");
        }
    }
    if (uSegments <= 0) {
        throw new IllegalArgumentException("U segments amount should be positive!");
    }
    if (vSegments < 0) {
        throw new IllegalArgumentException("V segments amount cannot be negative!");
    }
    if (nurbKnots.length != 2) {
        throw new IllegalArgumentException("Nurb surface should have two rows of knots!");
    }
    for (int i = 0; i < nurbKnots.length; ++i) {
        for (int j = 0; j < nurbKnots[i].size() - 1; ++j) {
            if (nurbKnots[i].get(j) > nurbKnots[i].get(j + 1)) {
                throw new IllegalArgumentException("The knots' values cannot decrease!");
            }
        }
    }
}
 
Example #6
Source File: LwjglKernel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setArg(int index, Vector4f v) {
    FloatBuffer buf = Utils.tempBuffers[0].b16f;
    buf.position(0);
    buf.limit(4);
    buf.put(0, v.x);
    buf.put(1, v.y);
    buf.put(2, v.z);
    buf.put(3, v.w);
    int ret = CL10.clSetKernelArg(kernel, index, buf);
    Utils.checkError(ret, "clSetKernelArg");
}
 
Example #7
Source File: IrUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void toTangentsWithParity(IrVertex vertex) {
    if (vertex.tang != null && vertex.bitang != null) {
        float wCoord = vertex.norm.cross(vertex.tang).dot(vertex.bitang) < 0f ? -1f : 1f;
        vertex.tang4d = new Vector4f(vertex.tang.x, vertex.tang.y, vertex.tang.z, wCoord);
        vertex.tang = null;
        vertex.bitang = null;
    }
}
 
Example #8
Source File: LwjglKernel.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void setArg(int index, Vector4f v) {
    int ret = CL10.clSetKernelArg4f(kernel, index, v.x, v.y, v.z, v.w);
    Utils.checkError(ret, "clSetKernelArg");
}
 
Example #9
Source File: Surface.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public List<List<Vector4f>> getControlPoints() {
    return controlPoints;
}
 
Example #10
Source File: Surface.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public List<List<Vector4f>> getControlPoints() {
    return controlPoints;
}
 
Example #11
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Sets the data contained in the given vector4 into the FloatBuffer at the
 * specified index.
 *
 * @param vec
 *            the {@link Vector4f} to insert
 * @param buf
 *            the buffer to insert into
 * @param index
 *            the position to place the data; in terms of vector4 not floats
 */
public static void setInBuffer(Vector4f vec, FloatBuffer buf, int index) {
    buf.position(index * 4);
    buf.put(vec.getX());
    buf.put(vec.getY());
    buf.put(vec.getZ());
    buf.put(vec.getW());
}
 
Example #12
Source File: BufferUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Updates the values of the given vector from the specified buffer at the
 * index provided.
 *
 * @param vector
 *            the vector to set data on
 * @param buf
 *            the buffer to read from
 * @param index
 *            the position (in terms of vectors, not floats) to read from
 *            the buf
 */
public static void populateFromBuffer(Vector4f vector, FloatBuffer buf, int index) {
    vector.x = buf.get(index * 4);
    vector.y = buf.get(index * 4 + 1);
    vector.z = buf.get(index * 4 + 2);
    vector.w = buf.get(index * 4 + 3);
}
 
Example #13
Source File: Surface.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * This method creates a NURBS surface.
 * @param controlPoints space control points
 * @param nurbKnots knots of the surface
 * @param uSegments the amount of U segments
 * @param vSegments the amount of V segments
 * @param basisUFunctionDegree the degree of basis U function
 * @param basisVFunctionDegree the degree of basis V function
 * @return an instance of NURBS surface
 */
public static final Surface createNurbsSurface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots,
        int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) {
    Surface result = new Surface(controlPoints, nurbKnots, uSegments, vSegments, basisUFunctionDegree, basisVFunctionDegree);
    result.type = SplineType.Nurb;
    return result;
}
 
Example #14
Source File: Surface.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * This method creates a NURBS surface. The created mesh is smooth by default.
 * @param controlPoints
 *            space control points
 * @param nurbKnots
 *            knots of the surface
 * @param uSegments
 *            the amount of U segments
 * @param vSegments
 *            the amount of V segments
 * @param basisUFunctionDegree
 *            the degree of basis U function
 * @param basisVFunctionDegree
 *            the degree of basis V function
 * @return an instance of NURBS surface
 */
public static final Surface createNurbsSurface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree) {
    return Surface.createNurbsSurface(controlPoints, nurbKnots, uSegments, vSegments, basisUFunctionDegree, basisVFunctionDegree, true);
}
 
Example #15
Source File: Surface.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * This method creates a NURBS surface.
 * @param controlPoints space control points
 * @param nurbKnots knots of the surface
 * @param uSegments the amount of U segments
 * @param vSegments the amount of V segments
 * @param basisUFunctionDegree the degree of basis U function
 * @param basisVFunctionDegree the degree of basis V function
 * @return an instance of NURBS surface
 */
public static final Surface createNurbsSurface(List<List<Vector4f>> controlPoints, List<Float>[] nurbKnots, int uSegments, int vSegments, int basisUFunctionDegree, int basisVFunctionDegree, boolean smooth) {
    Surface result = new Surface(controlPoints, nurbKnots, uSegments, vSegments, basisUFunctionDegree, basisVFunctionDegree, smooth);
    result.type = SplineType.Nurb;
    return result;
}
 
Example #16
Source File: Material.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Pass a Vector4f to the material shader.
 *
 * @param name the name of the Vector4f defined in the material definition (j3md)
 * @param value the Vector4f value
 */
public void setVector4(String name, Vector4f value) {
    setParam(name, VarType.Vector4, value);
}