jPCT-AE - a 3d engine for Android > Support

Camera always behind object

(1/3) > >>

bLAZY:
Hi,

could you give me some clue how to do that camera always looks on object the same way? Something like in Third Person Shooter. Should I calculate an angle and use translation or there is some better way?

EgonOlsen:
I tend to base such things on the object's virtual coordinate system. This might help you: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#getZAxis()

bLAZY:
I have to admit I don't know how to use it correctly. Probably don't understand 3D transormations. I found this on forum:

--- Code: ---   private void moveCamera() {
      SimpleVector oldCamPos = camera.getPosition();
      oldCamPos.scalarMul(9f);
      SimpleVector carCenter = car.getTransformedCenter();
      SimpleVector zOffset = car.getZAxis();
      zOffset.scalarMul(-250f);
      SimpleVector camPos = new SimpleVector(carCenter);
      camPos.add(camYOffset);
      camPos.add(zOffset);
      camPos.add(oldCamPos);
      camPos.scalarMul(0.1f);
      camera.setPosition(camPos);
      camera.lookAt(carCenter);
   }
--- End code ---

and there was also video. It works there exactly I would like to get. Could you clarify it for me?

EgonOlsen:
Well...that code looks like the one from the car example. What it does is pretty simple: It calculates a new camera position based on the car's orientation (i.e. behind the car by translating along the negative z-axis), adds a multiple of the current position to it and divides by (multiple+1). Then it does a lookAt() at the car. This simply smoothes out the camera movement. At the time that i wrote this, i was a quick hack to get something going. It turned out to work pretty well, so i kept it.

If it works for you, just use it...maybe tweak the parameters to fit your needs.

bLAZY:
Now it works almost. Already have such problems:
1. I call this method in ticker and screen shakes a little trying all the time adjust camera position even if there is no move, but I think I can solve it when I will call this only if there is some turning action and I will use another camera setter to keep camera in distance during game (object moves all the time forward like in AlienRunner),
2. moving left or right cause that camera is more and more closer and minimal distance is when object achives 180 degrees to default position (distance changing doesn't exist when there is no moving forward along Z axis ),
3. moving up and down behaves similiary but only when there was no left or right, if was e.g. 90 degrees right I can watch like it rotates form side,
4. I made mentioned object's moving forward in ticker by
--- Code: ---thing.translate(0, 0, move);
--- End code ---
and even if I turn by making some rotation object moves forward along the old Z axis (e.g. when its rotatated the movement is from right to left, not "into the screen") why not the new ? Is it the same like with camera?

Today I have no more time. Maybe you have met this issues and know some solutions.
Thanks for previous help:)

Navigation

[0] Message Index

[#] Next page

Go to full version