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