2
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
4
* This software is provided 'as-is', without any express or implied
5
* warranty. In no event will the authors be held liable for any damages
6
* arising from the use of this software.
7
* Permission is granted to anyone to use this software for any purpose,
8
* including commercial applications, and to alter it and redistribute it
9
* freely, subject to the following restrictions:
10
* 1. The origin of this software must not be misrepresented; you must not
11
* claim that you wrote the original software. If you use this software
12
* in a product, an acknowledgment in the product documentation would be
13
* appreciated but is not required.
14
* 2. Altered source versions must be plainly marked as such, and must not be
15
* misrepresented as being the original software.
16
* 3. This notice may not be removed or altered from any source distribution.
19
#ifndef TIME_OF_IMPACT_H
20
#define TIME_OF_IMPACT_H
22
class TimeOfImpact : public Test
27
m_shapeA.SetAsBox(25.0f, 5.0f);
28
m_shapeB.SetAsBox(2.5f, 2.5f);
33
return new TimeOfImpact;
36
void Step(Settings* settings)
41
sweepA.c0.Set(24.0f, -60.0f);
45
sweepA.localCenter.SetZero();
48
sweepB.c0.Set(53.474274f, -50.252514f);
49
sweepB.a0 = 513.36676f; // - 162.0f * b2_pi;
50
sweepB.c.Set(54.595478f, -51.083473f);
51
sweepB.a = 513.62781f; // - 162.0f * b2_pi;
52
sweepB.localCenter.SetZero();
54
//sweepB.a0 -= 300.0f * b2_pi;
55
//sweepB.a -= 300.0f * b2_pi;
58
input.proxyA.Set(&m_shapeA, 0);
59
input.proxyB.Set(&m_shapeB, 0);
60
input.sweepA = sweepA;
61
input.sweepB = sweepB;
66
b2TimeOfImpact(&output, &input);
68
m_debugDraw.DrawString(5, m_textLine, "toi = %g", output.t);
71
extern int32 b2_toiMaxIters, b2_toiMaxRootIters;
72
m_debugDraw.DrawString(5, m_textLine, "max toi iters = %d, max root iters = %d", b2_toiMaxIters, b2_toiMaxRootIters);
75
b2Vec2 vertices[b2_maxPolygonVertices];
77
b2Transform transformA;
78
sweepA.GetTransform(&transformA, 0.0f);
79
for (int32 i = 0; i < m_shapeA.m_vertexCount; ++i)
81
vertices[i] = b2Mul(transformA, m_shapeA.m_vertices[i]);
83
m_debugDraw.DrawPolygon(vertices, m_shapeA.m_vertexCount, b2Color(0.9f, 0.9f, 0.9f));
85
b2Transform transformB;
86
sweepB.GetTransform(&transformB, 0.0f);
88
b2Vec2 localPoint(2.0f, -0.1f);
89
b2Vec2 rB = b2Mul(transformB, localPoint) - sweepB.c0;
90
float32 wB = sweepB.a - sweepB.a0;
91
b2Vec2 vB = sweepB.c - sweepB.c0;
92
b2Vec2 v = vB + b2Cross(wB, rB);
94
for (int32 i = 0; i < m_shapeB.m_vertexCount; ++i)
96
vertices[i] = b2Mul(transformB, m_shapeB.m_vertices[i]);
98
m_debugDraw.DrawPolygon(vertices, m_shapeB.m_vertexCount, b2Color(0.5f, 0.9f, 0.5f));
100
sweepB.GetTransform(&transformB, output.t);
101
for (int32 i = 0; i < m_shapeB.m_vertexCount; ++i)
103
vertices[i] = b2Mul(transformB, m_shapeB.m_vertices[i]);
105
m_debugDraw.DrawPolygon(vertices, m_shapeB.m_vertexCount, b2Color(0.5f, 0.7f, 0.9f));
107
sweepB.GetTransform(&transformB, 1.0f);
108
for (int32 i = 0; i < m_shapeB.m_vertexCount; ++i)
110
vertices[i] = b2Mul(transformB, m_shapeB.m_vertices[i]);
112
m_debugDraw.DrawPolygon(vertices, m_shapeB.m_vertexCount, b2Color(0.9f, 0.5f, 0.5f));
115
for (float32 t = 0.0f; t < 1.0f; t += 0.1f)
117
sweepB.GetTransform(&transformB, t);
118
for (int32 i = 0; i < m_shapeB.m_vertexCount; ++i)
120
vertices[i] = b2Mul(transformB, m_shapeB.m_vertices[i]);
122
m_debugDraw.DrawPolygon(vertices, m_shapeB.m_vertexCount, b2Color(0.9f, 0.5f, 0.5f));
127
b2PolygonShape m_shapeA;
128
b2PolygonShape m_shapeB;