Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/EstimateCollisionResponse.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2023 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/Collision/ContactListener.h>78JPH_NAMESPACE_BEGIN910/// A structure that contains the estimated contact and friction impulses and the resulting body velocities11struct CollisionEstimationResult12{13Vec3 mLinearVelocity1; ///< The estimated linear velocity of body 1 after collision14Vec3 mAngularVelocity1; ///< The estimated angular velocity of body 1 after collision15Vec3 mLinearVelocity2; ///< The estimated linear velocity of body 2 after collision16Vec3 mAngularVelocity2; ///< The estimated angular velocity of body 2 after collision1718Vec3 mTangent1; ///< Normalized tangent of contact normal19Vec3 mTangent2; ///< Second normalized tangent of contact normal (forms a basis with mTangent1 and mWorldSpaceNormal)2021struct Impulse22{23float mContactImpulse; ///< Estimated contact impulses (kg m / s)24float mFrictionImpulse1; ///< Estimated friction impulses in the direction of tangent 1 (kg m / s)25float mFrictionImpulse2; ///< Estimated friction impulses in the direction of tangent 2 (kg m / s)26};2728using Impulses = StaticArray<Impulse, ContactPoints::Capacity>;2930Impulses mImpulses;31};3233/// This function estimates the contact impulses and body velocity changes as a result of a collision.34/// It can be used in the ContactListener::OnContactAdded to determine the strength of the collision to e.g. play a sound or trigger a particle system.35/// This function is accurate when two bodies collide but will not be accurate when more than 2 bodies collide at the same time as it does not know about these other collisions.36///37/// @param inBody1 Colliding body 138/// @param inBody2 Colliding body 239/// @param inManifold The collision manifold40/// @param outResult A structure that contains the estimated contact and friction impulses and the resulting body velocities41/// @param inCombinedFriction The combined friction of body 1 and body 2 (see ContactSettings::mCombinedFriction)42/// @param inCombinedRestitution The combined restitution of body 1 and body 2 (see ContactSettings::mCombinedRestitution)43/// @param inMinVelocityForRestitution Minimal velocity required for restitution to be applied (see PhysicsSettings::mMinVelocityForRestitution)44/// @param inNumIterations Number of iterations to use for the impulse estimation (see PhysicsSettings::mNumVelocitySteps, note you can probably use a lower number for a decent estimate). If you set the number of iterations to 1 then no friction will be calculated.45JPH_EXPORT void EstimateCollisionResponse(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, CollisionEstimationResult &outResult, float inCombinedFriction, float inCombinedRestitution, float inMinVelocityForRestitution = 1.0f, uint inNumIterations = 10);4647JPH_NAMESPACE_END484950