smoke_trail.cc 3.6 KB

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