Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DriveSprite.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2005. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: DriveSprite.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Sprite for rendering drive flares. Remains visible at extreme ranges.
13 */
14 
15 #include "MemDebug.h"
16 #include "DriveSprite.h"
17 
18 #include "Bitmap.h"
19 #include "Camera.h"
20 #include "Scene.h"
21 #include "Video.h"
22 
23 // +--------------------------------------------------------------------+
24 
26 : Sprite(), glow(0), effective_radius(0), front(0,0,0), bias(0)
27 { luminous = true; }
28 
30 : Sprite(animation), glow(g), effective_radius(0), front(0,0,0), bias(0)
31 { luminous = true; }
32 
33 DriveSprite::DriveSprite(Bitmap* animation, int length, int repeat, int share)
34 : Sprite(animation, length, repeat, share), glow(0), effective_radius(0),
35 front(0,0,0), bias(0)
36 { luminous = true; }
37 
39 { }
40 
41 // +--------------------------------------------------------------------+
42 
43 void
45 {
46  front = f;
47  front.Normalize();
48 }
49 
50 void
52 {
53  bias = b;
54 }
55 
56 // +--------------------------------------------------------------------+
57 
58 void
59 DriveSprite::Render(Video* video, DWORD flags)
60 {
61  if (!video || ((flags & RENDER_ADDITIVE) == 0))
62  return;
63 
64  if (shade > 0 && !hidden && (life > 0 || loop)) {
65  const Camera* cam = video->GetCamera();
66  bool z_disable = false;
67 
68  if (bias)
70 
71  if (front.length()) {
72  Point test = loc;
73 
74  if (scene && cam) {
75  Vec3 dir = front;
76 
77  double intensity = cam->vpn() * dir * -1;
78  double distance = Point(cam->Pos() - test).length();
79 
80  if (intensity > 0.05) {
81  if (!scene->IsLightObscured(cam->Pos(), test, 8)) {
82  video->SetRenderState(Video::Z_ENABLE, false);
83  z_disable = true;
84 
85  if (glow) {
86  intensity = pow(intensity, 3);
87 
88  if (distance > 5e3)
89  intensity *= (1 - (distance-5e3)/45e3);
90 
91  if (intensity > 0) {
92  Bitmap* tmp_frame = frames;
93  double tmp_shade = shade;
94  int tmp_w = w;
95  int tmp_h = h;
96 
97  if (glow->Width() != frames->Width()) {
98  double wscale = glow->Width() / frames->Width();
99  double hscale = glow->Height() / frames->Height();
100 
101  w = (int) (w * wscale);
102  h = (int) (h * hscale);
103  }
104 
105  shade = intensity;
106  frames = glow;
107 
108  Sprite::Render(video, flags);
109 
110  frames = tmp_frame;
111  shade = tmp_shade;
112  w = tmp_w;
113  h = tmp_h;
114  }
115  }
116  }
117  }
118  }
119  }
120 
121  if (effective_radius-radius > 0.1) {
122  double scale_up = effective_radius / radius;
123  int tmp_w = w;
124  int tmp_h = h;
125 
126  w = (int) (w * scale_up);
127  h = (int) (h * scale_up);
128 
129  Sprite::Render(video, flags);
130 
131  w = tmp_w;
132  h = tmp_h;
133  }
134 
135  else {
136  Sprite::Render(video, flags);
137  }
138 
139  if (bias) video->SetRenderState(Video::Z_BIAS, 0);
140  if (z_disable) video->SetRenderState(Video::Z_ENABLE, true);
141  }
142 }
143