Toggle navigation
PlayRho
0.9.0
GitHub
Main Page
Modules
Classes
Files
Examples
File List
File Members
Common
Sweep.hpp
Go to the documentation of this file.
1
/*
2
* Original work Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3
* Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
4
*
5
* This software is provided 'as-is', without any express or implied
6
* warranty. In no event will the authors be held liable for any damages
7
* arising from the use of this software.
8
*
9
* Permission is granted to anyone to use this software for any purpose,
10
* including commercial applications, and to alter it and redistribute it
11
* freely, subject to the following restrictions:
12
*
13
* 1. The origin of this software must not be misrepresented; you must not
14
* claim that you wrote the original software. If you use this software
15
* in a product, an acknowledgment in the product documentation would be
16
* appreciated but is not required.
17
* 2. Altered source versions must be plainly marked as such, and must not be
18
* misrepresented as being the original software.
19
* 3. This notice may not be removed or altered from any source distribution.
20
*/
21
22
#ifndef PLAYRHO_COMMON_SWEEP_HPP
23
#define PLAYRHO_COMMON_SWEEP_HPP
24
25
#include <
PlayRho/Common/Position.hpp
>
26
#include <
PlayRho/Common/Settings.hpp
>
27
#include <
PlayRho/Common/Vector2.hpp
>
28
29
namespace
playrho
{
30
namespace
d2 {
31
41
class
Sweep
42
{
43
public
:
44
46
Sweep
() =
default
;
47
49
PLAYRHO_CONSTEXPR
inline
Sweep
(
const
Sweep
& copy) =
default
;
50
52
PLAYRHO_CONSTEXPR
inline
Sweep
(
const
Position
p0,
const
Position
p1,
53
const
Length2
lc =
Length2
{0_m, 0_m},
54
Real
a0 = 0) noexcept:
55
pos0
{p0},
pos1
{p1}, localCenter{lc}, alpha0{a0}
56
{
57
assert(a0 >= 0);
58
assert(a0 < 1);
59
}
60
62
PLAYRHO_CONSTEXPR
inline
explicit
Sweep
(
const
Position
p,
63
const
Length2
lc =
Length2
{0_m, 0_m}):
64
Sweep
{p, p, lc, 0}
65
{
66
// Intentionally empty.
67
}
68
72
Length2
GetLocalCenter
() const noexcept {
return
localCenter; }
73
76
Real
GetAlpha0
() const noexcept {
return
alpha0; }
77
87
void
Advance0
(
Real
alpha) noexcept;
88
91
void
ResetAlpha0
() noexcept;
92
94
Position
pos0
;
95
97
Position
pos1
;
98
99
private:
102
Length2
localCenter =
Length2
{0_m, 0_m};
103
108
Real
alpha0 = 0;
109
};
110
111
inline
void
Sweep::Advance0
(
const
Real
alpha) noexcept
112
{
113
assert(
IsValid
(alpha));
114
assert(alpha >= 0);
115
assert(alpha < 1);
116
assert(alpha0 < 1);
117
118
const
auto
beta = (alpha - alpha0) / (1 - alpha0);
119
pos0 =
GetPosition
(pos0, pos1, beta);
120
alpha0 = alpha;
121
}
122
123
inline
void
Sweep::ResetAlpha0
() noexcept
124
{
125
alpha0 = 0;
126
}
127
128
// Free functions...
129
130
}
// namespace d2
131
134
template
<>
135
PLAYRHO_CONSTEXPR
inline
bool
IsValid
(
const
d2::Sweep
& value) noexcept
136
{
137
return
IsValid
(value.pos0) &&
IsValid
(value.pos1)
138
&&
IsValid
(value.GetLocalCenter()) &&
IsValid
(value.GetAlpha0());
139
}
140
141
}
// namespace playrho
142
143
#endif // PLAYRHO_COMMON_SWEEP_HPP