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

Last change on this file since 235 was 235, checked in by epyon, 11 years ago
  • camera class extension
  • additional built-in uniforms added
  • support for uniform arrays
  • BONEINDEX and BONEWEIGHT built in attributes added
  • i16vec's added to math
File size: 2.2 KB
Line 
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                {
27                        m_view      = glm::lookAt( eye, focus, up );
28                        m_position  = eye;
29                        m_direction = glm::normalize( focus - eye );
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                }
36                const mat4& get_projection() const
37                {
38                        return m_projection;
39                }
40                const mat4& get_view() const
41                {
42                        return m_view;
43                }
44                const vec3& get_position() const
45                {
46                        return m_position;
47                }
48                const vec3& get_direction() const
49                {
50                        return m_direction;
51                }
52        private:
53                bool m_dirty;
54                vec3 m_position;
55                vec3 m_direction;
56                mat4 m_projection;
57                mat4 m_view;
58        };
59
60        // TODO - this and camera should have dirty states
61        class scene_state
62        {
63        public:
64                const camera& get_camera() const   { return m_camera; }
65                camera& get_camera()               { return m_camera; }
66                void set_camera( const camera& c ) { m_camera = c; }
67                void set_model( const mat4& m )    { m_model  = m; }
68
69                const mat4& get_model()      const { return m_model; }
70                const mat4& get_view()       const { return m_camera.get_view(); }
71                const mat4& get_projection() const { return m_camera.get_projection(); }
72                mat4 get_modelview()  const { return get_view() * m_model; }
73                mat4 get_mvp()        const { return m_camera.get_projection() * get_modelview(); }
74
75                mat4 get_view_inv()   const { return glm::inverse( get_view() ); }
76                mat4 get_model_inv()  const { return glm::inverse( get_model() ); }
77                mat3 get_normal()     const { return glm::transpose(glm::inverse(glm::mat3( get_modelview() ) ) ); }
78        protected:
79                mat4   m_model;
80                camera m_camera;
81        };
82
83
84}
85
86#endif // NV_CAMERA_HH
Note: See TracBrowser for help on using the repository browser.