1 ////////////////////////////////////////////////////////////////////////////////
2 //    Scorched3D (c) 2000-2011
3 //
4 //    This file is part of Scorched3D.
5 //
6 //    Scorched3D 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 //    Scorched3D 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 along
17 //    with this program; if not, write to the Free Software Foundation, Inc.,
18 //    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #if !defined(AFX_GLCAMERAFRUSTUM_H__4C341296_0589_46D5_BFD7_3114534F7E2D__INCLUDED_)
22 #define AFX_GLCAMERAFRUSTUM_H__4C341296_0589_46D5_BFD7_3114534F7E2D__INCLUDED_
23 
24 #include <engine/GameStateI.h>
25 #include <common/Vector.h>
26 
27 class GLCameraFrustum : public GameStateI
28 {
29 public:
30 	static GLCameraFrustum *instance();
31 
32 	static Vector FrustrumRed;
33 	static Vector FrustrumBlue;
34 	static Vector FrustrumGreen;
35 	static Vector FrustrumWhite;
36 
37 	virtual void draw(const unsigned state);
38 
39 	bool sphereInFrustum(Vector &point, float fRadius = 1, Vector &color = FrustrumWhite);
40 	bool sphereInFrustumThreadSafe(Vector &point, float fRadius);
41 	void backupFrustum();
42 	void restoreFrustum();
43 	void drawBilboard(
44 		Vector &position, Vector &color, float alpha,
45 		float width, float height, bool additive, int texCoord);
46 
47 	Vector &getBilboardVectorX();
48 	Vector &getBilboardVectorY();
49 
getBilboardMatrix()50 	float *getBilboardMatrix() { return s.fBilboard; }
getViewMatrix()51 	float *getViewMatrix() { return s.fView; }
52 
53 protected:
54 	static GLCameraFrustum *instance_;
55 	struct Settings
56 	{
57 		float frustum_[6][4];
58 		float fProj[16];
59 		float fView[16];
60 		float fClip[16];
61 		float fBilboard[16];
62 		float viewport[4];
63 		float aspect;
64 	} s, b;
65 
66 	void normalize(float vector[4]);
67 
68 private:
69 	GLCameraFrustum();
70 	virtual ~GLCameraFrustum();
71 
72 };
73 
74 #endif // !defined(AFX_GLCAMERAFRUSTUM_H__4C341296_0589_46D5_BFD7_3114534F7E2D__INCLUDED_)
75