Java Code Examples for com.jme3.math.Transform#combineWithParent()

The following examples show how to use com.jme3.math.Transform#combineWithParent() . 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: DacLinks.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Calculate the physics transform to match the specified skeleton bone.
 *
 * @param bone the skeleton bone to match (not null, unaffected)
 * @param localOffset the location of the body's center (in the bone's local
 * coordinates, not null, unaffected)
 * @param storeResult storage for the result (modified if not null)
 * @return the calculated physics transform (either storeResult or a new
 * transform, not null)
 */
Transform physicsTransform(Joint bone, Vector3f localOffset,
        Transform storeResult) {
    Transform result
            = (storeResult == null) ? new Transform() : storeResult;
    /*
     * Start with the body's transform in the bone's local coordinates.
     */
    result.setTranslation(localOffset);
    result.setRotation(rotateIdentity);
    result.setScale(1f);
    /*
     * Convert to mesh coordinates.
     */
    Transform localToMesh = bone.getModelTransform();
    result.combineWithParent(localToMesh);
    /*
     * Convert to world (physics-space) coordinates.
     */
    Transform meshToWorld = meshTransform(null);
    result.combineWithParent(meshToWorld);

    return result;
}
 
Example 2
Source File: CollisionShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Calculate the correct transform for a collision shape relative to the
 * ancestor for which the shape was generated.
 *
 * @param spat
 * @param parent
 * @return a new instance (not null)
 */
private static Transform getTransform(Spatial spat, Spatial parent) {
    Transform shapeTransform = new Transform();
    Spatial parentNode = spat.getParent() != null ? spat.getParent() : spat;
    Spatial currentSpatial = spat;
    //if we have parents combine their transforms
    while (parentNode != null) {
        if (parent == currentSpatial) {
            //real parent -> only apply scale, not transform
            Transform trans = new Transform();
            trans.setScale(currentSpatial.getLocalScale());
            shapeTransform.combineWithParent(trans);
            parentNode = null;
        } else {
            shapeTransform.combineWithParent(currentSpatial.getLocalTransform());
            parentNode = currentSpatial.getParent();
            currentSpatial = parentNode;
        }
    }
    return shapeTransform;
}
 
Example 3
Source File: CollisionShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * returns the correct transform for a collisionshape in relation
 * to the ancestor for which the collisionshape is generated
 * @param spat
 * @param parent
 * @return
 */
private static Transform getTransform(Spatial spat, Spatial parent) {
    Transform shapeTransform = new Transform();
    Spatial parentNode = spat.getParent() != null ? spat.getParent() : spat;
    Spatial currentSpatial = spat;
    //if we have parents combine their transforms
    while (parentNode != null) {
        if (parent == currentSpatial) {
            //real parent -> only apply scale, not transform
            Transform trans = new Transform();
            trans.setScale(currentSpatial.getLocalScale());
            shapeTransform.combineWithParent(trans);
            parentNode = null;
        } else {
            shapeTransform.combineWithParent(currentSpatial.getLocalTransform());
            parentNode = currentSpatial.getParent();
            currentSpatial = parentNode;
        }
    }
    return shapeTransform;
}
 
Example 4
Source File: CollisionShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * returns the correct transform for a collisionshape in relation
 * to the ancestor for which the collisionshape is generated
 * @param spat
 * @param parent
 * @return
 */
private static Transform getTransform(Spatial spat, Spatial parent) {
    Transform shapeTransform = new Transform();
    Spatial parentNode = spat.getParent() != null ? spat.getParent() : spat;
    Spatial currentSpatial = spat;
    //if we have parents combine their transforms
    while (parentNode != null) {
        if (parent == currentSpatial) {
            //real parent -> only apply scale, not transform
            Transform trans = new Transform();
            trans.setScale(currentSpatial.getLocalScale());
            shapeTransform.combineWithParent(trans);
            parentNode = null;
        } else {
            shapeTransform.combineWithParent(currentSpatial.getLocalTransform());
            parentNode = currentSpatial.getParent();
            currentSpatial = parentNode;
        }
    }
    return shapeTransform;
}
 
Example 5
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 6
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 7
Source File: FbxNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void relocateSpatial(Spatial spatial, 
                                    Transform originalWorldTransform, Transform newWorldTransform) {
    Transform localTransform = new Transform();
    localTransform.set(originalWorldTransform);
    localTransform.combineWithParent(newWorldTransform.invert());
    spatial.setLocalTransform(localTransform);
}
 
Example 8
Source File: FbxToJmeTrack.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void applyInverse(Vector3f translation, Quaternion rotation, Vector3f scale, Transform inverseBindPose) {
    Transform t = new Transform();
    t.setTranslation(translation);
    t.setRotation(rotation);
    if (scale != null) {
        t.setScale(scale);
    }
    t.combineWithParent(inverseBindPose);
    
    t.getTranslation(translation);
    t.getRotation(rotation);
    if (scale != null) {
        t.getScale(scale);
    }
}
 
Example 9
Source File: SeparateJointModelTransform.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void applyBindPose(Transform localTransform, Matrix4f inverseModelBindMatrix, Joint parent) {
    localTransform.fromTransformMatrix(inverseModelBindMatrix.invert());
    if (parent != null) {
        localTransform.combineWithParent(parent.getModelTransform().invert());
    }
}