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