source: golgotha/src/golg/objs/model_draw.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 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: 7.3 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 "objs/model_draw.hh"
10#include "math/transform.hh"
11#include "g1_object.hh"
12#include "draw_context.hh"
13#include "objs/model_id.hh"
14#include "math/pi.hh"
15#include "math/angle.hh"
16#include "g1_render.hh"
17#include "g1_texture_id.hh"
18#include "r1_api.hh"
19#include "r1_clip.hh"
20#include "objs/map_piece.hh"
21#include "resources.hh"
22#include "lisp/lisp.hh"
23#include "map_man.hh"
24#include "map.hh"
25#include "tick_count.hh"
26#include "controller.hh"
27
28void g1_model_draw_parameters::setup(g1_quad_object_class *_model,
29                                     g1_quad_object_class *_shadow_model,
30                                     g1_quad_object_class *_lod_model)
31{
32  model=_model;
33  shadow_model=_shadow_model;
34  lod_model=_lod_model;
35}
36
37
38float g1_model_draw_parameters::extent() const    // gets extents of model_id from model_draw
39{
40  if (model)
41    return model->extent;
42  else
43    return 0;
44}
45
46void g1_model_draw_parameters::setup(w16 _model_id, w16 _shadow_model, w16 _lod_model)
47{
48  model=g1_model_list_man.get_model(_model_id);
49 
50  if (shadow_model)
51    shadow_model=g1_model_list_man.get_model(_model_id);
52  else
53    shadow_model=0;
54
55  if (_lod_model)
56    lod_model=g1_model_list_man.get_model(_lod_model);
57  else
58    lod_model=0;
59}
60
61void g1_model_draw_parameters::setup(const char *model_name, char *shadow_model_name,
62                                     char *lod_model_name)
63{
64  int id=g1_model_list_man.find_handle(model_name);
65  model = g1_model_list_man.get_model(id);
66   
67  if (shadow_model_name)
68  {
69    id=g1_model_list_man.find_handle(shadow_model_name);
70    if (id)
71      shadow_model = g1_model_list_man.get_model(id);
72    else
73      shadow_model = 0;
74  }
75  else
76    shadow_model = 0;
77
78  if (lod_model_name)
79  {
80    id=g1_model_list_man.find_handle(lod_model_name);
81    if (id)
82      lod_model = g1_model_list_man.get_model(id);
83    else
84      lod_model = 0;
85  }
86  else lod_model=0;
87
88}
89
90static li_symbol_ref team_icons("team_icons");
91
92void g1_model_draw(g1_object_class *_this,
93                   g1_model_draw_parameters &params,
94                   g1_draw_context_class *context)
95
96  i4_3d_vector cpos;
97
98  if (!g1_current_controller.get())
99    return;
100
101  g1_current_controller->get_pos(cpos);
102
103  float dist_sqrd=(cpos.x-_this->x)*(cpos.x-_this->x)+
104    (cpos.y-_this->y)*(cpos.y-_this->y)+
105    (cpos.z-_this->h)*(cpos.z-_this->h);
106
107
108  if (dist_sqrd>g1_resources.lod_disappear_dist)
109    return ;
110
111  if (dist_sqrd>g1_resources.lod_switch_dist && !params.lod_model)
112    return ;
113
114  g1_screen_box *bbox=0;
115 
116  i4_transform_class view_transform;
117
118  i4_transform_class *old = context->transform;
119  context->transform = &view_transform;
120 
121  view_transform.multiply(*old,*(_this->world_transform));
122   
123  if (_this->get_flag(g1_object_class::SELECTABLE | g1_object_class::TARGETABLE))
124  {
125    if (g1_render.current_selectable_list)
126      bbox=g1_render.current_selectable_list->add();
127    if (bbox)
128    {
129      bbox->x1 = 2048;
130      bbox->y1 = 2048;
131      bbox->x2 = -1;
132      bbox->y2 = -1;
133      bbox->z1 = 999999;
134      bbox->z2 = -999999;
135      bbox->w  = 1.0/999999;
136      bbox->object_id = _this->global_id;
137    }
138  }
139
140  int max_health=_this->get_type()->defaults->health;
141  int damage_level;
142 
143  if (_this->health >= max_health)
144    damage_level = 7;
145  else
146    if (_this->health < 0)
147      damage_level = 0;
148    else
149      damage_level = i4_f_to_i(7.f * _this->health / (float)max_health);
150   
151  g1_render.set_render_damage_level(damage_level);
152
153
154  if (dist_sqrd<g1_resources.lod_switch_dist)
155  {
156    if (params.shadow_model)
157    {
158      g1_quad_object_class *model = params.shadow_model;
159   
160      g1_render.r_api->disable_texture();
161      g1_render.r_api->set_shading_mode(R1_CONSTANT_SHADING);
162      g1_render.r_api->set_alpha_mode(R1_ALPHA_CONSTANT);
163      g1_render.r_api->set_constant_color(0x7F000000);
164      g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR);
165
166      i4_transform_class t=*(_this->world_transform), shadow_view_transform;
167      // drop shadow to ground   
168      t.t.z=g1_get_map()->map_height(_this->x, _this->y, _this->h);
169
170      shadow_view_transform.multiply(*old,t);
171     
172     
173      g1_render.render_object_polys(model,
174                                    &shadow_view_transform,
175                                    params.frame);
176
177      g1_render.r_api->set_shading_mode(R1_COLORED_SHADING);
178      g1_render.r_api->set_alpha_mode(R1_ALPHA_DISABLED);
179      g1_render.r_api->set_write_mode(R1_WRITE_W | R1_COMPARE_W | R1_WRITE_COLOR);
180    }
181
182    g1_quad_object_class *model = params.model;
183    if (model)
184    {
185      if (!(params.flags & g1_model_draw_parameters::SUPPRESS_SPECIALS) && model->num_special>0)
186        model->update(i4_float(g1_tick_counter + _this->global_id) + g1_render.frame_ratio);
187
188      g1_render.render_object(model,
189                              &view_transform,                         
190                              params.flags & g1_model_draw_parameters::NO_LIGHTING ?
191                              0 : _this->world_transform,
192                              1,                   
193                              _this->player_num,
194                              params.frame,
195                              bbox,
196                              0);
197
198      for (int i=0;i<_this->num_mini_objects;i++)
199      {
200        _this->mini_objects[i].draw(context,
201                                    _this->world_transform,
202                                    bbox,
203                                    _this->player_num);     
204      }
205    }
206  }
207  else
208  {
209    g1_render.r_api->set_filter_mode(R1_NO_FILTERING);
210
211    g1_render.render_object(params.lod_model,
212                            &view_transform,                         
213                            params.flags & g1_model_draw_parameters::NO_LIGHTING ?
214                            0 : _this->world_transform,
215                            1,                   
216                            _this->player_num,
217                            params.frame,
218                            bbox,
219                            0);
220
221    for (int i=0;i<_this->num_mini_objects;i++)
222    {
223      _this->mini_objects[i].draw(context,
224                                  _this->world_transform,
225                                  bbox,
226                                  _this->player_num,
227                                  0, i4_T, i4_T);
228    }
229
230    g1_render.r_api->set_filter_mode(R1_BILINEAR_FILTERING);
231
232  }
233
234  g1_render.set_render_damage_level(-1);
235
236  context->transform = old;
237}
238
239void g1_editor_model_draw(g1_object_class *_this,
240                          g1_model_draw_parameters &params,
241                          g1_draw_context_class *context)
242{
243  if (context->draw_editor_stuff)
244    g1_model_draw(_this, params, context);
245}
246
247
248
249
Note: See TracBrowser for help on using the repository browser.