1 /* $Id: 3d.h,v 1.13 2005-08-02 06:11:10 chris Exp $ */
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.
17 * Header file for 3d library
18 * except for functions implemented in interp.c
26 #include "vecmat.h" //the vector/matrix library
29 extern int g3d_interp_outline; //if on, polygon models outlined in white
31 extern vms_vector Matrix_scale; //how the matrix is currently scaled
33 extern short highest_texture_num;
35 //Structure for storing u,v,light values. This structure doesn't have a
36 //prefix because it was defined somewhere else before it was moved here
37 typedef struct g3s_uvl {
41 //Stucture to store clipping codes in a word
42 typedef struct g3s_codes {
43 ubyte or,and; //or is low byte, and is high byte
46 //flags for point structure
47 #define PF_PROJECTED 1 //has been projected, so sx,sy valid
48 #define PF_OVERFLOW 2 //can't project
49 #define PF_TEMP_POINT 4 //created during clip
50 #define PF_UVS 8 //has uv values set
51 #define PF_LS 16 //has lighting values set
53 //clipping codes flags
56 #define CC_OFF_RIGHT 2
59 #define CC_BEHIND 0x80
61 //Used to store rotated points for mines. Has frame count to indictate
62 //if rotated, and flag to indicate if projected.
63 typedef struct g3s_point {
64 vms_vector p3_vec; //x,y,z of rotated point
65 fix p3_u,p3_v,p3_l; //u,v,l coords
66 fix p3_sx,p3_sy; //screen x&y
67 ubyte p3_codes; //clipping codes
68 ubyte p3_flags; //projected?
69 short p3_pad; //keep structure longword aligned
72 //macros to reference x,y,z elements of a 3d point
77 //An object, such as a robot
78 typedef struct g3s_object {
79 vms_vector o3_pos; //location of this object
80 vms_angvec o3_orient; //orientation of this object
81 int o3_nverts; //number of points in the object
82 int o3_nfaces; //number of faces in the object
84 //this will be filled in later
88 //Functions in library
90 //3d system startup and shutdown:
92 //initialize the 3d system
95 //close down the 3d system
99 //Frame setup functions:
102 void g3_start_frame(void);
104 //set view from x,y,z & p,b,h, zoom. Must call one of g3_set_view_*()
105 void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom);
107 //set view from x,y,z, viewer matrix, and zoom. Must call one of g3_set_view_*()
108 void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom);
111 void g3_end_frame(void);
114 void g3_draw_horizon(int sky_color,int ground_color);
116 //get vectors that are edge of horizon
117 int g3_compute_sky_polygon(fix *points_2d,vms_vector *vecs);
121 //instance at specified point with specified orientation
122 void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient);
124 //instance at specified point with specified orientation
125 void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles);
127 //pops the old context
128 void g3_done_instance();
130 //Misc utility functions:
132 //get current field of view. Fills in angle for x & y
133 void g3_get_FOV(fixang *fov_x,fixang *fov_y);
135 //get zoom. For a given window size, return the zoom which will achieve
136 //the given FOV along the given axis.
137 fix g3_get_zoom(char axis,fixang fov,short window_width,short window_height);
139 //returns the normalized, unscaled view vectors
140 void g3_get_view_vectors(vms_vector *forward,vms_vector *up,vms_vector *right);
142 //returns true if a plane is facing the viewer. takes the unrotated surface
143 //normal of the plane, and a point on it. The normal need not be normalized
144 bool g3_check_normal_facing(vms_vector *v,vms_vector *norm);
146 //Point definition and rotation functions:
148 //specify the arrays refered to by the 'pointlist' parms in the following
149 //functions. I'm not sure if we will keep this function, but I need
151 //void g3_set_points(g3s_point *points,vms_vector *vecs);
153 //returns codes_and & codes_or of a list of points numbers
154 g3s_codes g3_check_codes(int nv,g3s_point **pointlist);
156 //rotates a point. returns codes. does not check if already rotated
157 ubyte g3_rotate_point(g3s_point *dest,vms_vector *src);
160 void g3_project_point(g3s_point *point);
162 //calculate the depth of a point - returns the z coord of the rotated point
163 fix g3_calc_point_depth(vms_vector *pnt);
165 //from a 2d point, compute the vector through that point
166 void g3_point_2_vec(vms_vector *v,short sx,short sy);
168 //code a point. fills in the p3_codes field of the point, and returns the codes
169 ubyte g3_code_point(g3s_point *point);
171 //delta rotation functions
172 vms_vector *g3_rotate_delta_x(vms_vector *dest,fix dx);
173 vms_vector *g3_rotate_delta_y(vms_vector *dest,fix dy);
174 vms_vector *g3_rotate_delta_z(vms_vector *dest,fix dz);
175 vms_vector *g3_rotate_delta_vec(vms_vector *dest,vms_vector *src);
176 ubyte g3_add_delta_vec(g3s_point *dest,g3s_point *src,vms_vector *deltav);
180 //draw a flat-shaded face.
181 //returns 1 if off screen, 0 if drew
182 bool g3_draw_poly(int nv,g3s_point **pointlist);
184 //draw a texture-mapped face.
185 //returns 1 if off screen, 0 if drew
186 bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm);
188 //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
189 //radius, but not to the distance from the eye
190 int g3_draw_sphere(g3s_point *pnt,fix rad);
192 //@@//return ligting value for a point
193 //@@fix g3_compute_lighting_value(g3s_point *rotated_point,fix normval);
196 //like g3_draw_poly(), but checks to see if facing. If surface normal is
197 //NULL, this routine must compute it, which will be slow. It is better to
198 //pre-compute the normal, and pass it to this function. When the normal
199 //is passed, this function works like g3_check_normal_facing() plus
201 //returns -1 if not facing, 1 if off screen, 0 if drew
202 bool g3_check_and_draw_poly(int nv,g3s_point **pointlist,vms_vector *norm,vms_vector *pnt);
203 bool g3_check_and_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm,vms_vector *norm,vms_vector *pnt);
205 //draws a line. takes two points.
206 bool g3_draw_line(g3s_point *p0,g3s_point *p1);
208 //draw a polygon that is always facing you
209 //returns 1 if off screen, 0 if drew
210 bool g3_draw_rod_flat(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width);
212 //draw a bitmap object that is always facing you
213 //returns 1 if off screen, 0 if drew
214 bool g3_draw_rod_tmap(grs_bitmap *bitmap,g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width,fix light);
216 //draws a bitmap with the specified 3d width & height
217 //returns 1 if off screen, 0 if drew
218 bool g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm, int orientation);
220 //specifies 2d drawing routines to use instead of defaults. Passing
221 //NULL for either or both restores defaults
222 void g3_set_special_render(void (*tmap_drawer)(),void (*flat_drawer)(),int (*line_drawer)(fix, fix, fix, fix));