Java Code Examples for com.jme3.math.Quaternion#fromAngleAxis()

The following examples show how to use com.jme3.math.Quaternion#fromAngleAxis() . 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: TestCustomAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf) {
	// Rotate around X axis
	Quaternion rotate = new Quaternion();
	rotate.fromAngleAxis(tpf, Vector3f.UNIT_X);

	// Combine rotation with previous
	rotation.multLocal(rotate);

	// Set new rotation into bone
	bone.setLocalTransform(new Transform(Vector3f.ZERO, rotation, Vector3f.UNIT_XYZ));

	// After changing skeleton transforms, must update world data
	armature.update();
}
 
Example 2
Source File: CurvesHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * This method transforms the first line of the bevel points positioning it
 * on the first point of the curve.
 * 
 * @param startingLinePoints
 *            the vbevel shape points
 * @param firstCurvePoint
 *            the first curve's point
 * @param secondCurvePoint
 *            the second curve's point
 * @return points of transformed bevel
 */
private Vector3f[] transformToFirstLineOfBevelPoints(Vector3f[] startingLinePoints, Vector3f firstCurvePoint, Vector3f secondCurvePoint) {
    Vector3f planeNormal = secondCurvePoint.subtract(firstCurvePoint).normalizeLocal();

    float angle = FastMath.acos(planeNormal.dot(Vector3f.UNIT_Y));
    planeNormal.crossLocal(Vector3f.UNIT_Y).normalizeLocal();// planeNormal is the rotation axis now
    Quaternion pointRotation = new Quaternion();
    pointRotation.fromAngleAxis(angle, planeNormal);

    Matrix4f m = new Matrix4f();
    m.setRotationQuaternion(pointRotation);
    m.setTranslation(firstCurvePoint);

    float[] temp = new float[] { 0, 0, 0, 1 };
    Vector3f[] verts = new Vector3f[startingLinePoints.length];
    for (int j = 0; j < verts.length; ++j) {
        temp[0] = startingLinePoints[j].x;
        temp[1] = startingLinePoints[j].y;
        temp[2] = startingLinePoints[j].z;
        temp = m.mult(temp);// the result is stored in the array
        if (fixUpAxis) {
            verts[j] = new Vector3f(temp[0], -temp[2], temp[1]);
        } else {
            verts[j] = new Vector3f(temp[0], temp[1], temp[2]);
        }
    }
    return verts;
}
 
Example 3
Source File: TestCustomAnim.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleUpdate(float tpf){
    // Rotate around X axis
    Quaternion rotate = new Quaternion();
    rotate.fromAngleAxis(tpf, Vector3f.UNIT_X);

    // Combine rotation with previous
    rotation.multLocal(rotate);

    // Set new rotation into bone
    bone.setUserTransforms(Vector3f.ZERO, rotation, Vector3f.UNIT_XYZ);

    // After changing skeleton transforms, must update world data
    skeleton.updateWorldVectors();
}