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