Starshatter_Open
Open source Starshatter engine
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Graphic.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: Graphic.cpp
7
AUTHOR: John DiCamillo
8
9
10
OVERVIEW
11
========
12
Abstract 3D Graphic Object
13
*/
14
15
#include "
MemDebug.h
"
16
#include "
Graphic.h
"
17
#include "
Scene.h
"
18
#include "
Projector.h
"
19
20
// +--------------------------------------------------------------------+
21
22
int
Graphic::id_key
= 1;
23
24
// +--------------------------------------------------------------------+
25
26
Graphic::Graphic
()
27
: id(id_key++), visible(true), loc(0.0f, 0.0f, 0.0f),
28
radius(0.0f), infinite(0), foreground(0), hidden(0), life(-1),
29
trans(false), shadow(false), luminous(false), depth(0.0f), scene(0)
30
{
31
screen_rect
.
x
= 0;
32
screen_rect
.
y
= 0;
33
screen_rect
.
w
= 0;
34
screen_rect
.
h
= 0;
35
36
ZeroMemory(
name
,
sizeof
(
name
));
37
strcpy_s(
name
,
"Graphic"
);
38
}
39
40
// +--------------------------------------------------------------------+
41
42
Graphic::~Graphic
()
43
{ }
44
45
int
46
Graphic::operator <
(
const
Graphic
& g)
const
47
{
48
if
(!
infinite
&& g.
infinite
)
49
return
1;
50
51
else
if
(
infinite
&& !g.
infinite
)
52
return
0;
53
54
double
za = fabs(
Depth
());
55
double
zb = fabs(g.
Depth
());
56
57
return
(za < zb);
58
}
59
60
int
61
Graphic::operator <=
(
const
Graphic
& g)
const
62
{
63
if
(!
infinite
&& g.
infinite
)
64
return
1;
65
66
else
if
(
infinite
&& !g.
infinite
)
67
return
0;
68
69
double
za = fabs(
Depth
());
70
double
zb = fabs(g.
Depth
());
71
72
return
(za <= zb);
73
}
74
75
// +--------------------------------------------------------------------+
76
77
void
78
Graphic::SetInfinite
(
bool
b)
79
{
80
infinite
= (BYTE) b;
81
82
if
(
infinite
)
83
depth
= 1.0e9f;
84
}
85
86
// +--------------------------------------------------------------------+
87
88
int
89
Graphic::Nearer
(
Graphic
* a,
Graphic
* b)
90
{
91
if
(a->
depth
< b->
depth
)
return
-1;
92
else
if
(a->
depth
== b->
depth
)
return
0;
93
else
return
1;
94
}
95
96
// +--------------------------------------------------------------------+
97
98
int
99
Graphic::Farther
(
Graphic
* a,
Graphic
* b)
100
{
101
if
(a->
depth
> b->
depth
)
return
-1;
102
else
if
(a->
depth
== b->
depth
)
return
0;
103
else
return
1;
104
}
105
106
// +--------------------------------------------------------------------+
107
108
void
109
Graphic::Destroy
()
110
{
111
if
(
scene
)
112
scene
->
DelGraphic
(
this
);
113
114
delete
this
;
115
}
116
117
// +--------------------------------------------------------------------+
118
119
int
120
Graphic::CollidesWith
(
Graphic
& o)
121
{
122
Point
delta_loc =
loc
- o.
loc
;
123
124
// bounding spheres test:
125
if
(delta_loc.
length
() >
radius
+ o.
radius
)
126
return
0;
127
128
return
1;
129
}
130
131
// +--------------------------------------------------------------------+
132
133
int
134
Graphic::CheckRayIntersection
(
Point
Q,
Point
w,
double
len,
Point
& ipt,
135
bool
treat_translucent_polys_as_solid)
136
{
137
return
0;
138
}
139
140
// +--------------------------------------------------------------------+
141
142
void
143
Graphic::ProjectScreenRect
(
Projector
* p)
144
{
145
screen_rect
.
x
= 2000;
146
screen_rect
.
y
= 2000;
147
screen_rect
.
w
= 0;
148
screen_rect
.
h
= 0;
149
}
150
151
// +--------------------------------------------------------------------+
152
153
bool
154
Graphic::CheckVisibility
(
Projector
& projector)
155
{
156
if
(projector.
IsVisible
(
Location
(),
Radius
()) &&
157
projector.
ApparentRadius
(
Location
(),
Radius
()) > 1) {
158
159
visible
=
true
;
160
}
161
else
{
162
visible
=
false
;
163
screen_rect
.
x
= 2000;
164
screen_rect
.
y
= 2000;
165
screen_rect
.
w
= 0;
166
screen_rect
.
h
= 0;
167
}
168
169
return
visible
;
170
}
nGenEx
Graphic.cpp
Generated on Tue Jun 5 2012 20:46:23 for Starshatter_Open by
1.8.1