/** * Enable or disable this control. * <p> * When the control is disabled, the body is removed from physics space. * When the control is enabled again, the body is moved to the current * location of the spatial and then added to the physics space. * * @param enabled true→enable the control, false→disable it */ public void setEnabled(boolean enabled) { this.enabled = enabled; if (space != null) { if (enabled && !added) { if (spatial != null) { setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); } space.addCollisionObject(this); added = true; } else if (!enabled && added) { space.removeCollisionObject(this); added = false; } } }
/** * Alter which spatial is controlled. Invoked when the control is added to * or removed from a spatial. Should be invoked only by a subclass or from * Spatial. Do not invoke directly from user code. * * @param spatial the spatial to control (or null) */ public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } if (collisionShape == null) { createCollisionShape(); rebuildRigidBody(); } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
/** * Enable or disable this control. * <p> * When the control is disabled, the body is removed from physics space. * When the control is enabled again, the body is moved to the current * location of the spatial and then added to the physics space. * * @param enabled true→enable the control, false→disable it */ public void setEnabled(boolean enabled) { this.enabled = enabled; if (space != null) { if (enabled && !added) { if (spatial != null) { setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); } space.addCollisionObject(this); added = true; } else if (!enabled && added) { space.removeCollisionObject(this); added = false; } } }
/** * Alter which spatial is controlled. Invoked when the control is added to * or removed from a spatial. Should be invoked only by a subclass or from * Spatial. Do not invoke directly from user code. * * @param spatial the spatial to control (or null) */ public void setSpatial(Spatial spatial) { this.spatial = spatial; setUserObject(spatial); if (spatial == null) { return; } if (collisionShape == null) { createCollisionShape(); rebuildRigidBody(); } setPhysicsLocation(getSpatialTranslation()); setPhysicsRotation(getSpatialRotation()); }
Node createTestNode(float mass, Vector3f location) { float size = 0.1f; Vector3f halfExtents = new Vector3f(size, size, size); CollisionShape shape = new BoxCollisionShape(halfExtents); RigidBodyControl control = new RigidBodyControl(shape, mass); Node node = new Node(); node.addControl(control); rootNode.attachChild(node); bulletAppState.getPhysicsSpace().add(node); control.setPhysicsLocation(location); return node; }
vehicle.setAngularVelocity(Vector3f.ZERO); vehicle.resetSuspension(); bridge.setPhysicsLocation(new Vector3f(0,1.4f,4)); bridge.setPhysicsRotation(Quaternion.DIRECTION_Z.toRotationMatrix());
private void reset() { // Reset the pickups for(Spatial pickUp : pickUps.getChildren()) { GhostControl pickUpControl = pickUp.getControl(GhostControl.class); if(pickUpControl != null) { pickUpControl.setEnabled(true); } pickUp.setLocalScale(1.0f); } // Reset the player player.setPhysicsLocation(PLAYER_START.clone()); player.setAngularVelocity(Vector3f.ZERO.clone()); player.setLinearVelocity(Vector3f.ZERO.clone()); // Reset the score score = 0; // Reset the message messageText.setLocalScale(0.0f); }
public void setupJoint() { Node holderNode=PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .1f, .1f, .1f)),0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,0,0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode=PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f( .3f, .3f, .3f)),1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f,-1,0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); joint=new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f,-1,0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); // Add a physics sphere to the world Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); // Add a physics sphere to the world Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); physicsSphere2.getControl(RigidBodyControl.class).addCollideWithGroup(PhysicsCollisionObject.COLLISION_GROUP_02); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); // an obstacle mesh, does not move (mass=0) Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); node2.getControl(RigidBodyControl.class).setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02); node2.getControl(RigidBodyControl.class).setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_02); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // the floor, does not move (mass=0) Node node3 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Box(100f, 0.2f, 100f)), 0); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3); }
physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); physicsBox1.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0, 40, 0)); rootNode.attachChild(physicsBox1); getPhysicsSpace().add(physicsBox1); physicsBox2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.5f, 80, -.8f)); rootNode.attachChild(physicsBox2); getPhysicsSpace().add(physicsBox2); node.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node); getPhysicsSpace().add(node);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0)); rootNode.attachChild(physicsSphere2); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3);
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); getPhysicsSpace().add(physicsSphere); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); rootNode.attachChild(physicsSphere2); getPhysicsSpace().add(physicsSphere2); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); rootNode.attachChild(physicsBox); getPhysicsSpace().add(physicsBox); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); rootNode.attachChild(physicsCylinder); getPhysicsSpace().add(physicsCylinder); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); rootNode.attachChild(node3); getPhysicsSpace().add(node3);
public void setupJoint() { Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0); holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f)); rootNode.attachChild(holderNode); getPhysicsSpace().add(holderNode); Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 1); hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -1, 0f)); rootNode.attachChild(hammerNode); getPhysicsSpace().add(hammerNode); //immovable collisionNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 0); collisionNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1.8f, 0, 0f)); rootNode.attachChild(collisionNode); getPhysicsSpace().add(collisionNode); //ghost node ghostControl = new GhostControl(new SphereCollisionShape(0.7f)); hammerNode.addControl(ghostControl); getPhysicsSpace().add(ghostControl); joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z); getPhysicsSpace().add(joint); }
physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); physicsSphere.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(4, 8, 0)); physicsSphere2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsSphere2); physicsBox.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(.6f, 4, .5f)); physicsBox.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsBox); physicsCylinder.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2, 2, 0)); physicsCylinder.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(physicsCylinder); node2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(2.5f, -4, 0f)); node2.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node2); node3.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -6, 0f)); node3.getControl(RigidBodyControl.class).setApplyPhysicsLocal(true); rootNode.attachChild(node3);
control.setKinematicSpatial(isKinematicSpatial()); control.setLinearSleepingThreshold(getLinearSleepingThreshold()); control.setPhysicsLocation(getPhysicsLocation(null)); control.setPhysicsRotation(getPhysicsRotationMatrix(null)); control.setRestitution(getRestitution());
control.setKinematicSpatial(isKinematicSpatial()); control.setLinearSleepingThreshold(getLinearSleepingThreshold()); control.setPhysicsLocation(getPhysicsLocation(null)); control.setPhysicsRotation(getPhysicsRotationMatrix(null)); control.setRestitution(getRestitution());
final void reset() { control.setPhysicsLocation(initialPosition); // Give the balls a little random motion so they will shake down to stable equilibrium Random random = new Random(new Long(uri.hashCode())); control.setLinearVelocity(new Vector3f(random.nextFloat() - 0.5f, 0.25f * (random.nextFloat() - 0.5f), random.nextFloat() - 0.5f)); }
private void setLocation(Node device, Vector3f loc) { RigidBodyControl rbc = device.getControl(RigidBodyControl.class); if(rbc != null) { rbc.setPhysicsLocation(loc); } else { device.setLocalTranslation(loc); } }
@Override public Void call() throws Exception { //geometry.addControl(control); myPhysics.add(control); myBallsNode.attachChild(geometry); control.setPhysicsLocation(initialPosition); // Probably unnecessary - setting this here, in reset() above, and using resetAllBalls in buildModelFromTurtle because they don't want to go to the initial position! Probably some sort of jME concurrency thing... return null; } });