Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
IcePoint.cpp
Go to the documentation of this file.
1
8
11
45
48
// Precompiled Header
49
#include "
Stdafx.h
"
50
51
52
using namespace
Opcode;
53
55
59
Point
&
Point::PositiveUnitRandomVector
()
61
{
62
x
=
UnitRandomFloat
();
63
y
=
UnitRandomFloat
();
64
z
=
UnitRandomFloat
();
65
Normalize
();
66
return
*
this
;
67
}
68
70
74
Point
&
Point::UnitRandomVector
()
76
{
77
x
=
UnitRandomFloat
() - 0.5f;
78
y
=
UnitRandomFloat
() - 0.5f;
79
z
=
UnitRandomFloat
() - 0.5f;
80
Normalize
();
81
return
*
this
;
82
}
83
84
// Cast operator
85
// WARNING: not inlined
86
Point::operator
HPoint
()
const
{
return
HPoint
(
x
,
y
,
z
, 0.0
f
); }
87
88
Point
&
Point::Refract
(
const
Point
&
eye
,
const
Point
& n,
float
refractindex,
Point
& refracted)
89
{
90
// Point EyePt = eye position
91
// Point p = current vertex
92
// Point n = vertex normal
93
// Point rv = refracted vector
94
// Eye vector - doesn't need to be normalized
95
Point
Env;
96
Env.
x
= eye.
x
-
x
;
97
Env.
y
= eye.
y
-
y
;
98
Env.
z
= eye.
z
-
z
;
99
100
float
NDotE = n|Env;
101
float
NDotN = n|n;
102
NDotE /= refractindex;
103
104
// Refracted vector
105
refracted = n*NDotE - Env*NDotN;
106
107
return
*
this
;
108
}
109
110
Point
&
Point::ProjectToPlane
(
const
Plane
& p)
111
{
112
*
this
-= (p.
d
+ (*
this
|p.
n
))*p.
n
;
113
return
*
this
;
114
}
115
116
void
Point::ProjectToScreen
(
float
halfrenderwidth,
float
halfrenderheight,
const
Matrix4x4
& mat,
HPoint
& projected)
const
117
{
118
projected =
HPoint
(
x
,
y
,
z
, 1.0
f
) * mat;
119
projected.
w
= 1.0f / projected.
w
;
120
121
projected.
x
*=projected.
w
;
122
projected.
y
*=projected.
w
;
123
projected.
z
*=projected.
w
;
124
125
projected.
x
*= halfrenderwidth; projected.
x
+= halfrenderwidth;
126
projected.
y
*= -halfrenderheight; projected.
y
+= halfrenderheight;
127
}
128
129
void
Point::SetNotUsed
()
130
{
131
// We use a particular integer pattern : 0xffffffff everywhere. This is a NAN.
132
IR
(
x
) = 0xffffffff;
133
IR
(
y
) = 0xffffffff;
134
IR
(
z
) = 0xffffffff;
135
}
136
137
bool
Point::IsNotUsed
()
const
138
{
139
if
(
IR
(
x
)!=0xffffffff)
return
FALSE
;
140
if
(
IR
(
y
)!=0xffffffff)
return
FALSE
;
141
if
(
IR
(
z
)!=0xffffffff)
return
FALSE
;
142
return
TRUE
;
143
}
144
145
Point
&
Point::Mult
(
const
Matrix3x3
& mat,
const
Point
&
a
)
146
{
147
x
= a.
x
* mat.
m
[0][0] + a.
y
* mat.
m
[0][1] + a.
z
* mat.
m
[0][2];
148
y
= a.
x
* mat.
m
[1][0] + a.
y
* mat.
m
[1][1] + a.
z
* mat.
m
[1][2];
149
z
= a.
x
* mat.
m
[2][0] + a.
y
* mat.
m
[2][1] + a.
z
* mat.
m
[2][2];
150
return
*
this
;
151
}
152
153
Point
&
Point::Mult2
(
const
Matrix3x3
& mat1,
const
Point
&
a1
,
const
Matrix3x3
& mat2,
const
Point
& a2)
154
{
155
x
= a1.
x
* mat1.
m
[0][0] + a1.
y
* mat1.
m
[0][1] + a1.
z
* mat1.
m
[0][2] + a2.
x
* mat2.
m
[0][0] + a2.
y
* mat2.
m
[0][1] + a2.
z
* mat2.
m
[0][2];
156
y
= a1.
x
* mat1.
m
[1][0] + a1.
y
* mat1.
m
[1][1] + a1.
z
* mat1.
m
[1][2] + a2.
x
* mat2.
m
[1][0] + a2.
y
* mat2.
m
[1][1] + a2.
z
* mat2.
m
[1][2];
157
z
= a1.
x
* mat1.
m
[2][0] + a1.
y
* mat1.
m
[2][1] + a1.
z
* mat1.
m
[2][2] + a2.
x
* mat2.
m
[2][0] + a2.
y
* mat2.
m
[2][1] + a2.
z
* mat2.
m
[2][2];
158
return
*
this
;
159
}
160
161
Point
&
Point::Mac
(
const
Matrix3x3
& mat,
const
Point
&
a
)
162
{
163
x
+= a.
x
* mat.
m
[0][0] + a.
y
* mat.
m
[0][1] + a.
z
* mat.
m
[0][2];
164
y
+= a.
x
* mat.
m
[1][0] + a.
y
* mat.
m
[1][1] + a.
z
* mat.
m
[1][2];
165
z
+= a.
x
* mat.
m
[2][0] + a.
y
* mat.
m
[2][1] + a.
z
* mat.
m
[2][2];
166
return
*
this
;
167
}
168
169
Point
&
Point::TransMult
(
const
Matrix3x3
& mat,
const
Point
&
a
)
170
{
171
x
= a.
x
* mat.
m
[0][0] + a.
y
* mat.
m
[1][0] + a.
z
* mat.
m
[2][0];
172
y
= a.
x
* mat.
m
[0][1] + a.
y
* mat.
m
[1][1] + a.
z
* mat.
m
[2][1];
173
z
= a.
x
* mat.
m
[0][2] + a.
y
* mat.
m
[1][2] + a.
z
* mat.
m
[2][2];
174
return
*
this
;
175
}
176
177
Point
&
Point::Transform
(
const
Point
& r,
const
Matrix3x3
& rotpos,
const
Point
& linpos)
178
{
179
x
= r.
x
* rotpos.
m
[0][0] + r.
y
* rotpos.
m
[0][1] + r.
z
* rotpos.
m
[0][2] + linpos.
x
;
180
y
= r.
x
* rotpos.
m
[1][0] + r.
y
* rotpos.
m
[1][1] + r.
z
* rotpos.
m
[1][2] + linpos.
y
;
181
z
= r.
x
* rotpos.
m
[2][0] + r.
y
* rotpos.
m
[2][1] + r.
z
* rotpos.
m
[2][2] + linpos.
z
;
182
return
*
this
;
183
}
184
185
Point
&
Point::InvTransform
(
const
Point
& r,
const
Matrix3x3
& rotpos,
const
Point
& linpos)
186
{
187
float
sx = r.
x
- linpos.
x
;
188
float
sy = r.
y
- linpos.
y
;
189
float
sz = r.
z
- linpos.
z
;
190
x
= sx * rotpos.
m
[0][0] + sy * rotpos.
m
[1][0] + sz * rotpos.
m
[2][0];
191
y
= sx * rotpos.
m
[0][1] + sy * rotpos.
m
[1][1] + sz * rotpos.
m
[2][1];
192
z
= sx * rotpos.
m
[0][2] + sy * rotpos.
m
[1][2] + sz * rotpos.
m
[2][2];
193
return
*
this
;
194
}
195
src
cmd
collide2
Ice
IcePoint.cpp
Generated on Fri May 29 2015 23:07:11 for Vegastrike 0.5.1 rc1 by
1.8.4