Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/SoftBody/SoftBodyManifold.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2024 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/SoftBody/SoftBodyMotionProperties.h>78JPH_NAMESPACE_BEGIN910/// An interface to query which vertices of a soft body are colliding with other bodies11class SoftBodyManifold12{13public:14/// Get the vertices of the soft body for iterating15const Array<SoftBodyVertex> & GetVertices() const { return mVertices; }1617/// Check if a vertex has collided with something in this update18JPH_INLINE bool HasContact(const SoftBodyVertex &inVertex) const19{20return inVertex.mHasContact;21}2223/// Get the local space contact point (multiply by GetCenterOfMassTransform() of the soft body to get world space)24JPH_INLINE Vec3 GetLocalContactPoint(const SoftBodyVertex &inVertex) const25{26return inVertex.mPosition - inVertex.mCollisionPlane.SignedDistance(inVertex.mPosition) * inVertex.mCollisionPlane.GetNormal();27}2829/// Get the contact normal for the vertex (assumes there is a contact).30JPH_INLINE Vec3 GetContactNormal(const SoftBodyVertex &inVertex) const31{32return -inVertex.mCollisionPlane.GetNormal();33}3435/// Get the body with which the vertex has collided in this update36JPH_INLINE BodyID GetContactBodyID(const SoftBodyVertex &inVertex) const37{38return inVertex.mHasContact? mCollidingShapes[inVertex.mCollidingShapeIndex].mBodyID : BodyID();39}4041/// Get the number of sensors that are in contact with the soft body42JPH_INLINE uint GetNumSensorContacts() const43{44return (uint)mCollidingSensors.size();45}4647/// Get the i-th sensor that is in contact with the soft body48JPH_INLINE BodyID GetSensorContactBodyID(uint inIndex) const49{50return mCollidingSensors[inIndex].mBodyID;51}5253private:54/// Allow SoftBodyMotionProperties to construct us55friend class SoftBodyMotionProperties;5657/// Constructor58explicit SoftBodyManifold(const SoftBodyMotionProperties *inMotionProperties) :59mVertices(inMotionProperties->mVertices),60mCollidingShapes(inMotionProperties->mCollidingShapes),61mCollidingSensors(inMotionProperties->mCollidingSensors)62{63}6465using CollidingShape = SoftBodyMotionProperties::CollidingShape;66using CollidingSensor = SoftBodyMotionProperties::CollidingSensor;6768const Array<SoftBodyVertex> & mVertices;69const Array<CollidingShape> & mCollidingShapes;70const Array<CollidingSensor> & mCollidingSensors;71};7273JPH_NAMESPACE_END747576