VR-Forces 4.5 Class Documentation
Home
Modules
Namespaces
Classes
Files
Examples
Behavior Models
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
include
vrvGraphicsUtils
DtVector2.h
Go to the documentation of this file.
1
/******************************************************************************
2
** Copyright (c) 2014 MAK Technologies, Inc.
3
** All rights reserved.
4
******************************************************************************/
5
9
#pragma once
10
11
#include "
DtCommonTypes.h
"
12
13
#include <list>
14
#include <vector>
15
16
#include "
DtAssert.h
"
17
#include "
DtMath.h
"
18
19
namespace
makVrv {
20
23
template
<
class
T>
24
class
DtVector2
25
{
26
public
:
28
DtVector2
(){}
30
DtVector2
(T _x, T _y):
x
(_x),
y
(_y){}
31
33
~DtVector2
(){}
34
35
const
void
*
ptr
(
void
)
const
{
return
&
x
;}
36
37
T
operator[]
(
size_t
index)
const
;
38
39
T
length
(
void
)
const
;
40
41
bool
isEqual
(
const
DtVector2
& rhs, T tolerance)
const
;
42
43
DtVector2
operator+
(
const
DtVector2
& rhs)
const
;
44
DtVector2
operator-
(
const
DtVector2
& rhs)
const
;
45
46
DtVector2
operator+
(T fScalar)
const
;
47
DtVector2
operator-
(T fScalar)
const
;
48
DtVector2
operator*
(T fScalar)
const
;
49
DtVector2
operator/
(T fScalar)
const
;
50
51
DtVector2
operator/
(
const
DtVector2
& rhs)
const
;
52
53
DtVector2
getNormalizedCopy
(
void
)
const
;
54
55
T
getDotProduct
(
const
DtVector2
& rhs)
const
;
56
57
T
x
,
y
;
58
59
static
DtVector2
ZERO_VECTOR
;
60
static
DtVector2
UNIT_SCALE
;
61
62
static
size_t
sizeInBytes
(
void
);
63
};
64
65
template
<
class
T>
66
DtVector2<T>
DtVector2<T>::ZERO_VECTOR
=
DtVector2<T>
(0,0);
67
template
<
class
T>
68
DtVector2<T>
DtVector2<T>::UNIT_SCALE
=
DtVector2<T>
(1,1);
69
70
template
<
class
T>
71
DtVector2<T>
DtVector2<T>::operator+
(
const
DtVector2<T>
& rhs)
const
72
{
73
return
DtVector2<T>
(x+rhs.
x
, y+rhs.
y
);
74
}
75
template
<
class
T>
76
DtVector2<T>
DtVector2<T>::operator-
(
const
DtVector2<T>& rhs)
const
77
{
78
return
DtVector2<T>(x-rhs.x, y-rhs.y);
79
}
80
81
template
<
class
T>
82
DtVector2<T>
DtVector2<T>::operator+
(T fScalar)
const
83
{
84
return
DtVector2<T>
(x+fScalar, y+fScalar);
85
}
86
87
template
<
class
T>
88
DtVector2<T>
DtVector2<T>::operator-
(T fScalar)
const
89
{
90
return
DtVector2<T>
(x-fScalar, y-fScalar);
91
}
92
93
template
<
class
T>
94
DtVector2<T>
DtVector2<T>::operator*
(T fScalar)
const
95
{
96
return
DtVector2<T>
(x*fScalar, y*fScalar);
97
}
98
99
template
<
class
T>
100
DtVector2<T>
DtVector2<T>::operator/
(T fScalar)
const
101
{
102
T OneByfScalar = T(1.0)/fScalar;
103
return
DtVector2<T>
(x*OneByfScalar, y*OneByfScalar);
104
}
105
106
template
<
class
T>
107
DtVector2<T>
DtVector2<T>::operator/
(
const
DtVector2<T>
& rhs)
const
108
{
109
return
DtVector2<T>
(x/rhs.
x
, y/rhs.
y
);
110
}
111
112
template
<
class
T>
113
bool
DtVector2<T>::isEqual
(
const
DtVector2<T>
& rhs, T tolerance)
const
114
{
115
return
DtMath::isEqual
(this->x, rhs.
x
,tolerance)
116
&&
DtMath::isEqual
(this->y, rhs.
y
,tolerance)
117
;
118
}
119
120
121
template
<
class
T>
122
T
DtVector2<T>::getDotProduct
(
const
DtVector2<T>
& rhs)
const
123
{
124
return
x*rhs.
x
+ y*rhs.
y
;
125
}
126
127
template
<
class
T>
128
DtVector2<T>
DtVector2<T>::getNormalizedCopy
(
void
)
const
129
{
130
T vecLength = length();
131
if
(vecLength<std::numeric_limits<T>::epsilon())
132
return
DtVector2::ZERO_VECTOR
;
133
134
T one_by_length = T(1.0)/vecLength;
135
return
(
DtVector2<T>
(x,y)*one_by_length);
136
}
137
138
template
<
class
T>
139
T
DtVector2<T>::operator[]
(
size_t
index)
const
140
{
141
ASSERT_PREDICATE_RETURN_DEFAULT_CONSTRUCTOR
(
DtVector2<T>
, index<=1);
142
const
T* ptrT =
static_cast<
const
T*
>
(ptr());
143
return
ptrT[index];
144
}
145
146
template
<
class
T>
147
T
DtVector2<T>::length
(
void
)
const
148
{
149
return
DtMath::Sqrt
(x*x+y*y);
150
}
151
152
template
<
class
T>
153
size_t
DtVector2<T>::sizeInBytes
(
void
)
154
{
155
return
2*
sizeof
(T);
156
}
157
158
}
//namespace makVrv
159
Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (
www.mak.com
)