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

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