Author Topic: Car Example's moveCamera() on X/Y Plane  (Read 963 times)

Offline AGP

  • quad
  • ******
  • Posts: 1638
    • View Profile
Car Example's moveCamera() on X/Y Plane
« on: January 12, 2012, 12:11:34 am »
What's the equivalent of the following code (your car example's camera) for a game on the X/Y plane? I tried switching the Zs and Ys around, but I get weird results. For one thing, my game is of a ship with greater maneuverability than the car and the camera  sometimes ends on opposite sides of the ship (sometimes it's under it, sometimes over it).

Code: [Select]
   private void moveCamera() {
      SimpleVector oldCamPos=camera.getPosition();
      SimpleVector oldestCamPos=new SimpleVector(oldCamPos);
      oldCamPos.scalarMul(9f);

      SimpleVector carCenter=car.getTransformedCenter();
      SimpleVector camPos=new SimpleVector(carCenter);
      SimpleVector zOffset=car.getZAxis();
      SimpleVector yOffset=new SimpleVector(0, -100, 0);
      zOffset.scalarMul(-250f);

      camPos.add(zOffset);
      camPos.add(yOffset);

      camPos.add(oldCamPos);
      camPos.scalarMul(0.1f);

      SimpleVector delta=camPos.calcSub(oldestCamPos);
      float len=delta.length();

      if (len!=0) {
         /**
          * Do a collision detection between the camera and the ground to prevent the camera from
          * moving into the ground.
          */
         theWorld.checkCameraCollisionEllipsoid(delta.normalize(), new SimpleVector(20, 20, 20), len, 3);
      }

      /**
       * And finally: Look at the car
       */
      camera.lookAt(car.getTransformedCenter());
   }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Car Example's moveCamera() on X/Y Plane
« Reply #1 on: January 12, 2012, 07:12:58 am »
I'm not sure if this is even applicable for something more dynamic then the car is. However, i would think that switching y/z as well as the values in the vectors and the signs might work. For example, new SimpleVector(0, -100, 0) should become new SimpleVector(0, 0, 100)...