diff --git a/Box2D/Dynamics/Joints/b2RigidPlasticJoint.cpp b/Box2D/Dynamics/Joints/b2RigidPlasticJoint.cpp index f660eb9f0..8a9d34d1a 100644 --- a/Box2D/Dynamics/Joints/b2RigidPlasticJoint.cpp +++ b/Box2D/Dynamics/Joints/b2RigidPlasticJoint.cpp @@ -157,52 +157,50 @@ void b2RigidPlasticJoint::SolveVelocityConstraints(const b2SolverData& data) Cdot.SetZero(); impulse.SetZero(); float32 h = data.step.dt; - if (!isOverLoaded()) { - /** Adapted from b2Friction.cpp - * - */ - // Solve linear part - b2Vec2 lCdot = vB + b2Cross(wB, m_rB) - vA - b2Cross(wA, m_rA); - if (lCdot.LengthSquared() > 0.f) { - b2Vec2 lImpulse = -b2Mul(m_linearMass, lCdot); - b2Vec2 oldLImpulse = m_linearImpulse; - m_linearImpulse += lImpulse; - if (m_linearImpulse.LengthSquared() > m_maxForce.LengthSquared()) - { - m_linearImpulse.Normalize(); - m_linearImpulse *= m_maxForce.Length(); - } - impulse.x = m_linearImpulse.x - oldLImpulse.x; - impulse.y = m_linearImpulse.y - oldLImpulse.y; - Cdot.x = lCdot.x; - Cdot.y = lCdot.y; - wA += m_invIA * b2Cross(m_rA, lImpulse); - wB += m_invIB * b2Cross(m_rB, lImpulse); - } - // Solve angular part - float32 aCdot = wB - wA - m_dw0; - if (b2Abs(aCdot) > 0.f) { - float32 aImpulse = -m_angularMass * aCdot; - float32 oldAImpulse = m_angularImpulse; - float32 maxImpulse = h * m_maxTorque; - m_angularImpulse = b2Clamp - (m_angularImpulse + aImpulse, -maxImpulse, maxImpulse); - aImpulse = m_angularImpulse - oldAImpulse; - impulse.z = aImpulse; + /** Adapted from b2Friction.cpp + * + */ + // Solve linear part + b2Vec2 lCdot = vB + b2Cross(wB, m_rB) - vA - b2Cross(wA, m_rA); + if (lCdot.LengthSquared() > 0.f) { + b2Vec2 lImpulse = -b2Mul(m_linearMass, lCdot); + b2Vec2 oldLImpulse = m_linearImpulse; + m_linearImpulse += lImpulse; + if (m_linearImpulse.LengthSquared() > m_maxForce.LengthSquared()) + { + m_linearImpulse.Normalize(); + m_linearImpulse *= m_maxForce.Length(); } - Cdot.z = aCdot; - m_impulse += impulse; + impulse.x = m_linearImpulse.x - oldLImpulse.x; + impulse.y = m_linearImpulse.y - oldLImpulse.y; + Cdot.x = lCdot.x; + Cdot.y = lCdot.y; + wA += m_invIA * b2Cross(m_rA, lImpulse); + wB += m_invIB * b2Cross(m_rB, lImpulse); + } + // Solve angular part + float32 aCdot = wB - wA - m_dw0; + if (b2Abs(aCdot) > 0.f) { + float32 aImpulse = -m_angularMass * aCdot; + float32 oldAImpulse = m_angularImpulse; + float32 maxImpulse = h * m_maxTorque; + m_angularImpulse = b2Clamp + (m_angularImpulse + aImpulse, -maxImpulse, maxImpulse); + aImpulse = m_angularImpulse - oldAImpulse; + impulse.z = aImpulse; + } + Cdot.z = aCdot; + m_impulse += impulse; #ifdef EP_LOG - if (epLogActive && epLogEnabled) { - if (b2Dot(Cdot, Cdot) > 0.f) { - epLog("RPJ:VC:%d Cdot=%g %g %g\n", id, - Cdot.x, Cdot.y, Cdot.z); - epLog("RPJ:VC:%d impulse=%g %g %g\n", id, - impulse.x, impulse.y, impulse.z); - } + if (epLogActive && epLogEnabled) { + if (b2Dot(Cdot, Cdot) > 0.f) { + epLog("RPJ:VC:%d Cdot=%g %g %g\n", id, + Cdot.x, Cdot.y, Cdot.z); + epLog("RPJ:VC:%d impulse=%g %g %g\n", id, + impulse.x, impulse.y, impulse.z); } -#endif } +#endif if (nullptr != debugListener) { debugListener->EndVelocityIteration(this, data); } diff --git a/ep/ep/Beam.h b/ep/ep/Beam.h index 91014786a..5720448d7 100644 --- a/ep/ep/Beam.h +++ b/ep/ep/Beam.h @@ -58,7 +58,10 @@ namespace { } namespace bo { - int b1,b2,b3; + int b1,b2,b3,b4; + void reset() { + b1 =b2=b3=b4= 0; + } } @@ -105,6 +108,9 @@ class Beam : public Test m_bombSpawnPoint = settings->bombSpawnPoint; LaunchBomb(); } + if (bo::b4) { + AddMass(settings->addMassPoint); + } } bool showMenu = true; virtual void Ui(){ @@ -276,13 +282,11 @@ void Beam::BeamExtraUi() if (ImGui::CollapsingHeader("BeamOptions", 0, true, openLists)) { float32 uihx=0.f,by=0.f; if (ImGui::Button("None")) { - bo::b1 = 0; - bo::b2 = 0; - bo::b3 = 0; + bo::reset(); } if (ImGui::RadioButton("B1-1", &bo::b1,1)) { - bo::b2 = 0; - bo::b3 = 0; + bo::reset(); + bo::b1 = 1; uihx = 10; by = 27.01f; settings->epDebugSteps = 10; @@ -297,8 +301,8 @@ hx=10\n\ } ImGui::SameLine(); if (ImGui::RadioButton("B1-2", &bo::b1,2)) { - bo::b2 = 0; - bo::b3 = 0; + bo::reset(); + bo::b1 = 2; uihx = 3; by = 13.01f; settings->epDebugSteps = 10; @@ -337,8 +341,8 @@ hx=3\n\ restartPending = true; } if (ImGui::RadioButton("B2-1", &bo::b2, 1)) { - bo::b1 = 0; - bo::b3 = 0; + bo::reset(); + bo::b2 = 1; uihx = 1.f; epLogEnabled = true; } @@ -366,8 +370,8 @@ hx=1\n\ restartPending = true; } if (ImGui::RadioButton("B3-1", &bo::b3, 1)) { - bo::b1 = 0; - bo::b2 = 0; + bo::reset(); + bo::b3 = 1; uihx = 40.f; epLogEnabled = true; } @@ -382,8 +386,8 @@ epDebug and log active\n\ } ImGui::SameLine(); if (ImGui::RadioButton("B3-11", &bo::b3, 11)) { - bo::b1 = 0; - bo::b2 = 0; + bo::reset(); + bo::b3 =11; uihx = 40.f; epLogEnabled = true; } @@ -398,8 +402,8 @@ epDebug and log active\n\ } ImGui::SameLine(); if (ImGui::RadioButton("B3-2", &bo::b3, 2)) { - bo::b1 = 0; - bo::b2 = 0; + bo::reset(); + bo::b3 = 2; uihx = 10.f; epLogEnabled = false; } @@ -435,6 +439,38 @@ epDebug and log not active\n\ openLists = true; restartPending = true; } + if (ImGui::RadioButton("B4-1", &bo::b4, 1)) { + bo::reset(); + bo::b4 = 1; + uihx = 10.f; + epLogEnabled = true; + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("Horizontal\n\ +rigidPlastic\n\ +hx=10\n\ +1 10 m body\n\ +epLog active\n\ +addMass=500 000\n\ +addMassPoint=(10,29)\n\ +"); + } + if (bo::b4 && uihx != 0.f) { + settings->pause = true; + hx = uihx; + so_count =1; + horizontal = true; + addSoft = false; + addHard = false; + addFriction = false; + addElasticPlastic = false; + addRigidPlastic = true; + firstIsHinge = false; + openLists = true; + restartPending = true; + settings->addMassPoint = b2Vec2(10, 29); + settings->addMass = 500000; + } } } diff --git a/ep/ep/Main.cpp b/ep/ep/Main.cpp index 2812ca029..85c83192f 100644 --- a/ep/ep/Main.cpp +++ b/ep/ep/Main.cpp @@ -704,6 +704,18 @@ static void sInterface() settings.addRigidTriangles = false; settings.addEPBeams = false; } + if (ImGui::Button("Add at @")) { + b2Vec2 p; + test->AddMass(settings.addMassPoint); + } + ImGui::SameLine(); + float mv[2]; + mv[0] = settings.addMassPoint.x; + mv[1] = settings.addMassPoint.y; + if (ImGui::InputFloat2("", mv,3)) { + settings.addMassPoint.x = mv[0]; + settings.addMassPoint.y = mv[1]; + } if (ImGui::IsItemHovered() && settings.addMasses) { ImGui::SetTooltip("Use ALT-MB1"); } @@ -962,7 +974,9 @@ int main(int, char**) ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar); if (opened){ ImGui::SetCursorPos(ImVec2(5, (float)g_camera.m_height - 20)); - ImGui::Text("%.1f ms, steppedTime=%.4f s", 1000.0 * frameTime, test->steppedTime); + b2Vec2 mp = test->GetMouseWorld(); + ImGui::Text("%.1f ms, steppedTime=%.4f s mouse @(%.3f,%.3f)", + 1000.0 * frameTime, test->steppedTime, mp.x,mp.y); } ImGui::End(); sSimulate(); diff --git a/ep/ep/Test.h b/ep/ep/Test.h index 5a210fc16..4dd7c8621 100644 --- a/ep/ep/Test.h +++ b/ep/ep/Test.h @@ -122,6 +122,7 @@ struct Settings bombMultiplier = 10; bombVelocity = b2Vec2(5, 0); bombSpawnPoint = b2Vec2(-0.5f*bombWidth, 0.5f*bombWidth); + addMassPoint = b2Vec2(0, 0); } float32 hz; float32 mouseJointForceScale; @@ -148,6 +149,7 @@ struct Settings float32 targetTime = 60; bool singleStep; bool addRigidTriangles, addMasses, addEPBeams,selectEPJoint; // using ALT-MB1 if active + b2Vec2 addMassPoint; float32 addMass = 1000000, addMassSize=2; bool initImpulses; float32 forceScale, momentScale; @@ -230,6 +232,7 @@ class Test : public b2ContactListener B2_NOT_USED(impulse); }; void ShiftOrigin(const b2Vec2& newOrigin); + b2Vec2 GetMouseWorld() { return m_mouseWorld; } // ep-start virtual void Ui(){}; virtual void UpdateCamera() {}; @@ -323,7 +326,7 @@ class Test : public b2ContactListener b2Vec2 m_bombSpawnPoint; bool m_bombSpawning; b2Vec2 m_bombVelocity; - b2Vec2 m_mouseWorld; + b2Vec2 m_mouseWorld=b2Vec2(0,0); int32 m_stepCount; b2Profile m_maxProfile;