1 // OGL_CAMERA.H : the OpenGL camera class + a transformer class.
2 
3 // Copyright (C) 1998 Tommi Hassinen.
4 
5 // This package is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 
10 // This package is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 
15 // You should have received a copy of the GNU General Public License
16 // along with this package; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 /*################################################################################################*/
20 
21 //#include "config.h"
22 
23 #ifndef OGL_CAMERA_H
24 #define OGL_CAMERA_H
25 
26 /*################################################################################################*/
27 
28 enum rmode { Normal = 0, Transform1 = 1, Transform2 = 2 };
29 
30 class ogl_camera;
31 
32 class ogl_transformer;
33 class ogl_transformer_client;
34 
35 #include "ogl_objects.h"
36 #include "base_wnd.h"
37 
38 /*################################################################################################*/
39 
40 /**	The "##camera" class holds information about position and orientation of the views
41 	in viewing windows. A single camera can pass this information to multiple windows.
42 	There can also be "##local lights", lights connected to a camera. If some
43 	translations/rotations are done to the camera, these lights will follow...
44 */
45 
46 class ogl_camera :
47 	public ogl_dummy_object
48 {
49 	private:
50 
51 	list<ogl_smart_object *> obj_list;
52 
53 	protected:
54 
55 	vector<base_wcl *> wcl_vector;
56 	vector<base_wnd *> wnd_vector;
57 
58 	friend class base_wcl;
59 	friend class base_wnd;
60 
61 	friend class base_app;
62 	friend class ogl_smart_object;		// for obj_list access...
63 
64 	public:
65 
66 	GLfloat focus;
67 	GLfloat clipping;
68 
69 	bool update_vdim;
70 
71 	bool use_local_lights;
72 	bool use_global_lights;
73 
74 	bool ortho;
75 	bool stereo_mode;	// this is true if any stereo mode; relaxed-eye or color-based.
76 	bool stereo_relaxed;	// this is true if relaxed_eye stereo mode.
77 
78 	float stereo_displacement;
79 	float relaxed_separation;
80 
81 	public:
82 
83 	ogl_camera(const ogl_object_location &, GLfloat);
84 	ogl_camera(const ogl_camera &);
85 	~ogl_camera(void);
86 
87 	protected:
88 
89 	void RegisterClient(base_wcl *);
90 	void UnregisterClient(base_wcl *);
91 
92 	void RegisterWnd(base_wnd *);
93 	void UnregisterWnd(base_wnd *);
94 
95 	public:
96 
97 	bool CopySettings(const ogl_camera *);
98 	void RenderScene(base_wnd *, bool, bool, int = -1, int = -1);
99 
GetObjectName(void)100 	const char * GetObjectName(void) { return "camera"; }		// virtual
101 
102 	void OrbitObject(const GLfloat *, const ogl_camera &);		// virtual
103 	void RotateObject(const GLfloat *, const ogl_camera &);		// virtual
104 
105 	void TranslateObject(const GLfloat *, const ogl_obj_loc_data *);	// virtual
106 
BeginTransformation(void)107 	bool BeginTransformation(void) { return false; }	// virtual
EndTransformation(void)108 	bool EndTransformation(void) { return false; }		// virtual
109 
Render(void)110 	void Render(void) { }		// virtual
111 
112 	void DoCameraEvents(void);
113 };
114 
115 /*################################################################################################*/
116 /**	The "##transformer" is a special class used only when rotating/translating some
117 	selected part of the model. transformer::GetMatrix() is used to get the transformation
118 	matrix for making those modifications permanent.
119 
120 	It is useful to switch orbiting and rotating, so that objects will behave similarly to
121 	lights and the whole scene...
122 */
123 
124 class ogl_transformer :
125 	public ogl_dummy_object
126 {
127 	public:
128 
129 	static ogl_transformer_client * client;
130 	static bool transform_in_progress;
131 
132 	public:
133 
134 	ogl_transformer(void);
135 	~ogl_transformer(void);
136 
137 	void Init(ogl_transformer_client *);
138 	void GetMatrix(GLfloat *) const;
139 
GetObjectName(void)140 	const char * GetObjectName(void) { return "transformer"; }	// virtual
141 
142 	bool BeginTransformation(void);		// virtual
143 	bool EndTransformation(void);		// virtual
144 
145 	void OrbitObject(const GLfloat *, const ogl_camera &);		// virtual
146 	void RotateObject(const GLfloat *, const ogl_camera &);		// virtual
147 
Render(void)148 	void Render(void) { }		// virtual
149 };
150 
151 class ogl_transformer_client
152 {
153 	public:
154 
155 	ogl_dummy_object * tc_object_ref;	// the object to be transformed.
156 
157 	public:
158 
159 	ogl_transformer_client(void);
160 	virtual ~ogl_transformer_client(void);
161 
162 /**	This should center the transformer object to the center of all
163 	selected objects, and shift the center of all selected objects
164 	to the origo.
165 */
166 	virtual void BeginClientTransformation(ogl_transformer *) = 0;
167 
168 /**	This should get the transformation matrix from the transformer
169 	object and use it to transform all selected objects to their
170 	new position and/or orientation.
171 */
172 	virtual void EndClientTransformation(ogl_transformer *) = 0;
173 };
174 
175 /*################################################################################################*/
176 
177 #endif	// OGL_CAMERA_H
178 
179 // eof
180