159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met: 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer. 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer in the 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * documentation and/or other materials provided with the distribution. 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * may be used to endorse or promote products derived from this software 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * without specific prior written permission. 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage com.jme3.bullet.joints; 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.joints.motors.RotationalLimitMotor; 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.joints.motors.TranslationalLimitMotor; 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.objects.PhysicsRigidBody; 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.InputCapsule; 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeExporter; 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeImporter; 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.OutputCapsule; 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Matrix3f; 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Vector3f; 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.io.IOException; 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.Iterator; 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.LinkedList; 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.logging.Level; 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.logging.Logger; 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * <i>From bullet manual:</i><br> 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * This generic constraint can emulate a variety of standard constraints, 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * by configuring each of the 6 degrees of freedom (dof). 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * The first 3 dof axis are linear axis, which represent translation of rigidbodies, 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * and the latter 3 dof axis represent the angular motion. Each axis can be either locked, 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * free or limited. On construction of a new btGeneric6DofConstraint, all axis are locked. 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Afterwards the axis can be reconfigured. Note that several combinations that 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * include free and/or limited angular degrees of freedom are undefined. 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author normenhansen 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class SixDofJoint extends PhysicsJoint { 6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Matrix3f rotA, rotB; 6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta boolean useLinearReferenceFrameA; 6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta LinkedList<RotationalLimitMotor> rotationalMotors = new LinkedList<RotationalLimitMotor>(); 6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta TranslationalLimitMotor translationalMotor; 6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Vector3f angularUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY); 6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Vector3f angularLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY); 6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Vector3f linearUpperLimit = new Vector3f(Vector3f.POSITIVE_INFINITY); 6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Vector3f linearLowerLimit = new Vector3f(Vector3f.NEGATIVE_INFINITY); 7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public SixDofJoint() { 7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param pivotA local translation of the joint connection point in node A 7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param pivotB local translation of the joint connection point in node B 7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { 7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super(nodeA, nodeB, pivotA, pivotB); 8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.useLinearReferenceFrameA = useLinearReferenceFrameA; 8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.rotA = rotA; 8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.rotB = rotB; 8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); 8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Created Joint {0}", Long.toHexString(objectId)); 8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gatherMotors(); 8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param pivotA local translation of the joint connection point in node A 9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param pivotB local translation of the joint connection point in node B 9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { 9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super(nodeA, nodeB, pivotA, pivotB); 9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this.useLinearReferenceFrameA = useLinearReferenceFrameA; 9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotA = new Matrix3f(); 9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotB = new Matrix3f(); 9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); 10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Created Joint {0}", Long.toHexString(objectId)); 10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gatherMotors(); 10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private void gatherMotors() { 10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (int i = 0; i < 3; i++) { 10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta RotationalLimitMotor rmot = new RotationalLimitMotor(getRotationalLimitMotor(objectId, i)); 10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalMotors.add(rmot); 10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta translationalMotor = new TranslationalLimitMotor(getTranslationalLimitMotor(objectId)); 11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private native long getRotationalLimitMotor(long objectId, int index); 11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private native long getTranslationalLimitMotor(long objectId); 11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * returns the TranslationalLimitMotor of this 6DofJoint which allows 11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * manipulating the translational axis 11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the TranslationalLimitMotor 12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public TranslationalLimitMotor getTranslationalLimitMotor() { 12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return translationalMotor; 12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * returns one of the three RotationalLimitMotors of this 6DofJoint which 12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * allow manipulating the rotational axes 12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param index the index of the RotationalLimitMotor 12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the RotationalLimitMotor at the given index 13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public RotationalLimitMotor getRotationalLimitMotor(int index) { 13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return rotationalMotors.get(index); 13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setLinearUpperLimit(Vector3f vector) { 13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta linearUpperLimit.set(vector); 13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setLinearUpperLimit(objectId, vector); 13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private native void setLinearUpperLimit(long objctId, Vector3f vector); 14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setLinearLowerLimit(Vector3f vector) { 14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta linearLowerLimit.set(vector); 14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setLinearLowerLimit(objectId, vector); 14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private native void setLinearLowerLimit(long objctId, Vector3f vector); 14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setAngularUpperLimit(Vector3f vector) { 15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta angularUpperLimit.set(vector); 15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setAngularUpperLimit(objectId, vector); 15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private native void setAngularUpperLimit(long objctId, Vector3f vector); 15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setAngularLowerLimit(Vector3f vector) { 15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta angularLowerLimit.set(vector); 15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setAngularLowerLimit(objectId, vector); 15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private native void setAngularLowerLimit(long objctId, Vector3f vector); 16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); 16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void read(JmeImporter im) throws IOException { 16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.read(im); 16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta InputCapsule capsule = im.getCapsule(this); 16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); 17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Created Joint {0}", Long.toHexString(objectId)); 17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gatherMotors(); 17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setAngularUpperLimit((Vector3f) capsule.readSavable("angularUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); 17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setAngularLowerLimit((Vector3f) capsule.readSavable("angularLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); 17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setLinearUpperLimit((Vector3f) capsule.readSavable("linearUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); 17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setLinearLowerLimit((Vector3f) capsule.readSavable("linearLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); 17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (int i = 0; i < 3; i++) { 18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta RotationalLimitMotor rotationalLimitMotor = getRotationalLimitMotor(i); 18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setBounce(capsule.readFloat("rotMotor" + i + "_Bounce", 0.0f)); 18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setDamping(capsule.readFloat("rotMotor" + i + "_Damping", 1.0f)); 18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setERP(capsule.readFloat("rotMotor" + i + "_ERP", 0.5f)); 18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setHiLimit(capsule.readFloat("rotMotor" + i + "_HiLimit", Float.POSITIVE_INFINITY)); 18559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setLimitSoftness(capsule.readFloat("rotMotor" + i + "_LimitSoftness", 0.5f)); 18659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setLoLimit(capsule.readFloat("rotMotor" + i + "_LoLimit", Float.NEGATIVE_INFINITY)); 18759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setMaxLimitForce(capsule.readFloat("rotMotor" + i + "_MaxLimitForce", 300.0f)); 18859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setMaxMotorForce(capsule.readFloat("rotMotor" + i + "_MaxMotorForce", 0.1f)); 18959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setTargetVelocity(capsule.readFloat("rotMotor" + i + "_TargetVelocity", 0)); 19059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rotationalLimitMotor.setEnableMotor(capsule.readBoolean("rotMotor" + i + "_EnableMotor", false)); 19159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 19259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta getTranslationalLimitMotor().setAccumulatedImpulse((Vector3f) capsule.readSavable("transMotor_AccumulatedImpulse", Vector3f.ZERO)); 19359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta getTranslationalLimitMotor().setDamping(capsule.readFloat("transMotor_Damping", 1.0f)); 19459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta getTranslationalLimitMotor().setLimitSoftness(capsule.readFloat("transMotor_LimitSoftness", 0.7f)); 19559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta getTranslationalLimitMotor().setLowerLimit((Vector3f) capsule.readSavable("transMotor_LowerLimit", Vector3f.ZERO)); 19659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta getTranslationalLimitMotor().setRestitution(capsule.readFloat("transMotor_Restitution", 0.5f)); 19759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta getTranslationalLimitMotor().setUpperLimit((Vector3f) capsule.readSavable("transMotor_UpperLimit", Vector3f.ZERO)); 19859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 19959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 20059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 20159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void write(JmeExporter ex) throws IOException { 20259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.write(ex); 20359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta OutputCapsule capsule = ex.getCapsule(this); 20459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(angularUpperLimit, "angularUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY)); 20559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(angularLowerLimit, "angularLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY)); 20659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(linearUpperLimit, "linearUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY)); 20759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(linearLowerLimit, "linearLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY)); 20859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta int i = 0; 20959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (Iterator<RotationalLimitMotor> it = rotationalMotors.iterator(); it.hasNext();) { 21059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta RotationalLimitMotor rotationalLimitMotor = it.next(); 21159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getBounce(), "rotMotor" + i + "_Bounce", 0.0f); 21259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getDamping(), "rotMotor" + i + "_Damping", 1.0f); 21359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getERP(), "rotMotor" + i + "_ERP", 0.5f); 21459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getHiLimit(), "rotMotor" + i + "_HiLimit", Float.POSITIVE_INFINITY); 21559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getLimitSoftness(), "rotMotor" + i + "_LimitSoftness", 0.5f); 21659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getLoLimit(), "rotMotor" + i + "_LoLimit", Float.NEGATIVE_INFINITY); 21759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getMaxLimitForce(), "rotMotor" + i + "_MaxLimitForce", 300.0f); 21859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getMaxMotorForce(), "rotMotor" + i + "_MaxMotorForce", 0.1f); 21959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.getTargetVelocity(), "rotMotor" + i + "_TargetVelocity", 0); 22059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(rotationalLimitMotor.isEnableMotor(), "rotMotor" + i + "_EnableMotor", false); 22159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta i++; 22259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 22359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getTranslationalLimitMotor().getAccumulatedImpulse(), "transMotor_AccumulatedImpulse", Vector3f.ZERO); 22459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getTranslationalLimitMotor().getDamping(), "transMotor_Damping", 1.0f); 22559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getTranslationalLimitMotor().getLimitSoftness(), "transMotor_LimitSoftness", 0.7f); 22659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getTranslationalLimitMotor().getLowerLimit(), "transMotor_LowerLimit", Vector3f.ZERO); 22759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getTranslationalLimitMotor().getRestitution(), "transMotor_Restitution", 0.5f); 22859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getTranslationalLimitMotor().getUpperLimit(), "transMotor_UpperLimit", Vector3f.ZERO); 22959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 23059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 231