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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
#ifndef COLLIDER_H
#define COLLIDER_H
#include "Runtime/BaseClasses/GameObject.h"
#include "Runtime/Geometry/AABB.h"
#include "Runtime/Profiler/Profiler.h"
class Transform;
class Matrix4x4f;
class Vector3f;
class Rigidbody;
class NxShape;
class NxShapeDesc;
class NxCCDSkeleton;
class PhysicMaterial;
namespace Unity { class InteractiveCloth; }
struct RaycastHit;
class Ray;
#if ENABLE_PROFILER
#define PROFILE_MODIFY_STATIC_COLLIDER if (m_Shape && m_Shape->getActor ().userData == NULL) { PROFILER_AUTO(gStaticColliderModify, this); }
extern ProfilerInformation gStaticColliderModify;
extern ProfilerInformation gStaticColliderMove;
extern ProfilerInformation gStaticColliderCreate;
extern ProfilerInformation gDynamicColliderCreate;
#else
#define PROFILE_MODIFY_STATIC_COLLIDER
#endif
class Collider : public Unity::Component
{
public:
REGISTER_DERIVED_ABSTRACT_CLASS (Collider, Component)
DECLARE_OBJECT_SERIALIZE (Collider)
Collider (MemLabelId label, ObjectCreationMode mode);
// virtual ~Collider (); declared-in-macro
virtual void Deactivate (DeactivateOperation operation);
virtual void AwakeFromLoad(AwakeFromLoadMode mode);
/// Enable or disable updates of this behaviour
virtual void SetEnabled (bool enab);
bool GetEnabled () const { return m_Enabled; }
virtual bool SupportsMaterial () const { return true; }
PPtr<PhysicMaterial> GetMaterial ();
void SetMaterial (PPtr<PhysicMaterial> material);
virtual void SetIsTrigger (bool trigger);
bool GetIsTrigger () { return m_IsTrigger; }
Rigidbody* GetRigidbody ();
static void InitializeClass ();
static void CleanupClass () {}
void SetupLayer ();
virtual void SupportedMessagesDidChange (int supported);
virtual AABB GetBounds ();
void ClosestPointOnBounds (const Vector3f& position, Vector3f& outPosition, float& outSqrDistance);
void SetupIgnoreLayer ();
bool Raycast (const Ray& ray, float distance, RaycastHit& outHit);
public:
// SUBCLASSES OVERRIDE THIS
virtual void Create (const Rigidbody* ignoreAttachRigidbody) = 0;
virtual void ScaleChanged () = 0;
virtual void Cleanup ();
virtual void ReCreate();
void CreateWithoutIgnoreAttach ();
NxShape* CreateShapeIfNeeded();
// Testing API
NxShape* GetShape() { return m_Shape; }
protected:
enum { kForceUpdateMass = 1 << 31 };
virtual bool GetRelativeToParentPositionAndRotation (Transform& transform, Transform& anyParent, Matrix4x4f& matrix);
static bool GetRelativeToParentPositionAndRotationUtility (Transform& transform, Transform& anyParent, const Vector3f& localOffset, Matrix4x4f& matrix);
bool HasActorRigidbody ();
int GetMaterialIndex ();
void RecreateCollider (const Rigidbody* ignoreRigidbody);
virtual void TransformChanged (int changeMask);
virtual void FetchPoseFromTransform ();
void FetchPoseFromTransformUtility (const Vector3f& offset);
void FinalizeCreate( NxShapeDesc& shape, bool dontSetMaterial, const Rigidbody* dontAttachToRigidbody );
virtual NxCCDSkeleton* CreateCCDSkeleton(float scale) { return NULL; }
NxCCDSkeleton* CreateCCDSkeleton();
void UpdateCCDSkeleton();
void RigidbodyMassDistributionChanged ();
#if UNITY_EDITOR
void RefreshPhysicsInEditMode();
#else
void RefreshPhysicsInEditMode() {}
#endif
/// Finds the rigid body we want this collider to attach to.
/// If this returns null the collider will create a kinematic actor.
Rigidbody* FindNewAttachedRigidbody (const Rigidbody* ignoreAttachRigidbody);
PPtr<PhysicMaterial> m_Material;
NxShape* m_Shape;
bool m_IsTrigger;
bool m_Enabled;
friend class Rigidbody;
friend class Unity::InteractiveCloth;
friend class PhysicsManager;
};
/*
PhysicMaterial& GetInstantiatedMaterial ()
{
PhysicMaterial* material = m_Material;
if (material)
{
if (material->m_Owner == PPtr<Object> (this))
return material;
}
else
{
material = new PhysicMaterial ();
material->Reset ();
material->m_Owner = this;
m_Material = material;
}
}*/
struct MonoContactPoint
{
Vector3f point;
Vector3f normal;
ScriptingObjectPtr thisCollider;
ScriptingObjectPtr otherCollider;
};
struct MonoCollision
{
Vector3f relativeVelocity;
ScriptingObjectPtr rigidbody;
ScriptingObjectPtr collider;
ScriptingArrayPtr contacts;
};
struct Collision;
ScriptingObjectPtr ConvertContactToMono (Collision* input);
#endif
|