Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BodyCreationSettings.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
15
17
18class StreamIn;
19class StreamOut;
20
23{
27};
28
31{
32public:
34
35
37 BodyCreationSettings(const ShapeSettings *inShape, RVec3Arg inPosition, QuatArg inRotation, EMotionType inMotionType, ObjectLayer inObjectLayer) : mPosition(inPosition), mRotation(inRotation), mObjectLayer(inObjectLayer), mMotionType(inMotionType), mShape(inShape) { }
38 BodyCreationSettings(const Shape *inShape, RVec3Arg inPosition, QuatArg inRotation, EMotionType inMotionType, ObjectLayer inObjectLayer) : mPosition(inPosition), mRotation(inRotation), mObjectLayer(inObjectLayer), mMotionType(inMotionType), mShapePtr(inShape) { }
39
41 const ShapeSettings * GetShapeSettings() const { return mShape; }
42 void SetShapeSettings(const ShapeSettings *inShape) { mShape = inShape; mShapePtr = nullptr; }
43
45 Shape::ShapeResult ConvertShapeSettings();
46
48 const Shape * GetShape() const;
49 void SetShape(const Shape *inShape) { mShapePtr = inShape; mShape = nullptr; }
50
52 bool HasMassProperties() const { return mAllowDynamicOrKinematic || mMotionType != EMotionType::Static; }
53
55 MassProperties GetMassProperties() const;
56
58 void SaveBinaryState(StreamOut &inStream) const;
59
61 void RestoreBinaryState(StreamIn &inStream);
62
69
73 void SaveWithChildren(StreamOut &inStream, ShapeToIDMap *ioShapeMap, MaterialToIDMap *ioMaterialMap, GroupFilterToIDMap *ioGroupFilterMap) const;
74
76
78 static BCSResult sRestoreWithChildren(StreamIn &inStream, IDToShapeMap &ioShapeMap, IDToMaterialMap &ioMaterialMap, IDToGroupFilterMap &ioGroupFilterMap);
79
80 RVec3 mPosition = RVec3::sZero();
81 Quat mRotation = Quat::sIdentity();
82 Vec3 mLinearVelocity = Vec3::sZero();
83 Vec3 mAngularVelocity = Vec3::sZero();
84
86 uint64 mUserData = 0;
87
89 ObjectLayer mObjectLayer = 0;
91
93 EMotionType mMotionType = EMotionType::Dynamic;
94 EAllowedDOFs mAllowedDOFs = EAllowedDOFs::All;
95 bool mAllowDynamicOrKinematic = false;
96 bool mIsSensor = false;
97 bool mSensorDetectsStatic = false;
98 bool mUseManifoldReduction = true;
99 EMotionQuality mMotionQuality = EMotionQuality::Discrete;
100 bool mAllowSleeping = true;
101 float mFriction = 0.2f;
102 float mRestitution = 0.0f;
103 float mLinearDamping = 0.05f;
104 float mAngularDamping = 0.05f;
105 float mMaxLinearVelocity = 500.0f;
106 float mMaxAngularVelocity = 0.25f * JPH_PI * 60.0f;
107 float mGravityFactor = 1.0f;
108
110 EOverrideMassProperties mOverrideMassProperties = EOverrideMassProperties::CalculateMassAndInertia;
111 float mInertiaMultiplier = 1.0f;
113
114private:
117 RefConst<Shape> mShapePtr;
118};
119
EAllowedDOFs
Enum used in BodyCreationSettings and MotionProperties to indicate which degrees of freedom a body ha...
Definition: AllowedDOFs.h:11
EOverrideMassProperties
Enum used in BodyCreationSettings to indicate how mass and inertia should be calculated.
Definition: BodyCreationSettings.h:23
@ CalculateInertia
Tells the system to take the mass from mMassPropertiesOverride and to calculate the inertia based on ...
@ MassAndInertiaProvided
Tells the system to take the mass and inertia from mMassPropertiesOverride.
@ CalculateMassAndInertia
Tells the system to calculate the mass and inertia based on density.
std::uint8_t uint8
Definition: Core.h:427
#define JPH_EXPORT
Definition: Core.h:214
std::uint64_t uint64
Definition: Core.h:430
#define JPH_NAMESPACE_END
Definition: Core.h:354
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:348
EMotionQuality
Motion quality, or how well it detects collisions when it has a high velocity.
Definition: MotionQuality.h:11
EMotionType
Motion type of a physics body.
Definition: MotionType.h:11
uint16 ObjectLayer
Definition: ObjectLayer.h:16
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, class_name)
Definition: SerializableObject.h:71
Settings for constructing a rigid body.
Definition: BodyCreationSettings.h:31
StreamUtils::IDToObjectMap< GroupFilter > IDToGroupFilterMap
Definition: BodyCreationSettings.h:64
void SetShape(const Shape *inShape)
Definition: BodyCreationSettings.h:49
StreamUtils::ObjectToIDMap< GroupFilter > GroupFilterToIDMap
Definition: BodyCreationSettings.h:63
StreamUtils::ObjectToIDMap< PhysicsMaterial > MaterialToIDMap
Definition: BodyCreationSettings.h:67
const ShapeSettings * GetShapeSettings() const
Access to the shape settings object. This contains serializable (non-runtime optimized) information a...
Definition: BodyCreationSettings.h:41
Shape::IDToShapeMap IDToShapeMap
Definition: BodyCreationSettings.h:66
BodyCreationSettings(const Shape *inShape, RVec3Arg inPosition, QuatArg inRotation, EMotionType inMotionType, ObjectLayer inObjectLayer)
Definition: BodyCreationSettings.h:38
bool HasMassProperties() const
Check if the mass properties of this body will be calculated (only relevant for kinematic or dynamic ...
Definition: BodyCreationSettings.h:52
StreamUtils::IDToObjectMap< PhysicsMaterial > IDToMaterialMap
Definition: BodyCreationSettings.h:68
CollisionGroup mCollisionGroup
The collision group this body belongs to (determines if two objects can collide)
Definition: BodyCreationSettings.h:90
Shape::ShapeToIDMap ShapeToIDMap
Definition: BodyCreationSettings.h:65
MassProperties mMassPropertiesOverride
Contains replacement mass settings which override the automatically calculated values.
Definition: BodyCreationSettings.h:112
void SetShapeSettings(const ShapeSettings *inShape)
Definition: BodyCreationSettings.h:42
Definition: CollisionGroup.h:20
Describes the mass and inertia properties of a body. Used during body construction only.
Definition: MassProperties.h:16
Definition: Quat.h:33
static JPH_INLINE Quat sIdentity()
Definition: Quat.h:103
Definition: Reference.h:151
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition: Shape.h:174
StreamUtils::IDToObjectMap< Shape > IDToShapeMap
Definition: Shape.h:378
StreamUtils::ObjectToIDMap< Shape > ShapeToIDMap
Definition: Shape.h:377
Definition: Shape.h:139
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13
Definition: Vec3.h:16
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107
Array< Ref< Type > > IDToObjectMap
Definition: StreamUtils.h:21
UnorderedMap< const Type *, uint32 > ObjectToIDMap
Definition: StreamUtils.h:18