view following an moving & rotating object???

Hi there,

I have a ship which rotates around the x- and y-axis and move in the direction of rotation.

My only problem is, that the View doesn’t follow properly! It should follow behind the ship looking at it all the time. I tried it this way:


  vpNewPosition.x = shipPosition.x + vpSTARTX; //vpSTARTX = 0.0f
  vpNewPosition.y = shipPosition.y + vpSTARTY; //vpSTARTY = 50.0f
  vpNewPosition.z = shipPosition.z + vpSTARTZ; //vpSTARTZ = 130.0f  
  
  shipRotXY3d.transform(vpNewPosition); 
    
  vpTrans3d.lookAt(vpNewPosition, shipPosition, vUp);
  
  vpTrans3d.invert();

  vpTrans.setTransform(vpTrans3d);

But this doesn’t work properly for example my view always looks upwards, so it looks like the ship turns around the z-axis, but only the view doesn’t follow!!!

The second step would be to smooth the camera movement and rotation, so that you can see the rotation and movement of the ship!!! Can anyone help me???

Greets,
Juan

I did write a tutorial on something approximate to this, but I’m not sure how relevant it is to your exact case. If you take a look at the last section here you should find some working code that may be adaptable.

In another thread I described my problem more clear, I think, so here is my problem again:

The View doesn’t follow the Ship proberly.

What the view should do:

  1. When my ship rotates, the View has to rotate around the ship so that it is always a littlebit behind (130m) and higher (50m) as the ship.
  2. The View should always look at the ship.
  3. It would be great if the camera would smooth a littlebit, so that, when the ship rotates and moves, the view doesn’t follow directly (e.g. viewPosition = ((shipPosition.x/y/z - vpSTARTX/vpSTARTY/vpSTARTZ)/CAMERASMOOTH); //vpSTARTX = 0.0f, vpSTARTY = 50.0f, vpSTARTZ = 130.0f, CAMERASMOOTH = 6.0f ).

What I tried:
I used the function viewTrans3d.setLookAt(viewPosition, shipPosition, vpUp);. shipPosition is clear and viewPosition is rotation.transform(new Transform3D(shipPosition.x/y/z - vpSTARTX/vpSTARTY/vpSTARTZ));

Problems:

  1. Because of the vpUP(0.0f,1.0f,0.0f);, my View y-axis looks Upwards everytime. But when I make a looping for example it looks like the ship is rotating around his z-axis, though only the View doesn’t follow this rotation!
  2. there’s no smooth, so the motion of the Ship looks very rigid (or stiff?Sorry, but I have looked up this words in a dictionary)and you can only see the movement by the movement of the background.

Greets,
Juan

well I wrote this code 2 days ago to do a smooth camera which always follows my avator … something Mario like, but still quite a lot of work to do about that one :slight_smile:

You can simply get the main idee for rotating around a point at www.gametutorials.com … the OpenGL tutorial of third person has this method good explained.

But to do smooth camera is rather hard to explain, but if you want you can e-mail me at kozen@pandora.be and then I’ll send you the code.

damn, i’ve seen that so many times, i wonder why people never use the scenegraph?!?
why not simply attach the camera on your ship?!?


            ViewingPlatform vp = myUniverse.getViewingPlatform(); //if you use a SimpleUniverse
            vp.detach();
            TransformGroup cameraToShip = ....; //Sets the relative pos of the camera to the ship
            cameraToShip .addChild(vp);
            shipTG.addChild(cameraToShip);

that’s all!