diff options
Diffstat (limited to 'libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionObject.cs')
-rw-r--r-- | libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionObject.cs | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionObject.cs b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionObject.cs new file mode 100644 index 0000000..4e9cf58 --- /dev/null +++ b/libraries/ModifiedBulletX/ModifiedBulletX/Collision/CollisionDispatch/CollisionObject.cs | |||
@@ -0,0 +1,163 @@ | |||
1 | /* | ||
2 | Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru | ||
3 | Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com | ||
4 | |||
5 | This software is provided 'as-is', without any express or implied | ||
6 | warranty. In no event will the authors be held liable for any damages | ||
7 | arising from the use of this software. | ||
8 | |||
9 | Permission is granted to anyone to use this software for any purpose, | ||
10 | including commercial applications, and to alter it and redistribute it | ||
11 | freely, subject to the following restrictions: | ||
12 | |||
13 | 1. The origin of this software must not be misrepresented; you must not | ||
14 | claim that you wrote the original software. If you use this software | ||
15 | in a product, an acknowledgment in the product documentation would be | ||
16 | appreciated but is not required. | ||
17 | 2. Altered source versions must be plainly marked as such, and must not be | ||
18 | misrepresented as being the original software. | ||
19 | 3. This notice may not be removed or altered from any source distribution. | ||
20 | */ | ||
21 | |||
22 | using System; | ||
23 | using System.Collections.Generic; | ||
24 | using System.Text; | ||
25 | using MonoXnaCompactMaths; | ||
26 | |||
27 | namespace XnaDevRu.BulletX | ||
28 | { | ||
29 | public enum ActivationState | ||
30 | { | ||
31 | Nothing = 0, | ||
32 | Active, | ||
33 | IslandSleeping, | ||
34 | WantsDeactivation, | ||
35 | DisableDeactivation, | ||
36 | DisableSimulation, | ||
37 | } | ||
38 | |||
39 | public enum CollisionOptions | ||
40 | { | ||
41 | StaticObject = 1, | ||
42 | KinematicObject = 2, | ||
43 | NoContactResponse = 4, | ||
44 | CustomMaterialCallback = 8,//this allows per-triangle material (friction/restitution) | ||
45 | } | ||
46 | |||
47 | /// <summary> | ||
48 | /// btCollisionObject can be used to manage collision detection objects. | ||
49 | /// btCollisionObject maintains all information that is needed for a collision detection: Shape, Transform and AABB proxy. | ||
50 | /// They can be added to the btCollisionWorld. | ||
51 | /// </summary> | ||
52 | public class CollisionObject | ||
53 | { | ||
54 | protected Matrix _worldTransform; | ||
55 | private BroadphaseProxy _broadphase; | ||
56 | private CollisionShape _collisionShape; | ||
57 | |||
58 | //m_interpolationWorldTransform is used for CCD and interpolation | ||
59 | //it can be either previous or future (predicted) transform | ||
60 | private Matrix _interpolationWorldTransform; | ||
61 | |||
62 | private CollisionOptions _collisionFlags; | ||
63 | |||
64 | private int _islandTag; | ||
65 | private ActivationState _activationState; | ||
66 | private float _deactivationTime; | ||
67 | |||
68 | private float _friction; | ||
69 | private float _restitution; | ||
70 | |||
71 | //users can point to their objects, m_userPointer is not used by Bullet | ||
72 | private object _userData; | ||
73 | |||
74 | //m_internalOwner one is used by optional Bullet high level interface | ||
75 | private object _internalOwner; | ||
76 | |||
77 | //time of impact calculation | ||
78 | private float _hitFraction; | ||
79 | |||
80 | //Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm:: | ||
81 | private float _ccdSweptSphereRadius; | ||
82 | |||
83 | // Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionTreshold | ||
84 | private float _ccdSquareMotionThreshold; | ||
85 | //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities) | ||
86 | //without destroying the continuous interpolated motion (which uses this interpolation velocities) | ||
87 | private Vector3 _interpolationLinearVelocity; | ||
88 | private Vector3 _interpolationAngularVelocity; | ||
89 | |||
90 | private int _companionID; | ||
91 | |||
92 | public CollisionObject() | ||
93 | { | ||
94 | _activationState = ActivationState.Active; | ||
95 | _hitFraction = 1; | ||
96 | } | ||
97 | |||
98 | public bool IsStaticObject { get { return (_collisionFlags & CollisionOptions.StaticObject) != 0; } } | ||
99 | public bool IsKinematicObject { get { return (_collisionFlags & CollisionOptions.KinematicObject) != 0; } } | ||
100 | public bool IsStaticOrKinematicObject { get { return (_collisionFlags & (CollisionOptions.KinematicObject | CollisionOptions.StaticObject)) != 0; } } | ||
101 | |||
102 | public bool HasContactResponse { get { return (_collisionFlags & CollisionOptions.NoContactResponse) == 0; } } | ||
103 | public bool MergesSimulationIslands | ||
104 | { | ||
105 | get | ||
106 | { | ||
107 | //static objects, kinematic and object without contact response don't merge islands | ||
108 | return (_collisionFlags & (CollisionOptions.StaticObject | CollisionOptions.KinematicObject | CollisionOptions.NoContactResponse)) == 0; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | public ActivationState ActivationState | ||
113 | { | ||
114 | get { return _activationState; } | ||
115 | set | ||
116 | { | ||
117 | if ((_activationState != ActivationState.DisableDeactivation) && (_activationState != ActivationState.DisableSimulation)) | ||
118 | _activationState = value; | ||
119 | } | ||
120 | } | ||
121 | |||
122 | public bool IsActive { get { return ((ActivationState != ActivationState.IslandSleeping) && (ActivationState != ActivationState.DisableSimulation)); } } | ||
123 | public float Restitution { get { return _restitution; } set { _restitution = value; } } | ||
124 | public float Friction { get { return _friction; } set { _friction = value; } } | ||
125 | public CollisionShape CollisionShape { get { return _collisionShape; } set { _collisionShape = value; } } | ||
126 | public float DeactivationTime { get { return _deactivationTime; } set { _deactivationTime = value; } } | ||
127 | public object Owner { get { return _internalOwner; } protected set { _internalOwner = value; } } | ||
128 | public Matrix WorldTransform { get { return _worldTransform; } set { _worldTransform = value; } } | ||
129 | public BroadphaseProxy Broadphase { get { return _broadphase; } set { _broadphase = value; } } | ||
130 | public Matrix InterpolationWorldTransform { get { return _interpolationWorldTransform; } set { _interpolationWorldTransform = value; } } | ||
131 | public Vector3 InterpolationLinearVelocity { get { return _interpolationLinearVelocity; } protected set { _interpolationLinearVelocity = value; } } | ||
132 | public Vector3 InterpolationAngularVelocity { get { return _interpolationAngularVelocity; } protected set { _interpolationAngularVelocity = value; } } | ||
133 | public int IslandTag { get { return _islandTag; } set { _islandTag = value; } } | ||
134 | public float HitFraction { get { return _hitFraction; } set { _hitFraction = value; } } | ||
135 | public CollisionOptions CollisionFlags { get { return _collisionFlags; } set { _collisionFlags = value; } } | ||
136 | //Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm | ||
137 | public float CcdSweptSphereRadius { get { return _ccdSweptSphereRadius; } set { _ccdSweptSphereRadius = value; } } | ||
138 | // Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionThreshold | ||
139 | public float CcdSquareMotionThreshold { get { return _ccdSquareMotionThreshold; } set { _ccdSquareMotionThreshold = value; } } | ||
140 | //users can point to their objects, userPointer is not used by Bullet | ||
141 | public object UserData { get { return _userData; } set { _userData = value; } } | ||
142 | public int CompanionID { get { return _companionID; } set { _companionID = value; } } | ||
143 | |||
144 | public void ForceActivationState(ActivationState newState) | ||
145 | { | ||
146 | _activationState = newState; | ||
147 | } | ||
148 | |||
149 | public void Activate() | ||
150 | { | ||
151 | Activate(false); | ||
152 | } | ||
153 | |||
154 | public void Activate(bool forceActivation) | ||
155 | { | ||
156 | if (forceActivation || (_collisionFlags & (CollisionOptions.StaticObject | CollisionOptions.KinematicObject)) == 0) | ||
157 | { | ||
158 | ActivationState = ActivationState.Active; | ||
159 | _deactivationTime = 0; | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | } | ||