source: golgotha/src/golg/load3d.cc

Last change on this file was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 5.8 KB
Line 
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#include "r1_api.hh"
10#include "tmanage.hh"
11#include "obj3d.hh"
12#include "file/file.hh"
13#include "error/error.hh"
14#include "error/alert.hh"
15#include "load3d.hh"
16#include "math/num_type.hh"
17#include "loaders/dir_load.hh"
18#include "string/str_checksum.hh"
19#include "saver_id.hh"
20
21#define G3DF_VERSION 3
22
23g1_quad_object_class *g1_quad_object_loader_class::allocate_object()
24{
25  g1_quad_object_class *o =(g1_quad_object_class*)heap->malloc(sizeof(g1_quad_object_class),
26                                                               "quad_object");
27
28  if (o) o->init();
29
30  return o;
31}
32
33void g1_quad_object_loader_class::set_num_vertex(w16 num_vertex)
34{
35  obj->num_vertex=num_vertex;
36}
37
38void g1_quad_object_loader_class::set_num_animations(w16 anims)
39{
40  obj->num_animations=anims;
41
42  int size=sizeof(g1_quad_object_class::animation_class) * anims;
43  obj->animation=(g1_quad_object_class::animation_class *)heap->malloc(size, "animation");
44}
45
46void g1_quad_object_loader_class::create_animation(w16 anim, const i4_const_str &name, w16 frames)
47{
48  obj->animation[anim].num_frames=frames;
49  obj->animation[anim].vertex=
50    (g1_vert_class *)heap->malloc(sizeof(g1_vert_class)*frames*obj->num_vertex, "num frames");
51}
52
53void g1_quad_object_loader_class::create_vertex(w16 anim, w16 frame,
54                                                w16 index, const i4_3d_vector& v)
55{
56  g1_vert_class *vert=obj->get_verts(anim,frame)+index;
57  vert->v = v;
58}
59
60void g1_quad_object_loader_class::store_vertex_normal(w16 anim, w16 frame, w16 index,
61                                               const i4_3d_vector& normal)
62{
63  g1_vert_class *vert=obj->get_verts(anim,frame)+index;
64  vert->normal = normal;
65}
66
67void g1_quad_object_loader_class::set_num_quads(w16 quads)
68{
69  obj->num_quad = quads;
70  obj->quad=(g1_quad_class *)heap->malloc(sizeof(g1_quad_class) * quads, "obj_quads");
71}
72
73void g1_quad_object_loader_class::create_quad(w16 quad, int verts, w16 *ref, w32 flags)
74{
75  g1_quad_class *q = &obj->quad[quad];
76
77  q->set(ref[0], ref[1], ref[2], (verts>3)?ref[3]:0xffff);
78  q->flags = flags;
79}
80
81void g1_quad_object_loader_class::store_texture_name(w32 quad, const i4_const_str &name)
82{
83  g1_quad_class *q = &obj->quad[quad];
84
85  if (name.null())
86  {
87    i4_alert(i4gets("no_texture"), 100, error_name);
88    q->material_ref = 0;
89  }
90  else
91    q->material_ref = tman->register_texture(name, *error_name);
92}
93
94void g1_quad_object_loader_class::store_texture_params(w32 quad, i4_float scale,
95                                                       i4_float *u, i4_float *v)
96{
97  g1_quad_class *q = &obj->quad[quad];
98
99  q->texture_scale = scale;
100  q->u[0] = u[0];
101  q->u[1] = u[1];
102  q->u[2] = u[2];
103  q->u[3] = u[3];
104  q->v[0] = v[0];
105  q->v[1] = v[1];
106  q->v[2] = v[2];
107  q->v[3] = v[3];
108}
109
110void g1_quad_object_loader_class::store_quad_normal(w16 quad, const i4_3d_vector& normal)
111{
112  g1_quad_class *q = &obj->quad[quad];
113
114  q->normal = normal;
115}
116
117void g1_quad_object_loader_class::set_num_mount_points(w16 mounts)
118{
119  obj->num_mounts = mounts;
120  obj->mount_id = (w32 *)heap->malloc(sizeof(w32) * mounts, "mount_ids");
121  obj->mount = (i4_3d_vector *)heap->malloc(sizeof(i4_3d_vector) * mounts, "mount_vectors");
122}
123
124void g1_quad_object_loader_class::create_mount_point(w32 index, const i4_const_str &name,
125                                                     const i4_3d_vector &off)
126{
127  obj->mount[index] = off;
128  obj->mount_id[index] = i4_str_checksum(name);
129}
130
131void g1_quad_object_loader_class::set_num_texture_animations(w16 num_textures)
132{
133  obj->num_special = num_textures;
134  obj->special = (g1_texture_animation *)heap
135    ->malloc(sizeof(g1_texture_animation) * num_textures, "texture_animations");
136}
137
138void g1_quad_object_loader_class::create_texture_animation(w32 index, w16 quad,
139                                                           w8 max_frames,
140                                                           w8 frames_x,
141                                                           i4_float du, i4_float dv,
142                                                           i4_float speed)
143{
144  g1_texture_animation *p = &obj->special[index];
145  p->quad_number = quad;
146  p->max_frames = max_frames;
147  p->frames_x = frames_x;
148  p->du = du;
149  p->dv = dv;
150  p->speed = speed;
151
152  g1_quad_class *q = &obj->quad[quad];
153  for (int i=0; i<q->num_verts(); i++)
154  {
155    p->u[i] = q->u[i];
156    p->v[i] = q->v[i];
157  }
158}
159
160void g1_quad_object_loader_class::create_texture_pan(w32 index, w16 quad,
161                        i4_float du, i4_float dv, i4_float speed)
162{
163  g1_texture_animation *p = &obj->special[index];
164  p->quad_number = quad;
165  p->max_frames = 0;
166  p->frames_x = 0;
167  p->du = du;
168  p->dv = dv;
169  p->speed = speed;
170
171  g1_quad_class *q = &obj->quad[quad];
172  for (int i=0; i<q->num_verts(); i++)
173  {
174    p->u[i] = q->u[i];
175    p->v[i] = q->v[i];
176  }
177}
178
179void g1_quad_object_loader_class::finish_object()
180{
181  obj->calc_extents();
182}
183
184g1_quad_object_class *g1_quad_object_loader_class::load(i4_loader_class *fp,
185                                                        const i4_const_str &_error_name,
186                                                        r1_texture_manager_class *_tman)
187{
188  tman = _tman;
189  error_name = &_error_name;
190
191  return g1_base_object_loader_class::load(fp);
192}
Note: See TracBrowser for help on using the repository browser.