source: golgotha/src/golg/objs/smoke_trail.cc

Last change on this file 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: 3.6 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/smoke_trail.hh"
10#include "saver.hh"
11#include "g1_render.hh"
12#include "map.hh"
13#include "map_man.hh"
14#include "object_definer.hh"
15#include "draw_context.hh"
16
17g1_object_definer<g1_smoke_trail_class>
18g1_smoke_trail_def("smoke_trail",
19                   g1_object_definition_class::HAS_ALPHA);
20
21void g1_smoke_trail_class::setup(i4_float start_x, i4_float start_y, i4_float start_h,
22                                 i4_float start_width, i4_float end_width,
23                                 i4_color start_color, i4_color end_color)
24{
25  lx=x=start_x;
26  ly=y=start_y;
27  lh=h=start_h;
28
29  ticks_advanced=0;
30
31  for (int i=0; i<TAIL_LENGTH; i++)
32    tspots[i]=i4_3d_point_class(start_x, start_y, start_h);
33
34  sc=start_color;
35  ec=end_color;
36  sw=start_width;
37  ew=end_width;
38}
39
40g1_smoke_trail_class::g1_smoke_trail_class(g1_object_type id,
41                                           g1_loader_class *fp)
42  : g1_object_class(id, fp)
43{
44  if (fp && fp->check_version(DATA_VERSION))
45  {
46    ticks_advanced=fp->read_16();
47
48    sc=fp->read_32();
49    ec=fp->read_32();
50
51    sw=fp->read_float();
52    ew=fp->read_float();
53
54    int t_spots=fp->read_8();
55    for (int i=0; i<t_spots; i++)
56    {
57      i4_float x,y,z;
58      x=fp->read_float();
59      y=fp->read_float();
60      z=fp->read_float();
61      if (i<TAIL_LENGTH)
62        tspots[i]=i4_3d_point_class(x,y,z);
63    }
64
65    fp->end_version(I4_LF);
66  }
67}
68
69void g1_smoke_trail_class::save(g1_saver_class *fp)
70{
71  g1_object_class::save(fp);
72
73  fp->start_version(DATA_VERSION);
74
75  fp->write_16(ticks_advanced);
76
77  fp->write_32(sc);
78  fp->write_32(ec);
79
80  fp->write_float(sw);
81  fp->write_float(ew);
82
83  fp->write_8(TAIL_LENGTH);
84  for (int i=0; i<TAIL_LENGTH; i++)
85  {
86    fp->write_float(tspots[i].x);
87    fp->write_float(tspots[i].y);
88    fp->write_float(tspots[i].y);
89  }
90
91  fp->end_version();
92}
93
94
95void g1_smoke_trail_class::update_head(i4_float nx, i4_float ny, i4_float nh)
96{
97  sw32 ix=(sw32)nx,iy=(sw32)ny;
98
99  if (ix>=0 && ix<g1_get_map()->width() && iy>=0 && iy<g1_get_map()->height())
100  {
101    unoccupy_location();
102
103    if (ticks_advanced<=TAIL_LENGTH)
104      ticks_advanced++;
105
106    for (int i=TAIL_LENGTH-1; i>0; i--)
107      tspots[i]=tspots[i-1];
108
109    tspots[0]=i4_3d_point_class(lx,ly,lh);
110
111    lx=x; ly=y; lh=h;
112
113    x=nx; y=ny; h=nh;
114 
115    occupy_location();
116  }
117}
118
119void g1_smoke_trail_class::draw(g1_draw_context_class *context)
120{
121  //w32 cur_frame=context->tmap->get_frame_counter();
122
123  i4_float fr=g1_render.frame_ratio;
124
125  i4_3d_point_class s[TAIL_LENGTH+1];
126  s[0].x=(x-lx)*fr + lx;     s[0].y=(y-ly)*fr + ly;      s[0].z=(h-lh)*fr + lh;
127
128  s[1].x=(lx-tspots[0].x)*fr + tspots[0].x;
129  s[1].y=(ly-tspots[0].y)*fr + tspots[0].y;
130  s[1].z=(lh-tspots[0].z)*fr + tspots[0].z;
131
132
133  for (int i=0; i<TAIL_LENGTH-1; i++)
134  {
135    s[i+2].x=(tspots[i].x-tspots[i+1].x)*fr + tspots[i+1].x;
136    s[i+2].y=(tspots[i].y-tspots[i+1].y)*fr + tspots[i+1].y;
137    s[i+2].z=(tspots[i].z-tspots[i+1].z)*fr + tspots[i+1].z;
138  }
139 
140  g1_render.add_translucent_trail(context->transform, s, ticks_advanced, sw, ew, 1, 0, sc, ec);
141
142}
143
144void g1_smoke_trail_class::think()
145{
146}
147
Note: See TracBrowser for help on using the repository browser.