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