Java Code Examples for com.jme3.bullet.PhysicsSpace#remove()
The following examples show how to use
com.jme3.bullet.PhysicsSpace#remove() .
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: BombControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void physicsTick(PhysicsSpace space, float f) { //get all overlapping objects and apply impulse to them for (Iterator<PhysicsCollisionObject> it = ghostObject.getOverlappingObjects().iterator(); it.hasNext();) { PhysicsCollisionObject physicsCollisionObject = it.next(); if (physicsCollisionObject instanceof PhysicsRigidBody) { PhysicsRigidBody rBody = (PhysicsRigidBody) physicsCollisionObject; rBody.getPhysicsLocation(vector2); vector2.subtractLocal(vector); float force = explosionRadius - vector2.length(); force *= forceFactor; force = force > 0 ? force : 0; vector2.normalizeLocal(); vector2.multLocal(force); ((PhysicsRigidBody) physicsCollisionObject).applyImpulse(vector2, Vector3f.ZERO); } } space.removeTickListener(this); space.remove(ghostObject); }
Example 2
Source File: KinematicRagdollControl.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void removePhysics(PhysicsSpace space) { if (baseRigidBody != null) { space.remove(baseRigidBody); } for (Iterator<PhysicsBoneLink> it = boneLinks.values().iterator(); it.hasNext();) { PhysicsBoneLink physicsBoneLink = it.next(); if (physicsBoneLink.joint != null) { space.remove(physicsBoneLink.joint); if (physicsBoneLink.rigidBody != null) { space.remove(physicsBoneLink.rigidBody); } } } space.removeCollisionListener(this); }
Example 3
Source File: DacLinks.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Remove all managed physics objects from the PhysicsSpace. */ @Override protected void removePhysics(PhysicsSpace space) { assert added; PhysicsRigidBody rigidBody; if (torsoLink != null) { rigidBody = torsoLink.getRigidBody(); space.remove(rigidBody); } for (BoneLink boneLink : boneLinks.values()) { rigidBody = boneLink.getRigidBody(); space.remove(rigidBody); PhysicsJoint joint = boneLink.getJoint(); space.remove(joint); } }
Example 4
Source File: BombControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void physicsTick(PhysicsSpace space, float f) { //get all overlapping objects and apply impulse to them for (Iterator<PhysicsCollisionObject> it = ghostObject.getOverlappingObjects().iterator(); it.hasNext();) { PhysicsCollisionObject physicsCollisionObject = it.next(); if (physicsCollisionObject instanceof PhysicsRigidBody) { PhysicsRigidBody rBody = (PhysicsRigidBody) physicsCollisionObject; rBody.getPhysicsLocation(vector2); vector2.subtractLocal(vector); float force = explosionRadius - vector2.length(); force *= forceFactor; force = force > 0 ? force : 0; vector2.normalizeLocal(); vector2.multLocal(force); ((PhysicsRigidBody) physicsCollisionObject).applyImpulse(vector2, Vector3f.ZERO); } } space.removeTickListener(this); space.remove(ghostObject); }
Example 5
Source File: CollisionTester.java From OpenRTS with MIT License | 4 votes |
public static boolean areColliding(Asset asset1, Asset asset2, boolean debug){ Spatial s1 = getSpatialFromAsset(asset1); Spatial s2 = getSpatialFromAsset(asset2); PhysicsSpace space = new PhysicsSpace(); RigidBodyControl ghost1 = new RigidBodyControl(getCollisionShape(asset1)); s1.addControl(ghost1); space.add(ghost1); RigidBodyControl ghost2 = new RigidBodyControl(getCollisionShape(asset2)); s2.addControl(ghost2); // ghost2.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02); // space.add(ghost2); space.update(1); // int numCollision = ghost1.getOverlappingCount(); // boolean collision = numCollision > 0; Transform t = new Transform(); t.setRotation(s2.getLocalRotation()); t.setTranslation(s2.getLocalTranslation()); boolean collision = false; for(ChildCollisionShape hull : getCollisionShape(asset2).getChildren()) if(!space.sweepTest(hull.shape, Transform.IDENTITY, t).isEmpty()){ collision = true; break; } space.remove(ghost1); // space.remove(ghost2); // if(!collision){ // Spatial debugS2 = DebugShapeFactory.getDebugShape(ghost2.getCollisionShape()); // debugS2.setLocalRotation(ghost2.getPhysicsRotation()); //// Spatial debugS2 = s2; // Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); // m.getAdditionalRenderState().setWireframe(true); // m.setColor("Color", ColorRGBA.Red); // debugS2.setMaterial(m); // debugS2.setLocalTranslation(ghost2.getPhysicsLocation()); // asset2.s = debugS2; // //EventManager.post(new GenericEvent(debugS2)); // } if(!collision){// && debug){ Material m = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); m.getAdditionalRenderState().setWireframe(true); m.setColor("Color", ColorRGBA.Red); Spatial debugS2 = DebugShapeFactory.getDebugShape(getCollisionShape(asset2)); debugS2.setLocalTransform(t); // debugS2.setLocalRotation(ghost2.getPhysicsRotation()); // debugS2.setLocalTranslation(ghost2.getPhysicsLocation()); debugS2.setMaterial(m); Material m2 = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md"); m2.getAdditionalRenderState().setWireframe(true); m2.setColor("Color", ColorRGBA.Blue); Geometry linegeom = new Geometry(); Line l = new Line(debugS2.getLocalTranslation().add(0, 0, 1), ghost1.getPhysicsLocation().add(0, 0, 1)); linegeom.setMesh(l); linegeom.setMaterial(m2); asset2.s = debugS2; if(l.getStart().distance(l.getEnd())<2) asset2.links.add(linegeom); // EventManager.post(new GenericEvent(debugS2)); // EventManager.post(new GenericEvent(linegeom)); } return collision; }