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
56 bool HasMassProperties() const { return mAllowDynamicOrKinematic || mMotionType != EMotionType::Static; }
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
84 RVec3 mPosition = RVec3::sZero();
85 Quat mRotation = Quat::sIdentity();
86 Vec3 mLinearVelocity = Vec3::sZero();
87 Vec3 mAngularVelocity = Vec3::sZero();
88
90 uint64 mUserData = 0;
91
93 ObjectLayer mObjectLayer = 0;
95
99 bool mAllowDynamicOrKinematic = false;
100 bool mIsSensor = false;
101 bool mCollideKinematicVsNonDynamic = false;
102 bool mUseManifoldReduction = true;
103 bool mApplyGyroscopicForce = false;
105 bool mEnhancedInternalEdgeRemoval = 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;
114 uint mNumVelocityStepsOverride = 0;
115 uint mNumPositionStepsOverride = 0;
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.
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:511
#define JPH_EXPORT
Definition Core.h:283
std::uint64_t uint64
Definition Core.h:515
unsigned int uint
Definition Core.h:510
#define JPH_NAMESPACE_END
Definition Core.h:434
#define JPH_NAMESPACE_BEGIN
Definition Core.h:428
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
@ Static
Non movable.
@ Dynamic
Responds to forces as a normal physics object.
uint16 ObjectLayer
Definition ObjectLayer.h:16
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:80
Definition Array.h:36
Settings for constructing a rigid body.
Definition BodyCreationSettings.h:31
void SetShape(const Shape *inShape)
Definition BodyCreationSettings.h:53
const ShapeSettings * GetShapeSettings() const
Access to the shape settings object. This contains serializable (non-runtime optimized) information a...
Definition BodyCreationSettings.h:45
BodyCreationSettings(const ShapeSettings *inShape, RVec3Arg inPosition, QuatArg inRotation, EMotionType inMotionType, ObjectLayer inObjectLayer)
Definition BodyCreationSettings.h:37
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:56
CollisionGroup mCollisionGroup
The collision group this body belongs to (determines if two objects can collide)
Definition BodyCreationSettings.h:94
BodyCreationSettings()=default
Constructor.
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
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
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
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 UnorderedMap.h:31
Definition Vec3.h:17
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:125