Velocity.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
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  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  */
20 
22 #include <PlayRho/Common/Math.hpp>
24 
25 namespace playrho {
26 namespace d2 {
27 
29 {
30  auto vp = VelocityPair{
31  Velocity{LinearVelocity2{}, 0_rpm},
32  Velocity{LinearVelocity2{}, 0_rpm}
33  };
34 
35  const auto normal = vc.GetNormal();
36  const auto tangent = vc.GetTangent();
37  const auto pointCount = vc.GetPointCount();
38  const auto bodyA = vc.GetBodyA();
39  const auto bodyB = vc.GetBodyB();
40 
41  const auto invMassA = bodyA->GetInvMass();
42  const auto invRotInertiaA = bodyA->GetInvRotInertia();
43 
44  const auto invMassB = bodyB->GetInvMass();
45  const auto invRotInertiaB = bodyB->GetInvRotInertia();
46 
47  for (auto j = decltype(pointCount){0}; j < pointCount; ++j)
48  {
49  // inverse moment of inertia : L^-2 M^-1 QP^2
50  // P is M L T^-2
51  // GetPointRelPosA() is Length2
52  // Cross(Length2, P) is: M L^2 T^-2
53  // L^-2 M^-1 QP^2 M L^2 T^-2 is: QP^2 T^-2
54  const auto& vcp = vc.GetPointAt(j);
55  const auto P = vcp.normalImpulse * normal + vcp.tangentImpulse * tangent;
56  const auto LA = Cross(vcp.relA, P) / Radian;
57  const auto LB = Cross(vcp.relB, P) / Radian;
58  std::get<0>(vp) -= Velocity{invMassA * P, invRotInertiaA * LA};
59  std::get<1>(vp) += Velocity{invMassB * P, invRotInertiaB * LB};
60  }
61 
62  return vp;
63 }
64 
65 } // namespace d2
66 } // namespace playrho