source: golgotha/src/golg/flare.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.9 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 "draw_context.hh"
10#include "r1_clip.hh"
11#include "math/transform.hh"
12#include "objs/sprite.hh"
13#include "g1_render.hh"
14#include "r1_api.hh"
15
16
17void g1_draw_flare(i4_3d_point_class world_pos,
18                   g1_draw_context_class *context,
19                   float flare_scale,
20                   int type)
21{
22  i4_3d_vector screen_pos;
23  context->transform->transform(world_pos, screen_pos);
24
25 
26  if (screen_pos.z > r1_near_clip_z)         
27  {
28    float center_x=g1_render.center_x, center_y=g1_render.center_y;
29    i4_float ooz = r1_ooz(screen_pos.z);                   
30    i4_float xs = center_x * ooz * g1_render.scale_x;
31    i4_float ys = center_y * ooz * g1_render.scale_y;       
32
33
34    float theta=atan2(screen_pos.y, screen_pos.x);   
35    float dist = sqrt(screen_pos.y*screen_pos.y + screen_pos.x*screen_pos.x);
36
37
38    g1_render.r_api->set_filter_mode(R1_BILINEAR_FILTERING);
39    //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR);
40
41
42    float dists[5]={dist, 0.0, -0.3*dist, -0.7*dist, -1*dist };
43    int sprite_types[5]={0, 1,1,1,1};
44    float sprite_scales[5]={ 1.0, 0.3, 0.8, 0.5, 1.0};
45
46    float cos_theta=cos(theta);
47    float sin_theta=sin(theta);
48
49    for (int i=0; i<5; i++)
50    {
51      float cx=center_x + cos_theta * dists[i] * xs;
52      float cy=center_y + sin_theta * dists[i] * ys;
53
54      g1_sprite_class *sprite=g1_sprite_list_man.get_sprite(sprite_types[i]);
55      float w=sprite->texture_scale * sprite_scales[i] * center_x * 2 * flare_scale;
56
57      r1_clip_render_textured_rect(i4_f_to_i(cx-w/2), i4_f_to_i(cy-w/2),
58                                   i4_f_to_i(cx+w/2), i4_f_to_i(cy+w/2), r1_near_clip_z, 1,
59                                   i4_f_to_i(center_x*2), i4_f_to_i(center_y*2),
60                                   sprite->texture,
61                                   0,
62                                   g1_render.r_api);
63    }
64
65    //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR | R1_WRITE_W);
66    g1_render.r_api->set_filter_mode(R1_NO_FILTERING);
67
68  }
69}
70
71
72
73void g1_draw_exhaust(i4_3d_point_class world_pos,
74                     g1_draw_context_class *context,
75                     float flare_scale,
76                     int type, float alpha)
77{
78  i4_3d_vector screen_pos;
79  context->transform->transform(world_pos, screen_pos);
80
81 
82  if (screen_pos.z > r1_near_clip_z)         
83  {
84    float center_x=g1_render.center_x, center_y=g1_render.center_y;
85    i4_float ooz = r1_ooz(screen_pos.z);                   
86
87    g1_render.r_api->set_filter_mode(R1_BILINEAR_FILTERING);
88    //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR);
89
90
91    float cx=center_x + screen_pos.x * center_x * ooz * g1_render.scale_x;
92    float cy=center_y + screen_pos.y * center_x * ooz * g1_render.scale_x;
93
94    g1_sprite_class *sprite=g1_sprite_list_man.get_sprite(0);
95    float w=sprite->texture_scale * center_x * 2 * flare_scale;
96
97    r1_clip_render_textured_rect(i4_f_to_i(cx-w/2), i4_f_to_i(cy-w/2),
98                                 i4_f_to_i(cx+w/2), i4_f_to_i(cy+w/2), screen_pos.z, alpha,
99                                 i4_f_to_i(center_x*2), i4_f_to_i(center_y*2),
100                                 sprite->texture,
101                                 0,
102                                 g1_render.r_api);
103
104    //g1_render.r_api->set_write_mode(R1_COMPARE_W | R1_WRITE_COLOR | R1_WRITE_W);
105    g1_render.r_api->set_filter_mode(R1_NO_FILTERING);
106  }
107}
Note: See TracBrowser for help on using the repository browser.