6#include <glm/gtc/constants.hpp>
8#include "system/physics/solver/solver.h"
10namespace Vkm::Engine::SolverMath {
19inline glm::vec3 velocityAt(
const PhysicsBody& body,
const glm::vec3& r) {
20 return body.linearVelocity + glm::cross(body.angularVelocity, r);
31inline void applyImpulse(PhysicsBody& body,
const glm::vec3& impulse,
const glm::vec3& r,
float sign) {
32 body.linearVelocity += impulse * (body.invMass * sign);
33 body.angularVelocity += body.invInertiaWorld * glm::cross(r, impulse * sign);
48inline float effectiveMass(
53 const glm::vec3& direction
55 const glm::vec3 crossA = glm::cross(rA, direction);
56 const glm::vec3 crossB = glm::cross(rB, direction);
57 const float k = a.invMass + b.invMass
58 + glm::dot(crossA, a.invInertiaWorld * crossA)
59 + glm::dot(crossB, b.invInertiaWorld * crossB);
60 return k > 0.0f ? 1.0f / k : 0.0f;
71 float biasRate = 0.0f;
72 float massScale = 1.0f;
73 float impulseScale = 0.0f;
84inline SoftConstraint softness(
float hertz,
float damping,
float dt) {
85 if (dt <= 0.0f)
return {};
87 const float clamped = std::min(hertz, 0.5f / dt);
88 const float omega = 2.0f * glm::pi<float>() * clamped;
89 const float a1 = 2.0f * damping + dt * omega;
90 const float a2 = dt * omega * a1;
91 const float a3 = 1.0f / (1.0f + a2);
92 return SoftConstraint{omega / a1, a2 * a3, a3};
The three numbers that make a correction a stiff, damped spring.
Definition solver_math.h:70