1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef OBJ3D_HH
|
---|
10 | #define OBJ3D_HH
|
---|
11 |
|
---|
12 | #include "arch.hh"
|
---|
13 | #include "math/point.hh"
|
---|
14 | #include "tex_id.hh"
|
---|
15 | #include "r1_vert.hh"
|
---|
16 | #include "g1_vert.hh"
|
---|
17 | #include "error/error.hh"
|
---|
18 |
|
---|
19 | class g1_texture_animation
|
---|
20 | {
|
---|
21 | public:
|
---|
22 | w16 quad_number; // quad number in model
|
---|
23 | w8 max_frames; // frames of animation (0 == panning texture)
|
---|
24 | w8 frames_x; // frames of animation in X direction
|
---|
25 | i4_float speed; // speed of animation in units/frame
|
---|
26 | i4_float du,dv; // total change in u & v in pan or animation
|
---|
27 | i4_float u[4], v[4]; // base u,v coordinates from the polygon
|
---|
28 | };
|
---|
29 |
|
---|
30 | class g1_quad_class
|
---|
31 | {
|
---|
32 | public:
|
---|
33 | enum { MAX_VERTS=4 };
|
---|
34 |
|
---|
35 | typedef w16 vertex_ref_type;
|
---|
36 |
|
---|
37 | w32 max_verts() const { return MAX_VERTS; }
|
---|
38 | w32 num_verts() const { return (vertex_ref[MAX_VERTS-1]==0xffff)? MAX_VERTS-1 : MAX_VERTS; }
|
---|
39 | vertex_ref_type vertex_ref[MAX_VERTS];
|
---|
40 | i4_float u[4],v[4], texture_scale;
|
---|
41 | i4_3d_vector normal;
|
---|
42 |
|
---|
43 | r1_texture_handle material_ref;
|
---|
44 | w32 flags;
|
---|
45 |
|
---|
46 | enum
|
---|
47 | {
|
---|
48 | TRANSLUCENCY = 0x1f,
|
---|
49 | TINT = (1<<5),
|
---|
50 | SELECTED = (1<<6),
|
---|
51 | ON = 0xff
|
---|
52 | };
|
---|
53 |
|
---|
54 | void set_flags(w8 mask, w8 value = ON) { flags = (flags&~mask) | (value&mask); }
|
---|
55 | w8 get_flags(w8 mask) const { return flags&mask; }
|
---|
56 |
|
---|
57 | void set(w32 a, w32 b, w32 c, w32 d = 0xffff)
|
---|
58 | //{{{
|
---|
59 | {
|
---|
60 | vertex_ref[0] = (w16)a;
|
---|
61 | vertex_ref[1] = (w16)b;
|
---|
62 | vertex_ref[2] = (w16)c;
|
---|
63 | vertex_ref[3] = (w16)d;
|
---|
64 | }
|
---|
65 | //}}}
|
---|
66 |
|
---|
67 | void set_material(r1_texture_handle _material_ref)
|
---|
68 | //{{{
|
---|
69 | {
|
---|
70 | material_ref=_material_ref;
|
---|
71 | }
|
---|
72 | //}}}
|
---|
73 | };
|
---|
74 |
|
---|
75 | class g1_quad_object_class
|
---|
76 | {
|
---|
77 | public:
|
---|
78 | class animation_class
|
---|
79 | {
|
---|
80 | public:
|
---|
81 | w16 num_frames;
|
---|
82 | g1_vert_class *vertex; // num_vert * num_frame entries
|
---|
83 | };
|
---|
84 | w16 num_vertex;
|
---|
85 |
|
---|
86 | g1_quad_class *quad;
|
---|
87 | w16 num_quad;
|
---|
88 |
|
---|
89 | animation_class *animation;
|
---|
90 | w16 num_animations;
|
---|
91 |
|
---|
92 | w32 *mount_id;
|
---|
93 | i4_3d_vector *mount;
|
---|
94 | w16 num_mounts;
|
---|
95 |
|
---|
96 | g1_texture_animation *special;
|
---|
97 | w16 num_special;
|
---|
98 |
|
---|
99 | i4_bool get_mount_point(char *name, i4_3d_vector& vect) const;
|
---|
100 |
|
---|
101 | g1_vert_class *get_verts(int anim, int frame)
|
---|
102 | //{{{
|
---|
103 | {
|
---|
104 | return animation[anim].vertex + num_vertex * frame;
|
---|
105 | }
|
---|
106 | //}}}
|
---|
107 |
|
---|
108 | i4_float extent;
|
---|
109 |
|
---|
110 | void scale(i4_float value);
|
---|
111 | void translate(i4_float xadd, i4_float yadd, i4_float zadd);
|
---|
112 |
|
---|
113 | void calc_extents(void);
|
---|
114 |
|
---|
115 | void init() { num_vertex=0; num_quad=0; num_mounts=0; num_animations=0; num_special=0; }
|
---|
116 | ~g1_quad_object_class() {}
|
---|
117 |
|
---|
118 | i4_bool intersect(const i4_3d_vector &point,
|
---|
119 | const i4_3d_vector &ray,
|
---|
120 | int anim, int frame,
|
---|
121 | i4_float *t=0,
|
---|
122 | int *poly_hit=0,
|
---|
123 | i4_3d_vector *normal_hit=0);
|
---|
124 |
|
---|
125 | void update(i4_float frame);
|
---|
126 | };
|
---|
127 |
|
---|
128 | class i4_loader_class;
|
---|
129 | class g1_base_object_loader_class
|
---|
130 | {
|
---|
131 | public:
|
---|
132 | g1_quad_object_class *obj;
|
---|
133 |
|
---|
134 | virtual g1_quad_object_class *allocate_object() = 0;
|
---|
135 |
|
---|
136 | virtual void set_num_vertex(w16 num_vertex) = 0;
|
---|
137 |
|
---|
138 | virtual void set_num_animations(w16 anims) = 0;
|
---|
139 | virtual void create_animation(w16 anim, const i4_const_str &name, w16 frames) = 0;
|
---|
140 |
|
---|
141 | virtual void create_vertex(w16 anim, w16 frame, w16 index, const i4_3d_vector& v) = 0;
|
---|
142 | virtual void store_vertex_normal(w16 anim, w16 frame, w16 index, const i4_3d_vector& normal) {}
|
---|
143 |
|
---|
144 | virtual void set_num_quads(w16 num_quads) = 0;
|
---|
145 | virtual void create_quad(w16 quad, int verts, w16 *ref, w32 flags) = 0;
|
---|
146 | virtual void store_texture_name(w32 quad, const i4_const_str &name) {}
|
---|
147 | virtual void store_texture_params(w32 quad, i4_float scale, i4_float *u, i4_float *v) {}
|
---|
148 | virtual void store_quad_normal(w16 quad, const i4_3d_vector& v) {}
|
---|
149 |
|
---|
150 | virtual void set_num_mount_points(w16 num_mounts) {}
|
---|
151 | virtual void create_mount_point(w32 index, const i4_const_str &name, const i4_3d_vector &off) {}
|
---|
152 |
|
---|
153 | virtual void set_num_texture_animations(w16 num_textures) {}
|
---|
154 | virtual void create_texture_animation(w32 index, w16 quad, w8 max_frames, w8 frames_x,
|
---|
155 | i4_float du, i4_float dv, i4_float speed) {}
|
---|
156 | virtual void create_texture_pan(w32 index, w16 quad,
|
---|
157 | i4_float du, i4_float dv, i4_float speed) {}
|
---|
158 |
|
---|
159 | virtual void finish_object() {}
|
---|
160 |
|
---|
161 | virtual g1_quad_object_class *load(i4_loader_class *fp);
|
---|
162 | };
|
---|
163 |
|
---|
164 | #endif
|
---|
165 |
|
---|
166 | //{{{ Emacs Locals
|
---|
167 | // Local Variables:
|
---|
168 | // folded-file: t
|
---|
169 | // End:
|
---|
170 | //}}}
|
---|