summaryrefslogtreecommitdiff
path: root/Runtime/Dynamics/PhysicMaterial.h
blob: b31cded30be3ec23928b4066b6f9864ea63f7d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef DYNAMICSMATERIAL_H
#define DYNAMICSMATERIAL_H

#if ENABLE_PHYSICS
#include "Runtime/BaseClasses/NamedObject.h"
#include "Runtime/Math/Vector3.h"
#include "JointDescriptions.h"

class NxMaterial;

class PhysicMaterial : public NamedObject
{
	public:
	
	REGISTER_DERIVED_CLASS (PhysicMaterial, NamedObject)
	DECLARE_OBJECT_SERIALIZE (PhysicMaterial)
	
	PhysicMaterial (MemLabelId label, ObjectCreationMode mode);
	// ~PhysicMaterial (); declared-by-macro

	virtual bool MainThreadCleanup ();
	
	static void InitializeClass ();
	static void CleanupClass () {}

	float GetDynamicFriction () const;
	void SetDynamicFriction (float friction);

	float GetStaticFriction () const;
	void SetStaticFriction (float friction);
	
	void SetBounciness (float bounce);
	float GetBounciness () const;
	
	void SetFrictionDirection2 (Vector3f dir);
	Vector3f GetFrictionDirection2 () const;

	float GetStaticFriction2 () const;
	void SetStaticFriction2 (float fric);

	float GetDynamicFriction2 () const;
	void SetDynamicFriction2 (float fric);
	
	void SetSpring (const JointSpring& spring);
	JointSpring GetSpring () const;
	
	void SetUseSpring (bool use);
	bool GetUseSpring () const;
	
	int GetMaterialIndex () const { Assert(m_MaterialIndex > 0); return m_MaterialIndex; }
	
	virtual void Reset ();

	static PhysicMaterial& GetInstantiatedMaterial (PhysicMaterial* material, Object& owner);
	
	int GetFrictionCombine ();
	void SetFrictionCombine (int mode);

	int GetBounceCombine ();
	void SetBounceCombine (int mode);

	virtual void AwakeFromLoad (AwakeFromLoadMode awakeMode);
	
	private:
	
	void UpdateFrictionDirection2 ();
	Vector3f    m_FrictionDirection2;///< Friction 
	int m_FrictionCombine;///< enum { Average = 0, Minimum = 1, Multiply = 2, Maximum = 3 }
	int m_BounceCombine;///< enum { Average = 0, Minimum = 1, Multiply = 2, Maximum = 3 }
	float m_DynamicFriction;///< range { 0, 1 }
	float m_StaticFriction;///< range { 0, infinity }
	float m_Bounciness;///< range { 0, 1 }
	float m_DynamicFriction2;///< range { 0, 1 }
	float m_StaticFriction2;///< range { 0, infinity }

#if DOXYGEN
	Vector3f    frictionDirection2;///< Friction 
	int frictionCombine;///< enum { Average = 0, Minimum = 1, Multiply = 2, Maximum = 3 }
	int bounceCombine;///< enum { Average = 0, Minimum = 1, Multiply = 2, Maximum = 3 }
	float dynamicFriction;///< range { 0, 1 }
	float staticFriction;///< range { 0, infinity }
	float bounciness;///< range { 0, 1 }
	float dynamicFriction2;///< range { 0, 1 }
	float staticFriction2;///< range { 0, infinity }
#endif
	
	void CopyMaterialToDefault () const;
	bool IsDefaultMaterial ();
	void ChangedMaterial ();
			
	int m_MaterialIndex;
	NxMaterial* m_Material;
	PPtr<Object> m_Owner;
	
	friend class PhysicsManager;
};

#endif //ENABLE_PHYSICS
#endif