Camera system

Hi,



I want to have a camera system like the one in UT2004 (when flying the raptor).



What I mean is to have the camera focusing on my vessel. When looking up the camera slides under the vessel and when looking down the camera is above the vessel.



How would I go about to implement this?



Thanks

Maybe someone knows the name of this system? So that I can search google or something… Just point me in a direction :slight_smile:

Did you try attaching a CameraNode to your ship, and have it translated 0,0,-5 looking in the (0,0,1) direction. When the ship rotates, the camera node will rotate around the ship.

Well, that’s not really what I want.



When the user move the camera with the mouse I want the camera to spin around the vessel at a constant distance while looking at the vessel.



Hmm… this was hard to explain, but the same system is implemented in UT2004, Tribes Vengence, Halo, Battlefield etc.

The goal is to make the vessel strive to be rotated in the same direction as the camera, allthough it does this at a given rotation speed.

When the user move the camera with the mouse I want the camera to spin around the vessel at a constant distance while looking at the vessel.


Why does the above not do that?

Well, the translation will keep the camera at distance 5 from the vessel. But how do I make the camera move around the vessel when the user moves the mouse, while looking at the vessel?



I want the camera to move around the vessel similar to how the box circles around the sphere in HelloAnimation.

Make the mouse rotate the ship. The ship will rotate, which means all the ship’s children will rotate. If the cameranode is a child of the ship, it will rotate around the ship as the ship rotates.

"Cep21" wrote:
Make the mouse rotate the ship. The ship will rotate, which means all the ship's children will rotate. If the cameranode is a child of the ship, it will rotate around the ship as the ship rotates.

Problem is that view should rotate with speed of mouse movement, while ship will turn considerably slower - depending on type of craft, it's status etc. You can turn the view 90 degrees in split of second and then wait with view not moving while ship slowly shadows your rotation in few seconds time.

I know what you mean :slight_smile:



As a matter of fact, ive tried doing so, but ive failed. You need to implement spherical coordinates so as to increase x or y (up) and it would rotate around a fixed point.



Just google for "spherical coordinates"



DP

"Cep21" wrote:
Make the mouse rotate the ship. The ship will rotate, which means all the ship's children will rotate. If the cameranode is a child of the ship, it will rotate around the ship as the ship rotates.

Yes, I understand that.

I don't really know how to explain this... Well, look at the HelloAnimation example and lets pretend that the sphere is my vessel and the box is the camera. Now lets say you can't rotate the vessel, it's static. So when moving the mouse you rotate the camera around the vessel allthough the camera still looks at the vessel all of the time.

I'm not talking about an ordinary chasecam where you would rotate the vessel and the camera follows. I want it to be the other way around - you rotate the camera and the vessel will follow.

Thanks dp and cep21.



I’ll try some google then :slight_smile:

What about doing what I did with the solar system?



Parent          ||||  Child
Ship Center      |||| Ship
Ship Center      ||||  CameraNode




If you want to rotate the ship, you rotate the Ship not the ShipCenter. If you want to rotate the camera node, you rotate the CameraNode. Here, you have two objects both rotating around a common center point, but with different rotation matricies.

I’m sorry but I don’t really understand what you mean Cep21.



About the spherical coordinates they seem to be way out of my legue :frowning:

mine too :slight_smile:



But I believe the all wise and all great renanse has done it. So im sure its doable :wink:



DP

Great. I’ll await a reply from renanse then :slight_smile:

When looking at this it doesn’t seem to be as hard as I thought. This would be enough to get the camera coordinates:





x = r*sin(theta)cos(phi)

y = r
sin(theta)sin(phi)

z = r
cos(phi)



When moving the mouse those angles should be the ones that change.



I still need help getting those angles though.

What you’re looking for is Spherical Coordinates. Here’s a few methods to help you get started.



  public static Vector3f sphericalToCartesian(Vector3f sphereCoords, Vector3f store) {
    store.y = sphereCoords.x * FastMath.sin(sphereCoords.z);

    float a = sphereCoords.x * FastMath.cos(sphereCoords.z);
    store.x = a * FastMath.cos(sphereCoords.y);
    store.z = a * FastMath.sin(sphereCoords.y);

    return store;
  }

  public static Vector3f cartesianToSpherical(Vector3f cartCoords, Vector3f store) {
    if (cartCoords.x == 0) cartCoords.x = FastMath.FLT_EPSILON;
    store.x = FastMath.sqrt((cartCoords.x*cartCoords.x) +
                           (cartCoords.y*cartCoords.y) +
                           (cartCoords.z*cartCoords.z));
    store.y = FastMath.atan(cartCoords.z / cartCoords.x);
    if (cartCoords.x < 0) store.y += FastMath.PI;
    store.z = FastMath.asin(cartCoords.y / store.x);
    return store;
  }



(Note: I use the Y axis as up as does most of jME demos)

Check out Dirt to see my camera system in action... I have the keyboard controlling the character and the mouse controlling the view, but there's no reason you couldn't control them together with one turning faster than the other.

Ok, great thanks! One question though: what does cartesian mean?

normal coordinates



where x is left/right



y is up/down



z is forward/backward



DP