-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLine.cpp
35 lines (30 loc) · 1.14 KB
/
Line.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "Precompiled.hpp"
#include "Line.hpp"
namespace Math
{
float Line::length() const
{
return DirectX::XMVectorGetX(DirectX::XMVector3Length(DirectX::XMVectorSubtract(end_point, start_point)));
}
float Line::length_squared() const
{
return DirectX::XMVectorGetX(DirectX::XMVector3LengthSq(DirectX::XMVectorSubtract(end_point, start_point)));
}
Vector3 Line::direction() const
{
return Vector3(DirectX::XMVector3Normalize(DirectX::XMVectorSubtract(end_point, start_point)));
}
Vector3 Line::mid_point() const
{
static const float HALF = 0.5f;
return Vector3(DirectX::XMVectorMultiply(XMVectorSubtract(end_point, start_point), DirectX::XMVectorReplicate(HALF)));
}
void Line::extend(float start_amount, float end_amount)
{
DirectX::XMVECTOR start = start_point;
DirectX::XMVECTOR end = end_point;
DirectX::XMVECTOR dir = DirectX::XMVector3Normalize(DirectX::XMVectorSubtract(end, start));
start_point = DirectX::XMVectorSubtract(start, DirectX::XMVectorMultiply(dir, DirectX::XMVectorReplicate(start_amount)));
end_point = DirectX::XMVectorAdd(end, DirectX::XMVectorMultiply(dir, DirectX::XMVectorReplicate(end_amount)));
}
}