O'Reilly logo

Mastering SFML Game Development by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Moving the camera around

Having a programmable camera is nice, but it still does not allow us to freely roam the scene. Let 's actually give our camera class the ability to be manipulated in real time, so that we can have the illusion of floating around the world:

enum class GL_Direction{ Up, Down, Left, Right, Forward, Back }; 
 
class GL_Camera { 
public: 
  ... 
  void MoveBy(GL_Direction l_dir, float l_amount); 
  void OffsetLookBy(float l_speed, float l_x, float l_y); 
  ... 
}; 

As you can see, we are going to use two methods for that: one for moving the camera, and another for rotating it. We are also defining a helpful enumeration of all six possible directions.

Moving a position vector is fairly simple. Assume we have a scalar value that represents the speed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required