c3program: Include digits in uniform names
[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         c3f fov;
34 } c3cam_t, *c3cam_p;
35
36 /******************************* set_distance() ***********/
37 /* This readjusts the distance from the eye to the lookat */
38 /* (changing the eye point in the process)                */
39 /* The lookat point is unaffected                         */
40 void
41 c3cam_set_distance(
42                 c3cam_p c,
43                 const c3f new_distance);
44
45 /******************************* set_up() ***************/
46 void
47 c3cam_set_upv(
48                 c3cam_p c,
49                 const c3vec3 new_up);
50 void
51 c3cam_set_upf(
52                 c3cam_p c,
53                 const c3f x,
54                 const c3f y,
55                 const c3f z);
56
57 /******************************* set_eye() ***************/
58 void
59 c3cam_set_eyev(
60                 c3cam_p c,
61                 const c3vec3 new_eye);
62 void
63 c3cam_set_eyef(
64                 c3cam_p c,
65                 const c3f x,
66                 const c3f y,
67                 const c3f z);
68
69 /******************************* set_lookat() ***************/
70 void
71 c3cam_set_lookatv(
72                 c3cam_p c,
73                 const c3vec3 new_lookat);
74 void
75 c3cam_set_lookatf(
76                 c3cam_p c,
77                 const c3f x,
78                 const c3f y,
79                 const c3f z);
80
81 /******************************* roll() *****************/
82 /* Rotates about the forward vector                     */
83 /* eye and lookat remain unchanged                      */
84 void
85 c3cam_roll(
86                 c3cam_p c,
87                 const c3f angle);
88
89 /******************************* eye_yaw() *********************/
90 /* Rotates the eye about the lookat point, using the up vector */
91 /* Lookat is unaffected                                        */
92 void
93 c3cam_eye_yaw(
94                 c3cam_p c,
95                 const c3f angle);
96
97 /******************************* eye_yaw_abs() ******************/
98 /* Rotates the eye about the lookat point, with a specific axis */
99 /* Lookat is unaffected                                         */
100 void
101 c3cam_eye_yaw_abs(
102                 c3cam_p c,
103                 const c3f angle,
104                 const c3vec3 axis);
105
106 /******************************* eye_pitch() ************/
107 /* Rotates the eye about the side vector                */
108 /* Lookat is unaffected                                 */
109 void
110 c3cam_eye_pitch(
111                 c3cam_p c,
112                 const c3f angle);
113
114 /******************************* lookat_yaw()************/
115 /* This assumes the up vector is correct.               */
116 /* Rotates the lookat about the side vector             */
117 /* Eye point is unaffected                              */
118 void
119 c3cam_lookat_yaw(
120                 c3cam_p c,
121                 const c3f angle);
122
123 /******************************* lookat_pitch() *********/
124 /* Rotates the lookat point about the side vector       */
125 /* This assumes the side vector is correct.             */
126 /* Eye point is unaffected                              */
127 void
128 c3cam_lookat_pitch(
129                 c3cam_p c,
130                 const c3f angle);
131
132 /******************************* reset_up() ******************/
133 /* Resets the up vector to a specified axis (0=X, 1=Y, 2=Z)  */
134 /* Also sets the eye point level with the lookat point,      */
135 /* along the specified axis                                  */
136 void
137 c3cam_reset_up_axis(
138                 c3cam_p c,
139                 const int axis_num);
140 void
141 c3cam_reset_up(
142                 c3cam_p c);
143
144 /******************************* move() ********************/
145 /* Moves a specified distance in the forward, side, and up */
146 /* directions.  This function does NOT move by world       */
147 /* coordinates.  To move by world coords, use the move_abs */
148 /* function.                                               */
149 void
150 c3cam_movef(
151                 c3cam_p c,
152                 const c3f side_move,
153                 const c3f up_move,
154                 const c3f forw_move);
155 void
156 c3cam_movev(
157                 c3cam_p c,
158                 const c3vec3 v); /* A vector version of the above command */
159
160 /******************************* move_by_eye() ***********/
161 /* Sets the eye point, AND moves the lookat point by the */
162 /* same amount as the eye is moved.                      */
163 void
164 c3cam_move_by_eye(
165                 c3cam_p c,
166                 const c3vec3 new_eye);
167
168 /******************************* move_by_lookat() *********/
169 /* Sets the lookat point, AND moves the eye point by the  */
170 /* same amount as the lookat is moved.                    */
171 void
172 c3cam_move_by_lookat(
173                 c3cam_p c,
174                 const c3vec3 new_lookat);
175
176 /******************************* move_abs() *****************/
177 /* Move the eye and lookat in world coordinates             */
178 void
179 c3cam_move_abs(
180                 c3cam_p c,
181                 const c3vec3 v);
182
183 /****************************** rot_about_eye() ************/
184 /* Rotates the lookat point about the eye, based on a 4x4  */
185 /* (pure) rotation matrix                                  */
186 void
187 c3cam_rot_about_eye(
188                 c3cam_p c,
189                 const c3mat4p rot);
190
191 /****************************** rot_about_lookat() ************/
192 /* Rotates the lookat point about the lookat, based on a 4x4  */
193 /* (pure) rotation matrix                                  */
194 void
195 c3cam_rot_about_lookat(
196                 c3cam_p c,
197                 const c3mat4p rot);
198
199 /******************************* make_mtx() *************/
200 /* Constructs a 4x4 matrix - used by load_to_openGL()   */
201 void
202 c3cam_update_matrix(
203                 c3cam_p c);
204
205 /******************************* load_to_openGL() ********/
206 /* Sets the OpenGL modelview matrix based on the current */
207 /* camera coordinates                                    */
208 //void c3cam_load_to_openGL();
209
210 /******************************* load_to_openGL_noident() ******/
211 /* Multiplies the current camera matrix by the existing openGL */
212 /* modelview matrix.  This is same as above function, but      */
213 /* does not set the OpenGL matrix to identity first            */
214 //void c3cam_load_to_openGL_noident();
215
216 /******************************* reset() ****************/
217 /* Resets the parameters of this class                  */
218 void
219 c3cam_reset(
220                 c3cam_p c);
221
222 /******************************* c3cam_t() ************/
223 /* Constructor                                          */
224 c3cam_p
225 c3cam_new();
226
227 void
228 c3cam_init(
229                 c3cam_p c);
230 /******************************* update() ****************/
231 /* updates the view params.  Call this after making      */
232 /* direct changes to the vectors or points of this class */
233 void c3cam_update(
234                 c3cam_p c);
235
236 #endif /* __C3VIEW_H___ */