NW4F G3d
Loading...
Searching...
No Matches
g3d_Vector2-inl.h
Go to the documentation of this file.
1
#
include
<
nw
/
g3d
/
math
/
g3d_MathCommon
.
h
>
2
3
namespace
nw
{
namespace
g3d
{
namespace
math
{
4
5
NW_G3D_MATH_INLINE
6
Vec2
Vec2
::
Make
(
float
x
,
float
y
)
7
{
8
return
Vec2
().
Set
(
x
,
y
);
9
}
10
11
NW_G3D_MATH_INLINE
12
Vec2
*
Vec2
::
Cast
(
float
*
a
)
13
{
14
return
reinterpret_cast
<
Vec2
*>(
a
);
15
}
16
17
NW_G3D_MATH_INLINE
18
const
Vec2
*
Vec2
::
Cast
(
const
float
*
a
)
19
{
20
return
reinterpret_cast
<
const
Vec2
*>(
a
);
21
}
22
23
NW_G3D_MATH_INLINE
24
Vec2
&
Vec2
::
Set
(
float
x
,
float
y
)
25
{
26
this
->
x
=
x
;
27
this
->
y
=
y
;
28
return
*
this
;
29
}
30
31
NW_G3D_MATH_INLINE
32
Vec2
&
Vec2
::
Set
(
const
float
*
a
)
33
{
34
NW_G3D_ASSERT_NOT_NULL
(
a
);
35
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
36
{
37
this
->
a
[
i
] =
a
[
i
];
38
}
39
return
*
this
;
40
}
41
42
NW_G3D_MATH_INLINE
43
Vec2
&
Vec2
::
Set
(
const
Vec2
&
v
)
44
{
45
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
46
{
47
a
[
i
] =
v
.
a
[
i
];
48
}
49
return
*
this
;
50
}
51
52
NW_G3D_MATH_INLINE
53
Vec2
&
Vec2
::
Zero
()
54
{
55
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
56
{
57
a
[
i
] = 0.0f;
58
}
59
return
*
this
;
60
}
61
62
NW_G3D_MATH_INLINE
63
Vec2
&
Vec2
::
Neg
(
const
Vec2
&
v
)
64
{
65
#
if
defined
(
__ghs__
)
66
ps
[0] =
__PS_NEG
(
v
.
ps
[0]);
67
#
else
68
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
69
{
70
a
[
i
] = -
v
.
a
[
i
];
71
}
72
#
endif
73
return
*
this
;
74
}
75
76
NW_G3D_MATH_INLINE
77
Vec2
&
Vec2
::
Rcp
(
const
Vec2
&
v
)
78
{
79
#
if
defined
(
__ghs__
)
80
ps
[0] =
Math
::
Rcp
(
v
.
ps
[0]);
81
#
else
82
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
83
{
84
a
[
i
] =
Math
::
Rcp
(
v
.
a
[
i
]);
85
}
86
#
endif
87
return
*
this
;
88
}
89
90
91
//--------------------------------------------------------------------------------------------------
92
93
NW_G3D_MATH_INLINE
94
Vec2
&
Vec2
::
Add
(
const
Vec2
&
lhs
,
const
Vec2
&
rhs
)
95
{
96
#
if
defined
(
__ghs__
)
97
ps
[0] =
__PS_ADD
(
lhs
.
ps
[0],
rhs
.
ps
[0]);
98
#
else
99
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
100
{
101
a
[
i
] =
lhs
.
a
[
i
] +
rhs
.
a
[
i
];
102
}
103
#
endif
104
return
*
this
;
105
}
106
107
NW_G3D_MATH_INLINE
108
Vec2
&
Vec2
::
Sub
(
const
Vec2
&
lhs
,
const
Vec2
&
rhs
)
109
{
110
#
if
defined
(
__ghs__
)
111
ps
[0] =
__PS_SUB
(
lhs
.
ps
[0],
rhs
.
ps
[0]);
112
#
else
113
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
114
{
115
a
[
i
] =
lhs
.
a
[
i
] -
rhs
.
a
[
i
];
116
}
117
#
endif
118
return
*
this
;
119
}
120
121
NW_G3D_MATH_INLINE
122
Vec2
&
Vec2
::
Mul
(
const
Vec2
&
lhs
,
const
Vec2
&
rhs
)
123
{
124
#
if
defined
(
__ghs__
)
125
ps
[0] =
__PS_MUL
(
lhs
.
ps
[0],
rhs
.
ps
[0]);
126
#
else
127
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
128
{
129
a
[
i
] =
lhs
.
a
[
i
] *
rhs
.
a
[
i
];
130
}
131
#
endif
132
return
*
this
;
133
}
134
135
NW_G3D_MATH_INLINE
136
Vec2
&
Vec2
::
Div
(
const
Vec2
&
lhs
,
const
Vec2
&
rhs
)
137
{
138
Vec2
rcp
;
139
rcp
.
Rcp
(
rhs
);
140
Mul
(
lhs
,
rhs
);
141
return
*
this
;
142
}
143
144
NW_G3D_MATH_INLINE
145
Vec2
&
Vec2
::
Mul
(
const
Vec2
&
lhs
,
float
rhs
)
146
{
147
#
if
defined
(
__ghs__
)
148
ps
[0] =
__PS_MULS0F
(
lhs
.
ps
[0],
rhs
);
149
#
else
150
for
(
int
i
= 0;
i
<
DIM
; ++
i
)
151
{
152
a
[
i
] =
lhs
.
a
[
i
] *
rhs
;
153
}
154
#
endif
155
return
*
this
;
156
}
157
158
NW_G3D_MATH_INLINE
159
Vec2
&
Vec2
::
Div
(
const
Vec2
&
lhs
,
float
rhs
)
160
{
161
float
rcp
=
Math
::
Rcp
(
rhs
);
162
this
->
Mul
(
lhs
,
rcp
);
163
return
*
this
;
164
}
165
166
//--------------------------------------------------------------------------------------------------
167
168
NW_G3D_MATH_INLINE
169
float
Vec2
::
Length
(
const
Vec2
&
v
)
170
{
171
return
Math
::
Sqrt
(
LengthSq
(
v
));
172
}
173
174
NW_G3D_MATH_INLINE
175
float
Vec2
::
LengthSq
(
const
Vec2
&
v
)
176
{
177
return
Dot
(
v
,
v
);
178
}
179
180
NW_G3D_MATH_INLINE
181
float
Vec2
::
Distance
(
const
Vec2
&
lhs
,
const
Vec2
&
rhs
)
182
{
183
Vec2
vec
;
184
vec
.
Sub
(
lhs
,
rhs
);
185
return
Length
(
vec
);
186
}
187
188
NW_G3D_MATH_INLINE
189
float
Vec2
::
DistanceSq
(
const
Vec2
&
lhs
,
const
Vec2
&
rhs
)
190
{
191
Vec2
vec
;
192
vec
.
Sub
(
lhs
,
rhs
);
193
return
LengthSq
(
vec
);
194
}
195
196
NW_G3D_MATH_INLINE
197
float
Vec2
::
Dot
(
const
Vec2
&
lhs
,
const
Vec2
&
rhs
)
198
{
199
#
if
defined
(
__ghs__
)
200
f32x2
ps
;
201
ps
=
__PS_MUL
(
lhs
.
ps
[0],
rhs
.
ps
[0]);
202
ps
=
__PS_SUM0
(
ps
,
ps
,
ps
);
203
return
ps
[0];
204
#
else
205
return
lhs
.
x
*
rhs
.
x
+
lhs
.
y
*
rhs
.
y
;
206
#
endif
207
}
208
209
NW_G3D_MATH_INLINE
210
float
Vec2
::
Normalize
(
const
Vec2
&
v
)
211
{
212
float
lengthSq
=
LengthSq
(
v
);
213
if
(
lengthSq
> 0.0f)
214
{
215
float
rcp
=
Math
::
RSqrt
(
lengthSq
);
216
Mul
(
v
,
rcp
);
217
return
lengthSq
*
rcp
;
218
}
219
return
0.0f;
220
}
221
222
223
} } }
// namespace nw::g3d::math
NW_G3D_ASSERT_NOT_NULL
#define NW_G3D_ASSERT_NOT_NULL(exp)
Definition
g3d_assert.h:20
NW_G3D_MATH_INLINE
#define NW_G3D_MATH_INLINE
Definition
g3d_defs.h:69
nw::g3d::math
Definition
g3d_MathCommon.h:6
nw::g3d
Definition
g3d_GfxManage.cpp:10
nw
include
nw
g3d
math
inl
g3d_Vector2-inl.h
Generated by
1.14.0