Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/PhysicsMaterial.h
22413 views
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
7
#include <Jolt/Core/Reference.h>
8
#include <Jolt/Core/Color.h>
9
#include <Jolt/Core/Result.h>
10
#include <Jolt/ObjectStream/SerializableObject.h>
11
12
JPH_NAMESPACE_BEGIN
13
14
class StreamIn;
15
class StreamOut;
16
17
/// This structure describes the surface of (part of) a shape. You should inherit from it to define additional
18
/// information that is interesting for the simulation. The 2 materials involved in a contact could be used
19
/// to decide which sound or particle effects to play.
20
///
21
/// If you inherit from this material, don't forget to create a suitable default material in sDefault
22
class JPH_EXPORT PhysicsMaterial : public SerializableObject, public RefTarget<PhysicsMaterial>
23
{
24
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, PhysicsMaterial)
25
26
public:
27
/// Constructor
28
PhysicsMaterial() = default;
29
virtual ~PhysicsMaterial() override = default;
30
31
/// Default material that is used when a shape has no materials defined
32
static RefConst<PhysicsMaterial> sDefault;
33
34
// Properties
35
virtual const char * GetDebugName() const { return "Unknown"; }
36
virtual Color GetDebugColor() const { return Color::sGrey; }
37
38
/// Saves the contents of the material in binary form to inStream.
39
virtual void SaveBinaryState(StreamOut &inStream) const;
40
41
using PhysicsMaterialResult = Result<Ref<PhysicsMaterial>>;
42
43
/// Creates a PhysicsMaterial of the correct type and restores its contents from the binary stream inStream.
44
static PhysicsMaterialResult sRestoreFromBinaryState(StreamIn &inStream);
45
46
protected:
47
/// Don't allow copy constructing this base class, but allow derived classes to copy themselves
48
PhysicsMaterial(const PhysicsMaterial &) = default;
49
PhysicsMaterial & operator = (const PhysicsMaterial &) = default;
50
51
/// This function should not be called directly, it is used by sRestoreFromBinaryState.
52
virtual void RestoreBinaryState(StreamIn &inStream);
53
};
54
55
using PhysicsMaterialList = Array<RefConst<PhysicsMaterial>>;
56
57
JPH_NAMESPACE_END
58
59