RPG Style Camera

Started by
0 comments, last by szecs 14 years, 5 months ago
Hey guys, I am trying to finish up my camera system but so far I am stuck. Everything works appropriately up until now as far as rotating it around the character and zooming in/out and so on, but I am trying to smooth out the zoom. (Not actually zoom, just make the camera closer/farther away from the player) Heres what I have currently...

bool WorldState::mouseMoved(const OIS::MouseEvent &arg)
{
   if(arg.state.buttonDown(OIS::MB_Right))
   {
      // If we are in camera-pivote state, spin/pitch the camera based
      // on relative mouse movement.
      // Get rid of the * -1.0 to invert the mouse movement
      chaseCam->spin(Degree(arg.state.X.rel * 0.14) * -1.0);
      chaseCam->pitch(Degree(arg.state.Y.rel * 0.1) * -1.0);
      return true;
   }

   if(arg.state.Z.rel)
   {
      static Real zDist;

      zDist = (-0.05f * arg.state.Z.rel);
      chaseCam->getCamera()->moveRelative(Vector3(0.0f, 0.0f, zDist));
   }

   return guiCanvas->injectMouseMove(arg.state.X.abs, arg.state.Y.abs);
}
Now the problem is when you use the mousewheel, its kind of jerky as it zooms closer/further from the player. I am trying to find someway to implement something like WoW or any other number of RPGs have, where when you zoom it kind of smooth transitions from like a node to the next node, with the first node being at the character, and the end node being X distance from the player. I have not really found anything from sites/snippets covering this though, so I am hoping you guys can help. I found a demo application from Ogre3D that makes the mouse follow a track, but it seems more oriented for doing an automated camera in like a video or something, so not sure if I should use it in this case (or if it would work at all)
Advertisement
How about zooming with a constant speed?
Store the needed 'node' in a variable.
If you scroll down with the mouse, you increase this variable, when you scroll up, you decrease it. Store the current (displayed) 'node' too.
If the current node is smaller than needed, increase it with constant speed, if larger, decrease it.
//scroll handlingif(scroll_up)    needed_node += step;if(scroll_down)    needed_node -= step;//game loopif( current_node < needed_node )    current node += delta_time*zoom_speed;else if( current_node > needed_node )    current node -= delta_time*zoom_speed;

So the zooming can only change with a limited value per frame, so it won't be jerky.
step is much bigger than delta_time*zoom_speed It's not precise, but I think you get the idea.

Warcraft III (the rts) uses this method (at least the result is the same). Or you could do some movement interpolation too based of the few former zooming actions, but that's beyond me.

This topic is closed to new replies.

Advertisement