1a719db3223fc4622260a3bbad726d7af7fb2ee7
[simavr] / examples / shared / libc3 / src / c3camera.h
1 /*
2  c3camera.h
3
4  Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
5  Copyright (c) 1998 Paul Rademacher
6
7  This file is part of libc3.
8
9  libc3 is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13
14  libc3 is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with libc3.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #ifndef __C3VIEW_H___
24 #define __C3VIEW_H___
25
26 #include "c3algebra.h"
27
28 typedef struct c3cam_t {
29         c3vec3 eye, lookat;
30         c3vec3 up, side, forward;
31         c3mat4 mtx;
32         c3f distance;
33 } c3cam_t, *c3cam_p;
34
35 /******************************* set_distance() ***********/
36 /* This readjusts the distance from the eye to the lookat */
37 /* (changing the eye point in the process)                */
38 /* The lookat point is unaffected                         */
39 void
40 c3cam_set_distance(
41                 c3cam_p c,
42                 const c3f new_distance);
43
44 /******************************* set_up() ***************/
45 void
46 c3cam_set_upv(
47                 c3cam_p c,
48                 const c3vec3 new_up);
49 void
50 c3cam_set_upf(
51                 c3cam_p c,
52                 const c3f x,
53                 const c3f y,
54                 const c3f z);
55
56 /******************************* set_eye() ***************/
57 void
58 c3cam_set_eyev(
59                 c3cam_p c,
60                 const c3vec3 new_eye);
61 void
62 c3cam_set_eyef(
63                 c3cam_p c,
64                 const c3f x,
65                 const c3f y,
66                 const c3f z);
67
68 /******************************* set_lookat() ***************/
69 void
70 c3cam_set_lookatv(
71                 c3cam_p c,
72                 const c3vec3 new_lookat);
73 void
74 c3cam_set_lookatf(
75                 c3cam_p c,
76                 const c3f x,
77                 const c3f y,
78                 const c3f z);
79
80 /******************************* roll() *****************/
81 /* Rotates about the forward vector                     */
82 /* eye and lookat remain unchanged                      */
83 void
84 c3cam_roll(
85                 c3cam_p c,
86                 const c3f angle);
87
88 /******************************* eye_yaw() *********************/
89 /* Rotates the eye about the lookat point, using the up vector */
90 /* Lookat is unaffected                                        */
91 void
92 c3cam_eye_yaw(
93                 c3cam_p c,
94                 const c3f angle);
95
96 /******************************* eye_yaw_abs() ******************/
97 /* Rotates the eye about the lookat point, with a specific axis */
98 /* Lookat is unaffected                                         */
99 void
100 c3cam_eye_yaw_abs(
101                 c3cam_p c,
102                 const c3f angle,
103                 const c3vec3 axis);
104
105 /******************************* eye_pitch() ************/
106 /* Rotates the eye about the side vector                */
107 /* Lookat is unaffected                                 */
108 void
109 c3cam_eye_pitch(
110                 c3cam_p c,
111                 const c3f angle);
112
113 /******************************* lookat_yaw()************/
114 /* This assumes the up vector is correct.               */
115 /* Rotates the lookat about the side vector             */
116 /* Eye point is unaffected                              */
117 void
118 c3cam_lookat_yaw(
119                 c3cam_p c,
120                 const c3f angle);
121
122 /******************************* lookat_pitch() *********/
123 /* Rotates the lookat point about the side vector       */
124 /* This assumes the side vector is correct.             */
125 /* Eye point is unaffected                              */
126 void
127 c3cam_lookat_pitch(
128                 c3cam_p c,
129                 const c3f angle);
130
131 /******************************* reset_up() ******************/
132 /* Resets the up vector to a specified axis (0=X, 1=Y, 2=Z)  */
133 /* Also sets the eye point level with the lookat point,      */
134 /* along the specified axis                                  */
135 void
136 c3cam_reset_up_axis(
137                 c3cam_p c,
138                 const int axis_num);
139 void
140 c3cam_reset_up(
141                 c3cam_p c);
142
143 /******************************* move() ********************/
144 /* Moves a specified distance in the forward, side, and up */
145 /* directions.  This function does NOT move by world       */
146 /* coordinates.  To move by world coords, use the move_abs */
147 /* function.                                               */
148 void
149 c3cam_movef(
150                 c3cam_p c,
151                 const c3f side_move,
152                 const c3f up_move,
153                 const c3f forw_move);
154 void
155 c3cam_movev(
156                 c3cam_p c,
157                 const c3vec3 v); /* A vector version of the above command */
158
159 /******************************* move_by_eye() ***********/
160 /* Sets the eye point, AND moves the lookat point by the */
161 /* same amount as the eye is moved.                      */
162 void
163 c3cam_move_by_eye(
164                 c3cam_p c,
165                 const c3vec3 new_eye);
166
167 /******************************* move_by_lookat() *********/
168 /* Sets the lookat point, AND moves the eye point by the  */
169 /* same amount as the lookat is moved.                    */
170 void
171 c3cam_move_by_lookat(
172                 c3cam_p c,
173                 const c3vec3 new_lookat);
174
175 /******************************* move_abs() *****************/
176 /* Move the eye and lookat in world coordinates             */
177 void
178 c3cam_move_abs(
179                 c3cam_p c,
180                 const c3vec3 v);
181
182 /****************************** rot_about_eye() ************/
183 /* Rotates the lookat point about the eye, based on a 4x4  */
184 /* (pure) rotation matrix                                  */
185 void
186 c3cam_rot_about_eye(
187                 c3cam_p c,
188                 const c3mat4p rot);
189
190 /****************************** rot_about_lookat() ************/
191 /* Rotates the lookat point about the lookat, based on a 4x4  */
192 /* (pure) rotation matrix                                  */
193 void
194 c3cam_rot_about_lookat(
195                 c3cam_p c,
196                 const c3mat4p rot);
197
198 /******************************* make_mtx() *************/
199 /* Constructs a 4x4 matrix - used by load_to_openGL()   */
200 void
201 c3cam_update_matrix(
202                 c3cam_p c);
203
204 /******************************* load_to_openGL() ********/
205 /* Sets the OpenGL modelview matrix based on the current */
206 /* camera coordinates                                    */
207 //void c3cam_load_to_openGL();
208
209 /******************************* load_to_openGL_noident() ******/
210 /* Multiplies the current camera matrix by the existing openGL */
211 /* modelview matrix.  This is same as above function, but      */
212 /* does not set the OpenGL matrix to identity first            */
213 //void c3cam_load_to_openGL_noident();
214
215 /******************************* reset() ****************/
216 /* Resets the parameters of this class                  */
217 void
218 c3cam_reset(
219                 c3cam_p c);
220
221 /******************************* c3cam_t() ************/
222 /* Constructor                                          */
223 c3cam_t
224 c3cam_new();
225
226 void
227 c3cam_init(
228                 c3cam_p c);
229 /******************************* update() ****************/
230 /* updates the view params.  Call this after making      */
231 /* direct changes to the vectors or points of this class */
232 void c3cam_update(
233                 c3cam_p c);
234
235 /******************************* dump() *******************/
236 /* Prints the contents of this class to a file, typically */
237 /* stdin or stderr                                        */
238 //void c3cam_dump(FILE *output);
239
240 #endif /* __C3VIEW_H___ */