+21
-15
lines changedFilter options
+21
-15
lines changed Original file line number Diff line number Diff line change
@@ -71,25 +71,25 @@ public Sweep set(Sweep other) {
71
71
/**
72
72
* Get the interpolated transform at a specific time.
73
73
*
74
-
* @param xf the result is placed here - must not be null
74
+
* @param xf the result is placed here
75
75
* @param beta the normalized time in [0,1]
76
76
*/
77
-
public void getTransform(final Transform xf, final float beta) {
78
-
assert xf != null;
79
-
// xf->p = (1.0f - beta) * c0 + beta * c;
80
-
// float32 angle = (1.0f - beta) * a0 + beta * a;
81
-
// xf->q.Set(angle);
82
-
xf.p.x = (1.0f - beta) * c0.x + beta * c.x;
83
-
xf.p.y = (1.0f - beta) * c0.y + beta * c.y;
77
+
public void getTransform(Transform xf, float beta) {
78
+
xf.p.set(
79
+
lerp(c0.x, c.x, beta),
80
+
lerp(c0.y, c.y, beta)
81
+
);
84
82
85
-
float angle = (1.0f - beta) * a0 + beta * a;
86
-
xf.q.set(angle);
83
+
xf.q.set(
84
+
lerp(a0, a, beta)
85
+
);
87
86
88
87
// Shift to origin
89
-
// xf->p -= b2Mul(xf->q, localCenter);
90
-
final Rotation q = xf.q;
91
-
xf.p.x -= q.c * localCenter.x - q.s * localCenter.y;
92
-
xf.p.y -= q.s * localCenter.x + q.c * localCenter.y;
88
+
xf.shift(localCenter);
89
+
}
90
+
91
+
private float lerp(float a, float b, float t) {
92
+
return (1.0f - t) * a + t * b;
93
93
}
94
94
95
95
/**
Original file line number Diff line number Diff line change
@@ -59,6 +59,11 @@ public float mulY(Vec2 v) {
59
59
return q.s * v.x + q.c * v.y + p.y;
60
60
}
61
61
62
+
public void shift(Vec2 v) {
63
+
p.x -= q.c * v.x - q.s * v.y;
64
+
p.y -= q.s * v.x + q.c * v.y;
65
+
}
66
+
62
67
public static Vec2 mul(Transform T, Vec2 v) {
63
68
return new Vec2(T.q.c * v.x - T.q.s * v.y + T.p.x, T.q.s * v.x + T.q.c * v.y + T.p.y);
64
69
}
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ class SweepTest {
38
38
39
39
@Test
40
40
fun `get transform at given time`() {
41
+
sweep.localCenter.set(3.5f, 1.2f)
41
42
sweep.c.set(2f, 0f)
42
43
sweep.a0 = 2f
43
44
sweep.a = 4f
@@ -46,7 +47,7 @@ class SweepTest {
46
47
47
48
sweep.getTransform(xf, 0.5f)
48
49
49
-
assertThat(xf.p, `is`(Vec2(1f, 0f)))
50
+
assertThat(xf.p, `is`(Vec2(4.634288f, 0.694177f)))
50
51
51
52
// Rotation(3f)
52
53
assertThat(xf.q.c, `is`(-0.9899941f))
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4