source: trunk/nv/interface/camera.hh @ 267

Last change on this file since 267 was 267, checked in by epyon, 11 years ago
  • gui::element class now pure data
  • gui::element related code in environment
  • gui shaders use general library mechanism
File size: 2.3 KB
RevLine 
[230]1// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6/**
7 * @file camera.hh
8 * @author Kornel Kisielewicz epyon@chaosforge.org
9 * @brief Camera interface class
10 */
11
12#ifndef NV_CAMERA_HH
13#define NV_CAMERA_HH
14
15#include <nv/common.hh>
16#include <nv/math.hh>
17
18namespace nv
19{
20        class camera
21        {
22        public:
23                camera() {}
24
25                void set_lookat( const vec3& eye, const vec3& focus, const vec3& up )
26                {
[235]27                        m_view      = glm::lookAt( eye, focus, up );
28                        m_position  = eye;
29                        m_direction = glm::normalize( focus - eye );
[230]30                }
31
32                void set_perspective( f32 fov, f32 aspect, f32 near, f32 far )
33                {
34                        m_projection = glm::perspective( fov, aspect, near, far );
35                }
[267]36                void set_ortho( f32 left, f32 right, f32 bottom, f32 top, f32 near = -1.0f, f32 far = 1.0f )
37                {
38                        m_projection = glm::ortho( left, right, bottom, top, near, far );
39                }
[230]40                const mat4& get_projection() const
41                {
42                        return m_projection;
43                }
44                const mat4& get_view() const
45                {
46                        return m_view;
47                }
[235]48                const vec3& get_position() const
49                {
50                        return m_position;
51                }
52                const vec3& get_direction() const
53                {
54                        return m_direction;
55                }
[230]56        private:
[232]57                bool m_dirty;
[235]58                vec3 m_position;
59                vec3 m_direction;
[230]60                mat4 m_projection;
61                mat4 m_view;
62        };
[232]63
64        // TODO - this and camera should have dirty states
65        class scene_state
66        {
67        public:
68                const camera& get_camera() const   { return m_camera; }
69                camera& get_camera()               { return m_camera; }
70                void set_camera( const camera& c ) { m_camera = c; }
71                void set_model( const mat4& m )    { m_model  = m; }
72
73                const mat4& get_model()      const { return m_model; }
74                const mat4& get_view()       const { return m_camera.get_view(); }
75                const mat4& get_projection() const { return m_camera.get_projection(); }
76                mat4 get_modelview()  const { return get_view() * m_model; }
77                mat4 get_mvp()        const { return m_camera.get_projection() * get_modelview(); }
78
79                mat4 get_view_inv()   const { return glm::inverse( get_view() ); }
[235]80                mat4 get_model_inv()  const { return glm::inverse( get_model() ); }
[232]81                mat3 get_normal()     const { return glm::transpose(glm::inverse(glm::mat3( get_modelview() ) ) ); }
82        protected:
83                mat4   m_model;
84                camera m_camera;
85        };
86
87
[230]88}
89
90#endif // NV_CAMERA_HH
Note: See TracBrowser for help on using the repository browser.