public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f ); reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f); this.batchNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); nbBrick++; }
public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f ); reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f); this.rootNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); }
public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); //for geometry with sphere mesh the physics system automatically uses a sphere collision shape reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f); this.rootNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); }
public void onAction(String binding, boolean value, float tpf) { if (binding.equals("shoot") && !value) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat); bulletg.setName("bullet"); bulletg.setLocalTranslation(cam.getLocation()); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1)); bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f); bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40)); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletg); } else if (binding.equals("shoot2") && !value) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setName("bullet"); bulletg.setLocalTranslation(cam.getLocation()); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1)); bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40)); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletg); } } }
public void initWall(float bLength, float bWidth, float bHeight) { Box brick = new Box(bLength, bHeight, bWidth); brick.scaleTextureCoordinates(new Vector2f(1f, .5f)); Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg"); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); mat2.setTexture("ColorMap", tex); float startpt = bLength / 4; float height = -5; for (int j = 0; j < 15; j++) { for (int i = 0; i < 4; i++) { Vector3f ori = new Vector3f(i * bLength * 2 + startpt, bHeight + height, -10); Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat2); reBoxg.setLocalTranslation(ori); //for geometry with sphere mesh the physics system automatically uses a sphere collision shape reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f); this.rootNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); } startpt = -startpt; height += 2 * bHeight; } }
ballGeometry.getControl(RigidBodyControl.class).setRestitution(1); rootNode.attachChild(ballGeometry); space.add(ballGeometry);
@Override public void makeSpheres(Material mat) { for (int i = 0; i < 5; i++) { RigidBodyControl rbc = new RigidBodyControl(.001f); Sphere s = findOrMakeMeshShapeFacade(null).makeSphereMesh(16, 16, 0.5f); Geometry ballGeometry = findOrMakeSceneGeometryFacade(null).makeGeom( GeomFactory.GEOM_SOCCER_BALL, s, mat, rbc); //RigidBodyControl automatically uses Sphere collision shapes when attached to single geometry with sphere mesh ballGeometry.getControl(RigidBodyControl.class).setRestitution(1); ballGeometry.setLocalTranslation(i, 2, -3); myParentNode.attachChild(ballGeometry); myPhysSpc.add(ballGeometry); } } @Override public void makeImmovableSphere(Material mat) {