]> icculus.org git repositories - taylor/freespace2.git/blob - include/3d.h
Initial revision
[taylor/freespace2.git] / include / 3d.h
1 /*
2  * $Logfile: /Freespace2/code/Render/3D.H $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Include file for 3d rendering functions
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:12  root
11  * Initial revision
12  *
13  * 
14  * 10    9/06/99 3:23p Andsager
15  * Make fireball and weapon expl ani LOD choice look at resolution of the
16  * bitmap
17  * 
18  * 9     8/27/99 9:07p Dave
19  * LOD explosions. Improved beam weapon accuracy.
20  * 
21  * 8     7/09/99 9:51a Dave
22  * Added thick polyline code.
23  * 
24  * 7     7/02/99 3:05p Anoop
25  * Oops. Fixed g3_draw_2d_poly() so that it properly handles poly bitmap
26  * and LFB bitmap calls.
27  * 
28  * 6     6/16/99 4:06p Dave
29  * New pilot info popup. Added new draw-bitmap-as-poly function.
30  * 
31  * 5     6/03/99 6:37p Dave
32  * More TNT fun. Made perspective bitmaps more flexible.
33  * 
34  * 4     5/27/99 6:17p Dave
35  * Added in laser glows.
36  * 
37  * 3     4/07/99 6:22p Dave
38  * Fred and Freespace support for multiple background bitmaps and suns.
39  * Fixed link errors on all subprojects. Moved encrypt_init() to
40  * cfile_init() and lcl_init(), since its safe to call twice.
41  * 
42  * 2     10/07/98 10:53a Dave
43  * Initial checkin.
44  * 
45  * 1     10/07/98 10:51a Dave
46  * 
47  * 28    5/05/98 11:15p Lawrance
48  * Optimize weapon flyby sound determination
49  * 
50  * 27    3/16/98 5:02p John
51  * Better comments
52  * 
53  * 26    3/16/98 4:51p John
54  * Added low-level code to clip all polygons against an arbritary plane.
55  * Took out all old model_interp_zclip and used this new method instead.  
56  * 
57  * 25    1/29/98 9:46a John
58  * Capped debris length
59  * 
60  * 24    1/06/98 6:18p John
61  * Made debris render as a blur.  Had to make g3_draw_laser take tmap
62  * flags.
63  * 
64  * 23    12/30/97 6:44p John
65  * Made g3_Draw_bitmap functions account for aspect of bitmap.
66  * 
67  * 22    12/15/97 11:32a John
68  * New Laser Code
69  * 
70  * 21    10/20/97 4:49p John
71  * added weapon trails.
72  * added facing bitmap code to 3d lib.
73  * 
74  * 20    7/11/97 11:54a John
75  * added rotated 3d bitmaps.
76  * 
77  * 19    4/29/97 12:24p Adam
78  * JAS:   Added code for delayed point to vec.   Fixed some FRED
79  * sequencing problems with g3_start_frame / g3_end_frame.
80  * 
81  * 18    4/29/97 9:55a John
82  * 
83  * 17    4/08/97 5:18p John
84  * First rev of decent (dynamic, correct) lighting in FreeSpace.
85  * 
86  * 16    3/05/97 12:49p John
87  * added Viewer_obj.  Took out the interp_??? variables for turning
88  * outline,etc on and put them in flags you pass to model_render.
89  * Cleaned up model_interp code to fit new coding styles.
90  * 
91  * 15    2/26/97 5:24p John
92  * Added g3_draw_sphere_ez
93  * 
94  * 14    2/17/97 5:18p John
95  * Added a bunch of RCS headers to a bunch of old files that don't have
96  * them.
97  *
98  * $NoKeywords: $
99  */
100
101 #ifndef _3D_H
102 #define _3D_H
103
104 #include "vecmat.h"
105 #include "tmapper.h"
106
107 //flags for point structure
108 #define PF_PROJECTED     1      //has been projected, so sx,sy valid
109 #define PF_OVERFLOW              2      //can't project
110 #define PF_TEMP_POINT    4      //created during clip
111
112 //clipping codes flags
113 #define CC_OFF_LEFT     1
114 #define CC_OFF_RIGHT    2
115 #define CC_OFF_BOT      4
116 #define CC_OFF_TOP      8
117 #define CC_OFF_USER     16
118 #define CC_BEHIND               0x80
119
120 // Combo!
121 #define CC_OFF                  (CC_OFF_LEFT | CC_OFF_RIGHT | CC_OFF_BOT | CC_OFF_TOP | CC_OFF_USER | CC_BEHIND)
122
123
124 //Functions in library
125
126 //Frame setup functions:
127 //start the frame. Pass non-zero to enable zbuffering
128 #define g3_start_frame(zbuffer_flag) g3_start_frame_func(zbuffer_flag, __FILE__, __LINE__ )
129
130 // use the g3_start_frame macro instead of calling this directly.
131 extern void g3_start_frame_func(int zbuffer_flag, char * filename, int lineno);
132
133
134 //set view from x,y,z & p,b,h, zoom.  Must call one of g3_set_view_*()
135 void g3_set_view_angles(vector *view_pos,angles *view_orient,float zoom);
136
137 //set view from x,y,z, viewer matrix, and zoom.  Must call one of g3_set_view_*()
138 void g3_set_view_matrix(vector *view_pos,matrix *view_matrix,float zoom);
139
140 // Never set these!
141 extern matrix           View_matrix;            // The matrix to convert local coordinates to screen
142 extern vector           View_position;          // The offset to convert local coordinates to screen
143
144 extern matrix           Light_matrix;           // Used to rotate world points into current local coordinates
145 extern vector           Light_base;                     // Used to rotate world points into current local coordinates
146
147 extern matrix           Eye_matrix;                     // Where the viewer's eye is pointing in World coordinates
148 extern vector           Eye_position;           // Where the viewer's eye is at in World coordinates
149
150
151 //end the frame
152 void g3_end_frame(void);
153
154 //draw a horizon
155 void g3_draw_horizon(int sky_color,int ground_color);
156
157 //draws a line representing the horizon
158 void g3_draw_horizon_line();
159
160 //get vectors that are edge of horizon
161 int g3_compute_sky_polygon(float *points_2d,vector *vecs);
162
163 //Instancing
164
165 //instance at specified point with specified orientation
166 void g3_start_instance_matrix(vector *pos,matrix *orient);
167
168 //instance at specified point with specified orientation
169 void g3_start_instance_angles(vector *pos,angles *orient);
170
171 //pops the old context
172 void g3_done_instance();
173
174 //Misc utility functions:
175
176 //get current field of view.  Fills in angle for x & y
177 void g3_get_FOV(float *fov_x,float *fov_y);
178
179 //get zoom.  For a given window size, return the zoom which will achieve
180 //the given FOV along the given axis.
181 float g3_get_zoom(char axis,float fov,int window_width,int window_height);
182
183 //returns the normalized, unscaled view vectors
184 void g3_get_view_vectors(vector *forward,vector *up,vector *right);
185
186 //returns true if a plane is facing the viewer. takes the unrotated surface
187 //normal of the plane, and a point on it.  The normal need not be normalized
188 int g3_check_normal_facing(vector *v,vector *norm);
189
190 //Point definition and rotation functions:
191
192 //specify the arrays refered to by the 'pointlist' parms in the following
193 //functions.  I'm not sure if we will keep this function, but I need
194 //it now.
195 //void g3_set_points(g3s_point *points,vms_vector *vecs);
196
197 //returns codes_and & codes_or of a list of points numbers
198 ccodes g3_check_codes(int nv,vertex **pointlist);
199
200 //rotates a point. returns codes.  does not check if already rotated
201 ubyte g3_rotate_vertex(vertex *dest,vector *src);
202
203 // same as above, only ignores the current instancing
204 ubyte g3_rotate_vertex_popped(vertex *dest,vector *src);
205
206 //use this for stars, etc
207 ubyte g3_rotate_faraway_vertex(vertex *dest,vector *src);
208
209
210 //projects a point
211 int g3_project_vertex(vertex *point);
212
213 //projects a vector
214 ubyte g3_project_vector(vector *p, float *sx, float *sy );
215
216 //rotates a point.  returns codes.
217 ubyte g3_rotate_vector(vector *dest,vector *src);
218
219 //Codes a vector.  Returns the codes of a point.
220 ubyte g3_code_vector(vector * p);
221
222 //calculate the depth of a point - returns the z coord of the rotated point
223 float g3_calc_point_depth(vector *pnt);
224
225 //From a 2d point, compute the vector through that point
226 void g3_point_to_vec(vector *v,int sx,int sy);
227
228 //From a 2d point, compute the vector through that point.
229 // This can be called outside of a g3_start_frame/g3_end_frame
230 // pair as long g3_start_frame was previously called.
231 void g3_point_to_vec_delayed(vector *v,int sx,int sy);
232
233 //code a point.  fills in the p3_codes field of the point, and returns the codes
234 ubyte g3_code_vertex(vertex *point);
235
236 //delta rotation functions
237 vector *g3_rotate_delta_x(vector *dest,float dx);
238 vector *g3_rotate_delta_y(vector *dest,float dy);
239 vector *g3_rotate_delta_z(vector *dest,float dz);
240 vector *g3_rotate_delta_vec(vector *dest,vector *src);
241 ubyte g3_add_delta_vec(vertex *dest,vertex *src,vector *deltav);
242
243 //Drawing functions:
244
245 //draw a polygon.
246 //Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.
247 //returns 1 if off screen, 0 if drew
248 int g3_draw_poly(int nv,vertex **pointlist,uint tmap_flags);
249
250 // Draw a polygon.  Same as g3_draw_poly, but it bashes sw to a constant value
251 // for all vertexes.  Needs to be done after clipping to get them all.
252 //Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.
253 //returns 1 if off screen, 0 if drew
254 int g3_draw_poly_constant_sw(int nv,vertex **pointlist,uint tmap_flags, float constant_sw);
255
256 //like g3_draw_poly(), but checks to see if facing.  If surface normal is
257 //NULL, this routine must compute it, which will be slow.  It is better to
258 //pre-compute the normal, and pass it to this function.  When the normal
259 //is passed, this function works like g3_check_normal_facing() plus
260 //g3_draw_poly().
261 //Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.
262 //returns -1 if not facing, 1 if off screen, 0 if drew
263 int g3_draw_poly_if_facing(int nv,vertex **pointlist,uint tmap_flags,vector *norm,vector *pnt);
264
265 //draws a line. takes two points.
266 int g3_draw_line(vertex *p0,vertex *p1);
267
268 // Draws a polygon always facing the viewer.
269 // compute the corners of a rod.  fills in vertbuf.
270 // Verts has any needs uv's or l's or can be NULL if none needed.
271 int g3_draw_rod(vector *p0,float width1,vector *p1,float width2, vertex * verts, uint tmap_flags);
272
273 //draws a bitmap with the specified 3d width & height
274 //Set TMAP_FLAG_TEXTURED in the tmap_flags to texture map it with current texture.
275 //returns 1 if off screen, 0 if drew
276 // If bitmap is not square, rad will be the 3d size of the smallest dimension.
277 // orient flips the bitmap in some way.  Pass 0 for normal or else pass a 
278 // random nuber between 0 and 7, inclusive.
279 int g3_draw_bitmap(vertex *pos,int orient, float radius, uint tmap_flags);
280
281 // get bitmap dims onscreen as if g3_draw_bitmap() had been called
282 int g3_get_bitmap_dims(int bitmap, vertex *pos, float radius, int *x, int *y, int *w, int *h, int *size);
283
284 //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
285 //radius, but not to the distance from the eye.  Uses the current 2d color.
286 int g3_draw_sphere(vertex *pnt,float rad);
287
288 // Same as g3_draw_sphere, but you pass a vector and this rotates
289 // and projects it and then call g3_draw_sphere.
290 int g3_draw_sphere_ez(vector *pnt,float rad);
291
292 //Draw a laser shaped 3d looking thing.
293 // If max_len is > 1.0, then this caps the length to be no longer than max_len pixels
294 float g3_draw_laser(vector *headp, float head_width, vector *tailp, float tail_width, uint tmap_flags = TMAP_FLAG_TEXTURED, float max_len = 0.0f );
295
296 // Draw a laser shaped 3d looking thing using vertex coloring (useful for things like colored laser glows)
297 // If max_len is > 1.0, then this caps the length to be no longer than max_len pixels
298 float g3_draw_laser_rgb(vector *headp, float head_width, vector *tailp, float tail_width, int r, int g, int b, uint tmap_flags = TMAP_FLAG_TEXTURED | TMAP_FLAG_RGB, float max_len = 0.0f );
299
300 // Draw a bitmap that is always facing, but rotates.
301 // If bitmap is not square, rad will be the 3d size of the smallest dimension.
302 int g3_draw_rotated_bitmap(vertex *pnt,float angle, float radius, uint tmap_flags);
303
304 // draw a perspective bitmap based on angles and radius
305 int g3_draw_perspective_bitmap(angles *a, float scale_x, float scale_y, int div_x, int div_y, uint tmap_flags);
306
307 // draw a 2d bitmap on a poly
308 int g3_draw_2d_poly_bitmap(int x, int y, int w, int h, uint additional_tmap_flags = 0);
309
310 // Enables clipping with an arbritary plane.   This will be on
311 // until g3_stop_clip_plane is called or until next frame.
312 // The points passed should be relative to the instance.  Probably
313 // that means world coordinates.
314 /*
315   This works like any other clip plane... if this is enabled and you
316 rotate a point, the CC_OFF_USER bit will be set in the clipping codes.
317 It is completely handled by most g3_draw primitives, except maybe lines.
318
319   As far as performance, when enabled, it will slow down each point
320 rotation (or g3_code_vertex call) by a vector subtraction and dot
321 product.   It won't slow anything down for polys that are completely
322 clipped on or off by the plane, and will slow each clipped polygon by
323 not much more than any other clipping we do.
324 */
325 void g3_start_user_clip_plane( vector *plane_point, vector *plane_normal );
326
327 // Stops arbritary plane clipping
328 void g3_stop_user_clip_plane();
329
330
331
332 #endif
333