flare.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "draw_context.hh"
  9. #include "r1_clip.hh"
  10. #include "math/transform.hh"
  11. #include "objs/sprite.hh"
  12. #include "g1_render.hh"
  13. #include "r1_api.hh"
  14. void g1_draw_flare(i4_3d_point_class world_pos,
  15. g1_draw_context_class *context,
  16. float flare_scale,
  17. int type)
  18. {
  19. i4_3d_vector screen_pos;
  20. context->transform->transform(world_pos, screen_pos);
  21. if (screen_pos.z > r1_near_clip_z)
  22. {
  23. float center_x=g1_render.center_x, center_y=g1_render.center_y;
  24. i4_float ooz = r1_ooz(screen_pos.z);
  25. i4_float xs = center_x * ooz * g1_render.scale_x;
  26. i4_float ys = center_y * ooz * g1_render.scale_y;
  27. float theta=atan2(screen_pos.y, screen_pos.x);
  28. float dist = sqrt(screen_pos.y*screen_pos.y + screen_pos.x*screen_pos.x);
  29. g1_render.r_api->set_filter_mode(R1_BILINEAR_FILTERING);
  30. //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR);
  31. float dists[5]={dist, 0.0, -0.3*dist, -0.7*dist, -1*dist };
  32. int sprite_types[5]={0, 1,1,1,1};
  33. float sprite_scales[5]={ 1.0, 0.3, 0.8, 0.5, 1.0};
  34. float cos_theta=cos(theta);
  35. float sin_theta=sin(theta);
  36. for (int i=0; i<5; i++)
  37. {
  38. float cx=center_x + cos_theta * dists[i] * xs;
  39. float cy=center_y + sin_theta * dists[i] * ys;
  40. g1_sprite_class *sprite=g1_sprite_list_man.get_sprite(sprite_types[i]);
  41. float w=sprite->texture_scale * sprite_scales[i] * center_x * 2 * flare_scale;
  42. r1_clip_render_textured_rect(i4_f_to_i(cx-w/2), i4_f_to_i(cy-w/2),
  43. i4_f_to_i(cx+w/2), i4_f_to_i(cy+w/2), r1_near_clip_z, 1,
  44. i4_f_to_i(center_x*2), i4_f_to_i(center_y*2),
  45. sprite->texture,
  46. 0,
  47. g1_render.r_api);
  48. }
  49. //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR | R1_WRITE_W);
  50. g1_render.r_api->set_filter_mode(R1_NO_FILTERING);
  51. }
  52. }
  53. void g1_draw_exhaust(i4_3d_point_class world_pos,
  54. g1_draw_context_class *context,
  55. float flare_scale,
  56. int type, float alpha)
  57. {
  58. i4_3d_vector screen_pos;
  59. context->transform->transform(world_pos, screen_pos);
  60. if (screen_pos.z > r1_near_clip_z)
  61. {
  62. float center_x=g1_render.center_x, center_y=g1_render.center_y;
  63. i4_float ooz = r1_ooz(screen_pos.z);
  64. g1_render.r_api->set_filter_mode(R1_BILINEAR_FILTERING);
  65. //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR);
  66. float cx=center_x + screen_pos.x * center_x * ooz * g1_render.scale_x;
  67. float cy=center_y + screen_pos.y * center_x * ooz * g1_render.scale_x;
  68. g1_sprite_class *sprite=g1_sprite_list_man.get_sprite(0);
  69. float w=sprite->texture_scale * center_x * 2 * flare_scale;
  70. r1_clip_render_textured_rect(i4_f_to_i(cx-w/2), i4_f_to_i(cy-w/2),
  71. i4_f_to_i(cx+w/2), i4_f_to_i(cy+w/2), screen_pos.z, alpha,
  72. i4_f_to_i(center_x*2), i4_f_to_i(center_y*2),
  73. sprite->texture,
  74. 0,
  75. g1_render.r_api);
  76. //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR | R1_WRITE_W);
  77. g1_render.r_api->set_filter_mode(R1_NO_FILTERING);
  78. }
  79. }