1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 /* Frustum
14  * Encapsulates a camera.
15  */
16 
17 #ifndef BZF_FRUSTUM_H
18 #define BZF_FRUSTUM_H
19 
20 #include "common.h"
21 
22 // FIXME -- will need a means for off center projections for
23 // looking through teleporters
24 
25 class Frustum
26 {
27 public:
28     Frustum();
29     ~Frustum();
30 
31     const float*    getEye() const;
32     const float*    getDirection() const;
33     const float*    getUp() const;
34     const float*    getRight() const;
35     const float*    getSide(int index) const;
36     int         getPlaneCount() const;
37     const float*    getFarCorner(int index) const;
38     float       getTilt() const; // degrees
39     float       getRotation() const; // degrees
40     float       getNear() const;
41     float       getFar() const;
42     const float*    getViewMatrix() const;
43     float       getFOVx() const;
44     float       getFOVy() const;
45     const float*    getProjectionMatrix() const;
46     float       getEyeDepth(const float*) const;
47     float       getAreaFactor() const;
48 
49     void        setView(const float* eye, const float* target);
50     void        setProjection(float fov,
51                               float m_near, float m_far, float m_deep_far,
52                               int width, int height, int viewHeight);
53     void        setOffset(float eyeOffset, float focalPlane);
54     void        setFarPlaneCull(bool useCulling);
55     void        flipVertical();
56     void        flipHorizontal();
57 
58     // used for radar culling
59     void        setOrthoPlanes(const Frustum& view,
60                                float width, float breadth);
61 
62 protected:
63     void        makePlane(const float* v1, const float* v2, int);
64 
65 protected:
66     float       eye[3];
67     float       target[3];
68     float       right[3], up[3];
69     float       plane[6][4];        // pointing in
70     int         planeCount;
71     float       farCorner[4][3];
72     float       tilt;
73     float       rotation;
74     float       viewMatrix[16];
75     float       billboardMatrix[16];
76     float       m_near, m_far;
77     float       fovx, fovy;
78     float       areaFactor;
79     float       projectionMatrix[16];
80     float       deepProjectionMatrix[16];
81 };
82 
83 //
84 // Frustum
85 //
86 
getEye()87 inline const float* Frustum::getEye() const
88 {
89     return eye;
90 }
91 
getDirection()92 inline const float* Frustum::getDirection() const
93 {
94     return plane[0];
95 }
96 
getSide(int index)97 inline const float* Frustum::getSide(int index) const
98 {
99     return plane[index];
100 }
101 
getPlaneCount()102 inline int      Frustum::getPlaneCount() const
103 {
104     return planeCount;
105 }
106 
getFarCorner(int index)107 inline const float* Frustum::getFarCorner(int index) const
108 {
109     return farCorner[index];
110 }
111 
getTilt()112 inline float        Frustum::getTilt() const
113 {
114     return tilt;
115 }
116 
getRotation()117 inline float        Frustum::getRotation() const
118 {
119     return rotation;
120 }
121 
getUp()122 inline const float* Frustum::getUp() const
123 {
124     return up;
125 }
126 
getRight()127 inline const float* Frustum::getRight() const
128 {
129     return right;
130 }
131 
getNear()132 inline float        Frustum::getNear() const
133 {
134     return m_near;
135 }
136 
getFar()137 inline float        Frustum::getFar() const
138 {
139     return m_far;
140 }
141 
getFOVx()142 inline float        Frustum::getFOVx() const
143 {
144     return fovx;
145 }
146 
getFOVy()147 inline float        Frustum::getFOVy() const
148 {
149     return fovy;
150 }
151 
getViewMatrix()152 inline const float* Frustum::getViewMatrix() const
153 {
154     return viewMatrix;
155 }
156 
getProjectionMatrix()157 inline const float* Frustum::getProjectionMatrix() const
158 {
159     return projectionMatrix;
160 }
161 
getAreaFactor()162 inline float        Frustum::getAreaFactor() const
163 {
164     return areaFactor;
165 }
166 
167 #endif // BZF_FRUSTUM_H
168 
169 // Local Variables: ***
170 // mode: C++ ***
171 // tab-width: 4 ***
172 // c-basic-offset: 4 ***
173 // indent-tabs-mode: nil ***
174 // End: ***
175 // ex: shiftwidth=4 tabstop=4
176