Wednesday, August 11, 2010

"Flying spectator" camera

Here we are, let's get started!

My first though was that whatever I want to start with and get displayed on my screen as first I definitely want to examine it properly.

To make it happen I want to create a camera that can fly around in world space.

The camera is implemented as a Microsoft.Xna.Framework.GameComponent to encapsulate camera logic as much as possible and create as little dependency between classes (currently between cam class and the main game class) as possible. I defined an ICamera interface, created an implementation for it and added the implementation into GameServiceContainerMy main game class gets the ICamera service without being aware of the implementation (i.e. the current active camera). The ICamera has getters to access view and projection matrices and directions like: up, forward, right  corresponding camera directions.

With my current implementation I want to be able to fly around in the scene. To achieve it following happens:
  • cam inits itself with 
    • cam position (0, 0, 10) (somewhere on z-axis)
    • target position (0, 0, 0)
    • up direction (0, 1, 0)
  • when mouse is moved horizontally then 
    • up and forward directions of the cam are rotated around y-axis (of word's coordinate system)
  • when mouse is moved vertically then
    • up and forward directions of the cam are rotated around "right" direction (of the cam)
  • when one of the move or elevate buttons (e.g. w, s, a, d, q, e) are pressed then simply both position and target of the camera are moved in matching camera directions: up, forward or right.

See it in action on the video. 



Note: two dummy triangles were rendered in a fixed world position to have the feeling that our camera is moving.


No comments:

Post a Comment