Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
QuantumFlash.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: QuantumFlash.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Quantum Warp Out special effect class
13 */
14 
15 #include "MemDebug.h"
16 #include "QuantumFlash.h"
17 
18 #include "Light.h"
19 #include "Bitmap.h"
20 #include "DataLoader.h"
21 #include "Game.h"
22 #include "Random.h"
23 #include "Scene.h"
24 
25 // +--------------------------------------------------------------------+
26 
27 static Bitmap* quantum_flash_texture = 0;
28 
29 // +--------------------------------------------------------------------+
30 
32 : nverts(64), npolys(16), mtl(0), verts(0), polys(0), beams(0),
33 texture(quantum_flash_texture), length(8000), width(0),
34 shade(1.0)
35 {
36  trans = true;
37  luminous = true;
38 
39  if (!texture || texture->Width() < 1) {
41  loader->SetDataPath("Explosions/");
42  loader->LoadTexture("quantum.pcx", quantum_flash_texture, Bitmap::BMP_TRANSLUCENT);
43  loader->SetDataPath(0);
44  texture = quantum_flash_texture;
45  }
46 
47  loc = Vec3(0.0f, 0.0f, 1000.0f);
48 
49  mtl = new(__FILE__,__LINE__) Material;
50  verts = new(__FILE__,__LINE__) VertexSet(nverts);
51  polys = new(__FILE__,__LINE__) Poly[npolys];
52  beams = new(__FILE__,__LINE__) Matrix[npolys];
53 
54  mtl->Kd = Color::White;
58  mtl->luminous = true;
59 
60  verts->nverts = nverts;
61 
62  for (int i = 0; i < npolys; i++) {
63  verts->loc[4*i+0] = Point( width, 0, 1000);
64  verts->loc[4*i+1] = Point( width, -length, 1000);
65  verts->loc[4*i+2] = Point(-width, -length, 1000);
66  verts->loc[4*i+3] = Point(-width, 0, 1000);
67 
68  for (int n = 0; n < 4; n++) {
69  verts->diffuse[4*i+n] = D3DCOLOR_RGBA(255,255,255,255);
70  verts->specular[4*i+n] = D3DCOLOR_RGBA( 0, 0, 0,255);
71  verts->tu[4*i+n] = (n < 2) ? 0.0f : 1.0f;
72  verts->tv[4*i+n] = (n > 0 && n < 3) ? 1.0f : 0.0f;
73  }
74 
75  beams[i].Roll( Random(-2*PI, 2*PI));
76  beams[i].Pitch(Random(-2*PI, 2*PI));
77  beams[i].Yaw( Random(-2*PI, 2*PI));
78 
79  polys[i].nverts = 4;
80  polys[i].visible = 1;
81  polys[i].sortval = 0;
82  polys[i].vertex_set = verts;
83  polys[i].material = mtl;
84 
85  polys[i].verts[0] = 4*i+0;
86  polys[i].verts[1] = 4*i+1;
87  polys[i].verts[2] = 4*i+2;
88  polys[i].verts[3] = 4*i+3;
89  }
90 
91  radius = (float) length;
92  length = 0;
93  strcpy_s(name, "QuantumFlash");
94 }
95 
96 // +--------------------------------------------------------------------+
97 
99 {
100  delete mtl;
101  delete verts;
102  delete [] polys;
103  delete [] beams;
104 }
105 
106 // +--------------------------------------------------------------------+
107 
108 void
109 QuantumFlash::Render(Video* video, DWORD flags)
110 {
111  if (hidden || !visible || !video || ((flags & RENDER_ADDITIVE) == 0))
112  return;
113 
114  const Camera* cam = video->GetCamera();
115 
116  if (cam) {
117  UpdateVerts(cam->Pos());
118  video->DrawPolys(npolys, polys);
119  }
120 }
121 
122 // +--------------------------------------------------------------------+
123 
124 void
126 {
127  if (length < radius) {
128  length += radius/80;
129  width += 1;
130  }
131 
132  for (int i = 0; i < npolys; i++) {
133  Matrix& m = beams[i];
134 
135  m.Yaw(0.05);
136  Point vpn = Point(m(2,0), m(2,1), m(2,2));
137 
138  Point head = loc;
139  Point tail = loc - vpn * length;
140  Point vtail = tail - head;
141  Point vcam = cam_pos - loc;
142  Point vtmp = vcam.cross(vtail);
143  vtmp.Normalize();
144  Point vlat = vtmp * -width;
145 
146  verts->loc[4*i+0] = head + vlat;
147  verts->loc[4*i+1] = tail + vlat * 8;
148  verts->loc[4*i+2] = tail - vlat * 8;
149  verts->loc[4*i+3] = head - vlat;
150 
151  DWORD color = D3DCOLOR_RGBA((BYTE) (255*shade), (BYTE) (255*shade), (BYTE) (255*shade), 255);
152 
153  for (int n = 0; n < 4; n++) {
154  verts->diffuse[4*i+n] = color;
155  }
156  }
157 }
158 
159 // +--------------------------------------------------------------------+
160 
161 void
163 {
164  orientation = o;
165 }
166 
167 void
169 {
170  if (s < 0) s = 0;
171  else if (s > 1) s = 1;
172 
173  shade = s;
174 }
175