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 |
|
---|
18 | namespace 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 | }
|
---|
29 |
|
---|
30 | void set_perspective( f32 fov, f32 aspect, f32 near, f32 far )
|
---|
31 | {
|
---|
32 | m_projection = glm::perspective( fov, aspect, near, far );
|
---|
33 | }
|
---|
34 | const mat4& get_projection() const
|
---|
35 | {
|
---|
36 | return m_projection;
|
---|
37 | }
|
---|
38 | const mat4& get_view() const
|
---|
39 | {
|
---|
40 | return m_view;
|
---|
41 | }
|
---|
42 | private:
|
---|
43 | bool m_dirty;
|
---|
44 | mat4 m_projection;
|
---|
45 | mat4 m_view;
|
---|
46 | };
|
---|
47 |
|
---|
48 | // TODO - this and camera should have dirty states
|
---|
49 | class scene_state
|
---|
50 | {
|
---|
51 | public:
|
---|
52 | const camera& get_camera() const { return m_camera; }
|
---|
53 | camera& get_camera() { return m_camera; }
|
---|
54 | void set_camera( const camera& c ) { m_camera = c; }
|
---|
55 | void set_model( const mat4& m ) { m_model = m; }
|
---|
56 |
|
---|
57 | const mat4& get_model() const { return m_model; }
|
---|
58 | const mat4& get_view() const { return m_camera.get_view(); }
|
---|
59 | const mat4& get_projection() const { return m_camera.get_projection(); }
|
---|
60 | mat4 get_modelview() const { return get_view() * m_model; }
|
---|
61 | mat4 get_mvp() const { return m_camera.get_projection() * get_modelview(); }
|
---|
62 |
|
---|
63 | mat4 get_view_inv() const { return glm::inverse( get_view() ); }
|
---|
64 | mat3 get_normal() const { return glm::transpose(glm::inverse(glm::mat3( get_modelview() ) ) ); }
|
---|
65 | protected:
|
---|
66 | mat4 m_model;
|
---|
67 | camera m_camera;
|
---|
68 | };
|
---|
69 |
|
---|
70 |
|
---|
71 | }
|
---|
72 |
|
---|
73 | #endif // NV_CAMERA_HH
|
---|