/** * Access the user object of collision object A, provided it's a Spatial. * * @return the pre-existing Spatial, or null if none */ public Spatial getNodeA() { if (nodeA.getUserObject() instanceof Spatial) { return (Spatial) nodeA.getUserObject(); } return null; }
@Override public void setCollisionShape(CollisionShape collisionShape) { super.setCollisionShape(collisionShape); if (gObject == null) { buildObject(); }else{ gObject.setCollisionShape(collisionShape.getCShape()); } }
public boolean needBroadphaseCollision(BroadphaseProxy bp, BroadphaseProxy bp1) { boolean collides = (bp.collisionFilterGroup & bp1.collisionFilterMask) != 0; if (collides) { collides = (bp1.collisionFilterGroup & bp.collisionFilterMask) != 0; } if (collides) { assert (bp.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject && bp1.clientObject instanceof com.bulletphysics.collision.dispatch.CollisionObject); com.bulletphysics.collision.dispatch.CollisionObject colOb = (com.bulletphysics.collision.dispatch.CollisionObject) bp.clientObject; com.bulletphysics.collision.dispatch.CollisionObject colOb1 = (com.bulletphysics.collision.dispatch.CollisionObject) bp1.clientObject; assert (colOb.getUserPointer() != null && colOb1.getUserPointer() != null); PhysicsCollisionObject collisionObject = (PhysicsCollisionObject) colOb.getUserPointer(); PhysicsCollisionObject collisionObject1 = (PhysicsCollisionObject) colOb1.getUserPointer(); if ((collisionObject.getCollideWithGroups() & collisionObject1.getCollisionGroup()) > 0 || (collisionObject1.getCollideWithGroups() & collisionObject.getCollisionGroup()) > 0) { PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup()); PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup()); if(listener != null){ collides = listener.collide(collisionObject, collisionObject1); } if(listener1 != null && collisionObject.getCollisionGroup() != collisionObject1.getCollisionGroup()){ collides = listener1.collide(collisionObject, collisionObject1) && collides; } } else { return false; } } return collides; } };
@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)); } }
@Override public void write(JmeExporter e) throws IOException { super.write(e); OutputCapsule capsule = e.getCapsule(this); capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); }
@Override public void simpleUpdate(float tpf) { float move = tpf * 1; boolean colliding = false; List<PhysicsSweepTestResult> sweepTest = bulletAppState.getPhysicsSpace().sweepTest(capsuleCollisionShape, new Transform(capsule.getWorldTranslation()), new Transform(capsule.getWorldTranslation().add(dist, 0, 0))); for (PhysicsSweepTestResult result : sweepTest) { if (result.getCollisionObject().getCollisionShape() != capsuleCollisionShape) { PhysicsCollisionObject collisionObject = result.getCollisionObject(); fpsText.setText("Almost colliding with " + collisionObject.getUserObject().toString()); colliding = true; } } if (!colliding) { // if the sweep is clear then move the spatial capsule.move(move, 0, 0); } } }
/** * Remove collision groups from the set with which this object can collide. * * @param collisionGroup groups to remove, ORed together (bit mask) */ public void removeCollideWithGroup(int collisionGroup) { this.collisionGroupsMask = this.collisionGroupsMask & ~collisionGroup; if (objectId != 0) { setCollideWithGroups(this.collisionGroupsMask); } }
/** * This method is invoked from native code. */ private boolean notifyCollisionGroupListeners_native(PhysicsCollisionObject node, PhysicsCollisionObject node1){ PhysicsCollisionGroupListener listener = collisionGroupListeners.get(node.getCollisionGroup()); PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(node1.getCollisionGroup()); boolean result = true; if(listener != null){ result = listener.collide(node, node1); } if(listener1 != null && node.getCollisionGroup() != node1.getCollisionGroup()){ result = listener1.collide(node, node1) && result; } return result; }
/** * Finalize this physics character just before it is destroyed. Should be * invoked only by a subclass or by the garbage collector. * * @throws Throwable ignored by the garbage collector */ @Override protected void finalize() throws Throwable { super.finalize(); finalizeNativeCharacter(characterId); }
/** * Finalize this collision object just before it is destroyed. Should be * invoked only by a subclass or by the garbage collector. * * @throws Throwable ignored by the garbage collector */ @Override protected void finalize() throws Throwable { super.finalize(); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing CollisionObject {0}", Long.toHexString(objectId)); finalizeNative(objectId); }
native void initUserPointer(long objectId, int group, int groups);
/** * Alter the collision group for this physics object. * <p> * Groups are represented by integer bit masks with exactly 1 bit set. * Pre-made variables are available in PhysicsCollisionObject. By default, * physics objects are in COLLISION_GROUP_01. * <p> * Two objects can collide only if one of them has the collisionGroup of the * other in its collideWithGroups set. * * @param collisionGroup the collisionGroup to apply (bit mask with exactly * 1 bit set) */ public void setCollisionGroup(int collisionGroup) { this.collisionGroup = collisionGroup; if (objectId != 0) { setCollisionGroup(objectId, collisionGroup); } }
/** * De-serialize this object from the specified importer, for example when * loading from a J3O file. * * @param e importer (not null) * @throws IOException from importer */ @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)); } }
/** * Serialize this object, 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(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); }
/** * Directly alter the collision groups with which this object can collide. * * @param collisionGroups desired groups, ORed together (bit mask) */ public void setCollideWithGroups(int collisionGroups) { this.collisionGroupsMask = collisionGroups; if (objectId != 0) { setCollideWithGroups(objectId, this.collisionGroupsMask); } }
private boolean notifyCollisionGroupListeners_native(PhysicsCollisionObject node, PhysicsCollisionObject node1){ PhysicsCollisionGroupListener listener = collisionGroupListeners.get(node.getCollisionGroup()); PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(node1.getCollisionGroup()); boolean result = true; if(listener != null){ result = listener.collide(node, node1); } if(listener1 != null && node.getCollisionGroup() != node1.getCollisionGroup()){ result = listener1.collide(node, node1) && result; } return result; }
@Override protected void finalize() throws Throwable { super.finalize(); finalizeNativeCharacter(characterId); }
@Override protected void finalize() throws Throwable { super.finalize(); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Finalizing CollisionObject {0}", Long.toHexString(objectId)); finalizeNative(objectId); }
native void initUserPointer(long objectId, int group, int groups); /**
/** * Sets the collision group number for this physics object. <br> * The groups are integer bit masks and some pre-made variables are available in CollisionObject. * All physics objects are by default in COLLISION_GROUP_01.<br> * Two object will collide when <b>one</b> of the partys has the * collisionGroup of the other in its collideWithGroups set. * @param collisionGroup the collisionGroup to set */ public void setCollisionGroup(int collisionGroup) { this.collisionGroup = collisionGroup; if (objectId != 0) { setCollisionGroup(objectId, collisionGroup); } }