/** * 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; }
/** * Constructs the MainGameState. Creates the scene and add the different objects to the * Scenegraph. * * @param name name of the GameState */ public MainGameState(String name) { super(name); // the node where newly created objects get attached to objectsNode = new Node("object Node"); rootNode.attachChild(objectsNode); // create the scene picker = new PhysicsPicker(input, rootNode, getPhysicsSpace(), true); picker.getInputHandler().setEnabled(false); init(); setupInput(); setupLight(); // add a few objects to the scene ObjectFactory.createObjectFactory(getPhysicsSpace()); createFloor(50, 50); createOuterWalls(75); wall = new Wall( getPhysicsSpace(), SceneSettings.get().getWallWidth(), SceneSettings.get().getWallHeigth(), SceneSettings.get().getWallElementSize()); wall.setLocalTranslation(0, 0, -3); rootNode.attachChild(wall); seesaw = new Seesaw(getPhysicsSpace()); seesaw.setLocalTranslation(-13, -1, 5); rootNode.attachChild(seesaw); // swing = new Swing(getPhysicsSpace()); // swing.setLocalTranslation(15, 3f, 4); // rootNode.attachChild(swing); rootNode.updateGeometricState(0, true); rootNode.updateRenderState(); }