convert line ends
[canaan.git] / prj / tech / libsrc / md / md.h
blob69858ce13771da8bb323ac554ea5256e89495c0c
1 /*
2 * $Source: x:/prj/tech/libsrc/md/RCS/md.h $
3 * $Revision: 1.25 $
4 * $Author: buzzard $
5 * $Date: 1998/06/30 18:56:11 $
7 * Model Library prototypes
9 */
12 #ifndef __MD_H
13 #define __MD_H
14 #pragma once
16 #include <mds.h>
18 #include <r3ds.h>
20 // Normal way to render a model. Pass in pointer to the model and parms
21 // list
22 EXTERN void md_render_model(mds_model *m,mds_parm parms[]);
24 // Call this if you want to render the model from a vcall
25 EXTERN void md_render_vcall(mds_model *m);
27 // Given a model, returns the needed size of the buffer for it
28 EXTERN int md_buffsize(mds_model *m);
30 // Use this buffer for the next model rendered
31 EXTERN void md_set_buff(mds_model *m,void *buff);
33 // Only transforms points, polygon normals, and lighting values
34 // into the buffer. Does not render.
35 EXTERN void md_transform_only(mds_model *m,mds_parm parms[]);
37 // Only render the model, assumes it has been transformed, and in fact,
38 // only works then.
39 EXTERN void md_render_only(mds_model *m,mds_parm parms[]);
41 // Renders only a subobject, nothing else.
42 EXTERN void md_render_subobj(mds_model *m,mds_parm parms[],int sub);
44 // Return a pointer to the material list.
45 #define md_mat_list(m) ((mds_mat *)((uchar *)(m)+((m)->mat_off)))
47 // Return a point to the subobject list
48 #define md_subobj_list(m) ((mds_subobj *)((uchar *)(m)+((m)->subobj_off)))
50 // Return a pointer to the vhot list
51 #define md_vhot_list(m) ((mds_vhot*)((uchar *)(m)+((m)->vhot_off)))
53 // Return a pointer to the light list
54 #define md_light_list(m) ((mds_light*)((uchar *)(m)+((m)->light_off)))
56 // Return a pointer to the point list
57 #define md_point_list(m) ((mxs_vector*)((uchar *)(m)+((m)->point_off)))
59 // Return a pointer to the normal list
60 #define md_norm_list(m) ((mxs_vector*)((uchar *)m+m->norm_off))
62 // Just evaluate the vhots, stuffing them into their positions.
63 EXTERN void md_eval_vhots(mds_model *m,mds_parm parms[]);
65 // These tables are for the vcolors, textures, vcalls, and for reading the result of vhots. The vhots are in
66 // world coords. You set the vcolor to the color index (if 8 bit) or color (if 16 bit or higher). You set the
67 // vtext tab to the handle of the texture.
69 #define MD_TAB_SIZE 128
71 // What is a vcall?
72 typedef void (* mdf_vcall)(mds_node_vcall *v);
74 EXTERN int *mdd_vcolor_tab;
75 EXTERN r3s_texture *mdd_vtext_tab;
76 EXTERN mdf_vcall *mdd_vcall_tab;
77 EXTERN mxs_vector *mdd_vhot_tab;
79 #define md_set_table_entry(index, val, table) \
80 do { \
81 int __mdmac_index = (index); \
82 AssertMsg1(((__mdmac_index < MD_TAB_SIZE)&& \
83 (__mdmac_index >= 0)), \
84 "MD library table index out of range: %i\n", \
85 __mdmac_index); \
86 table[__mdmac_index] = (val); \
87 } while (0)
89 #define md_set_vtext(index, val) \
90 md_set_table_entry(index, val, mdd_vtext_tab)
92 #define md_set_vcolor(index, val) \
93 md_set_table_entry(index, val, mdd_vcolor_tab)
95 #define md_set_vcall(index, val) \
96 md_set_table_entry(index, val, mdd_vcall_tab)
98 #define md_set_vhot(index, val) \
99 md_set_table_entry(index, val, mdd_vhot_tab)
101 // Typedef defining a function to render a polygon. This is used as
102 // the callback type.
104 typedef void (* mdf_pgon_cback)(mds_pgon *pgon);
106 // Set the polygon callback function. Gets reset at the end of the
107 // next rendering. Returns current one so you can chain if you want.
108 EXTERN mdf_pgon_cback md_set_pgon_callback(mdf_pgon_cback func);
110 typedef void (* mdf_render_pgon_cback)(mds_pgon *p, r3s_phandle *vlist,
111 grs_bitmap *bm, ulong color, ulong type);
113 // Set a lower-level polygon rendering callback. This gets passed
114 // in most of the stuff that's passed to the r3d. It returns the
115 // current *mdf_pgon_cback* which you can chain.
116 EXTERN mdf_pgon_cback md_set_render_pgon_callback(mdf_render_pgon_cback func);
118 // Exposed so people doing pgon callbacks
119 // can pre or post render
120 EXTERN void md_render_pgon(mds_pgon *p);
122 // By default is set true, you can set it false here, and change the
123 // render order for doing craziness like span
124 // clipping, and potentially Z buffer.
125 EXTERN void md_render_back_to_front(bool f);
127 // By default is set false. If set true, evaluates a bounding sphere
128 // at each node to determine if the node needs
129 // to be rendered or not.
130 EXTERN void md_check_bounding_sphere(bool f);
132 // Converts a normal to a compressed light value
133 EXTERN void md_norm2light(ulong *l,mxs_vector *n);
135 // set the render mode
136 enum {
137 MD_RMODE_NORMAL,
138 MD_RMODE_SOLID,
139 MD_RMODE_WIRE
142 // render normally, as solid, or wire
143 // let's you change the primitive
144 // Also has the effect of eliminating color setting
145 EXTERN void md_set_render_prim(ubyte mode);
147 // to light, or not to light.
148 EXTERN void md_set_render_light(bool l);
151 EXTERN bool mdd_rgb_lighting;
153 // Sets the per subobject callback and returns the old one.
154 mdf_subobj_cback md_set_subobj_callback(mdf_subobj_cback);
156 // Sets the light callback, and gets the old one back
157 mdf_light_setup_cback md_set_light_setup_callback(mdf_light_setup_cback);
158 mdf_light_cback md_set_light_callback(mdf_light_cback);
159 mdf_light_obj_cback md_set_light_obj_callback(mdf_light_obj_cback);
161 // This is the default implementaton of lighting, just
162 // call md_light_init() to install, and use it
163 // like the old 3d library lighting
165 #define MD_LT_NONE 0
166 #define MD_LT_AMB 1
167 #define MD_LT_DIFF 2
168 #define MD_LT_SPEC 4
170 // Set the light type
171 EXTERN void md_light_set_type(uchar type);
173 // Recomputes constants based on type of lighting
174 // call explicitly if you change object frame and
175 // need to recompute lights.
176 EXTERN void md_light_recompute();
178 // Call this to install the default
179 // lighter
180 EXTERN void md_light_init();
182 // Just set these directly
183 EXTERN mxs_vector mdd_sun_vec;
184 EXTERN float mdd_lt_amb; // ambient value
185 EXTERN float mdd_lt_diff; // diffuse value
186 EXTERN float mdd_lt_spec; // specular value
188 // Set true to get linear, false to get perspective
189 // This is superceded and overwritten if you use the
190 // fancy util renderer
192 EXTERN void md_set_tmap_linear(bool l);
195 // Scale a model according to the scaling vector s. The scaling is
196 // done in source space. If the model *dst is NULL, it allocates memory
197 // for it
198 // light is whether or not to retransform the lighting vectors. Depending,
199 // you may actually want it to be the same, plus it's the slowest thing to
200 // do
201 EXTERN mds_model *md_scale_model(mds_model *dst,mds_model *src,mxs_vector *s,bool light);
203 // Shear a model according to the shearing factor s. The shearing is
204 // done in source space, in the ax_src-ax_targ plane.
205 // For example, if ax_targ=2 (z-axis) and ax_src=1 (y-axis), then
206 // the transformation is x->x, y->y, z->z+sy. The result is that a rectangle in
207 // the y-z plane centered at the origin will become a parallelogram with
208 // two vertical sides, and two sides with slope s.
210 // If the model *dst is NULL, it allocates memory for it
211 // light is whether or not to retransform the lighting vectors. Depending,
212 // you may actually want it to be the same, plus it's the slowest thing to
213 // do
214 EXTERN mds_model *md_shear_model(mds_model *dst,mds_model *src,int ax_src,int ax_targ,mxs_real s,bool light);
216 #endif // __MD_H