]> icculus.org git repositories - btb/d2x.git/blob - include/3d.h
don't use hardcoded descriptions of joystick buttons/axes
[btb/d2x.git] / include / 3d.h
1 /* $Id: 3d.h,v 1.12 2004-08-28 23:17:45 schaffner 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  */
21
22 #ifndef _3D_H
23 #define _3D_H
24
25 #include "fix.h"
26 #include "vecmat.h" //the vector/matrix library
27 #include "gr.h"
28
29 extern int g3d_interp_outline;      //if on, polygon models outlined in white
30
31 extern vms_vector Matrix_scale;     //how the matrix is currently scaled
32
33 extern short highest_texture_num;
34
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 {
38         fix u,v,l;
39 } g3s_uvl;
40
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
44 } g3s_codes;
45
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
52
53 //clipping codes flags
54
55 #define CC_OFF_LEFT     1
56 #define CC_OFF_RIGHT    2
57 #define CC_OFF_BOT      4
58 #define CC_OFF_TOP      8
59 #define CC_BEHIND       0x80
60
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 #ifdef D1XD3D
66         vms_vector p3_orig;
67 #endif
68         fix p3_u,p3_v,p3_l; //u,v,l coords
69         fix p3_sx,p3_sy;    //screen x&y
70         ubyte p3_codes;     //clipping codes
71         ubyte p3_flags;     //projected?
72         short p3_pad;       //keep structure longword aligned
73 } g3s_point;
74
75 //macros to reference x,y,z elements of a 3d point
76 #define p3_x p3_vec.x
77 #define p3_y p3_vec.y
78 #define p3_z p3_vec.z
79
80 //An object, such as a robot
81 typedef struct g3s_object {
82         vms_vector o3_pos;       //location of this object
83         vms_angvec o3_orient;    //orientation of this object
84         int o3_nverts;           //number of points in the object
85         int o3_nfaces;           //number of faces in the object
86
87         //this will be filled in later
88
89 } g3s_object;
90
91 //Functions in library
92
93 //3d system startup and shutdown:
94
95 //initialize the 3d system
96 void g3_init(void);
97
98 //close down the 3d system
99 void g3_close(void);
100
101
102 //Frame setup functions:
103
104 //start the frame
105 void g3_start_frame(void);
106
107 //set view from x,y,z & p,b,h, zoom.  Must call one of g3_set_view_*() 
108 void g3_set_view_angles(vms_vector *view_pos,vms_angvec *view_orient,fix zoom);
109
110 //set view from x,y,z, viewer matrix, and zoom.  Must call one of g3_set_view_*() 
111 void g3_set_view_matrix(vms_vector *view_pos,vms_matrix *view_matrix,fix zoom);
112
113 //end the frame
114 void g3_end_frame(void);
115
116 //draw a horizon
117 void g3_draw_horizon(int sky_color,int ground_color);
118
119 //get vectors that are edge of horizon
120 int g3_compute_sky_polygon(fix *points_2d,vms_vector *vecs);
121
122 //Instancing
123
124 //instance at specified point with specified orientation
125 void g3_start_instance_matrix(vms_vector *pos,vms_matrix *orient);
126
127 //instance at specified point with specified orientation
128 void g3_start_instance_angles(vms_vector *pos,vms_angvec *angles);
129
130 //pops the old context
131 void g3_done_instance();
132
133 //Misc utility functions:
134
135 //get current field of view.  Fills in angle for x & y
136 void g3_get_FOV(fixang *fov_x,fixang *fov_y);
137
138 //get zoom.  For a given window size, return the zoom which will achieve
139 //the given FOV along the given axis.
140 fix g3_get_zoom(char axis,fixang fov,short window_width,short window_height);
141
142 //returns the normalized, unscaled view vectors
143 void g3_get_view_vectors(vms_vector *forward,vms_vector *up,vms_vector *right);
144
145 //returns true if a plane is facing the viewer. takes the unrotated surface 
146 //normal of the plane, and a point on it.  The normal need not be normalized
147 bool g3_check_normal_facing(vms_vector *v,vms_vector *norm);
148
149 //Point definition and rotation functions:
150
151 //specify the arrays refered to by the 'pointlist' parms in the following
152 //functions.  I'm not sure if we will keep this function, but I need
153 //it now.
154 //void g3_set_points(g3s_point *points,vms_vector *vecs);
155
156 //returns codes_and & codes_or of a list of points numbers
157 g3s_codes g3_check_codes(int nv,g3s_point **pointlist);
158
159 //rotates a point. returns codes.  does not check if already rotated
160 ubyte g3_rotate_point(g3s_point *dest,vms_vector *src);
161
162 //projects a point
163 void g3_project_point(g3s_point *point);
164
165 //calculate the depth of a point - returns the z coord of the rotated point
166 fix g3_calc_point_depth(vms_vector *pnt);
167
168 //from a 2d point, compute the vector through that point
169 void g3_point_2_vec(vms_vector *v,short sx,short sy);
170
171 //code a point.  fills in the p3_codes field of the point, and returns the codes
172 ubyte g3_code_point(g3s_point *point);
173
174 //delta rotation functions
175 vms_vector *g3_rotate_delta_x(vms_vector *dest,fix dx);
176 vms_vector *g3_rotate_delta_y(vms_vector *dest,fix dy);
177 vms_vector *g3_rotate_delta_z(vms_vector *dest,fix dz);
178 vms_vector *g3_rotate_delta_vec(vms_vector *dest,vms_vector *src);
179 ubyte g3_add_delta_vec(g3s_point *dest,g3s_point *src,vms_vector *deltav);
180
181 //Drawing functions:
182
183 //draw a flat-shaded face.
184 //returns 1 if off screen, 0 if drew
185 bool g3_draw_poly(int nv,g3s_point **pointlist);
186
187 //draw a texture-mapped face.
188 //returns 1 if off screen, 0 if drew
189 bool g3_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm);
190
191 //draw a sortof sphere - i.e., the 2d radius is proportional to the 3d
192 //radius, but not to the distance from the eye
193 int g3_draw_sphere(g3s_point *pnt,fix rad);
194
195 //@@//return ligting value for a point
196 //@@fix g3_compute_lighting_value(g3s_point *rotated_point,fix normval);
197
198
199 //like g3_draw_poly(), but checks to see if facing.  If surface normal is
200 //NULL, this routine must compute it, which will be slow.  It is better to 
201 //pre-compute the normal, and pass it to this function.  When the normal
202 //is passed, this function works like g3_check_normal_facing() plus
203 //g3_draw_poly().
204 //returns -1 if not facing, 1 if off screen, 0 if drew
205 bool g3_check_and_draw_poly(int nv,g3s_point **pointlist,vms_vector *norm,vms_vector *pnt);
206 bool g3_check_and_draw_tmap(int nv,g3s_point **pointlist,g3s_uvl *uvl_list,grs_bitmap *bm,vms_vector *norm,vms_vector *pnt);
207
208 //draws a line. takes two points.
209 bool g3_draw_line(g3s_point *p0,g3s_point *p1);
210
211 //draw a polygon that is always facing you
212 //returns 1 if off screen, 0 if drew
213 bool g3_draw_rod_flat(g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width);
214
215 //draw a bitmap object that is always facing you
216 //returns 1 if off screen, 0 if drew
217 bool g3_draw_rod_tmap(grs_bitmap *bitmap,g3s_point *bot_point,fix bot_width,g3s_point *top_point,fix top_width,fix light);
218
219 //draws a bitmap with the specified 3d width & height
220 //returns 1 if off screen, 0 if drew
221 bool g3_draw_bitmap(vms_vector *pos,fix width,fix height,grs_bitmap *bm, int orientation);
222
223 //specifies 2d drawing routines to use instead of defaults.  Passing
224 //NULL for either or both restores defaults
225 void g3_set_special_render(void (*tmap_drawer)(),void (*flat_drawer)(),int (*line_drawer)(fix, fix, fix, fix));
226
227 #endif