]> icculus.org git repositories - btb/d2x.git/blob - include/3d.h
added audio flag macros
[btb/d2x.git] / include / 3d.h
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13 /*
14  * $Source: /cvs/cvsroot/d2x/include/3d.h,v $
15  * $Revision: 1.5 $
16  * $Author: bradleyb $
17  * $Date: 2001-11-05 07:38:09 $
18  *
19  * Header file for 3d library
20  *
21  * $Log: not supported by cvs2svn $
22  * Revision 1.4  2001/10/31 07:41:54  bradleyb
23  * Sync with d1x
24  *
25  * Revision 1.3  2001/10/25 02:06:58  bradleyb
26  * added prototype for g3_uninit_polygon_model
27  *
28  * Revision 1.2  2001/01/20 13:49:14  bradleyb
29  * Got rid of all compiler warnings, for non-OpenGL on linux, anyway...
30  *
31  * Revision 1.1.1.1  2001/01/19 03:30:16  bradleyb
32  * Import of d2x-0.0.8
33  *
34  * Revision 1.1.1.1  1999/06/14 22:02:03  donut
35  * Import of d1x 1.37 source.
36  *
37  * Revision 1.2  1995/09/14  14:08:58  allender
38  * return value for g3_draw_sphere
39  *
40  * Revision 1.1  1995/05/05  08:48:41  allender
41  * Initial revision
42  *
43  * 
44  *
45  */
46
47 #ifndef _3D_H
48 #define _3D_H
49
50 #include "fix.h"
51 #include "vecmat.h"     //the vector/matrix library
52 #include "gr.h"
53
54 extern int g3d_interp_outline;          //if on, polygon models outlined in white
55 extern vms_vector Matrix_scale;
56 extern short highest_texture_num;
57
58 //Structure for storing u,v,light values.  This structure doesn't have a
59 //prefix because it was defined somewhere else before it was moved here
60 typedef struct g3s_uvl {
61         fix u,v,l;
62 } g3s_uvl;
63
64 //Stucture to store clipping codes in a word
65 typedef struct g3s_codes {
66         ubyte or,and;   //or is low byte, and is high byte
67 } g3s_codes;
68
69 //flags for point structure
70 #define PF_PROJECTED    1       //has been projected, so sx,sy valid
71 #define PF_OVERFLOW             2       //can't project
72 #define PF_TEMP_POINT   4       //created during clip
73 #define PF_UVS                          8       //has uv values set
74 #define PF_LS                           16      //has lighting values set
75
76 //clipping codes flags
77
78 #define CC_OFF_LEFT     1
79 #define CC_OFF_RIGHT    2
80 #define CC_OFF_BOT      4
81 #define CC_OFF_TOP      8
82 #define CC_BEHIND               0x80
83
84 //Used to store rotated points for mines.  Has frame count to indictate
85 //if rotated, and flag to indicate if projected.
86 typedef struct g3s_point {
87         vms_vector p3_vec;         //reference as vector...
88 #ifdef D1XD3D
89         vms_vector p3_orig;
90 #endif
91         fix p3_u,p3_v,p3_l;
92         fix p3_sx,p3_sy;                //screen x&y
93         ubyte p3_codes;         //clipping codes
94         ubyte p3_flags;         //projected?
95         short p3_pad;                   //keep structure longwork aligned
96 } g3s_point;
97
98 //macros to reference x,y,z elements of a 3d point
99 #define p3_x p3_vec.x
100 #define p3_y p3_vec.y
101 #define p3_z p3_vec.z
102
103 //An object, such as a robot
104 typedef struct g3s_object {
105         vms_vector o3_pos;       //location of this object
106         vms_angvec o3_orient;    //orientation of this object
107         int o3_nverts;           //number of points in the object
108         int o3_nfaces;           //number of faces in the object
109
110         //this will be filled in later
111
112 } g3s_object;
113
114 //Functions in library
115
116 //3d system startup and shutdown:
117
118 //initialize the 3d system
119 void g3_init(void);
120
121 //close down the 3d system
122 void g3_close(void);
123
124
125 //Frame setup functions:
126
127 //start the frame
128 void g3_start_frame(void);
129
130 //set view from x,y,z & p,b,h, zoom.  Must call one of g3_set_view_*() 
131 void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom);
132
133 //set view from x,y,z, viewer matrix, and zoom.  Must call one of g3_set_view_*() 
134 void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom);
135
136 //end the frame
137 void g3_end_frame(void);
138
139 //draw a horizon
140 void g3_draw_horizon(int sky_color,int ground_color);
141
142 //get vectors that are edge of horizon
143 int g3_compute_sky_polygon(fix *points_2d,vms_vector *vecs);
144
145 //Instancing
146
147 //instance at specified point with specified orientation
148 void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient);
149
150 //instance at specified point with specified orientation
151 void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles);
152
153 //pops the old context
154 void g3_done_instance();
155
156 //Misc utility functions:
157
158 //get current field of view.  Fills in angle for x & y
159 void g3_get_FOV(fixang *fov_x,fixang *fov_y);
160
161 //get zoom.  For a given window size, return the zoom which will achieve
162 //the given FOV along the given axis.
163 fix g3_get_zoom(char axis,fixang fov,short window_width,short window_height);
164
165 //returns the normalized, unscaled view vectors
166 void g3_get_view_vectors(vms_vector *forward,vms_vector *up,vms_vector *right);
167
168 //returns true if a plane is facing the viewer. takes the unrotated surface 
169 //normal of the plane, and a point on it.  The normal need not be normalized
170 bool g3_check_normal_facing(vms_vector *v,vms_vector *norm);
171
172 //Point definition and rotation functions:
173
174 //specify the arrays refered to by the 'pointlist' parms in the following
175 //functions.  I'm not sure if we will keep this function, but I need
176 //it now.
177 //void g3_set_points(g3s_point *points,vms_vector *vecs);
178
179 //returns codes_and & codes_or of a list of points numbers
180 g3s_codes g3_check_codes(int nv,g3s_point **pointlist);
181
182 //rotates a point. returns codes.  does not check if already rotated
183 ubyte g3_rotate_point(g3s_point *dest,vms_vector *src);
184
185 //projects a point
186 void g3_project_point(g3s_point *point);
187
188 //calculate the depth of a point - returns the z coord of the rotated point
189 fix g3_calc_point_depth(vms_vector *pnt);
190
191 //from a 2d point, compute the vector through that point
192 void g3_point_2_vec(vms_vector *v,short sx,short sy);
193
194 //code a point.  fills in the p3_codes field of the point, and returns the codes
195 ubyte g3_code_point(g3s_point *point);
196
197 //delta rotation functions
198 vms_vector *g3_rotate_delta_x(vms_vector *dest,fix dx);
199 vms_vector *g3_rotate_delta_y(vms_vector *dest,fix dy);
200 vms_vector *g3_rotate_delta_z(vms_vector *dest,fix dz);
201 vms_vector *g3_rotate_delta_vec(vms_vector *dest,vms_vector *src);
202 ubyte g3_add_delta_vec(g3s_point *dest,g3s_point *src,vms_vector *deltav);
203
204 //Drawing functions:
205
206 //draw a flat-shaded face.
207 //returns 1 if off screen, 0 if drew
208 bool g3_draw_poly(int nv,g3s_point **pointlist);
209
210 //draw a texture-mapped face.
211 //returns 1 if off screen, 0 if drew
212 bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm);
213
214 //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
215 //radius, but not to the distance from the eye
216 int g3_draw_sphere(g3s_point *pnt,fix rad);
217
218 //@@//return ligting value for a point
219 //@@fix g3_compute_lighting_value(g3s_point *rotated_point,fix normval);
220
221
222 //like g3_draw_poly(), but checks to see if facing.  If surface normal is
223 //NULL, this routine must compute it, which will be slow.  It is better to 
224 //pre-compute the normal, and pass it to this function.  When the normal
225 //is passed, this function works like g3_check_normal_facing() plus
226 //g3_draw_poly().
227 //returns -1 if not facing, 1 if off screen, 0 if drew
228 bool g3_check_and_draw_poly(int nv,g3s_point **pointlist,vms_vector *norm,vms_vector *pnt);
229 bool g3_check_and_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm,vms_vector *norm,vms_vector *pnt);
230
231 //draws a line. takes two points.
232 bool g3_draw_line(g3s_point *p0,g3s_point *p1);
233
234 //draw a polygon that is always facing you
235 //returns 1 if off screen, 0 if drew
236 bool g3_draw_rod_flat(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width);
237
238 //draw a bitmap object that is always facing you
239 //returns 1 if off screen, 0 if drew
240 bool g3_draw_rod_tmap(grs_bitmap *bitmap,g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width,fix light);
241
242 //draws a bitmap with the specified 3d width & height 
243 //returns 1 if off screen, 0 if drew
244 bool g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm,int orientation);
245
246 //specifies 2d drawing routines to use instead of defaults.  Passing
247 //NULL for either or both restores defaults
248 void g3_set_special_render(void (*tmap_drawer)(),void (*flat_drawer)(),int (*line_drawer)(fix, fix, fix, fix));
249
250 //Object functions:
251
252 //gives the interpreter an array of points to use
253 void g3_set_interp_points(g3s_point *pointlist);
254
255 //calls the object interpreter to render an object.  The object renderer
256 //is really a seperate pipeline. returns true if drew
257 bool g3_draw_polygon_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,fix *glow_values);
258
259 //init code for bitmap models
260 void g3_init_polygon_model(void *model_ptr);
261 //maps the colors back to RGB15
262 void g3_uninit_polygon_model(void *model_ptr);
263
264 //alternate interpreter for morphing object
265 bool g3_draw_morphing_model(void *model_ptr,grs_bitmap **model_bitmaps,vms_angvec *anim_angles,fix light,vms_vector *new_points);
266
267 // routine to convert little to big endian in polygon model data
268 void swap_polygon_model_data(ubyte *data);
269
270 #endif
271