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

Last change on this file since 486 was 486, checked in by epyon, 9 years ago
  • mass update once again...
File size: 3.0 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;
[454]30                        m_direction = math::normalize( focus - eye );
[230]31                }
32
33                void set_perspective( f32 fov, f32 aspect, f32 near, f32 far )
34                {
[453]35                        m_projection = math::perspective( math::radians( fov ), aspect, near, far );
[486]36                        m_near = near;
37                        m_far  = far;
[230]38                }
[267]39                void set_ortho( f32 left, f32 right, f32 bottom, f32 top, f32 near = -1.0f, f32 far = 1.0f )
40                {
[451]41                        m_projection = math::ortho( left, right, bottom, top, near, far );
[486]42                        m_near = near;
43                        m_far  = far;
[267]44                }
[230]45                const mat4& get_projection() const
46                {
47                        return m_projection;
48                }
49                const mat4& get_view() const
50                {
51                        return m_view;
52                }
[235]53                const vec3& get_position() const
54                {
55                        return m_position;
56                }
57                const vec3& get_direction() const
58                {
59                        return m_direction;
60                }
[486]61                float get_near() const { return m_near;  }
62                float get_far() const { return m_far; }
[230]63        private:
[232]64                bool m_dirty;
[235]65                vec3 m_position;
66                vec3 m_direction;
[230]67                mat4 m_projection;
68                mat4 m_view;
[486]69                float m_near;
70                float m_far;
[230]71        };
[232]72
73        // TODO - this and camera should have dirty states
74        class scene_state
75        {
76        public:
77                const camera& get_camera() const   { return m_camera; }
78                camera& get_camera()               { return m_camera; }
79                void set_camera( const camera& c ) { m_camera = c; }
80                void set_model( const mat4& m )    { m_model  = m; }
[342]81                void set_viewport( const ivec4& v ){ m_viewport = v; }
82                const ivec4& get_viewport()  const { return m_viewport; }
[232]83                const mat4& get_model()      const { return m_model; }
84                const mat4& get_view()       const { return m_camera.get_view(); }
85                const mat4& get_projection() const { return m_camera.get_projection(); }
86                mat4 get_modelview()  const { return get_view() * m_model; }
87                mat4 get_mvp()        const { return m_camera.get_projection() * get_modelview(); }
88
[472]89                mat4 get_view_inv()       const { return math::inverse( get_view() ); }
90                mat4 get_model_inv()      const { return math::inverse( get_model() ); }
91                mat4 get_modelview_inv()  const { return math::inverse( get_modelview() ); }
92                mat4 get_projection_inv() const { return math::inverse( get_projection() ); }
93                mat4 get_mvp_inv()        const { return math::inverse( get_mvp() ); }
94                mat3 get_normal()         const { return math::transpose( math::inverse( mat3( get_modelview() ) ) ); }
[232]95        protected:
96                mat4   m_model;
97                camera m_camera;
[342]98                ivec4  m_viewport;
[232]99        };
100
101
[230]102}
103
[395]104#endif // NV_INTERFACE_CAMERA_HH
Note: See TracBrowser for help on using the repository browser.