示例#1
0
文件: Main.java 项目: Wigglez/GSP362
  @Override
  public void simpleUpdate(float tpf) {
    Juggernaut.Update(tpf);
    // Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
    //        walkDirection.set( 0, 0, 0);
    //        if(left)    { walkDirection.addLocal(Vector3f.UNIT_X.negate().multLocal(0.4f));}
    //        if(right)   { walkDirection.addLocal(Vector3f.UNIT_X.clone().multLocal(0.4f));}
    //        player.setWalkDirection(walkDirection);
    //        if( walkDirection != Vector3f.ZERO){
    //            player.setViewDirection(walkDirection.negate());
    //        }
    //
    //        playerDebug.setLocalTranslation(player.getPhysicsLocation());
    elevator1.setLocalTranslation(304 + 20 * FastMath.cos(timer.getTimeInSeconds()), 20, 0);
    elvtr1.setPhysicsLocation(elevator1.getLocalTranslation());

    //        elevator2.setLocalTranslation( 192, 208 + 35*FastMath.cos(timer.getTimeInSeconds()),
    // 0);
    //        elvtr2.setPhysicsLocation(elevator2.getLocalTranslation());
    elvtr2.setLinearVelocity(new Vector3f(0, 25 * FastMath.cos(timer.getTimeInSeconds()), 0));
    elvtr2.setPhysicsRotation(Matrix3f.IDENTITY);
    System.out.print(landscape.getCollideWithGroups() + "\n");

    for (int i = 0; i < views.length; i++) {
      if (views[i].testForPlayer(Juggernaut)) {
        currentView = views[i];
      }
    }

    cam.setLocation(currentView.CamPosition());
    cam.lookAt(currentView.CamLookAt(), Vector3f.UNIT_Y);
  }
示例#2
0
 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(getCam().getLocation());
     RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1);
     //                RigidBodyControl bulletNode = new
     // RigidBodyControl(bulletCollisionShape, 1);
     bulletNode.setLinearVelocity(getCam().getDirection().mult(25));
     bulletg.addControl(bulletNode);
     rootNode.attachChild(bulletg);
     getPhysicsSpace().add(bulletNode);
   }
 }
示例#3
0
 /**
  * This method creates one individual physical cannon ball. By defaul, the ball is accelerated and
  * flies from the camera position in the camera direction.
  */
 public void makeCannonBall() {
   /** Create a cannon ball geometry and attach to scene graph. */
   Geometry ball_geo = new Geometry("cannon ball", sphere);
   ball_geo.setMaterial(stone_mat);
   rootNode.attachChild(ball_geo);
   /** Position the cannon ball and activate shadows */
   ball_geo.setLocalTranslation(cam.getLocation());
   ball_geo.setShadowMode(ShadowMode.CastAndReceive);
   /** Make the ball physcial with a mass > 0.0f */
   ball_phy = new RigidBodyControl(1f);
   /** Add physical ball to physics space. */
   ball_geo.addControl(ball_phy);
   bulletAppState.getPhysicsSpace().add(ball_phy);
   /** Accelerate the physcial ball to shoot it. */
   ball_phy.setLinearVelocity(cam.getDirection().mult(25));
 }
示例#4
0
 @Override
 protected void controlUpdate(float tpf) {
   RigidBodyControl diceControl = spatial.getControl(RigidBodyControl.class);
   if (number != 0) {
     diceControl.setEnabled(true);
     int numberValue = 0;
     synchronized (spatial) {
       numberValue = number;
     }
     switch (numberValue) {
       case 1:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.HALF_PI, new Vector3f(1, 0, 0)));
         break;
       case 2:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(-FastMath.HALF_PI, new Vector3f(0, 1, 0)));
         break;
       case 3:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.ZERO_TOLERANCE, new Vector3f(1, 0, 0)));
         break;
       case 4:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.PI, new Vector3f(1, 0, 0)));
         break;
       case 5:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(FastMath.HALF_PI, new Vector3f(0, 1, 0)));
         break;
       case 6:
         diceControl.setPhysicsRotation(
             new Quaternion().fromAngleAxis(-FastMath.HALF_PI, new Vector3f(1, 0, 0)));
         break;
     }
     diceControl.setLinearVelocity(new Vector3f(0, 0, 0));
     diceControl.setAngularVelocity(new Vector3f(0, 0, 0));
     diceControl.setPhysicsLocation(putLocation);
     spatial.getControl(AbstractRollControl.class).setEnabled(false);
     Geometry d6 = ((Geometry) spatial);
     d6.getMaterial().setColor("Diffuse", ColorRGBA.White);
     number = 0;
   } else {
     diceControl.setEnabled(false);
     this.setEnabled(false);
   }
 }
示例#5
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
  }
示例#6
0
 /** Sets the speed at which the camera should move forward */
 public void setSpeed(float speed) {
   centralNodeControl.setLinearVelocity(new Vector3f(0, speed, 0));
 }