コード例 #1
0
ファイル: GameCamera.java プロジェクト: no2665/Roll-Ball-Roll
  /**
   * 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
  }
コード例 #2
0
ファイル: AvatarControl.java プロジェクト: psyras/game-system
 @SuppressWarnings(value = "unused")
 public void setCamera(final Camera camera) {
   final CameraNode cameraNode = new CameraNode("CameraNode", camera);
   cameraNode.setControlDir(CameraControl.ControlDirection.SpatialToCamera);
   this.head.attachChild(cameraNode);
 }