示例#1
0
  public static Spatial AddModel(Vector3f position, String name) {
    s_Model = Main.s_AssetManager.loadModel("Models/tree.obj");

    s_Model.setLocalTranslation(position);
    s_Model.scale(0.8f);
    s_Model.setName(name);

    s_Model.setShadowMode(ShadowMode.CastAndReceive);

    CollisionShape collision = new CapsuleCollisionShape(0.5f, 1f);
    physicsControl = new RigidBodyControl(collision, 0);
    physicsControl.setKinematic(true);
    s_Model.addControl(physicsControl);
    Main.bulletAppState.getPhysicsSpace().add(s_Model);
    // Main.s_TreeNode.attachChild(s_Model);

    return s_Model;
  }
示例#2
0
文件: Main.java 项目: Wigglez/GSP362
  @Override
  public void simpleInitApp() {

    //        setUpKeys();
    flyCam.setEnabled(false);

    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    Juggernaut = new Character(this, bulletAppState);

    setUpCameraBoxes();
    // Load in the level
    // Material m = assetManager.loadMaterial("Models/levelLayout - Update.mtl");
    Spatial map = assetManager.loadModel("Models/levelLayout - Update_cameraPos.obj");
    rootNode.attachChild(map);

    Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    //       mark_mat.setColor("Color", ColorRGBA.White);
    //       mark.setMaterial(mark_mat);
    //        mark.setLocalTranslation(1f,1f,1f);
    //        rootNode.attachChild(mark);

    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(map);
    landscape = new RigidBodyControl(sceneShape, 0);
    map.addControl(landscape);
    landscape.setCollisionGroup(1);
    landscape.removeCollideWithGroup(2);

    //        //Load Ninja as filler for character model
    //        ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    //        //ninja.rotate(0, -1.5f, 0);
    //        ninja.scale(0.02f, 0.02f, 0.02f);
    //        ninja.setLocalTranslation(new Vector3f(341, 300, 0));
    //        //ninja.setMaterial(mark_mat);
    //        rootNode.attachChild(ninja);
    //        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1f, 2f);
    //        player = new CharacterControl(capsuleShape, .05f);
    //        player.setJumpSpeed(50);
    //        player.setFallSpeed(50);
    //        player.setGravity(120);
    //        player.setPhysicsLocation(new Vector3f(1f,8f,1f));
    //        player.setViewDirection(new Vector3f(-1.0f, 0, 0));
    //        player.setCollideWithGroups(2);
    //
    //
    //
    //        playerDebug = player.createDebugShape(assetManager);
    //        ninja.addControl(player);
    //        rootNode.attachChild(playerDebug);
    //
    //        bulletAppState.getPhysicsSpace().add(player);
    bulletAppState.getPhysicsSpace().add(landscape);

    // Elevator 1
    elevator1 = new Geometry("Elevator1", new Box(4, 1, 5));
    elevator1.setLocalTranslation(304, 20, 0);
    elevator1.setMaterial(mark_mat);
    elvtr1 = new RigidBodyControl(10);

    elevator1.addControl(elvtr1);
    elvtr1.setFriction(1000.0f);
    elvtr1.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr1);
    rootNode.attachChild(elevator1);

    // Elevator 2
    elevator2 = new Geometry("Elevator2", new Box(4, 1, 5));
    elevator2.setLocalTranslation(192, 208, 0);
    elevator2.setMaterial(mark_mat);
    elvtr2 = new RigidBodyControl(1000000000);

    elevator2.addControl(elvtr2);
    elvtr2.setAngularDamping(100000.0f);
    elvtr2.setFriction(1000.0f);
    //        elvtr2.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr2);
    rootNode.attachChild(elevator2);

    // Add lights to see the models
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White);
    rootNode.addLight(al);

    //        cam.setLocation(new Vector3f(player.getPhysicsLocation().x,
    // player.getPhysicsLocation().y + 5, player.getPhysicsLocation().z +40 ));
    //        cam.lookAt(player.getPhysicsLocation(), Vector3f.UNIT_Y);
    cam.setLocation(new Vector3f(0, 5, 40));
    cam.lookAt(new Vector3f(0, 5, 0), Vector3f.UNIT_Y);
  }
示例#3
0
  /**
   * Initialises and sets up the camera. This should be called as soon as possible
   *
   * @param root The node to attach the camera to
   * @param physics The physics of the physics engine
   * @param cam The camera that we are going to position here
   */
  public void loadCamera(Node root, PhysicsSpace physics, Camera cam) {
    // Create a node that is at the origin
    centralNode = new Node(nodeName);
    // Create a physics control, that we can move the node with
    centralNodeControl = new RigidBodyControl(1);
    // Add the control
    centralNode.addControl(centralNodeControl);

    // Set up camera
    CameraNode camNode = new CameraNode("cam", cam);
    // The node moves the camera, instead of the camera moving the node
    camNode.setControlDir(CameraControl.ControlDirection.SpatialToCamera);
    // Move it back and up a bit
    camNode.setLocalTranslation(new Vector3f(0, -10, 20));
    // camNode.setLocalTranslation(new Vector3f(0, -10, 50));
    // Look at the origin
    camNode.lookAt(centralNode.getLocalTranslation(), Vector3f.UNIT_Z);

    // Attach the camera to the node at the origin, so that the camera
    // follows the node
    centralNode.attachChild(camNode);

    // Plane that stays at the top of the screen to stop the ball rolling
    // out of sight
    Plane upperPlane = new Plane(Vector3f.UNIT_Y.negate(), -11f);
    RigidBodyControl upperCollision = new RigidBodyControl(new PlaneCollisionShape(upperPlane), 1f);
    Node upperPlaneNode = new Node("uplane");
    upperPlaneNode.addControl(upperCollision);
    // And another plane for bottom of the screen
    Plane lowerPlane = new Plane(Vector3f.UNIT_Y, -19f);

    RigidBodyControl lowerCollision = new RigidBodyControl(new PlaneCollisionShape(lowerPlane), 1f);
    Node lowerPlaneNode = new Node("lplane");
    lowerPlaneNode.addControl(lowerCollision);
    // Put the planes into their own group so that boxes do not collide with them
    upperCollision.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    lowerCollision.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_02);
    // Makes the planes un-affected by forces
    upperCollision.setKinematic(true);
    lowerCollision.setKinematic(true);

    // Attach the planes to the central point that the camera looks at
    // That way we can move them both by moving the central point.
    centralNode.attachChild(upperPlaneNode);
    centralNode.attachChild(lowerPlaneNode);

    // Add some lighting
    PointLight light = new PointLight();
    light.setColor(ColorRGBA.White);
    // light.setRadius(30);
    LightControl lightControl = new LightControl(light);
    // Needs to be added to the camera, as a point in space
    camNode.addControl(lightControl);
    // And added to the root, to have an effect on everything
    root.addLight(light);

    // Finally, add the centre point to the root node
    root.attachChild(centralNode);

    // And add the planes and the centre point to the physics space
    physics.add(upperPlaneNode);
    physics.add(lowerPlaneNode);
    physics.add(centralNode);

    centralNodeControl.setGravity(Vector3f.ZERO); // No gravity
    centralNodeControl.setLinearVelocity(Vector3f.UNIT_Y); // Moves forward
  }