first commit
[blok] / Box2D / Source / Common / b2Math.cpp
1 /*
2 * Copyright (c) 2007 Erin Catto http://www.gphysics.com
3 *
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.
17 */
18
19 #include "b2Math.h"
20
21 const b2Vec2 b2Vec2_zero(0.0f, 0.0f);
22 const b2Mat22 b2Mat22_identity(1.0f, 0.0f, 0.0f, 1.0f);
23 const b2XForm b2XForm_identity(b2Vec2_zero, b2Mat22_identity);
24
25 void b2Sweep::GetXForm(b2XForm* xf, float32 t) const
26 {
27         // center = p + R * localCenter
28         if (1.0f - t0 > B2_FLT_EPSILON)
29         {
30                 float32 alpha = (t - t0) / (1.0f - t0);
31                 xf->position = (1.0f - alpha) * c0 + alpha * c;
32                 float32 angle = (1.0f - alpha) * a0 + alpha * a;
33                 xf->R.Set(angle);
34         }
35         else
36         {
37                 xf->position = c;
38                 xf->R.Set(a);
39         }
40
41         // Shift to origin
42         xf->position -= b2Mul(xf->R, localCenter);
43 }
44
45 void b2Sweep::Advance(float32 t)
46 {
47         if (t0 < t && 1.0f - t0 > B2_FLT_EPSILON)
48         {
49                 float32 alpha = (t - t0) / (1.0f - t0);
50                 c0 = (1.0f - alpha) * c0 + alpha * c;
51                 a0 = (1.0f - alpha) * a0 + alpha * a;
52                 t0 = t;
53         }
54 }