Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
camera.hpp
1 //////////////////////////////
2 //
3 // File: lxs/coregraphics/camera.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Nov 27 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_CAMERA__
15 #define __LXS_CAMERA__
16 #include "helper/opengl.h"
17 #include "lxs/coregraphics/renderable.hpp"
18 namespace LxS
19 {
20  namespace CoreGraphics
21  {
22  //! global camera setup (class for calculating transformation matrices given view angles and so on). (compare: R3DCamera, which is higher level object implementing Renderable interface)
23  class GLCamera
24  {
25  //static GLfloat matrix[16];
26  static float angle_x;
27  static float angle_y;
28  static float angle_z;
29  static float pos_x;
30  static float pos_y;
31  static float pos_z;
32  static float viewing_angle;
33  static GLfloat mvmatrix[16];
34  static GLfloat orthomatrix[16];
35  public:
36  //! set up the camera for rendering;
37  //! \param mode mode of rendering
38  //! \param width width of context (in px)
39  //! \param height height of context (in px)
40  //! \param DPC Dots Per Centimeter (resolution of screen)
41  virtual void Render(Renderable::Rendermode mode,int width, int height,float DPC);
42  //! get recalculated projection matrix - for rendering 3D stuff
43  static GLfloat * GetProjectionMatrix() {return &mvmatrix[0];}
44  //! get recalculated ortho matrix, mainly for UI
45  static GLfloat * GetOrthoMatrix() {return &orthomatrix[0];}
46 
47  //! Project point over GLOrtho
48  static GLfloat * c3Dto2D(float x, float y, float z);
49  //! rotate around Z axis of target
50  static void RotateX(float dx) {angle_x+=dx;}
51  //! rotate around Y axis of target
52  static void RotateY(float dy) {angle_y+=dy;}
53  //! rotate around Z axis of target
54  static void RotateZ(float dz) {angle_z+=dz;}
55  //! Move alongside X axis of global coordinate system
56  static void MoveX(float dx) {pos_x+=dx;}
57  //! Move alongside Y axis of global coordinate system
58  static void MoveY(float dy) {pos_y+=dy;}
59  //! Move alongside Z axis of global coordinate system
60  static void MoveZ(float dz) {pos_z+=dz;}
61  //! Set (absolute) rotation around X axis of target
62  static void SetRotationX(float dx) {angle_x=dx;}
63  //! Set (absolute) rotation around Y axis of target
64  static void SetRotationY(float dy) {angle_y=dy;}
65  //! Set (absolute) rotation around Z axis of target
66  static void SetRotationZ(float dz) {angle_z=dz;}
67  //! Set (absolute) position in global coordinate system (x axis)
68  static void SetPositionX(float dx) {pos_x=dx;}
69  //! Set (absolute) position in global coordinate system (y axis)
70  static void SetPositionY(float dy) {pos_y=dy;}
71  //! Set (absolute) position in global coordinate system (z axis)
72  static void SetPositionZ(float dz) {pos_z=dz;}
73 
74  //! get WIDTH of viewing angle
75  static float GetViewingAngle() { return viewing_angle; }
76  //! where does the camera look
77  static float GetRotationX() {return angle_x;}
78  //! where camera is
79  static float GetPositionX() {return pos_x;}
80  //! where does the camera look
81  static float GetRotationY() {return angle_y;}
82  //! where camera is
83  static float GetPositionY() {return pos_y;}
84  //! where does the camera look
85  static float GetRotationZ() {return angle_z;}
86  //! where camera is
87  static float GetPositionZ() {return pos_z;}
88  };
89  }
90 }
91 
92 #endif