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
28
31{
33
34public:
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 bool operator == (const BodyCreationSettings &inRHS) const;
42 bool operator != (const BodyCreationSettings &inRHS) const { return !(*this == inRHS); }
43
45 const ShapeSettings * GetShapeSettings() const { return mShape; }
46 void SetShapeSettings(const ShapeSettings *inShape) { mShape = inShape; mShapePtr = nullptr; }
47
49 Shape::ShapeResult ConvertShapeSettings();
50
52 const Shape * GetShape() const;
53 void SetShape(const Shape *inShape) { mShapePtr = inShape; mShape = nullptr; }
54
57
59 MassProperties GetMassProperties() const;
60
62 void SaveBinaryState(StreamOut &inStream) const;
63
65 void RestoreBinaryState(StreamIn &inStream);
66
73
77 void SaveWithChildren(StreamOut &inStream, ShapeToIDMap *ioShapeMap, MaterialToIDMap *ioMaterialMap, GroupFilterToIDMap *ioGroupFilterMap) const;
78
80
82 static BCSResult sRestoreWithChildren(StreamIn &inStream, IDToShapeMap &ioShapeMap, IDToMaterialMap &ioMaterialMap, IDToGroupFilterMap &ioGroupFilterMap);
83
88
91
95
100 bool mIsSensor = false;
106 bool mAllowSleeping = true;
107 float mFriction = 0.2f;
108 float mRestitution = 0.0f;
109 float mLinearDamping = 0.05f;
110 float mAngularDamping = 0.05f;
111 float mMaxLinearVelocity = 500.0f;
112 float mMaxAngularVelocity = 0.25f * JPH_PI * 60.0f;
113 float mGravityFactor = 1.0f;
116
119 float mInertiaMultiplier = 1.0f;
121
122private:
125 RefConst<Shape> mShapePtr;
126};
127
EAllowedDOFs
Enum used in BodyCreationSettings and MotionProperties to indicate which degrees of freedom a body ha...
Definition AllowedDOFs.h:11
@ All
All degrees of freedom are allowed.
Definition AllowedDOFs.h:13
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 ...
Definition BodyCreationSettings.h:25
@ MassAndInertiaProvided
Tells the system to take the mass and inertia from mMassPropertiesOverride.
Definition BodyCreationSettings.h:26
@ CalculateMassAndInertia
Tells the system to calculate the mass and inertia based on density.
Definition BodyCreationSettings.h:24
std::uint8_t uint8
Definition Core.h:547
#define JPH_EXPORT
Definition Core.h:286
std::uint64_t uint64
Definition Core.h:551
unsigned int uint
Definition Core.h:546
#define JPH_NAMESPACE_END
Definition Core.h:469
#define JPH_NAMESPACE_BEGIN
Definition Core.h:463
const Quat QuatArg
Definition MathTypes.h:28
EMotionQuality
Motion quality, or how well it detects collisions when it has a high velocity.
Definition MotionQuality.h:11
@ Discrete
Definition MotionQuality.h:14
EMotionType
Motion type of a physics body.
Definition MotionType.h:11
@ Static
Non movable.
Definition MotionType.h:12
@ Dynamic
Responds to forces as a normal physics object.
Definition MotionType.h:14
uint16 ObjectLayer
Definition ObjectLayer.h:16
Vec3Arg RVec3Arg
Definition Real.h:30
Vec3 RVec3
Definition Real.h:29
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:80
Settings for constructing a rigid body.
Definition BodyCreationSettings.h:31
StreamUtils::IDToObjectMap< GroupFilter > IDToGroupFilterMap
Definition BodyCreationSettings.h:68
void SetShape(const Shape *inShape)
Definition BodyCreationSettings.h:53
StreamUtils::ObjectToIDMap< GroupFilter > GroupFilterToIDMap
Definition BodyCreationSettings.h:67
void SaveWithChildren(StreamOut &inStream, ShapeToIDMap *ioShapeMap, MaterialToIDMap *ioMaterialMap, GroupFilterToIDMap *ioGroupFilterMap) const
Definition BodyCreationSettings.cpp:220
bool mAllowSleeping
If this body can go to sleep or not.
Definition BodyCreationSettings.h:106
StreamUtils::ObjectToIDMap< PhysicsMaterial > MaterialToIDMap
Definition BodyCreationSettings.h:71
Vec3 mLinearVelocity
World space linear velocity of the center of mass (m/s).
Definition BodyCreationSettings.h:86
const ShapeSettings * GetShapeSettings() const
Access to the shape settings object. This contains serializable (non-runtime optimized) information a...
Definition BodyCreationSettings.h:45
Shape::IDToShapeMap IDToShapeMap
Definition BodyCreationSettings.h:70
Vec3 mAngularVelocity
World space angular velocity (rad/s).
Definition BodyCreationSettings.h:87
Result< BodyCreationSettings > BCSResult
Definition BodyCreationSettings.h:79
bool mEnhancedInternalEdgeRemoval
Set to indicate that extra effort should be made to try to remove ghost contacts (collisions with int...
Definition BodyCreationSettings.h:105
float mGravityFactor
Value to multiply gravity with for this body.
Definition BodyCreationSettings.h:113
float mFriction
Friction of the body (dimensionless number, usually between 0 and 1, 0 = no friction,...
Definition BodyCreationSettings.h:107
float mInertiaMultiplier
When calculating the inertia (not when it is provided) the calculated inertia will be multiplied by t...
Definition BodyCreationSettings.h:119
bool mApplyGyroscopicForce
Set to indicate that the gyroscopic force should be applied to this body (aka Dzhanibekov effect,...
Definition BodyCreationSettings.h:103
bool mUseManifoldReduction
If this body should use manifold reduction (see description at Body::SetUseManifoldReduction).
Definition BodyCreationSettings.h:102
float mMaxLinearVelocity
Maximum linear velocity that this body can reach (m/s).
Definition BodyCreationSettings.h:111
EMotionQuality mMotionQuality
Motion quality, or how well it detects collisions when it has a high velocity.
Definition BodyCreationSettings.h:104
BodyCreationSettings(const ShapeSettings *inShape, RVec3Arg inPosition, QuatArg inRotation, EMotionType inMotionType, ObjectLayer inObjectLayer)
Definition BodyCreationSettings.h:37
RVec3 mPosition
Position of the body (not of the center of mass).
Definition BodyCreationSettings.h:84
BodyCreationSettings(const Shape *inShape, RVec3Arg inPosition, QuatArg inRotation, EMotionType inMotionType, ObjectLayer inObjectLayer)
Definition BodyCreationSettings.h:38
bool mCollideKinematicVsNonDynamic
If kinematic objects can generate contact points against other kinematic or static objects....
Definition BodyCreationSettings.h:101
uint mNumVelocityStepsOverride
Used only when this body is dynamic and colliding. Override for the number of solver velocity iterati...
Definition BodyCreationSettings.h:114
float mMaxAngularVelocity
Maximum angular velocity that this body can reach (rad/s).
Definition BodyCreationSettings.h:112
EAllowedDOFs mAllowedDOFs
Which degrees of freedom this body has (can be used to limit simulation to 2D).
Definition BodyCreationSettings.h:98
Quat mRotation
Rotation of the body.
Definition BodyCreationSettings.h:85
bool HasMassProperties() const
Check if the mass properties of this body will be calculated (only relevant for kinematic or dynamic ...
Definition BodyCreationSettings.h:56
ObjectLayer mObjectLayer
The collision layer this body belongs to (determines if two objects can collide).
Definition BodyCreationSettings.h:93
uint mNumPositionStepsOverride
Used only when this body is dynamic and colliding. Override for the number of solver position iterati...
Definition BodyCreationSettings.h:115
EOverrideMassProperties mOverrideMassProperties
Determines how mMassPropertiesOverride will be used.
Definition BodyCreationSettings.h:118
float mAngularDamping
Angular damping: dw/dt = -c * w. c. Value should be zero or positive and is usually close to 0.
Definition BodyCreationSettings.h:110
uint64 mUserData
User data value (can be used by application).
Definition BodyCreationSettings.h:90
float mLinearDamping
Linear damping: dv/dt = -c * v. c. Value should be zero or positive and is usually close to 0.
Definition BodyCreationSettings.h:109
static BCSResult sRestoreWithChildren(StreamIn &inStream, IDToShapeMap &ioShapeMap, IDToMaterialMap &ioMaterialMap, IDToGroupFilterMap &ioGroupFilterMap)
Restore body creation settings, its shape, materials and group filter. Pass in an empty map in ioShap...
Definition BodyCreationSettings.cpp:235
float mRestitution
Restitution of body (dimensionless number, usually between 0 and 1, 0 = completely inelastic collisio...
Definition BodyCreationSettings.h:108
bool mIsSensor
If this body is a sensor. A sensor will receive collision callbacks, but will not cause any collision...
Definition BodyCreationSettings.h:100
EMotionType mMotionType
Motion type, determines if the object is static, dynamic or kinematic.
Definition BodyCreationSettings.h:97
StreamUtils::IDToObjectMap< PhysicsMaterial > IDToMaterialMap
Definition BodyCreationSettings.h:72
CollisionGroup mCollisionGroup
The collision group this body belongs to (determines if two objects can collide).
Definition BodyCreationSettings.h:94
BodyCreationSettings()=default
Constructor.
Shape::ShapeToIDMap ShapeToIDMap
Definition BodyCreationSettings.h:69
MassProperties mMassPropertiesOverride
Contains replacement mass settings which override the automatically calculated values.
Definition BodyCreationSettings.h:120
void SetShapeSettings(const ShapeSettings *inShape)
Definition BodyCreationSettings.h:46
bool mAllowDynamicOrKinematic
When this body is created as static, this setting tells the system to create a MotionProperties objec...
Definition BodyCreationSettings.h:99
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:104
Definition Reference.h:166
Helper class that either contains a valid result or an error.
Definition Result.h:12
Base class for all shapes (collision volume of a body). Defines a virtual interface for collision det...
Definition Shape.h:185
StreamUtils::IDToObjectMap< Shape > IDToShapeMap
Definition Shape.h:393
ShapeSettings::ShapeResult ShapeResult
Definition Shape.h:189
StreamUtils::ObjectToIDMap< Shape > ShapeToIDMap
Definition Shape.h:392
Definition Shape.h:146
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13
Definition Vec3.h:17
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:125
UnorderedMap< const Type *, uint32 > ObjectToIDMap
Definition ObjectToIDMap.h:14
Array< Ref< Type > > IDToObjectMap
Definition ObjectToIDMap.h:17