added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / gfx / base_cam.hpp
1 /*
2 This file is part of the graphics core library.
3
4 Copyright (c) 2004, 2005 John Tsiombikas <nuclear@siggraph.org>
5
6 the graphics core library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 the graphics core library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with the graphics core library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 #ifndef _BASE_CAM_HPP_
21 #define _BASE_CAM_HPP_
22
23 #include "3dgeom.hpp"
24 #include "animation.hpp"
25 #include "n3dmath2/n3dmath2.hpp"
26
27 enum ClipPlane {CLIP_NEAR, CLIP_FAR};
28
29 /* DON'T change the order of these enums!
30  * The frustum plane extraction algorithm depends on it.
31  */
32 enum {FRUSTUM_LEFT, FRUSTUM_RIGHT, FRUSTUM_BOTTOM, FRUSTUM_TOP, FRUSTUM_NEAR, FRUSTUM_FAR};
33
34 class FrustumPlane {
35 public:
36         scalar_t a, b, c, d;    // the plane equation coefficients
37
38         FrustumPlane();
39         FrustumPlane(scalar_t a, scalar_t b, scalar_t c, scalar_t d);
40         FrustumPlane(const Matrix4x4 &mat, int plane);
41 };
42         
43
44 class BaseCamera : public XFormNode {
45 protected:
46         scalar_t fov;
47         scalar_t near_clip, far_clip;
48         Vector3 up;
49         scalar_t aspect;
50
51         mutable FrustumPlane frustum[6];
52
53         struct {bool x, y, z;} flip_view;
54
55         virtual void setup_frustum(const Matrix4x4 &m);
56         
57 public:
58         BaseCamera(const Vector3 &trans = Vector3(0,0,0), const Quaternion &rot = Quaternion());
59         virtual ~BaseCamera();
60         
61         virtual void set_up_vector(const Vector3 &up);
62         
63         virtual void set_fov(scalar_t angle);
64         virtual scalar_t get_fov() const;
65
66         virtual void set_aspect(scalar_t aspect);
67         virtual scalar_t get_aspect() const;
68         
69         virtual void set_clipping_planes(scalar_t near_clip, scalar_t far_clip);
70         virtual void set_clipping_plane(scalar_t val, ClipPlane which);
71         virtual scalar_t get_clipping_plane(ClipPlane which) const;
72
73         virtual void zoom(scalar_t zoom_factor, unsigned long msec = XFORM_LOCAL_PRS);
74         virtual void pan(const Vector2 &dir, unsigned long msec = XFORM_LOCAL_PRS);
75         virtual void roll(scalar_t angle, unsigned long msec = XFORM_LOCAL_PRS);
76
77         virtual void flip(bool x, bool y, bool z);
78
79         virtual const FrustumPlane *get_frustum() const;
80
81         virtual Matrix4x4 get_camera_matrix(unsigned long msec = XFORM_LOCAL_PRS) const = 0;
82         virtual Matrix4x4 get_projection_matrix() const;
83
84         virtual void activate(unsigned long msec = XFORM_LOCAL_PRS) const;
85 };
86
87 #endif  // _BASE_CAM_HPP_