From 4315e6ec79b694b2a0b11a0dc48739ae9a412d63 Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Tue, 11 Oct 2022 17:50:31 +0200 Subject: [PATCH] Improvised Damping, looking good --- Content/Blueprints/BP_Puma.uasset | Bin 162289 -> 162289 bytes Content/Blueprints/BP_Robot.uasset | Bin 177011 -> 177184 bytes Content/Levels/Main.umap | Bin 636527 -> 636527 bytes Source/PBDRobotics/Joint.cpp | 58 ++++++++++++++++++----------- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Content/Blueprints/BP_Puma.uasset b/Content/Blueprints/BP_Puma.uasset index 8e8ca6991d2d1c0209079308e0a92aed8d5d4cf2..e28a1caf5bb42ddded1cb9fac6665c0cd8273d81 100644 GIT binary patch delta 58 zcmV-A0LB0D^9k|u39upo5EmbB{0i#hMx!0yr1(4O?t?M`hcW>Hw=w|&eQE&@x3Fsh QCIXkQYXY^mi*5pD3;pXCqyPW_ delta 58 zcmezPne*dk&J9Y80yQ;V*UiNwe40ceXSP+9R5lwiwi_`rZZ~3Ns?B0#*uEi~NsVdx O`fR4H+q?6a(zpSj^%V&K diff --git a/Content/Blueprints/BP_Robot.uasset b/Content/Blueprints/BP_Robot.uasset index 0a262c868693637dd667f6261f9d6949a6c46d77..2762e6de3cfd2ee017a142b67119df8e9e3d69bf 100644 GIT binary patch delta 1904 zcmZ9NdrTBZ9LI0w2OPa7WY`{f5Ue$6%kT1<)wL=#9feWXcGQe$Im3o&W5bKLCSrjuNycF(0ePktv=n zpakC!C?@5}vm{vHS{?WZKdb(F6NNFa-O7^eGVbV7FWp87jHE|tK^{KctH~txvO-vd zV#RIm8=Z`ApEfdK%e>Rq7jo&TGOjwKv4f4J61)~-DKPIy{yTw!(`y?Db-if>|2?R) z6ehYoqT4>CWiE_9(6${?gy_93dflp)C9xwJgvDl9vH6_Q@$>k^$b|WM=jKSr6=ll! zwa-HwIL=I_6^D<8TvV2fFBmw`>B_R=+%H0%pLyrHfdifTY%6a3GSr#K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?e4IOCXI2 z(Njxd?vO3@)Dd|5un;YE6q=3-i0t5Ood&5PeE$K!@Aa|F7oc$Eq^&U$&;WlbgrlB9 zf(en&x7Ta%rx4-k`lJWY*Wue6<1xw)-)(s9O`}OeijlJw#fRA>9$e8SZtP3MdragH zdXArw!;}qZ^z>UuNAZ2Vz2`#EeAY;4LusQ|+EC&GaFu>yoCzam$D%!GbkQFCtIK$H n0LL1C1o%t!08YODv@#A3;U&mvJU4)cjT3`-cJ$H^ej@H)!u4#g diff --git a/Content/Levels/Main.umap b/Content/Levels/Main.umap index 532bc84fa3155b70e229283dab7c62c170f373bf..938892a18d2af11ca2dcbe0d07f3d3f0d659c4af 100644 GIT binary patch delta 120 zcmaF=M(zC@wGC#B0&a(nR(xsp_n350b@Ri??B6!KF~0F+HL=h$HrZ_MZR^6Va=6)L z<@q_z3oK_(uJ1SE5W7FeneV%s^Q8Wg$s62wHm{y&%GjJYu|01hBM>tIF*6Xe05K~N RvjH(X5OZwLo5;zi3IMM+GM@kd delta 120 zcmaF=M(zC@wGC#B0w1?0zjHKpcAnu{epu#KxBg}~#y6g(OE z&RgYD%Q$m#eZLV$XZI>+)=AaQlln_0Z*b$;yn3Q3V{_ib_PmLVK+FWh%s|Wn#H>Kf Q2E^<@%&|RhA}6CN0M2DE>i_@% diff --git a/Source/PBDRobotics/Joint.cpp b/Source/PBDRobotics/Joint.cpp index e37b182..29def97 100644 --- a/Source/PBDRobotics/Joint.cpp +++ b/Source/PBDRobotics/Joint.cpp @@ -109,32 +109,48 @@ void UJoint::SolvePosition(const double H) const{ void UJoint::SolveVelocity(const double H) const{ ULink* L1 = FirstLink; ULink* L2 = SecondLink; - - // Damping - const Vector3d V1 = L1->Velocity; - const Vector3d V2 = L2->Velocity; - constexpr double MuLin = 10000; // Damping strength - const Vector3d DeltaV = (V2 - V1) * (MuLin * H < 1 ? MuLin * H : 1); - - const Vector3d R1 = GetFirstWorldDirection(); - const Vector3d R2 = GetSecondWorldDirection(); - const Vector3d N = (R2 - R1).normalized(); + // Positional Damping + { + const Vector3d V1 = L1->Velocity; + const Vector3d V2 = L2->Velocity; - const Matrix3d I1 = L1->GetInertia(); - const Matrix3d I2 = L2->GetInertia(); + const Vector3d R1 = GetFirstWorldDirection(); + const Vector3d R2 = GetSecondWorldDirection(); - const double W1 = L1->GetPositionalInverseMass(R1, N); - const double W2 = L2->GetPositionalInverseMass(R2, N); + constexpr double MuLin = 1000; // Damping strength + const Vector3d DeltaV = (V2 - V1) * (MuLin * H < 1 ? MuLin * H : 1); + + const Vector3d N = GetConnection().normalized(); - const Vector3d P = DeltaV / (W1 + W2); - - //UE_LOG(LogTemp, Log, TEXT("%f | %f | %f | %f | %f"), P.norm(), MuLin * H, DeltaV.norm(), (V2 - V1).norm()); + const double W1 = L1->GetPositionalInverseMass(R1, N); + const double W2 = L2->GetPositionalInverseMass(R2, N); + + const Vector3d P = DeltaV / (W1 + W2); - //L1->Velocity += P / L1->Mass; - //L2->Velocity -= P / L2->Mass; - //L1->AngularVelocity += I1.inverse() * R1.cross(P); - //L2->AngularVelocity -= I2.inverse() * R2.cross(P); + //L1->Velocity += P / L1->Mass; + //L2->Velocity -= P / L2->Mass; + + const Matrix3d I1 = L1->GetInertia(); + const Matrix3d I2 = L2->GetInertia(); + + //L1->AngularVelocity += I1.inverse() * R1.cross(P); + //L2->AngularVelocity -= I2.inverse() * R2.cross(P); + + constexpr double Damp = 1 - 1. / 1000; + + L1->Velocity *= Damp; + L2->Velocity *= Damp; + L1->AngularVelocity *= Damp; + L2->AngularVelocity *= Damp; + } + // Rotational Damping + { + //constexpr double MuAng = 10000; + //const Vector3d DeltaWV = (WV2 - WV1) * (MuAng * H < 1 ? MuAng * H : 1); + + + } } UJoint::UJoint()