com.jme3.math.Matrix3f Java Examples

The following examples show how to use com.jme3.math.Matrix3f. 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: CollisionShapePropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@FxThread
private void build(@NotNull final ChildCollisionShape shape, @NotNull final VBox container,
                   @NotNull final ModelChangeConsumer changeConsumer) {

    final Vector3f location = shape.location;
    final Matrix3f rotation = shape.rotation;

    final DefaultSinglePropertyControl<ModelChangeConsumer, ChildCollisionShape, Vector3f> locationControl =
            new DefaultSinglePropertyControl<>(location, Messages.MODEL_PROPERTY_LOCATION, changeConsumer);

    locationControl.setSyncHandler(collisionShape -> collisionShape.location);
    locationControl.setToStringFunction(Vector3f::toString);
    locationControl.setEditObject(shape);

    final DefaultSinglePropertyControl<ModelChangeConsumer, ChildCollisionShape, Matrix3f> rotationControl =
            new DefaultSinglePropertyControl<>(rotation, Messages.MODEL_PROPERTY_ROTATION, changeConsumer);

    rotationControl.setSyncHandler(collisionShape -> collisionShape.rotation);
    rotationControl.setToStringFunction(matrix3f -> new Quaternion().fromRotationMatrix(matrix3f).toString());
    rotationControl.setEditObject(shape);
    rotationControl.reload();

    FXUtils.addToPane(locationControl, container);
    FXUtils.addToPane(rotationControl, container);
}
 
Example #2
Source File: PhysicsRigidBody.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void write(JmeExporter e) throws IOException {
    super.write(e);
    OutputCapsule capsule = e.getCapsule(this);

    capsule.write(getMass(), "mass", 1.0f);

    capsule.write(getGravity(), "gravity", Vector3f.ZERO);
    capsule.write(getFriction(), "friction", 0.5f);
    capsule.write(getRestitution(), "restitution", 0);
    capsule.write(getAngularFactor(), "angularFactor", 1);
    capsule.write(kinematic, "kinematic", false);

    capsule.write(getLinearDamping(), "linearDamping", 0);
    capsule.write(getAngularDamping(), "angularDamping", 0);
    capsule.write(getLinearSleepingThreshold(), "linearSleepingThreshold", 0.8f);
    capsule.write(getAngularSleepingThreshold(), "angularSleepingThreshold", 1.0f);

    capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0);
    capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0);

    capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f());
    capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f());

    capsule.writeSavableArrayList(joints, "joints", null);
}
 
Example #3
Source File: SceneExplorerProperty.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public SceneExplorerProperty(T instance, Class valueType, String getter, String setter, ScenePropertyChangeListener listener) throws NoSuchMethodException {
    super(instance, valueType, getter, setter);
    addPropertyChangeListener(listener);
    if (valueType == Vector3f.class) {
        setPropertyEditorClass(Vector3fPropertyEditor.class);
    } else if (valueType == Quaternion.class) {
        setPropertyEditorClass(QuaternionPropertyEditor.class);
    } else if (valueType == Matrix3f.class) {
        setPropertyEditorClass(Matrix3fPropertyEditor.class);
    } else if (valueType == ColorRGBA.class) {
        setPropertyEditorClass(ColorRGBAPropertyEditor.class);
    } else if (valueType == EmitterShape.class) {
        setPropertyEditorClass(EmitterShapePropertyEditor.class);
    } else if (valueType == Vector2f.class) {
        setPropertyEditorClass(Vector2fPropertyEditor.class);
    }

    for (SceneExplorerPropertyEditor di : Lookup.getDefault().lookupAll(SceneExplorerPropertyEditor.class)) {
        di.setEditor(valueType, this);
    }
}
 
Example #4
Source File: NewtonianParticleInfluencer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
    emitterShape.getRandomPointAndNormal(particle.position, particle.velocity);
    // influencing the particle's velocity
    if (surfaceTangentFactor == 0.0f) {
        particle.velocity.multLocal(normalVelocity);
    } else {
        // calculating surface tangent (velocity contains the 'normal' value)
        temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor);
        if (surfaceTangentRotation != 0.0f) {// rotating the tangent
            Matrix3f m = new Matrix3f();
            m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity);
            temp = m.multLocal(temp);
        }
        // applying normal factor (this must be done first)
        particle.velocity.multLocal(normalVelocity);
        // adding tangent vector
        particle.velocity.addLocal(temp);
    }
    if (velocityVariation != 0.0f) {
        this.applyVelocityVariation(particle);
    }
}
 
Example #5
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Callback from Control.render(), do not use.
 * 
 * @param rm
 * @param vp 
 */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();

    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;

        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }

    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();

        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
 
Example #6
Source File: PhysicsRigidBody.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);

    InputCapsule capsule = e.getCapsule(this);
    float mass = capsule.readFloat("mass", 1.0f);
    this.mass = mass;
    rebuildRigidBody();
    setGravity((Vector3f) capsule.readSavable("gravity", Vector3f.ZERO.clone()));
    setFriction(capsule.readFloat("friction", 0.5f));
    setKinematic(capsule.readBoolean("kinematic", false));

    setRestitution(capsule.readFloat("restitution", 0));
    setAngularFactor(capsule.readFloat("angularFactor", 1));
    setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0));
    setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f));
    setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
    setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0));

    setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f()));
    setPhysicsRotation((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f()));

    joints = capsule.readSavableArrayList("joints", null);
}
 
Example #7
Source File: PhysicsRigidBody.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);

    InputCapsule capsule = e.getCapsule(this);
    float mass = capsule.readFloat("mass", 1.0f);
    this.mass = mass;
    rebuildRigidBody();
    setGravity((Vector3f) capsule.readSavable("gravity", Vector3f.ZERO.clone()));
    setFriction(capsule.readFloat("friction", 0.5f));
    setKinematic(capsule.readBoolean("kinematic", false));

    setRestitution(capsule.readFloat("restitution", 0));
    setAngularFactor(capsule.readFloat("angularFactor", 1));
    setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0));
    setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f));
    setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
    setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0));

    setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f()));
    setPhysicsRotation((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f()));

    joints = capsule.readSavableArrayList("joints", null);
}
 
Example #8
Source File: PhysicsRigidBody.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void write(JmeExporter e) throws IOException {
    super.write(e);
    OutputCapsule capsule = e.getCapsule(this);

    capsule.write(getMass(), "mass", 1.0f);

    capsule.write(getGravity(), "gravity", Vector3f.ZERO);
    capsule.write(getFriction(), "friction", 0.5f);
    capsule.write(getRestitution(), "restitution", 0);
    capsule.write(getAngularFactor(), "angularFactor", 1);
    capsule.write(kinematic, "kinematic", false);

    capsule.write(constructionInfo.linearDamping, "linearDamping", 0);
    capsule.write(constructionInfo.angularDamping, "angularDamping", 0);
    capsule.write(constructionInfo.linearSleepingThreshold, "linearSleepingThreshold", 0.8f);
    capsule.write(constructionInfo.angularSleepingThreshold, "angularSleepingThreshold", 1.0f);

    capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0);
    capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0);

    capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f());
    capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f());

    capsule.writeSavableArrayList(joints, "joints", null);
}
 
Example #9
Source File: NewtonianParticleInfluencer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void influenceParticle(Particle particle, EmitterShape emitterShape) {
    emitterShape.getRandomPointAndNormal(particle.position, particle.velocity);
    // influencing the particle's velocity
    if (surfaceTangentFactor == 0.0f) {
        particle.velocity.multLocal(normalVelocity);
    } else {
        // calculating surface tangent (velocity contains the 'normal' value)
        temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor);
        if (surfaceTangentRotation != 0.0f) {// rotating the tangent
            Matrix3f m = new Matrix3f();
            m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity);
            temp = m.multLocal(temp);
        }
        // applying normal factor (this must be done first)
        particle.velocity.multLocal(normalVelocity);
        // adding tangent vector
        particle.velocity.addLocal(temp);
    }
    if (velocityVariation != 0.0f) {
        this.applyVelocityVariation(particle);
    }
}
 
Example #10
Source File: ConeJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param pivotA local translation of the joint connection point in node A
 * @param pivotB local translation of the joint connection point in node B
 */
public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB) {
    super(nodeA, nodeB, pivotA, pivotB);
    this.rotA = rotA;
    this.rotB = rotB;
    createJoint();
}
 
Example #11
Source File: SixDofJoint.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @param pivotA local translation of the joint connection point in node A
 * @param pivotB local translation of the joint connection point in node B
 */
public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) {
    super(nodeA, nodeB, pivotA, pivotB);
    this.useLinearReferenceFrameA = useLinearReferenceFrameA;

    Transform transA = new Transform(Converter.convert(new Matrix3f()));
    Converter.convert(pivotA, transA.origin);

    Transform transB = new Transform(Converter.convert(new Matrix3f()));
    Converter.convert(pivotB, transB.origin);

    constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA);
    gatherMotors();
}
 
Example #12
Source File: PMDPhysicsWorld.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void _convPMDEuler(Matrix3f out, float x, float y, float z) {
    Quaternion qx = new Quaternion();
    Quaternion qy = new Quaternion();
    Quaternion qz = new Quaternion();

    qx.fromAngles(x, 0, 0);
    qy.fromAngles(0, y, 0);
    qz.fromAngles(0, 0, z);

    qz.multLocal(qy);
    qz.multLocal(qx);

    qz.toRotationMatrix(out);
}
 
Example #13
Source File: SliderJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param pivotA local translation of the joint connection point in node A
 * @param pivotB local translation of the joint connection point in node B
 */
public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) {
    super(nodeA, nodeB, pivotA, pivotB);
    this.rotA=new Matrix3f();
    this.rotB=new Matrix3f();
    this.useLinearReferenceFrameA=useLinearReferenceFrameA;
    createJoint();
}
 
Example #14
Source File: ConeJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param pivotA local translation of the joint connection point in node A
 * @param pivotB local translation of the joint connection point in node B
 */
public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB) {
    super(nodeA, nodeB, pivotA, pivotB);
    this.rotA = rotA;
    this.rotB = rotB;
    createJoint();
}
 
Example #15
Source File: ConeJoint.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(JmeExporter ex) throws IOException {
    super.write(ex);
    OutputCapsule capsule = ex.getCapsule(this);
    capsule.write(rotA, "rotA", new Matrix3f());
    capsule.write(rotB, "rotB", new Matrix3f());

    capsule.write(angularOnly, "angularOnly", false);
    capsule.write(swingSpan1, "swingSpan1", 1e30f);
    capsule.write(swingSpan2, "swingSpan2", 1e30f);
    capsule.write(twistSpan, "twistSpan", 1e30f);
}
 
Example #16
Source File: PhysicsGhostObject.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void read(JmeImporter e) throws IOException {
    super.read(e);
    InputCapsule capsule = e.getCapsule(this);
    buildObject();
    setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f()));
    setPhysicsRotation(((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f())));
    setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
    setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0));
}
 
Example #17
Source File: PhysicsRigidBody.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Serialize this body, for example when saving to a J3O file.
 *
 * @param e exporter (not null)
 * @throws IOException from exporter
 */
@Override
public void write(JmeExporter e) throws IOException {
    super.write(e);
    OutputCapsule capsule = e.getCapsule(this);

    capsule.write(getMass(), "mass", 1.0f);

    capsule.write(getGravity(), "gravity", Vector3f.ZERO);
    capsule.write(isContactResponse(), "contactResponse", true);
    capsule.write(getFriction(), "friction", 0.5f);
    capsule.write(getRestitution(), "restitution", 0);
    Vector3f angularFactor = getAngularFactor(null);
    if (angularFactor.x == angularFactor.y && angularFactor.y == angularFactor.z) {
        capsule.write(getAngularFactor(), "angularFactor", 1);
    } else {
        capsule.write(getAngularFactor(null), "angularFactor", Vector3f.UNIT_XYZ);
        capsule.write(getLinearFactor(), "linearFactor", Vector3f.UNIT_XYZ);
    }
    capsule.write(kinematic, "kinematic", false);

    capsule.write(getLinearDamping(), "linearDamping", 0);
    capsule.write(getAngularDamping(), "angularDamping", 0);
    capsule.write(getLinearSleepingThreshold(), "linearSleepingThreshold", 0.8f);
    capsule.write(getAngularSleepingThreshold(), "angularSleepingThreshold", 1.0f);

    capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0);
    capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0);

    capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f());
    capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f());
    capsule.write(getLinearVelocity(), "linearVelocity", null);
    capsule.write(getAngularVelocity(), "angularVelocity", null);

    capsule.writeSavableArrayList(joints, "joints", null);
}
 
Example #18
Source File: ConeJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule capsule = im.getCapsule(this);
    this.rotA = (Matrix3f) capsule.readSavable("rotA", new Matrix3f());
    this.rotB = (Matrix3f) capsule.readSavable("rotB", new Matrix3f());

    this.angularOnly = capsule.readBoolean("angularOnly", false);
    this.swingSpan1 = capsule.readFloat("swingSpan1", 1e30f);
    this.swingSpan2 = capsule.readFloat("swingSpan2", 1e30f);
    this.twistSpan = capsule.readFloat("twistSpan", 1e30f);
    createJoint();
}
 
Example #19
Source File: ConeJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param pivotA local translation of the joint connection point in node A
 * @param pivotB local translation of the joint connection point in node B
 */
public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB) {
    super(nodeA, nodeB, pivotA, pivotB);
    this.rotA = new Matrix3f();
    this.rotB = new Matrix3f();
    createJoint();
}
 
Example #20
Source File: CompoundCollisionShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * adds a child shape at the given local translation
 * @param shape the child shape to add
 * @param location the local location of the child shape
 */
public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) {
    if(shape instanceof CompoundCollisionShape){
        throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!");
    }
    Transform transA = new Transform(Converter.convert(rotation));
    Converter.convert(location, transA.origin);
    Converter.convert(rotation, transA.basis);
    children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape));
    ((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
 
Example #21
Source File: CompoundCollisionShape.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * adds a child shape at the given local translation
 * @param shape the child shape to add
 * @param location the local location of the child shape
 */
public void addChildShape(CollisionShape shape, Vector3f location) {
    Transform transA = new Transform(Converter.convert(new Matrix3f()));
    Converter.convert(location, transA.origin);
    children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape));
    ((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
 
Example #22
Source File: SliderJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param pivotA local translation of the joint connection point in node A
 * @param pivotB local translation of the joint connection point in node B
 */
public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) {
    super(nodeA, nodeB, pivotA, pivotB);
    this.rotA = rotA;
    this.rotB = rotB;
    this.useLinearReferenceFrameA = useLinearReferenceFrameA;
    createJoint();
}
 
Example #23
Source File: CollisionShapeFactory.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * This method moves each child shape of a compound shape by the given vector
 * @param vector
 */
public static void shiftCompoundShapeContents(CompoundCollisionShape compoundShape, Vector3f vector) {
    for (Iterator<ChildCollisionShape> it = new LinkedList<>(compoundShape.getChildren()).iterator(); it.hasNext();) {
        ChildCollisionShape childCollisionShape = it.next();
        CollisionShape child = childCollisionShape.shape;
        Vector3f location = childCollisionShape.location;
        Matrix3f rotation = childCollisionShape.rotation;
        compoundShape.removeChildShape(child);
        compoundShape.addChildShape(child, location.add(vector), rotation);
    }
}
 
Example #24
Source File: DebugShapeFactory.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a debug shape from the given collision shape. This is mostly used internally.<br>
 * To attach a debug shape to a physics object, call <code>attachDebugShape(AssetManager manager);</code> on it.
 * @param collisionShape
 * @return
 */
public static Spatial getDebugShape(CollisionShape collisionShape) {
    if (collisionShape == null) {
        return null;
    }
    Spatial debugShape;
    if (collisionShape instanceof CompoundCollisionShape) {
        CompoundCollisionShape shape = (CompoundCollisionShape) collisionShape;
        List<ChildCollisionShape> children = shape.getChildren();
        Node node = new Node("DebugShapeNode");
        for (Iterator<ChildCollisionShape> it = children.iterator(); it.hasNext();) {
            ChildCollisionShape childCollisionShape = it.next();
            CollisionShape ccollisionShape = childCollisionShape.shape;
            Geometry geometry = createDebugShape(ccollisionShape);

            // apply translation
            geometry.setLocalTranslation(childCollisionShape.location);

            // apply rotation
            TempVars vars = TempVars.get();                
            Matrix3f tempRot = vars.tempMat3;

            tempRot.set(geometry.getLocalRotation());
            childCollisionShape.rotation.mult(tempRot, tempRot);
            geometry.setLocalRotation(tempRot);

            vars.release();

            node.attachChild(geometry);
        }
        debugShape = node;
    } else {
        debugShape = createDebugShape(collisionShape);
    }
    if (debugShape == null) {
        return null;
    }
    debugShape.updateGeometricState();
    return debugShape;
}
 
Example #25
Source File: ConeJoint.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule capsule = im.getCapsule(this);
    this.rotA = (Matrix3f) capsule.readSavable("rotA", new Matrix3f());
    this.rotB = (Matrix3f) capsule.readSavable("rotB", new Matrix3f());

    this.angularOnly = capsule.readBoolean("angularOnly", false);
    this.swingSpan1 = capsule.readFloat("swingSpan1", 1e30f);
    this.swingSpan2 = capsule.readFloat("swingSpan2", 1e30f);
    this.twistSpan = capsule.readFloat("twistSpan", 1e30f);
    createJoint();
}
 
Example #26
Source File: CompoundCollisionShape.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) {
    if(shape instanceof CompoundCollisionShape){
        throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!");
    }
    Transform transA = new Transform(Converter.convert(rotation));
    Converter.convert(location, transA.origin);
    Converter.convert(rotation, transA.basis);
    ((CompoundShape) cShape).addChildShape(transA, shape.getCShape());
}
 
Example #27
Source File: PhysicsRigidBody.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the physics object rotation
 * @param rotation the rotation of the actual physics object
 */
public void setPhysicsRotation(Matrix3f rotation) {
    rBody.getCenterOfMassTransform(tempTrans);
    Converter.convert(rotation, tempTrans.basis);
    rBody.setCenterOfMassTransform(tempTrans);
    motionState.setWorldTransform(tempTrans);
}
 
Example #28
Source File: PhysicsRigidBody.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Serialize this body, for example when saving to a J3O file.
 *
 * @param e exporter (not null)
 * @throws IOException from exporter
 */
@Override
public void write(JmeExporter e) throws IOException {
    super.write(e);
    OutputCapsule capsule = e.getCapsule(this);

    capsule.write(getMass(), "mass", 1.0f);

    capsule.write(getGravity(), "gravity", Vector3f.ZERO);
    capsule.write(getFriction(), "friction", 0.5f);
    capsule.write(getRestitution(), "restitution", 0);
    capsule.write(getAngularFactor(), "angularFactor", 1);
    capsule.write(kinematic, "kinematic", false);

    capsule.write(constructionInfo.linearDamping, "linearDamping", 0);
    capsule.write(constructionInfo.angularDamping, "angularDamping", 0);
    capsule.write(constructionInfo.linearSleepingThreshold, "linearSleepingThreshold", 0.8f);
    capsule.write(constructionInfo.angularSleepingThreshold, "angularSleepingThreshold", 1.0f);

    capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0);
    capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0);

    capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f());
    capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f());
    capsule.write(getLinearVelocity(), "linearVelocity", null);
    capsule.write(getAngularVelocity(), "angularVelocity", null);

    capsule.writeSavableArrayList(joints, "joints", null);
}
 
Example #29
Source File: PhysicsRigidBody.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * De-serialize this body, for example when loading from a J3O file.
 *
 * @param e importer (not null)
 * @throws IOException from importer
 */
@Override
@SuppressWarnings("unchecked")
public void read(JmeImporter e) throws IOException {
    super.read(e);

    InputCapsule capsule = e.getCapsule(this);
    float mass = capsule.readFloat("mass", 1.0f);
    this.mass = mass;
    rebuildRigidBody();
    setGravity((Vector3f) capsule.readSavable("gravity", Vector3f.ZERO.clone()));
    setContactResponse(capsule.readBoolean("contactResponse", true));
    setFriction(capsule.readFloat("friction", 0.5f));
    setKinematic(capsule.readBoolean("kinematic", false));

    setRestitution(capsule.readFloat("restitution", 0));
    setAngularFactor(capsule.readFloat("angularFactor", 1));
    setDamping(capsule.readFloat("linearDamping", 0), capsule.readFloat("angularDamping", 0));
    setSleepingThresholds(capsule.readFloat("linearSleepingThreshold", 0.8f), capsule.readFloat("angularSleepingThreshold", 1.0f));
    setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0));
    setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0));

    setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f()));
    setPhysicsRotation((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f()));
    setLinearVelocity((Vector3f) capsule.readSavable("linearVelocity", new Vector3f()));
    setAngularVelocity((Vector3f) capsule.readSavable("angularVelocity", new Vector3f()));

    joints = capsule.readSavableArrayList("joints", null);
}
 
Example #30
Source File: VehicleEditorController.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void doStopVehicle() {
        testing = false;
        vehicleControl.setPhysicsLocation(Vector3f.ZERO);
        vehicleControl.setPhysicsRotation(new Matrix3f());
        vehicleControl.setLinearVelocity(Vector3f.ZERO);
        vehicleControl.setAngularVelocity(Vector3f.ZERO);
        vehicleControl.resetSuspension();
        vehicleControl.createDebugShape(SceneApplication.getApplication().getAssetManager());
        bulletState.getPhysicsSpace().removeAll(toolsNode);
        bulletState.getPhysicsSpace().remove(vehicleControl);
//        chaseCam.setEnabled(false);
//        cameraController.enable();
    }