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.objects; 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.bulletphysics.collision.dispatch.CollisionFlags; 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.bulletphysics.collision.dispatch.PairCachingGhostObject; 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.bulletphysics.linearmath.Transform; 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.collision.PhysicsCollisionObject; 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.collision.shapes.CollisionShape; 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.bullet.util.Converter; 4059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.InputCapsule; 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeExporter; 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.JmeImporter; 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.export.OutputCapsule; 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Matrix3f; 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Quaternion; 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.math.Vector3f; 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.scene.Spatial; 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.io.IOException; 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.LinkedList; 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.List; 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * <i>From Bullet manual:</i><br> 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * GhostObject can keep track of all objects that are overlapping. 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * By default, this overlap is based on the AABB. 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * This is useful for creating a character controller, 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * collision sensors/triggers, explosions etc.<br> 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author normenhansen 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class PhysicsGhostObject extends PhysicsCollisionObject { 6159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 6259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected PairCachingGhostObject gObject; 6359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected boolean locationDirty = false; 6459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta //TEMP VARIABLES 6559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); 6659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected Transform tempTrans = new Transform(Converter.convert(new Matrix3f())); 6759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private com.jme3.math.Transform physicsLocation = new com.jme3.math.Transform(); 6859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected javax.vecmath.Quat4f tempRot = new javax.vecmath.Quat4f(); 6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private List<PhysicsCollisionObject> overlappingObjects = new LinkedList<PhysicsCollisionObject>(); 7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public PhysicsGhostObject() { 7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public PhysicsGhostObject(CollisionShape shape) { 7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta collisionShape = shape; 7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta buildObject(); 7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public PhysicsGhostObject(Spatial child, CollisionShape shape) { 8059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta collisionShape = shape; 8159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta buildObject(); 8259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 8359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 8459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta protected void buildObject() { 8559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (gObject == null) { 8659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject = new PairCachingGhostObject(); 8759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setCollisionFlags(gObject.getCollisionFlags() | CollisionFlags.NO_CONTACT_RESPONSE); 8859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 8959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setCollisionShape(collisionShape.getCShape()); 9059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setUserPointer(this); 9159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 9259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 9359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 9459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setCollisionShape(CollisionShape collisionShape) { 9559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.setCollisionShape(collisionShape); 9659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (gObject == null) { 9759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta buildObject(); 9859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta }else{ 9959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setCollisionShape(collisionShape.getCShape()); 10059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 10159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Sets the physics object location 10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param location the location of the actual physics object 10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setPhysicsLocation(Vector3f location) { 10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(location, tempTrans.origin); 11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setWorldTransform(tempTrans); 11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Sets the physics object rotation 11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param rotation the rotation of the actual physics object 11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setPhysicsRotation(Matrix3f rotation) { 11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(rotation, tempTrans.basis); 12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setWorldTransform(tempTrans); 12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Sets the physics object rotation 12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param rotation the rotation of the actual physics object 12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setPhysicsRotation(Quaternion rotation) { 12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 12959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(rotation, tempTrans.basis); 13059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setWorldTransform(tempTrans); 13159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 13259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 13359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 13459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the physicsLocation 13559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 13659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public com.jme3.math.Transform getPhysicsTransform() { 13759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return physicsLocation; 13859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 13959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 14059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 14159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the physicsLocation 14259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 14359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Vector3f getPhysicsLocation(Vector3f trans) { 14459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (trans == null) { 14559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta trans = new Vector3f(); 14659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 14759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 14859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(tempTrans.origin, physicsLocation.getTranslation()); 14959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return trans.set(physicsLocation.getTranslation()); 15059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 15159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 15259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 15359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the physicsLocation 15459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 15559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Quaternion getPhysicsRotation(Quaternion rot) { 15659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (rot == null) { 15759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rot = new Quaternion(); 15859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 15959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 16059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation()); 16159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return rot.set(physicsLocation.getRotation()); 16259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 16359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 16459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 16559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the physicsLocation 16659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 16759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Matrix3f getPhysicsRotationMatrix(Matrix3f rot) { 16859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (rot == null) { 16959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta rot = new Matrix3f(); 17059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 17159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 17259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation()); 17359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return rot.set(physicsLocation.getRotation()); 17459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 17559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 17659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 17759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the physicsLocation 17859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 17959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Vector3f getPhysicsLocation() { 18059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 18159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(tempTrans.origin, physicsLocation.getTranslation()); 18259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return physicsLocation.getTranslation(); 18359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 18459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 18559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 18659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return the physicsLocation 18759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 18859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Quaternion getPhysicsRotation() { 18959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 19059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation()); 19159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return physicsLocation.getRotation(); 19259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 19359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 19459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Matrix3f getPhysicsRotationMatrix() { 19559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.getWorldTransform(tempTrans); 19659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation()); 19759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return physicsLocation.getRotation().toRotationMatrix(); 19859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 19959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 20059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 20159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * used internally 20259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 20359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public PairCachingGhostObject getObjectId() { 20459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return gObject; 20559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 20659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 20759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 20859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * destroys this PhysicsGhostNode and removes it from memory 20959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 21059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void destroy() { 21159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 21259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 21359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 21459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Another Object is overlapping with this GhostNode, 21559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * if and if only there CollisionShapes overlaps. 21659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * They could be both regular PhysicsRigidBodys or PhysicsGhostObjects. 21759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return All CollisionObjects overlapping with this GhostNode. 21859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 21959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public List<PhysicsCollisionObject> getOverlappingObjects() { 22059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta overlappingObjects.clear(); 22159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta for (com.bulletphysics.collision.dispatch.CollisionObject collObj : gObject.getOverlappingPairs()) { 22259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta overlappingObjects.add((PhysicsCollisionObject) collObj.getUserPointer()); 22359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 22459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return overlappingObjects; 22559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 22659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 22759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 22859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 22959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return With how many other CollisionObjects this GhostNode is currently overlapping. 23059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 23159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public int getOverlappingCount() { 23259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return gObject.getNumOverlappingObjects(); 23359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 23459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 23559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 23659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 23759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param index The index of the overlapping Node to retrieve. 23859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return The Overlapping CollisionObject at the given index. 23959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 24059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public PhysicsCollisionObject getOverlapping(int index) { 24159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return overlappingObjects.get(index); 24259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 24359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 24459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setCcdSweptSphereRadius(float radius) { 24559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setCcdSweptSphereRadius(radius); 24659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 24759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 24859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void setCcdMotionThreshold(float threshold) { 24959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta gObject.setCcdMotionThreshold(threshold); 25059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 25159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 25259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public float getCcdSweptSphereRadius() { 25359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return gObject.getCcdSweptSphereRadius(); 25459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 25559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 25659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public float getCcdMotionThreshold() { 25759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return gObject.getCcdMotionThreshold(); 25859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 25959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 26059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public float getCcdSquareMotionThreshold() { 26159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return gObject.getCcdSquareMotionThreshold(); 26259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 26359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 26459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 26559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void write(JmeExporter e) throws IOException { 26659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.write(e); 26759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta OutputCapsule capsule = e.getCapsule(this); 26859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); 26959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); 27059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); 27159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); 27259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 27359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 27459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 27559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public void read(JmeImporter e) throws IOException { 27659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta super.read(e); 27759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta InputCapsule capsule = e.getCapsule(this); 27859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta buildObject(); 27959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); 28059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setPhysicsRotation(((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f()))); 28159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); 28259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); 28359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 28459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 285