Pyrogenesis
13997
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
source
maths
Vector3D.cpp
Go to the documentation of this file.
1
/* Copyright (C) 2010 Wildfire Games.
2
* This file is part of 0 A.D.
3
*
4
* 0 A.D. is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 2 of the License, or
7
* (at your option) any later version.
8
*
9
* 0 A.D. is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
/*
19
* Provides an interface for a vector in R3 and allows vector and
20
* scalar operations on it
21
*/
22
23
#include "precompiled.h"
24
25
#include "
Vector3D.h
"
26
27
#include <math.h>
28
#include <float.h>
29
#include "
MathUtil.h
"
30
#include "
FixedVector3D.h
"
31
32
CVector3D::CVector3D
(
const
CFixedVector3D
& v) :
33
X
(v.
X
.ToFloat()),
Y
(v.
Y
.ToFloat()),
Z
(v.
Z
.ToFloat())
34
{
35
}
36
37
int
CVector3D::operator !
()
const
38
{
39
if
(
X
!= 0.0f ||
40
Y
!= 0.0f ||
41
Z
!= 0.0f)
42
43
return
0;
44
45
return
1;
46
}
47
48
float
CVector3D::Dot
(
const
CVector3D
&vector)
const
49
{
50
return
(
X
* vector.
X
+
51
Y
* vector.
Y
+
52
Z
* vector.
Z
);
53
}
54
55
CVector3D
CVector3D::Cross
(
const
CVector3D
&vector)
const
56
{
57
CVector3D
Temp;
58
59
Temp.
X
= (
Y
* vector.
Z
) - (
Z
* vector.
Y
);
60
Temp.
Y
= (
Z
* vector.
X
) - (
X
* vector.
Z
);
61
Temp.
Z
= (
X
* vector.
Y
) - (
Y
* vector.
X
);
62
63
return
Temp;
64
}
65
66
67
float
CVector3D::LengthSquared
()
const
68
{
69
return
(
SQR
(
X
) +
SQR
(
Y
) +
SQR
(
Z
) );
70
}
71
72
float
CVector3D::Length
()
const
73
{
74
return
sqrtf (
LengthSquared
() );
75
}
76
77
void
CVector3D::Normalize
()
78
{
79
float
scale = 1.0f/
Length
();
80
81
X
*= scale;
82
Y
*= scale;
83
Z
*= scale;
84
}
85
86
CVector3D
CVector3D::Normalized
()
const
87
{
88
float
scale = 1.0f/
Length
();
89
90
return
CVector3D
(
X
* scale,
Y
* scale,
Z
* scale);
91
}
92
93
94
//-----------------------------------------------------------------------------
95
96
float
MaxComponent
(
const
CVector3D
& v)
97
{
98
float
max = -FLT_MAX;
99
for
(
int
i = 0; i < 3; i++)
100
max = std::max(max, v[i]);
101
return
max;
102
}
CVector3D::CVector3D
CVector3D()
Definition:
Vector3D.h:34
Y
Definition:
Decompose.h:22
X
Definition:
Decompose.h:22
CVector3D::Dot
float Dot(const CVector3D &vector) const
Definition:
Vector3D.cpp:48
CVector3D::Cross
CVector3D Cross(const CVector3D &vector) const
Definition:
Vector3D.cpp:55
CVector3D
Definition:
Vector3D.h:28
SQR
#define SQR(x)
Definition:
MathUtil.h:23
CVector3D::Normalize
void Normalize()
Definition:
Vector3D.cpp:77
CVector3D::operator!
int operator!() const
Definition:
Vector3D.cpp:37
CVector3D::X
float X
Definition:
Vector3D.h:31
CVector3D::Length
float Length() const
Definition:
Vector3D.cpp:72
CVector3D::Y
float Y
Definition:
Vector3D.h:31
CFixedVector3D
Definition:
FixedVector3D.h:24
MathUtil.h
FixedVector3D.h
Z
Definition:
Decompose.h:22
CVector3D::LengthSquared
float LengthSquared() const
Definition:
Vector3D.cpp:67
Vector3D.h
CVector3D::Z
float Z
Definition:
Vector3D.h:31
MaxComponent
float MaxComponent(const CVector3D &v)
Definition:
Vector3D.cpp:96
CVector3D::Normalized
CVector3D Normalized() const
Definition:
Vector3D.cpp:86
Generated on Mon Oct 14 2013 00:58:08 for Pyrogenesis by
1.8.5