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

The following examples show how to use com.jme3.math.Quaternion#mult() . 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: RagUtils.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Convert a transform from the mesh coordinate system to the local
 * coordinate system of the specified bone.
 *
 * @param parentBone (not null)
 * @param transform the transform to convert (not null, modified)
 */
static void meshToLocal(Joint parentBone, Transform transform) {
    Vector3f location = transform.getTranslation();
    Quaternion orientation = transform.getRotation();
    Vector3f scale = transform.getScale();

    Transform pmx = parentBone.getModelTransform();
    Vector3f pmTranslate = pmx.getTranslation();
    Quaternion pmRotInv = pmx.getRotation().inverse();
    Vector3f pmScale = pmx.getScale();

    location.subtractLocal(pmTranslate);
    location.divideLocal(pmScale);
    pmRotInv.mult(location, location);
    scale.divideLocal(pmScale);
    pmRotInv.mult(orientation, orientation);
}
 
Example 2
Source File: VRGuiManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Position the GUI to the given location.
 * @param pos the position of the GUI.
 * @param dir the rotation of the GUI.
 * @param tpf the time per frame.
 */
private void positionTo(Vector3f pos, Quaternion dir, float tpf) {

	if (environment != null){
		Vector3f guiPos = guiQuadNode.getLocalTranslation();
		guiPos.set(0f, 0f, guiDistance);
		dir.mult(guiPos, guiPos);
		guiPos.x += pos.x;
		guiPos.y += pos.y + environment.getVRHeightAdjustment();
		guiPos.z += pos.z;        
		if( guiPositioningElastic > 0f && posMode != VRGUIPositioningMode.MANUAL ) {
			// mix pos & dir with current pos & dir            
			guiPos.interpolateLocal(EoldPos, guiPos, Float.min(1f, tpf * guiPositioningElastic));
			EoldPos.set(guiPos);
		}
	} else {
		throw new IllegalStateException("VR GUI manager is not attached to any environment.");
	}
}
 
Example 3
Source File: TorsoLink.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Calculate the local bone transform to match the physics transform of the
 * rigid body.
 *
 * @param storeResult storage for the result (modified if not null)
 * @return the calculated bone transform (in local coordinates, either
 * storeResult or a new transform, not null)
 */
private Transform localBoneTransform(Transform storeResult) {
    Transform result
            = (storeResult == null) ? new Transform() : storeResult;
    Vector3f location = result.getTranslation();
    Quaternion orientation = result.getRotation();
    Vector3f scale = result.getScale();
    /*
     * Start with the rigid body's transform in physics/world coordinates.
     */
    PhysicsRigidBody body = getRigidBody();
    body.getPhysicsLocation(result.getTranslation());
    body.getPhysicsRotation(result.getRotation());
    result.setScale(body.getCollisionShape().getScale());
    /*
     * Convert to mesh coordinates.
     */
    Transform worldToMesh = getControl().meshTransform(null).invert();
    result.combineWithParent(worldToMesh);
    /*
     * Subtract the body's local offset, rotated and scaled.
     */
    Vector3f meshOffset = localOffset(null);
    meshOffset.multLocal(scale);
    orientation.mult(meshOffset, meshOffset);
    location.subtractLocal(meshOffset);

    return result;
}
 
Example 4
Source File: BoneLink.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Calculate the local bone transform to match the physics transform of the
 * rigid body.
 *
 * @param storeResult storage for the result (modified if not null)
 * @return the calculated bone transform (in local coordinates, either
 * storeResult or a new transform, not null)
 */
private Transform localBoneTransform(Transform storeResult) {
    Transform result
            = (storeResult == null) ? new Transform() : storeResult;
    Vector3f location = result.getTranslation();
    Quaternion orientation = result.getRotation();
    Vector3f scale = result.getScale();
    /*
     * Start with the rigid body's transform in physics/world coordinates.
     */
    PhysicsRigidBody body = getRigidBody();
    body.getPhysicsLocation(result.getTranslation());
    body.getPhysicsRotation(result.getRotation());
    result.setScale(body.getCollisionShape().getScale());
    /*
     * Convert to mesh coordinates.
     */
    Transform worldToMesh = getControl().meshTransform(null).invert();
    result.combineWithParent(worldToMesh);
    /*
     * Convert to the bone's local coordinate system by factoring out the
     * parent bone's transform.
     */
    Joint parentBone = getBone().getParent();
    RagUtils.meshToLocal(parentBone, result);
    /*
     * Subtract the body's local offset, rotated and scaled.
     */
    Vector3f parentOffset = localOffset(null);
    parentOffset.multLocal(scale);
    orientation.mult(parentOffset, parentOffset);
    location.subtractLocal(parentOffset);

    return result;
}
 
Example 5
Source File: ModelPerformer.java    From OpenRTS with MIT License 5 votes vote down vote up
private Point3D getBoneWorldPos(ModelActor actor, Point3D actorPos, double actorYaw, String boneName) {
	Spatial s = actor.getViewElements().spatial;
	Vector3f modelSpacePos = s.getControl(AnimControl.class).getSkeleton().getBone(boneName).getModelSpacePosition();
	Quaternion q = actor.getViewElements().spatial.getLocalRotation();
	modelSpacePos = q.mult(modelSpacePos);
	modelSpacePos.multLocal(s.getLocalScale());
	modelSpacePos = modelSpacePos.add(s.getLocalTranslation());
	// float scale
	// Point2D p2D = Translator.toPoint2D(modelSpacePos);
	// p2D = p2D.getRotation(actorYaw+Angle.RIGHT);
	// Point3D p3D = new Point3D(p2D.getMult(DEFAULT_SCALE), modelSpacePos.z*DEFAULT_SCALE, 1);
	// p3D = p3D.getAddition(actorPos);
	// return p3D;
	return TranslateUtil.toPoint3D(modelSpacePos);
}