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{
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
95 bool mAllowDynamicOrKinematic = false;
96 bool mIsSensor = false;
97 bool mCollideKinematicVsNonDynamic = false;
98 bool mUseManifoldReduction = true;
99 bool mApplyGyroscopicForce = false;
101 bool mEnhancedInternalEdgeRemoval = false;
102 bool mAllowSleeping = true;
103 float mFriction = 0.2f;
104 float mRestitution = 0.0f;
105 float mLinearDamping = 0.05f;
106 float mAngularDamping = 0.05f;
107 float mMaxLinearVelocity = 500.0f;
108 float mMaxAngularVelocity = 0.25f * JPH_PI * 60.0f;
109 float mGravityFactor = 1.0f;
110 uint mNumVelocityStepsOverride = 0;
111 uint mNumPositionStepsOverride = 0;
112
115 float mInertiaMultiplier = 1.0f;
117
118private:
121 RefConst<Shape> mShapePtr;
122};
123
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:449
#define JPH_EXPORT
Definition Core.h:236
std::uint64_t uint64
Definition Core.h:452
unsigned int uint
Definition Core.h:448
#define JPH_NAMESPACE_END
Definition Core.h:377
#define JPH_NAMESPACE_BEGIN
Definition Core.h:371
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: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
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
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:116
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:178
StreamUtils::IDToObjectMap< Shape > IDToShapeMap
Definition Shape.h:382
StreamUtils::ObjectToIDMap< Shape > ShapeToIDMap
Definition Shape.h:381
Definition Shape.h:139
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:107
UnorderedMap< const Type *, uint32 > ObjectToIDMap
Definition StreamUtils.h:18