/** * create a new Object. The ObjectFactory create an object depending on what we selected in the * GUI GameState. - the new Object gets attached to the objectNode, - is moved a bit in front of * the camera - and finally we add force to it. */ private void spawnObject() { DynamicPhysicsNode node = ObjectFactory.get().createObject(); node.setName("physics node"); node.getLocalTranslation().set(cam.getLocation()); node.getLocalTranslation() .addLocal(cam.getDirection().mult(new Vector3f(2, 2, 2).add(node.getLocalScale()))); node.addForce(cam.getDirection().mult(ObjectFactory.get().getForce())); objectsNode.attachChild(node); objectsNode.updateRenderState(); objectsNode.updateGeometricState(0, false); }
/** * a simple helper method to create a static physic wall. * * @param name node name * @param x x extent * @param y y extent * @param z z extent * @param loc location * @param type type of material/texture * @return staticPhysicNode with the attached box */ public StaticPhysicsNode makeWall( String name, float x, float y, float z, Vector3f loc, MaterialType type) { Box box = new Box(name, new Vector3f(), x, y, z); box.setModelBound(new BoundingBox()); box.updateModelBound(); if (type != null) ObjectFactory.get().applyRenderStates(box, type); StaticPhysicsNode physicWall = getPhysicsSpace().createStaticNode(); physicWall.attachChild(box); physicWall.setLocalTranslation(loc); physicWall.generatePhysicsGeometry(); return physicWall; }