Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Bolt.cpp
Go to the documentation of this file.
1
/* Project nGenEx
2
Destroyer Studios LLC
3
Copyright © 1997-2004. All Rights Reserved.
4
5
SUBSYSTEM: nGenEx.lib
6
FILE: Bolt.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
3D Bolt (Polygon) Object
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
Bolt.h
"
17
#include "
Bitmap.h
"
18
#include "
Camera.h
"
19
#include "
Video.h
"
20
21
void
Print
(
const
char
* fmt, ...);
22
23
// +--------------------------------------------------------------------+
24
25
Bolt::Bolt
(
double
len,
double
wid,
Bitmap
* tex,
int
share)
26
: vset(4), poly(0), texture(tex),
27
length(len), width(wid), shade(1.0), vpn(0, 1, 0), shared(share)
28
{
29
trans
=
true
;
30
31
loc
=
Vec3
(0.0f, 0.0f, 1000.0f);
32
33
vset
.
nverts
= 4;
34
35
vset
.
loc
[0] =
Point
(
width
, 0, 1000);
36
vset
.
loc
[1] =
Point
(
width
, -
length
, 1000);
37
vset
.
loc
[2] =
Point
(-
width
, -
length
, 1000);
38
vset
.
loc
[3] =
Point
(-
width
, 0, 1000);
39
40
vset
.
tu
[0] = 0.0f;
41
vset
.
tv
[0] = 0.0f;
42
vset
.
tu
[1] = 1.0f;
43
vset
.
tv
[1] = 0.0f;
44
vset
.
tu
[2] = 1.0f;
45
vset
.
tv
[2] = 1.0f;
46
vset
.
tu
[3] = 0.0f;
47
vset
.
tv
[3] = 1.0f;
48
49
Plane
plane(
vset
.
loc
[0],
vset
.
loc
[1],
vset
.
loc
[2]);
50
51
for
(
int
i = 0; i < 4; i++) {
52
vset
.
nrm
[i] = plane.
normal
;
53
}
54
55
mtl
.
Ka
=
Color::White
;
56
mtl
.
Kd
=
Color::White
;
57
mtl
.
Ks
=
Color::Black
;
58
mtl
.
Ke
=
Color::White
;
59
mtl
.
tex_diffuse
=
texture
;
60
mtl
.
tex_emissive
=
texture
;
61
mtl
.
blend
=
Video::BLEND_ADDITIVE
;
62
63
poly
.
nverts
= 4;
64
poly
.
vertex_set
= &
vset
;
65
poly
.
material
= &
mtl
;
66
poly
.
verts
[0] = 0;
67
poly
.
verts
[1] = 1;
68
poly
.
verts
[2] = 2;
69
poly
.
verts
[3] = 3;
70
71
radius
= (float) ((
length
>
width
) ? (
length
) : (
width
*2));
72
73
if
(
texture
) {
74
strncpy_s(
name
,
texture
->
GetFilename
(), 31);
75
name
[31] = 0;
76
}
77
}
78
79
// +--------------------------------------------------------------------+
80
81
Bolt::~Bolt
()
82
{
83
}
84
85
// +--------------------------------------------------------------------+
86
87
void
88
Bolt::Render
(
Video
* video, DWORD flags)
89
{
90
if
((flags &
RENDER_ADDITIVE
) == 0)
91
return
;
92
93
if
(
visible
&& !
hidden
&& video &&
life
) {
94
const
Camera
* camera = video->
GetCamera
();
95
96
Point
head =
loc
;
97
Point
tail =
origin
;
98
Point
vtail = tail - head;
99
Point
vcam = camera->
Pos
() -
loc
;
100
Point
vtmp = vcam.
cross
(vtail);
101
vtmp.
Normalize
();
102
Point
vlat = vtmp * -
width
;
103
Vec3
vnrm = camera->
vpn
() * -1;
104
105
vset
.
loc
[0] = head + vlat;
106
vset
.
loc
[1] = tail + vlat;
107
vset
.
loc
[2] = tail - vlat;
108
vset
.
loc
[3] = head - vlat;
109
110
vset
.
nrm
[0] = vnrm;
111
vset
.
nrm
[1] = vnrm;
112
vset
.
nrm
[2] = vnrm;
113
vset
.
nrm
[3] = vnrm;
114
115
ColorValue
white((
float
)
shade
, (
float
) shade, (
float
) shade);
116
mtl
.
Ka
= white;
117
mtl
.
Kd
= white;
118
mtl
.
Ks
=
Color::Black
;
119
mtl
.
Ke
= white;
120
121
video->
DrawPolys
(1, &
poly
);
122
}
123
}
124
125
// +--------------------------------------------------------------------+
126
127
void
128
Bolt::Update
()
129
{
130
}
131
132
// +--------------------------------------------------------------------+
133
134
void
135
Bolt::TranslateBy
(
const
Point
& ref)
136
{
137
loc
=
loc
- ref;
138
origin
=
origin
- ref;
139
}
140
141
// +--------------------------------------------------------------------+
142
143
void
144
Bolt::SetOrientation
(
const
Matrix
& o)
145
{
146
vpn
=
Point
(o(2,0), o(2,1), o(2,2));
147
origin
=
loc
+ (
vpn
* -
length
);
148
}
149
150
void
151
Bolt::SetDirection
(
const
Point
& v)
152
{
153
vpn
= v;
154
origin
=
loc
+ (
vpn
* -
length
);
155
}
156
157
void
158
Bolt::SetEndPoints
(
const
Point
& from,
const
Point
& to)
159
{
160
loc
= to;
161
origin
= from;
162
vpn
= to - from;
163
length
=
vpn
.
Normalize
();
164
radius
= (float)
length
;
165
}
166
167
void
168
Bolt::SetTextureOffset
(
double
from,
double
to)
169
{
170
vset
.
tu
[0] = (float) from;
171
vset
.
tu
[1] = (float) to;
172
vset
.
tu
[2] = (float) to;
173
vset
.
tu
[3] = (float) from;
174
}
175
176
nGenEx
Bolt.cpp
Generated on Tue Jun 5 2012 20:46:19 for Starshatter_Open by
1.8.1