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