]> icculus.org git repositories - btb/d2x.git/blob - include/3d.h
02175f32353cb2bf5082b95d11ce40481954f8b5
[btb/d2x.git] / include / 3d.h
1 /* $Id: 3d.h,v 1.6 2002-09-05 08:03:22 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Header file for 3d library
18  *
19  * Old Log:
20  * Revision 1.2  1995/09/14  14:08:58  allender
21  * return value for g3_draw_sphere
22  *
23  * Revision 1.1  1995/05/05  08:48:41  allender
24  * Initial revision
25  *
26  * Revision 1.34  1994/11/11  19:22:14  matt
27  * Added new function, g3_calc_point_depth()
28  *
29  * Revision 1.33  1994/09/09  14:23:58  matt
30  * Added support for glowing textures, to add engine glow to Descent.
31  *
32  * Revision 1.32  1994/09/01  10:42:27  matt
33  * Blob routine, renamed g3_draw_bitmap(), now takes seperate 3d width & height.
34  *
35  * Revision 1.31  1994/07/29  18:16:14  matt
36  * Added instance by angles, and corrected parms for g3_init()
37  *
38  * Revision 1.30  1994/07/25  00:00:00  matt
39  * Made 3d no longer deal with point numbers, but only with pointers.
40  *
41  * Revision 1.29  1994/07/22  17:57:27  matt
42  * Changed the name of the rod functions, and took out some debugging code
43  *
44  * Revision 1.28  1994/06/07  16:49:12  matt
45  * Made interpreter take lighting value as parm, rather than in global var
46  *
47  * Revision 1.27  1994/05/31  18:35:28  matt
48  * Added light value to g3_draw_facing_bitmap()
49  *
50  * Revision 1.26  1994/05/30  22:48:04  matt
51  * Added support for morph effect
52  *
53  * Revision 1.25  1994/05/30  11:34:57  matt
54  * Added g3_set_special_render() to allow a user to specify functions to
55  * call for 2d draws.
56  *
57  * Revision 1.24  1994/05/19  21:46:31  matt
58  * Moved texture lighting out of 3d and into the game
59  *
60  * Revision 1.23  1994/05/14  15:26:48  matt
61  * Added extern for polyobj outline flag
62  *
63  * Revision 1.22  1994/04/19  18:26:33  matt
64  * Added g3_draw_sphere() function.
65  *
66  * Revision 1.21  1994/03/25  18:22:28  matt
67  * g3_draw_polygon_model() now takes ptr to list of angles
68  *
69  * Revision 1.20  1994/03/15  21:23:23  matt
70  * Added interpreter functions
71  *
72  * Revision 1.19  1994/02/15  17:37:34  matt
73  * New function, g3_draw_blob()
74  *
75  * Revision 1.18  1994/02/09  11:47:47  matt
76  * Added rod & delta point functions
77  *
78  * Revision 1.17  1994/01/26  12:38:11  matt
79  * Added function g3_compute_lighting_value()
80  *
81  * Revision 1.16  1994/01/25  18:00:02  yuan
82  * Fixed variable beam_brightness...
83  *
84  * Revision 1.15  1994/01/24  14:08:34  matt
85  * Added instancing functions
86  *
87  * Revision 1.14  1994/01/22  18:21:48  matt
88  * New lighting stuff now done in 3d; g3_draw_tmap() takes lighting parm
89  *
90  * Revision 1.13  1994/01/20  17:21:24  matt
91  * New function g3_compute_sky_polygon()
92  *
93  * Revision 1.12  1994/01/14  17:20:25  matt
94  * Added prototype for new function g3_draw_horizon()
95  *
96  * Revision 1.10  1993/12/20  20:21:52  matt
97  * Added g3_point_2_vec()
98  *
99  * Revision 1.9  1993/12/07  23:05:47  matt
100  * Fixed mistyped function name.
101  *
102  * Revision 1.8  1993/12/05  23:47:03  matt
103  * Added function g3_draw_line_ptrs()
104  *
105  * Revision 1.7  1993/12/05  23:13:22  matt
106  * Added prototypes for g3_rotate_point() and g3_project_point()
107  *
108  * Revision 1.6  1993/12/05  23:03:28  matt
109  * Changed uvl structs to g3s_uvl
110  *
111  * Revision 1.5  1993/11/22  10:51:09  matt
112  * Moved uvl structure here from segment.h, made texture map functions use it
113  *
114  * Revision 1.4  1993/11/21  20:08:31  matt
115  * Added function g3_draw_object()
116  *
117  * Revision 1.3  1993/11/04  18:49:19  matt
118  * Added system to only rotate points once per frame
119  *
120  * Revision 1.2  1993/11/04  08:16:06  mike
121  * Add light field (p3_l) to g3s_point.
122  *
123  * Revision 1.1  1993/10/29  22:20:56  matt
124  * Initial revision
125  *
126  */
127
128 #ifndef _3D_H
129 #define _3D_H
130
131 #include "fix.h"
132 #include "vecmat.h" //the vector/matrix library
133 #include "gr.h"
134
135 extern int g3d_interp_outline;      //if on, polygon models outlined in white
136
137 extern vms_vector Matrix_scale;     //how the matrix is currently scaled
138
139 extern short highest_texture_num;
140
141 //Structure for storing u,v,light values.  This structure doesn't have a
142 //prefix because it was defined somewhere else before it was moved here
143 typedef struct g3s_uvl {
144         fix u,v,l;
145 } g3s_uvl;
146
147 //Stucture to store clipping codes in a word
148 typedef struct g3s_codes {
149         ubyte or,and;   //or is low byte, and is high byte
150 } g3s_codes;
151
152 //flags for point structure
153 #define PF_PROJECTED    1   //has been projected, so sx,sy valid
154 #define PF_OVERFLOW     2   //can't project
155 #define PF_TEMP_POINT   4   //created during clip
156 #define PF_UVS          8   //has uv values set
157 #define PF_LS           16  //has lighting values set
158
159 //clipping codes flags
160
161 #define CC_OFF_LEFT     1
162 #define CC_OFF_RIGHT    2
163 #define CC_OFF_BOT      4
164 #define CC_OFF_TOP      8
165 #define CC_BEHIND       0x80
166
167 //Used to store rotated points for mines.  Has frame count to indictate
168 //if rotated, and flag to indicate if projected.
169 typedef struct g3s_point {
170         vms_vector p3_vec;  //x,y,z of rotated point
171 #ifdef D1XD3D
172         vms_vector p3_orig;
173 #endif
174         fix p3_u,p3_v,p3_l; //u,v,l coords
175         fix p3_sx,p3_sy;    //screen x&y
176         ubyte p3_codes;     //clipping codes
177         ubyte p3_flags;     //projected?
178         short p3_pad;       //keep structure longword aligned
179 } g3s_point;
180
181 //macros to reference x,y,z elements of a 3d point
182 #define p3_x p3_vec.x
183 #define p3_y p3_vec.y
184 #define p3_z p3_vec.z
185
186 //An object, such as a robot
187 typedef struct g3s_object {
188         vms_vector o3_pos;       //location of this object
189         vms_angvec o3_orient;    //orientation of this object
190         int o3_nverts;           //number of points in the object
191         int o3_nfaces;           //number of faces in the object
192
193         //this will be filled in later
194
195 } g3s_object;
196
197 //Functions in library
198
199 //3d system startup and shutdown:
200
201 //initialize the 3d system
202 void g3_init(void);
203
204 //close down the 3d system
205 void g3_close(void);
206
207
208 //Frame setup functions:
209
210 //start the frame
211 void g3_start_frame(void);
212
213 //set view from x,y,z & p,b,h, zoom.  Must call one of g3_set_view_*() 
214 void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom);
215
216 //set view from x,y,z, viewer matrix, and zoom.  Must call one of g3_set_view_*() 
217 void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom);
218
219 //end the frame
220 void g3_end_frame(void);
221
222 //draw a horizon
223 void g3_draw_horizon(int sky_color,int ground_color);
224
225 //get vectors that are edge of horizon
226 int g3_compute_sky_polygon(fix *points_2d,vms_vector *vecs);
227
228 //Instancing
229
230 //instance at specified point with specified orientation
231 void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient);
232
233 //instance at specified point with specified orientation
234 void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles);
235
236 //pops the old context
237 void g3_done_instance();
238
239 //Misc utility functions:
240
241 //get current field of view.  Fills in angle for x & y
242 void g3_get_FOV(fixang *fov_x,fixang *fov_y);
243
244 //get zoom.  For a given window size, return the zoom which will achieve
245 //the given FOV along the given axis.
246 fix g3_get_zoom(char axis,fixang fov,short window_width,short window_height);
247
248 //returns the normalized, unscaled view vectors
249 void g3_get_view_vectors(vms_vector *forward,vms_vector *up,vms_vector *right);
250
251 //returns true if a plane is facing the viewer. takes the unrotated surface 
252 //normal of the plane, and a point on it.  The normal need not be normalized
253 bool g3_check_normal_facing(vms_vector *v,vms_vector *norm);
254
255 //Point definition and rotation functions:
256
257 //specify the arrays refered to by the 'pointlist' parms in the following
258 //functions.  I'm not sure if we will keep this function, but I need
259 //it now.
260 //void g3_set_points(g3s_point *points,vms_vector *vecs);
261
262 //returns codes_and & codes_or of a list of points numbers
263 g3s_codes g3_check_codes(int nv,g3s_point **pointlist);
264
265 //rotates a point. returns codes.  does not check if already rotated
266 ubyte g3_rotate_point(g3s_point *dest,vms_vector *src);
267
268 //projects a point
269 void g3_project_point(g3s_point *point);
270
271 //calculate the depth of a point - returns the z coord of the rotated point
272 fix g3_calc_point_depth(vms_vector *pnt);
273
274 //from a 2d point, compute the vector through that point
275 void g3_point_2_vec(vms_vector *v,short sx,short sy);
276
277 //code a point.  fills in the p3_codes field of the point, and returns the codes
278 ubyte g3_code_point(g3s_point *point);
279
280 //delta rotation functions
281 vms_vector *g3_rotate_delta_x(vms_vector *dest,fix dx);
282 vms_vector *g3_rotate_delta_y(vms_vector *dest,fix dy);
283 vms_vector *g3_rotate_delta_z(vms_vector *dest,fix dz);
284 vms_vector *g3_rotate_delta_vec(vms_vector *dest,vms_vector *src);
285 ubyte g3_add_delta_vec(g3s_point *dest,g3s_point *src,vms_vector *deltav);
286
287 //Drawing functions:
288
289 //draw a flat-shaded face.
290 //returns 1 if off screen, 0 if drew
291 bool g3_draw_poly(int nv,g3s_point **pointlist);
292
293 //draw a texture-mapped face.
294 //returns 1 if off screen, 0 if drew
295 bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm);
296
297 //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
298 //radius, but not to the distance from the eye
299 int g3_draw_sphere(g3s_point *pnt,fix rad);
300
301 //@@//return ligting value for a point
302 //@@fix g3_compute_lighting_value(g3s_point *rotated_point,fix normval);
303
304
305 //like g3_draw_poly(), but checks to see if facing.  If surface normal is
306 //NULL, this routine must compute it, which will be slow.  It is better to 
307 //pre-compute the normal, and pass it to this function.  When the normal
308 //is passed, this function works like g3_check_normal_facing() plus
309 //g3_draw_poly().
310 //returns -1 if not facing, 1 if off screen, 0 if drew
311 bool g3_check_and_draw_poly(int nv,g3s_point **pointlist,vms_vector *norm,vms_vector *pnt);
312 bool g3_check_and_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm,vms_vector *norm,vms_vector *pnt);
313
314 //draws a line. takes two points.
315 bool g3_draw_line(g3s_point *p0,g3s_point *p1);
316
317 //draw a polygon that is always facing you
318 //returns 1 if off screen, 0 if drew
319 bool g3_draw_rod_flat(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width);
320
321 //draw a bitmap object that is always facing you
322 //returns 1 if off screen, 0 if drew
323 bool g3_draw_rod_tmap(grs_bitmap *bitmap,g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width,fix light);
324
325 //draws a bitmap with the specified 3d width & height
326 //returns 1 if off screen, 0 if drew
327 bool g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm, int orientation);
328
329 //specifies 2d drawing routines to use instead of defaults.  Passing
330 //NULL for either or both restores defaults
331 void g3_set_special_render(void (*tmap_drawer)(),void (*flat_drawer)(),int (*line_drawer)(fix, fix, fix, fix));
332
333 //Object functions:
334
335 //gives the interpreter an array of points to use
336 void g3_set_interp_points(g3s_point *pointlist);
337
338 //calls the object interpreter to render an object.  The object renderer
339 //is really a seperate pipeline. returns true if drew
340 bool g3_draw_polygon_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,fix *glow_values);
341
342 //init code for bitmap models
343 void g3_init_polygon_model(void *model_ptr);
344
345 //un-initialize, i.e., convert color entries back to RGB15
346 void g3_uninit_polygon_model(void *model_ptr);
347
348 //alternate interpreter for morphing object
349 bool g3_draw_morphing_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,vms_vector *new_points);
350
351 //this remaps the 15bpp colors for the models into a new palette.  It should
352 //be called whenever the palette changes
353 void g3_remap_interp_colors(void);
354
355 // routine to convert little to big endian in polygon model data
356 void swap_polygon_model_data(ubyte *data);
357
358 #endif
359