Search in sources :

Example 46 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class ConstraintDefinitionLocLike method bake.

@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
    if (influence == 0 || targetTransform == null || !this.isTrackToBeChanged()) {
        return;
    }
    Transform ownerTransform = this.getOwnerTransform(ownerSpace);
    Vector3f ownerLocation = ownerTransform.getTranslation();
    Vector3f targetLocation = targetTransform.getTranslation();
    Vector3f startLocation = ownerTransform.getTranslation().clone();
    Vector3f offset = Vector3f.ZERO;
    if ((flag & LOCLIKE_OFFSET) != 0) {
        // we add the original location to the copied location
        offset = startLocation;
    }
    if ((flag & LOCLIKE_X) != 0) {
        ownerLocation.x = targetLocation.x;
        if ((flag & LOCLIKE_X_INVERT) != 0) {
            ownerLocation.x = -ownerLocation.x;
        }
    }
    if ((flag & LOCLIKE_Y) != 0) {
        ownerLocation.y = targetLocation.y;
        if ((flag & LOCLIKE_Y_INVERT) != 0) {
            ownerLocation.y = -ownerLocation.y;
        }
    }
    if ((flag & LOCLIKE_Z) != 0) {
        ownerLocation.z = targetLocation.z;
        if ((flag & LOCLIKE_Z_INVERT) != 0) {
            ownerLocation.z = -ownerLocation.z;
        }
    }
    ownerLocation.addLocal(offset);
    if (influence < 1.0f) {
        startLocation.subtractLocal(ownerLocation).normalizeLocal().mult(influence);
        ownerLocation.addLocal(startLocation);
    }
    this.applyOwnerTransform(ownerTransform, ownerSpace);
}
Also used : Vector3f(com.jme3.math.Vector3f) Transform(com.jme3.math.Transform)

Example 47 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class ConstraintDefinitionRotLike method bake.

@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
    if (influence == 0 || targetTransform == null || !trackToBeChanged) {
        // no need to do anything
        return;
    }
    Transform ownerTransform = this.getOwnerTransform(ownerSpace);
    Quaternion ownerRotation = ownerTransform.getRotation();
    ownerAngles = ownerRotation.toAngles(ownerAngles);
    targetAngles = targetTransform.getRotation().toAngles(targetAngles);
    Quaternion startRotation = ownerRotation.clone();
    Quaternion offset = Quaternion.IDENTITY;
    if ((flag & ROTLIKE_OFFSET) != 0) {
        // we add the original rotation to
        // the copied rotation
        offset = startRotation;
    }
    if ((flag & ROTLIKE_X) != 0) {
        ownerAngles[0] = targetAngles[0];
        if ((flag & ROTLIKE_X_INVERT) != 0) {
            ownerAngles[0] = -ownerAngles[0];
        }
    }
    if ((flag & ROTLIKE_Y) != 0) {
        ownerAngles[1] = targetAngles[1];
        if ((flag & ROTLIKE_Y_INVERT) != 0) {
            ownerAngles[1] = -ownerAngles[1];
        }
    }
    if ((flag & ROTLIKE_Z) != 0) {
        ownerAngles[2] = targetAngles[2];
        if ((flag & ROTLIKE_Z_INVERT) != 0) {
            ownerAngles[2] = -ownerAngles[2];
        }
    }
    ownerRotation.fromAngles(ownerAngles).multLocal(offset);
    if (influence < 1.0f) {
    // startLocation.subtractLocal(ownerLocation).normalizeLocal().mult(influence);
    // ownerLocation.addLocal(startLocation);
    // TODO
    }
    this.applyOwnerTransform(ownerTransform, ownerSpace);
}
Also used : Quaternion(com.jme3.math.Quaternion) Transform(com.jme3.math.Transform)

Example 48 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class ConstraintDefinitionRotLimit method bake.

@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
    if (influence == 0 || !trackToBeChanged) {
        return;
    }
    Transform ownerTransform = this.getOwnerTransform(ownerSpace);
    ownerTransform.getRotation().toAngles(angles);
    /*
         * for (int i = 0; i < 3; ++i) { int multFactor =
         * (int)Math.abs(angles[i] / FastMath.TWO_PI) ; if(angles[i] < 0) {
         * angles[i] += FastMath.TWO_PI * (multFactor + 1); } else { angles[i]
         * -= FastMath.TWO_PI * multFactor; } }
         */
    if ((flag & LIMIT_XROT) != 0) {
        float difference = 0.0f;
        if (angles[0] < limits[0][0]) {
            difference = (angles[0] - limits[0][0]) * influence;
        } else if (angles[0] > limits[0][1]) {
            difference = (angles[0] - limits[0][1]) * influence;
        }
        angles[0] -= difference;
    }
    if ((flag & LIMIT_YROT) != 0) {
        float difference = 0.0f;
        if (angles[1] < limits[1][0]) {
            difference = (angles[1] - limits[1][0]) * influence;
        } else if (angles[1] > limits[1][1]) {
            difference = (angles[1] - limits[1][1]) * influence;
        }
        angles[1] -= difference;
    }
    if ((flag & LIMIT_ZROT) != 0) {
        float difference = 0.0f;
        if (angles[2] < limits[2][0]) {
            difference = (angles[2] - limits[2][0]) * influence;
        } else if (angles[2] > limits[2][1]) {
            difference = (angles[2] - limits[2][1]) * influence;
        }
        angles[2] -= difference;
    }
    ownerTransform.getRotation().fromAngles(angles);
    this.applyOwnerTransform(ownerTransform, ownerSpace);
}
Also used : Transform(com.jme3.math.Transform)

Example 49 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class ConstraintDefinitionSizeLimit method bake.

@Override
public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) {
    if (influence == 0 || !trackToBeChanged) {
        return;
    }
    Transform ownerTransform = this.getOwnerTransform(ownerSpace);
    Vector3f scale = ownerTransform.getScale();
    if ((flag & LIMIT_XMIN) != 0 && scale.x < limits[0][0]) {
        scale.x -= (scale.x - limits[0][0]) * influence;
    }
    if ((flag & LIMIT_XMAX) != 0 && scale.x > limits[0][1]) {
        scale.x -= (scale.x - limits[0][1]) * influence;
    }
    if ((flag & LIMIT_YMIN) != 0 && scale.y < limits[1][0]) {
        scale.y -= (scale.y - limits[1][0]) * influence;
    }
    if ((flag & LIMIT_YMAX) != 0 && scale.y > limits[1][1]) {
        scale.y -= (scale.y - limits[1][1]) * influence;
    }
    if ((flag & LIMIT_ZMIN) != 0 && scale.z < limits[2][0]) {
        scale.z -= (scale.z - limits[2][0]) * influence;
    }
    if ((flag & LIMIT_ZMAX) != 0 && scale.z > limits[2][1]) {
        scale.z -= (scale.z - limits[2][1]) * influence;
    }
    this.applyOwnerTransform(ownerTransform, ownerSpace);
}
Also used : Vector3f(com.jme3.math.Vector3f) Transform(com.jme3.math.Transform)

Example 50 with Transform

use of com.jme3.math.Transform in project jmonkeyengine by jMonkeyEngine.

the class RagdollUtils method setTransform.

/**
     * Updates a bone position and rotation.
     * if the child bones are not in the bone list this means, they are not associated with a physic shape.
     * So they have to be updated
     * @param bone the bone
     * @param pos the position
     * @param rot the rotation
     */
public static void setTransform(Bone bone, Vector3f pos, Quaternion rot, boolean restoreBoneControl, Set<String> boneList) {
    //we ensure that we have the control
    if (restoreBoneControl) {
        bone.setUserControl(true);
    }
    //we set te user transforms of the bone
    bone.setUserTransformsInModelSpace(pos, rot);
    for (Bone childBone : bone.getChildren()) {
        //each child bone that is not in the list is updated
        if (!boneList.contains(childBone.getName())) {
            Transform t = childBone.getCombinedTransform(pos, rot);
            setTransform(childBone, t.getTranslation(), t.getRotation(), restoreBoneControl, boneList);
        }
    }
    //we give back the control to the keyframed animation
    if (restoreBoneControl) {
        bone.setUserControl(false);
    }
}
Also used : Bone(com.jme3.animation.Bone) Transform(com.jme3.math.Transform)

Aggregations

Vector3f (com.jme3.math.Vector3f)29 Transform (com.jme3.math.Transform)26 TempVars (com.jme3.util.TempVars)24 Quaternion (com.jme3.math.Quaternion)11 Matrix4f (com.jme3.math.Matrix4f)10 Bone (com.jme3.animation.Bone)9 BoundingBox (com.jme3.bounding.BoundingBox)6 BoneContext (com.jme3.scene.plugins.blender.animations.BoneContext)5 PointLight (com.jme3.light.PointLight)4 Spatial (com.jme3.scene.Spatial)4 FloatBuffer (java.nio.FloatBuffer)4 Transform (com.bulletphysics.linearmath.Transform)3 ChildCollisionShape (com.jme3.bullet.collision.shapes.infos.ChildCollisionShape)3 DirectionalLight (com.jme3.light.DirectionalLight)3 Light (com.jme3.light.Light)3 SpotLight (com.jme3.light.SpotLight)3 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)2 BoneTrack (com.jme3.animation.BoneTrack)2 SpatialTrack (com.jme3.animation.SpatialTrack)2 BoundingVolume (com.jme3.bounding.BoundingVolume)2