protected void createGhostObject() { ghostObject = new PhysicsGhostObject(new SphereCollisionShape(explosionRadius)); }
@Override public void simpleInitApp() { assetManager.registerLocator(".", FileLocator.class); CollisionShape shape = new SphereCollisionShape(1f); RigidBodyControl rbc = new RigidBodyControl(shape, 1f); setParameters(rbc); verifyParameters(rbc); RigidBodyControl rbcCopy = (RigidBodyControl) saveThenLoad(rbc); verifyParameters(rbcCopy); stop(); }
@Override public void simpleInitApp() { CollisionShape capsule = new SphereCollisionShape(1f); PhysicsRigidBody body1 = new PhysicsRigidBody(capsule, 1f); PhysicsRigidBody body2 = new PhysicsRigidBody(capsule, 1f); Vector3f pivot1 = new Vector3f(); Vector3f pivot2 = new Vector3f(); Point2PointJoint joint = new Point2PointJoint(body1, body2, pivot1, pivot2); joint.setImpulseClamp(42f); joint.setTau(99f); if (joint.getImpulseClamp() != 42f) { throw new RuntimeException(); } if (joint.getTau() != 99f) { throw new RuntimeException(); } stop(); } }
public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(cam.getLocation()); SphereCollisionShape bulletCollisionShape = new SphereCollisionShape(0.4f); RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); // RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1); bulletNode.setLinearVelocity(cam.getDirection().mult(25)); bulletg.addControl(bulletNode); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletNode); } if (name.equals("gc") && !keyPressed) { System.gc(); } } };
private void prepareBullet() { bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); bulletCollisionShape = new SphereCollisionShape(0.4f); matBullet = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); matBullet.setColor("Color", ColorRGBA.Green); matBullet.setColor("GlowColor", ColorRGBA.Green); getPhysicsSpace().addCollisionListener(this); }
@Override public void simpleInitApp() { CollisionShape capsule = new SphereCollisionShape(1f); PhysicsRigidBody body1 = new PhysicsRigidBody(capsule, 1f); PhysicsRigidBody body2 = new PhysicsRigidBody(capsule, 1f); Vector3f pivot1 = new Vector3f(); Vector3f pivot2 = new Vector3f(); SixDofJoint joint = new SixDofJoint(body1, body2, pivot1, pivot2, true); joint.getTranslationalLimitMotor().getLimitSoftness(); stop(); } }
@Override public void simpleInitApp() { CollisionShape capsule = new SphereCollisionShape(1f); PhysicsRigidBody body = new PhysicsRigidBody(capsule, 1f); assert body.getAngularSleepingThreshold() == 1f; assert body.getLinearSleepingThreshold() == 0.8f; body.setAngularSleepingThreshold(0.03f); assert body.getAngularSleepingThreshold() == 0.03f; float lst = body.getLinearSleepingThreshold(); assert lst == 0.8f : lst; // fails, actual value is 1f body.setLinearSleepingThreshold(0.17f); float ast = body.getAngularSleepingThreshold(); assert ast == 0.03f : ast; // fails, actual value is 1f stop(); } }
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); bulletCollisionShape = new SphereCollisionShape(0.4f); PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace()); PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace()); // add ourselves as collision listener getPhysicsSpace().addCollisionListener(this); }
@Override public void simpleInitApp() { //set far frustum only so we see the outer world longer cam.setFrustumFar(10000); cam.setLocation(Vector3f.ZERO); debugTools = new DebugTools(assetManager); rootNode.attachChild(debugTools.debugNode); poiMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); poiMaterial.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); poiMesh = new Sphere(16, 16, 1f); ballMaterial = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); ballMaterial.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); ballMaterial.setColor("Color", ColorRGBA.Red); ballMesh = new Sphere(16, 16, 1.0f); poiHorizonCollisionShape = new MeshCollisionShape(new Sphere(128, 128, poiRadius)); poiCollisionShape = new SphereCollisionShape(1f); ballCollisionShape = new SphereCollisionShape(1f); setupKeys(); setupDisplay(); setupFog(); }
/** * Set the collision shape based on the controlled spatial and its * descendents. */ protected void createCollisionShape() { if (spatial == null) { return; } if (spatial instanceof Geometry) { Geometry geom = (Geometry) spatial; Mesh mesh = geom.getMesh(); if (mesh instanceof Sphere) { collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius()); return; } else if (mesh instanceof Box) { collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent())); return; } } if (mass > 0) { collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial); } else { collisionShape = CollisionShapeFactory.createMeshShape(spatial); } }
/** * Set the collision shape based on the controlled spatial and its * descendents. */ protected void createCollisionShape() { if (spatial == null) { return; } if (spatial instanceof Geometry) { Geometry geom = (Geometry) spatial; Mesh mesh = geom.getMesh(); if (mesh instanceof Sphere) { collisionShape = new SphereCollisionShape(((Sphere) mesh).getRadius()); return; } else if (mesh instanceof Box) { collisionShape = new BoxCollisionShape(new Vector3f(((Box) mesh).getXExtent(), ((Box) mesh).getYExtent(), ((Box) mesh).getZExtent())); return; } } if (mass > 0) { collisionShape = CollisionShapeFactory.createDynamicMeshShape(spatial); } else { collisionShape = CollisionShapeFactory.createMeshShape(spatial); } }
@Override public void simpleInitApp() { flyCam.setEnabled(false); BulletAppState bulletAppState = new BulletAppState(); bulletAppState.setDebugEnabled(true); bulletAppState.setSpeed(0f); stateManager.attach(bulletAppState); PhysicsSpace space = bulletAppState.getPhysicsSpace(); float radius = 1f; CollisionShape sphere = new SphereCollisionShape(radius); CollisionShape box = new BoxCollisionShape(Vector3f.UNIT_XYZ); RigidBodyControl rbc = new RigidBodyControl(box); rbc.setEnabled(false); rbc.setPhysicsSpace(space); rootNode.addControl(rbc); BetterCharacterControl bcc = new BetterCharacterControl(radius, 4f, 1f); bcc.setEnabled(false); bcc.setPhysicsSpace(space); rootNode.addControl(bcc); GhostControl gc = new GhostControl(sphere); gc.setEnabled(false); gc.setPhysicsSpace(space); rootNode.addControl(gc); } }
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); }
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL); // bulletAppState.setEnabled(false); stateManager.attach(bulletAppState); bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); bulletCollisionShape = new SphereCollisionShape(0.4f); brick = new Box(brickWidth, brickHeight, brickDepth); brick.scaleTextureCoordinates(new Vector2f(1f, .5f)); //bulletAppState.getPhysicsSpace().enableDebug(assetManager); initMaterial(); initTower(); initFloor(); initCrossHairs(); this.cam.setLocation(new Vector3f(0, 25f, 8f)); cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0)); cam.setFrustumFar(80); inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addListener(actionListener, "shoot"); rootNode.setShadowMode(ShadowMode.Off); }
player = new PhysicsCharacter(new SphereCollisionShape(5), .01f); player.setJumpSpeed(20); player.setFallSpeed(30);
@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); }
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL); stateManager.attach(bulletAppState); bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); bulletCollisionShape = new SphereCollisionShape(0.4f); brick = new Box(bLength, bHeight, bWidth); brick.scaleTextureCoordinates(new Vector2f(1f, .5f)); initMaterial(); initWall(); initFloor(); initCrossHairs(); this.cam.setLocation(new Vector3f(0, 6f, 6f)); cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0)); cam.setFrustumFar(15); inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); inputManager.addListener(actionListener, "shoot"); inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X)); inputManager.addListener(actionListener, "gc"); rootNode.setShadowMode(ShadowMode.Off); }
bulletAppState.setDebugEnabled(true); Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere); Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0)); rootNode.attachChild(physicsSphere2);
@Override public void simpleInitApp() { bulletAppState = new BulletAppState(); stateManager.attach(bulletAppState); bulletAppState.setDebugEnabled(true); bullet = new Sphere(32, 32, 0.4f, true, false); bullet.setTextureMode(TextureMode.Projected); bulletCollisionShape = new SphereCollisionShape(0.1f); setupKeys(); mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.getAdditionalRenderState().setWireframe(true); mat.setColor("Color", ColorRGBA.Green); mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat2.getAdditionalRenderState().setWireframe(true); mat2.setColor("Color", ColorRGBA.Red); // An obstacle mesh, does not move (mass=0) Node node2 = new Node(); node2.setName("mesh"); node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f)); node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(4, 4, 0.1f)), 0)); rootNode.attachChild(node2); getPhysicsSpace().add(node2); // The floor, does not move (mass=0) Node node3 = new Node(); node3.setLocalTranslation(new Vector3f(0f, -6, 0f)); node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0)); rootNode.attachChild(node3); getPhysicsSpace().add(node3); }
Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1); physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0)); rootNode.attachChild(physicsSphere);