diff options
author | Teravus Ovares | 2009-04-05 08:43:29 +0000 |
---|---|---|
committer | Teravus Ovares | 2009-04-05 08:43:29 +0000 |
commit | cf1e8b17237a7e4e5367e7bde887f97eba2547d8 (patch) | |
tree | 0c0fcd4b5473fdc5fedbd1c756dddc509d3e416f /OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs | |
parent | * Committing what I have on the BulletDotNETPlugin that I have so far. (diff) | |
download | opensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.zip opensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.tar.gz opensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.tar.bz2 opensim-SC_OLD-cf1e8b17237a7e4e5367e7bde887f97eba2547d8.tar.xz |
* Fixing SVN properties
Diffstat (limited to 'OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs | 2208 |
1 files changed, 1104 insertions, 1104 deletions
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs index 6791671..9f3349e 100644 --- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs +++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETCharacter.cs | |||
@@ -1,1104 +1,1104 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Reflection; | 2 | using System.Reflection; |
3 | using BulletDotNET; | 3 | using BulletDotNET; |
4 | using OpenMetaverse; | 4 | using OpenMetaverse; |
5 | using OpenSim.Framework; | 5 | using OpenSim.Framework; |
6 | using OpenSim.Region.Physics.Manager; | 6 | using OpenSim.Region.Physics.Manager; |
7 | using log4net; | 7 | using log4net; |
8 | 8 | ||
9 | namespace OpenSim.Region.Physics.BulletDotNETPlugin | 9 | namespace OpenSim.Region.Physics.BulletDotNETPlugin |
10 | { | 10 | { |
11 | public class BulletDotNETCharacter : PhysicsActor | 11 | public class BulletDotNETCharacter : PhysicsActor |
12 | { | 12 | { |
13 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 13 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
14 | 14 | ||
15 | public btRigidBody Body; | 15 | public btRigidBody Body; |
16 | public btCollisionShape Shell; | 16 | public btCollisionShape Shell; |
17 | public btVector3 tempVector1; | 17 | public btVector3 tempVector1; |
18 | public btVector3 tempVector2; | 18 | public btVector3 tempVector2; |
19 | public btVector3 tempVector3; | 19 | public btVector3 tempVector3; |
20 | public btVector3 tempVector4; | 20 | public btVector3 tempVector4; |
21 | 21 | ||
22 | public btVector3 tempVector5RayCast; | 22 | public btVector3 tempVector5RayCast; |
23 | public btVector3 tempVector6RayCast; | 23 | public btVector3 tempVector6RayCast; |
24 | public btVector3 tempVector7RayCast; | 24 | public btVector3 tempVector7RayCast; |
25 | 25 | ||
26 | public btQuaternion tempQuat1; | 26 | public btQuaternion tempQuat1; |
27 | public btTransform tempTrans1; | 27 | public btTransform tempTrans1; |
28 | 28 | ||
29 | public ClosestNotMeRayResultCallback ClosestCastResult; | 29 | public ClosestNotMeRayResultCallback ClosestCastResult; |
30 | private btTransform m_bodyTransform; | 30 | private btTransform m_bodyTransform; |
31 | private btVector3 m_bodyPosition; | 31 | private btVector3 m_bodyPosition; |
32 | private btVector3 m_CapsuleOrientationAxis; | 32 | private btVector3 m_CapsuleOrientationAxis; |
33 | private btQuaternion m_bodyOrientation; | 33 | private btQuaternion m_bodyOrientation; |
34 | private btDefaultMotionState m_bodyMotionState; | 34 | private btDefaultMotionState m_bodyMotionState; |
35 | private btGeneric6DofConstraint m_aMotor; | 35 | private btGeneric6DofConstraint m_aMotor; |
36 | private PhysicsVector m_movementComparision; | 36 | private PhysicsVector m_movementComparision; |
37 | private PhysicsVector m_position; | 37 | private PhysicsVector m_position; |
38 | private PhysicsVector m_zeroPosition; | 38 | private PhysicsVector m_zeroPosition; |
39 | private bool m_zeroFlag = false; | 39 | private bool m_zeroFlag = false; |
40 | private bool m_lastUpdateSent = false; | 40 | private bool m_lastUpdateSent = false; |
41 | private PhysicsVector m_velocity; | 41 | private PhysicsVector m_velocity; |
42 | private PhysicsVector m_target_velocity; | 42 | private PhysicsVector m_target_velocity; |
43 | private PhysicsVector m_acceleration; | 43 | private PhysicsVector m_acceleration; |
44 | private PhysicsVector m_rotationalVelocity; | 44 | private PhysicsVector m_rotationalVelocity; |
45 | private bool m_pidControllerActive = true; | 45 | private bool m_pidControllerActive = true; |
46 | public float PID_D = 80.0f; | 46 | public float PID_D = 80.0f; |
47 | public float PID_P = 90.0f; | 47 | public float PID_P = 90.0f; |
48 | public float CAPSULE_RADIUS = 0.37f; | 48 | public float CAPSULE_RADIUS = 0.37f; |
49 | public float CAPSULE_LENGTH = 2.140599f; | 49 | public float CAPSULE_LENGTH = 2.140599f; |
50 | public float heightFudgeFactor = 0.52f; | 50 | public float heightFudgeFactor = 0.52f; |
51 | public float walkDivisor = 1.3f; | 51 | public float walkDivisor = 1.3f; |
52 | public float runDivisor = 0.8f; | 52 | public float runDivisor = 0.8f; |
53 | private float m_mass = 80f; | 53 | private float m_mass = 80f; |
54 | public float m_density = 60f; | 54 | public float m_density = 60f; |
55 | private bool m_flying = false; | 55 | private bool m_flying = false; |
56 | private bool m_iscolliding = false; | 56 | private bool m_iscolliding = false; |
57 | private bool m_iscollidingGround = false; | 57 | private bool m_iscollidingGround = false; |
58 | private bool m_wascolliding = false; | 58 | private bool m_wascolliding = false; |
59 | private bool m_wascollidingGround = false; | 59 | private bool m_wascollidingGround = false; |
60 | private bool m_iscollidingObj = false; | 60 | private bool m_iscollidingObj = false; |
61 | private bool m_alwaysRun = false; | 61 | private bool m_alwaysRun = false; |
62 | private bool m_hackSentFall = false; | 62 | private bool m_hackSentFall = false; |
63 | private bool m_hackSentFly = false; | 63 | private bool m_hackSentFly = false; |
64 | public uint m_localID = 0; | 64 | public uint m_localID = 0; |
65 | public bool m_returnCollisions = false; | 65 | public bool m_returnCollisions = false; |
66 | // taints and their non-tainted counterparts | 66 | // taints and their non-tainted counterparts |
67 | public bool m_isPhysical = false; // the current physical status | 67 | public bool m_isPhysical = false; // the current physical status |
68 | public bool m_tainted_isPhysical = false; // set when the physical status is tainted (false=not existing in physics engine, true=existing) | 68 | public bool m_tainted_isPhysical = false; // set when the physical status is tainted (false=not existing in physics engine, true=existing) |
69 | private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes. | 69 | private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes. |
70 | private bool m_taintRemove = false; | 70 | private bool m_taintRemove = false; |
71 | private bool m_taintedPosition = false; | 71 | private bool m_taintedPosition = false; |
72 | private PhysicsVector m_taintedPosition_value; | 72 | private PhysicsVector m_taintedPosition_value; |
73 | private PhysicsVector m_taintedForce; | 73 | private PhysicsVector m_taintedForce; |
74 | 74 | ||
75 | private float m_buoyancy = 0f; | 75 | private float m_buoyancy = 0f; |
76 | 76 | ||
77 | // private CollisionLocker ode; | 77 | // private CollisionLocker ode; |
78 | 78 | ||
79 | private string m_name = String.Empty; | 79 | private string m_name = String.Empty; |
80 | 80 | ||
81 | private bool[] m_colliderarr = new bool[11]; | 81 | private bool[] m_colliderarr = new bool[11]; |
82 | private bool[] m_colliderGroundarr = new bool[11]; | 82 | private bool[] m_colliderGroundarr = new bool[11]; |
83 | 83 | ||
84 | 84 | ||
85 | 85 | ||
86 | private BulletDotNETScene m_parent_scene; | 86 | private BulletDotNETScene m_parent_scene; |
87 | 87 | ||
88 | public int m_eventsubscription = 0; | 88 | public int m_eventsubscription = 0; |
89 | private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); | 89 | private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate(); |
90 | 90 | ||
91 | public BulletDotNETCharacter(string avName, BulletDotNETScene parent_scene, PhysicsVector pos, PhysicsVector size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor) | 91 | public BulletDotNETCharacter(string avName, BulletDotNETScene parent_scene, PhysicsVector pos, PhysicsVector size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor) |
92 | { | 92 | { |
93 | m_taintedForce = new PhysicsVector(); | 93 | m_taintedForce = new PhysicsVector(); |
94 | m_velocity = new PhysicsVector(); | 94 | m_velocity = new PhysicsVector(); |
95 | m_target_velocity = new PhysicsVector(); | 95 | m_target_velocity = new PhysicsVector(); |
96 | m_position = pos; | 96 | m_position = pos; |
97 | m_zeroPosition = new PhysicsVector(pos.X, pos.Y, pos.Z); // this is a class, not a struct. Must make new, or m_zeroPosition will == position regardless | 97 | m_zeroPosition = new PhysicsVector(pos.X, pos.Y, pos.Z); // this is a class, not a struct. Must make new, or m_zeroPosition will == position regardless |
98 | m_acceleration = new PhysicsVector(); | 98 | m_acceleration = new PhysicsVector(); |
99 | m_parent_scene = parent_scene; | 99 | m_parent_scene = parent_scene; |
100 | PID_D = pid_d; | 100 | PID_D = pid_d; |
101 | PID_P = pid_p; | 101 | PID_P = pid_p; |
102 | CAPSULE_RADIUS = capsule_radius; | 102 | CAPSULE_RADIUS = capsule_radius; |
103 | m_density = density; | 103 | m_density = density; |
104 | heightFudgeFactor = height_fudge_factor; | 104 | heightFudgeFactor = height_fudge_factor; |
105 | walkDivisor = walk_divisor; | 105 | walkDivisor = walk_divisor; |
106 | runDivisor = rundivisor; | 106 | runDivisor = rundivisor; |
107 | 107 | ||
108 | for (int i = 0; i < 11; i++) | 108 | for (int i = 0; i < 11; i++) |
109 | { | 109 | { |
110 | m_colliderarr[i] = false; | 110 | m_colliderarr[i] = false; |
111 | } | 111 | } |
112 | for (int i = 0; i < 11; i++) | 112 | for (int i = 0; i < 11; i++) |
113 | { | 113 | { |
114 | m_colliderGroundarr[i] = false; | 114 | m_colliderGroundarr[i] = false; |
115 | } | 115 | } |
116 | CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; | 116 | CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; |
117 | m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH; | 117 | m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH; |
118 | m_isPhysical = false; // current status: no ODE information exists | 118 | m_isPhysical = false; // current status: no ODE information exists |
119 | m_tainted_isPhysical = true; // new tainted status: need to create ODE information | 119 | m_tainted_isPhysical = true; // new tainted status: need to create ODE information |
120 | 120 | ||
121 | m_parent_scene.AddPhysicsActorTaint(this); | 121 | m_parent_scene.AddPhysicsActorTaint(this); |
122 | 122 | ||
123 | m_name = avName; | 123 | m_name = avName; |
124 | tempVector1 = new btVector3(0, 0, 0); | 124 | tempVector1 = new btVector3(0, 0, 0); |
125 | tempVector2 = new btVector3(0, 0, 0); | 125 | tempVector2 = new btVector3(0, 0, 0); |
126 | tempVector3 = new btVector3(0, 0, 0); | 126 | tempVector3 = new btVector3(0, 0, 0); |
127 | tempVector4 = new btVector3(0, 0, 0); | 127 | tempVector4 = new btVector3(0, 0, 0); |
128 | 128 | ||
129 | tempVector5RayCast = new btVector3(0, 0, 0); | 129 | tempVector5RayCast = new btVector3(0, 0, 0); |
130 | tempVector6RayCast = new btVector3(0, 0, 0); | 130 | tempVector6RayCast = new btVector3(0, 0, 0); |
131 | tempVector7RayCast = new btVector3(0, 0, 0); | 131 | tempVector7RayCast = new btVector3(0, 0, 0); |
132 | 132 | ||
133 | tempQuat1 = new btQuaternion(0, 0, 0, 1); | 133 | tempQuat1 = new btQuaternion(0, 0, 0, 1); |
134 | tempTrans1 = new btTransform(tempQuat1, tempVector1); | 134 | tempTrans1 = new btTransform(tempQuat1, tempVector1); |
135 | m_movementComparision = new PhysicsVector(0, 0, 0); | 135 | m_movementComparision = new PhysicsVector(0, 0, 0); |
136 | m_CapsuleOrientationAxis = new btVector3(1, 0, 1); | 136 | m_CapsuleOrientationAxis = new btVector3(1, 0, 1); |
137 | 137 | ||
138 | 138 | ||
139 | 139 | ||
140 | } | 140 | } |
141 | 141 | ||
142 | /// <summary> | 142 | /// <summary> |
143 | /// This creates the Avatar's physical Surrogate at the position supplied | 143 | /// This creates the Avatar's physical Surrogate at the position supplied |
144 | /// </summary> | 144 | /// </summary> |
145 | /// <param name="npositionX"></param> | 145 | /// <param name="npositionX"></param> |
146 | /// <param name="npositionY"></param> | 146 | /// <param name="npositionY"></param> |
147 | /// <param name="npositionZ"></param> | 147 | /// <param name="npositionZ"></param> |
148 | 148 | ||
149 | // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access | 149 | // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access |
150 | // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only | 150 | // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only |
151 | // place that is safe to call this routine AvatarGeomAndBodyCreation. | 151 | // place that is safe to call this routine AvatarGeomAndBodyCreation. |
152 | private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ) | 152 | private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ) |
153 | { | 153 | { |
154 | 154 | ||
155 | if (CAPSULE_LENGTH <= 0) | 155 | if (CAPSULE_LENGTH <= 0) |
156 | { | 156 | { |
157 | m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); | 157 | m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); |
158 | CAPSULE_LENGTH = 0.01f; | 158 | CAPSULE_LENGTH = 0.01f; |
159 | 159 | ||
160 | } | 160 | } |
161 | 161 | ||
162 | if (CAPSULE_RADIUS <= 0) | 162 | if (CAPSULE_RADIUS <= 0) |
163 | { | 163 | { |
164 | m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); | 164 | m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!"); |
165 | CAPSULE_RADIUS = 0.01f; | 165 | CAPSULE_RADIUS = 0.01f; |
166 | 166 | ||
167 | } | 167 | } |
168 | 168 | ||
169 | Shell = new btCapsuleShape(CAPSULE_RADIUS, CAPSULE_LENGTH); | 169 | Shell = new btCapsuleShape(CAPSULE_RADIUS, CAPSULE_LENGTH); |
170 | 170 | ||
171 | if (m_bodyPosition == null) | 171 | if (m_bodyPosition == null) |
172 | m_bodyPosition = new btVector3(npositionX, npositionY, npositionZ); | 172 | m_bodyPosition = new btVector3(npositionX, npositionY, npositionZ); |
173 | 173 | ||
174 | m_bodyPosition.setValue(npositionX, npositionY, npositionZ); | 174 | m_bodyPosition.setValue(npositionX, npositionY, npositionZ); |
175 | 175 | ||
176 | if (m_bodyOrientation == null) | 176 | if (m_bodyOrientation == null) |
177 | m_bodyOrientation = new btQuaternion(m_CapsuleOrientationAxis, (Utils.DEG_TO_RAD * 90)); | 177 | m_bodyOrientation = new btQuaternion(m_CapsuleOrientationAxis, (Utils.DEG_TO_RAD * 90)); |
178 | 178 | ||
179 | if (m_bodyTransform == null) | 179 | if (m_bodyTransform == null) |
180 | m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition); | 180 | m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition); |
181 | else | 181 | else |
182 | { | 182 | { |
183 | m_bodyTransform.Dispose(); | 183 | m_bodyTransform.Dispose(); |
184 | m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition); | 184 | m_bodyTransform = new btTransform(m_bodyOrientation, m_bodyPosition); |
185 | } | 185 | } |
186 | 186 | ||
187 | if (m_bodyMotionState == null) | 187 | if (m_bodyMotionState == null) |
188 | m_bodyMotionState = new btDefaultMotionState(m_bodyTransform); | 188 | m_bodyMotionState = new btDefaultMotionState(m_bodyTransform); |
189 | else | 189 | else |
190 | m_bodyMotionState.setWorldTransform(m_bodyTransform); | 190 | m_bodyMotionState.setWorldTransform(m_bodyTransform); |
191 | 191 | ||
192 | m_mass = Mass; | 192 | m_mass = Mass; |
193 | 193 | ||
194 | Body = new btRigidBody(m_mass, m_bodyMotionState, Shell); | 194 | Body = new btRigidBody(m_mass, m_bodyMotionState, Shell); |
195 | Body.setUserPointer(new IntPtr((int)Body.Handle)); | 195 | Body.setUserPointer(new IntPtr((int)Body.Handle)); |
196 | 196 | ||
197 | if (ClosestCastResult != null) | 197 | if (ClosestCastResult != null) |
198 | ClosestCastResult.Dispose(); | 198 | ClosestCastResult.Dispose(); |
199 | ClosestCastResult = new ClosestNotMeRayResultCallback(Body); | 199 | ClosestCastResult = new ClosestNotMeRayResultCallback(Body); |
200 | 200 | ||
201 | m_parent_scene.AddRigidBody(Body); | 201 | m_parent_scene.AddRigidBody(Body); |
202 | Body.setActivationState(4); | 202 | Body.setActivationState(4); |
203 | if (m_aMotor != null) | 203 | if (m_aMotor != null) |
204 | { | 204 | { |
205 | if (m_aMotor.Handle != IntPtr.Zero) | 205 | if (m_aMotor.Handle != IntPtr.Zero) |
206 | { | 206 | { |
207 | m_parent_scene.getBulletWorld().removeConstraint(m_aMotor); | 207 | m_parent_scene.getBulletWorld().removeConstraint(m_aMotor); |
208 | m_aMotor.Dispose(); | 208 | m_aMotor.Dispose(); |
209 | } | 209 | } |
210 | m_aMotor = null; | 210 | m_aMotor = null; |
211 | } | 211 | } |
212 | 212 | ||
213 | m_aMotor = new btGeneric6DofConstraint(Body, m_parent_scene.TerrainBody, | 213 | m_aMotor = new btGeneric6DofConstraint(Body, m_parent_scene.TerrainBody, |
214 | m_parent_scene.TransZero, | 214 | m_parent_scene.TransZero, |
215 | m_parent_scene.TransZero, false); | 215 | m_parent_scene.TransZero, false); |
216 | m_aMotor.setAngularLowerLimit(m_parent_scene.VectorZero); | 216 | m_aMotor.setAngularLowerLimit(m_parent_scene.VectorZero); |
217 | m_aMotor.setAngularUpperLimit(m_parent_scene.VectorZero); | 217 | m_aMotor.setAngularUpperLimit(m_parent_scene.VectorZero); |
218 | 218 | ||
219 | 219 | ||
220 | } | 220 | } |
221 | public void Remove() | 221 | public void Remove() |
222 | { | 222 | { |
223 | m_taintRemove = true; | 223 | m_taintRemove = true; |
224 | } | 224 | } |
225 | public override bool Stopped | 225 | public override bool Stopped |
226 | { | 226 | { |
227 | get { return m_zeroFlag; } | 227 | get { return m_zeroFlag; } |
228 | } | 228 | } |
229 | 229 | ||
230 | public override PhysicsVector Size | 230 | public override PhysicsVector Size |
231 | { | 231 | { |
232 | get { return new PhysicsVector(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); } | 232 | get { return new PhysicsVector(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); } |
233 | set | 233 | set |
234 | { | 234 | { |
235 | m_pidControllerActive = true; | 235 | m_pidControllerActive = true; |
236 | 236 | ||
237 | PhysicsVector SetSize = value; | 237 | PhysicsVector SetSize = value; |
238 | m_tainted_CAPSULE_LENGTH = (SetSize.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; | 238 | m_tainted_CAPSULE_LENGTH = (SetSize.Z * 1.15f) - CAPSULE_RADIUS * 2.0f; |
239 | //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); | 239 | //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); |
240 | 240 | ||
241 | Velocity = new PhysicsVector(0f, 0f, 0f); | 241 | Velocity = new PhysicsVector(0f, 0f, 0f); |
242 | 242 | ||
243 | m_parent_scene.AddPhysicsActorTaint(this); | 243 | m_parent_scene.AddPhysicsActorTaint(this); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | /// <summary> | 247 | /// <summary> |
248 | /// turn the PID controller on or off. | 248 | /// turn the PID controller on or off. |
249 | /// The PID Controller will turn on all by itself in many situations | 249 | /// The PID Controller will turn on all by itself in many situations |
250 | /// </summary> | 250 | /// </summary> |
251 | /// <param name="status"></param> | 251 | /// <param name="status"></param> |
252 | public void SetPidStatus(bool status) | 252 | public void SetPidStatus(bool status) |
253 | { | 253 | { |
254 | m_pidControllerActive = status; | 254 | m_pidControllerActive = status; |
255 | } | 255 | } |
256 | 256 | ||
257 | public override PrimitiveBaseShape Shape | 257 | public override PrimitiveBaseShape Shape |
258 | { | 258 | { |
259 | set { return; } | 259 | set { return; } |
260 | } | 260 | } |
261 | 261 | ||
262 | public override uint LocalID | 262 | public override uint LocalID |
263 | { | 263 | { |
264 | set { m_localID = value; } | 264 | set { m_localID = value; } |
265 | } | 265 | } |
266 | 266 | ||
267 | public override bool Grabbed | 267 | public override bool Grabbed |
268 | { | 268 | { |
269 | set { return; } | 269 | set { return; } |
270 | } | 270 | } |
271 | 271 | ||
272 | public override bool Selected | 272 | public override bool Selected |
273 | { | 273 | { |
274 | set { return; } | 274 | set { return; } |
275 | } | 275 | } |
276 | 276 | ||
277 | 277 | ||
278 | public override void CrossingFailure() | 278 | public override void CrossingFailure() |
279 | { | 279 | { |
280 | 280 | ||
281 | } | 281 | } |
282 | 282 | ||
283 | public override void link(PhysicsActor obj) | 283 | public override void link(PhysicsActor obj) |
284 | { | 284 | { |
285 | 285 | ||
286 | } | 286 | } |
287 | 287 | ||
288 | public override void delink() | 288 | public override void delink() |
289 | { | 289 | { |
290 | 290 | ||
291 | } | 291 | } |
292 | 292 | ||
293 | public override void LockAngularMotion(PhysicsVector axis) | 293 | public override void LockAngularMotion(PhysicsVector axis) |
294 | { | 294 | { |
295 | 295 | ||
296 | } | 296 | } |
297 | 297 | ||
298 | public override PhysicsVector Position | 298 | public override PhysicsVector Position |
299 | { | 299 | { |
300 | get { return m_position; } | 300 | get { return m_position; } |
301 | set | 301 | set |
302 | { | 302 | { |
303 | m_taintedPosition_value = value; | 303 | m_taintedPosition_value = value; |
304 | m_position = value; | 304 | m_position = value; |
305 | m_taintedPosition = true; | 305 | m_taintedPosition = true; |
306 | } | 306 | } |
307 | } | 307 | } |
308 | 308 | ||
309 | public override float Mass | 309 | public override float Mass |
310 | { | 310 | { |
311 | get | 311 | get |
312 | { | 312 | { |
313 | float AVvolume = (float)(Math.PI * Math.Pow(CAPSULE_RADIUS, 2) * CAPSULE_LENGTH); | 313 | float AVvolume = (float)(Math.PI * Math.Pow(CAPSULE_RADIUS, 2) * CAPSULE_LENGTH); |
314 | return m_density * AVvolume; | 314 | return m_density * AVvolume; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | 317 | ||
318 | public override PhysicsVector Force | 318 | public override PhysicsVector Force |
319 | { | 319 | { |
320 | get { return new PhysicsVector(m_target_velocity.X, m_target_velocity.Y, m_target_velocity.Z); } | 320 | get { return new PhysicsVector(m_target_velocity.X, m_target_velocity.Y, m_target_velocity.Z); } |
321 | set { return; } | 321 | set { return; } |
322 | } | 322 | } |
323 | 323 | ||
324 | public override int VehicleType | 324 | public override int VehicleType |
325 | { | 325 | { |
326 | get { return 0; } | 326 | get { return 0; } |
327 | set { return; } | 327 | set { return; } |
328 | } | 328 | } |
329 | 329 | ||
330 | public override void VehicleFloatParam(int param, float value) | 330 | public override void VehicleFloatParam(int param, float value) |
331 | { | 331 | { |
332 | 332 | ||
333 | } | 333 | } |
334 | 334 | ||
335 | public override void VehicleVectorParam(int param, PhysicsVector value) | 335 | public override void VehicleVectorParam(int param, PhysicsVector value) |
336 | { | 336 | { |
337 | 337 | ||
338 | } | 338 | } |
339 | 339 | ||
340 | public override void VehicleRotationParam(int param, Quaternion rotation) | 340 | public override void VehicleRotationParam(int param, Quaternion rotation) |
341 | { | 341 | { |
342 | 342 | ||
343 | } | 343 | } |
344 | 344 | ||
345 | public override void SetVolumeDetect(int param) | 345 | public override void SetVolumeDetect(int param) |
346 | { | 346 | { |
347 | 347 | ||
348 | } | 348 | } |
349 | 349 | ||
350 | public override PhysicsVector GeometricCenter | 350 | public override PhysicsVector GeometricCenter |
351 | { | 351 | { |
352 | get { return PhysicsVector.Zero; } | 352 | get { return PhysicsVector.Zero; } |
353 | } | 353 | } |
354 | 354 | ||
355 | public override PhysicsVector CenterOfMass | 355 | public override PhysicsVector CenterOfMass |
356 | { | 356 | { |
357 | get { return PhysicsVector.Zero; } | 357 | get { return PhysicsVector.Zero; } |
358 | } | 358 | } |
359 | 359 | ||
360 | public override PhysicsVector Velocity | 360 | public override PhysicsVector Velocity |
361 | { | 361 | { |
362 | get | 362 | get |
363 | { | 363 | { |
364 | // There's a problem with PhysicsVector.Zero! Don't Use it Here! | 364 | // There's a problem with PhysicsVector.Zero! Don't Use it Here! |
365 | if (m_zeroFlag) | 365 | if (m_zeroFlag) |
366 | return new PhysicsVector(0f, 0f, 0f); | 366 | return new PhysicsVector(0f, 0f, 0f); |
367 | m_lastUpdateSent = false; | 367 | m_lastUpdateSent = false; |
368 | return m_velocity; | 368 | return m_velocity; |
369 | } | 369 | } |
370 | set | 370 | set |
371 | { | 371 | { |
372 | m_pidControllerActive = true; | 372 | m_pidControllerActive = true; |
373 | m_target_velocity = value; | 373 | m_target_velocity = value; |
374 | } | 374 | } |
375 | } | 375 | } |
376 | 376 | ||
377 | public override PhysicsVector Torque | 377 | public override PhysicsVector Torque |
378 | { | 378 | { |
379 | get { return PhysicsVector.Zero; } | 379 | get { return PhysicsVector.Zero; } |
380 | set { return; } | 380 | set { return; } |
381 | } | 381 | } |
382 | 382 | ||
383 | public override float CollisionScore | 383 | public override float CollisionScore |
384 | { | 384 | { |
385 | get { return 0f; } | 385 | get { return 0f; } |
386 | set { } | 386 | set { } |
387 | } | 387 | } |
388 | 388 | ||
389 | public override PhysicsVector Acceleration | 389 | public override PhysicsVector Acceleration |
390 | { | 390 | { |
391 | get { return m_acceleration; } | 391 | get { return m_acceleration; } |
392 | } | 392 | } |
393 | 393 | ||
394 | public override Quaternion Orientation | 394 | public override Quaternion Orientation |
395 | { | 395 | { |
396 | get { return Quaternion.Identity; } | 396 | get { return Quaternion.Identity; } |
397 | set | 397 | set |
398 | { | 398 | { |
399 | 399 | ||
400 | } | 400 | } |
401 | } | 401 | } |
402 | 402 | ||
403 | public override int PhysicsActorType | 403 | public override int PhysicsActorType |
404 | { | 404 | { |
405 | get { return (int)ActorTypes.Agent; } | 405 | get { return (int)ActorTypes.Agent; } |
406 | set { return; } | 406 | set { return; } |
407 | } | 407 | } |
408 | 408 | ||
409 | public override bool IsPhysical | 409 | public override bool IsPhysical |
410 | { | 410 | { |
411 | get { return false; } | 411 | get { return false; } |
412 | set { return; } | 412 | set { return; } |
413 | } | 413 | } |
414 | 414 | ||
415 | public override bool Flying | 415 | public override bool Flying |
416 | { | 416 | { |
417 | get { return m_flying; } | 417 | get { return m_flying; } |
418 | set { m_flying = value; } | 418 | set { m_flying = value; } |
419 | } | 419 | } |
420 | 420 | ||
421 | public override bool SetAlwaysRun | 421 | public override bool SetAlwaysRun |
422 | { | 422 | { |
423 | get { return m_alwaysRun; } | 423 | get { return m_alwaysRun; } |
424 | set { m_alwaysRun = value; } | 424 | set { m_alwaysRun = value; } |
425 | } | 425 | } |
426 | 426 | ||
427 | 427 | ||
428 | public override bool ThrottleUpdates | 428 | public override bool ThrottleUpdates |
429 | { | 429 | { |
430 | get { return false; } | 430 | get { return false; } |
431 | set { return; } | 431 | set { return; } |
432 | } | 432 | } |
433 | 433 | ||
434 | /// <summary> | 434 | /// <summary> |
435 | /// Returns if the avatar is colliding in general. | 435 | /// Returns if the avatar is colliding in general. |
436 | /// This includes the ground and objects and avatar. | 436 | /// This includes the ground and objects and avatar. |
437 | /// </summary> | 437 | /// </summary> |
438 | public override bool IsColliding | 438 | public override bool IsColliding |
439 | { | 439 | { |
440 | get { return m_iscolliding; } | 440 | get { return m_iscolliding; } |
441 | set | 441 | set |
442 | { | 442 | { |
443 | int i; | 443 | int i; |
444 | int truecount = 0; | 444 | int truecount = 0; |
445 | int falsecount = 0; | 445 | int falsecount = 0; |
446 | 446 | ||
447 | if (m_colliderarr.Length >= 10) | 447 | if (m_colliderarr.Length >= 10) |
448 | { | 448 | { |
449 | for (i = 0; i < 10; i++) | 449 | for (i = 0; i < 10; i++) |
450 | { | 450 | { |
451 | m_colliderarr[i] = m_colliderarr[i + 1]; | 451 | m_colliderarr[i] = m_colliderarr[i + 1]; |
452 | } | 452 | } |
453 | } | 453 | } |
454 | m_colliderarr[10] = value; | 454 | m_colliderarr[10] = value; |
455 | 455 | ||
456 | for (i = 0; i < 11; i++) | 456 | for (i = 0; i < 11; i++) |
457 | { | 457 | { |
458 | if (m_colliderarr[i]) | 458 | if (m_colliderarr[i]) |
459 | { | 459 | { |
460 | truecount++; | 460 | truecount++; |
461 | } | 461 | } |
462 | else | 462 | else |
463 | { | 463 | { |
464 | falsecount++; | 464 | falsecount++; |
465 | } | 465 | } |
466 | } | 466 | } |
467 | 467 | ||
468 | // Equal truecounts and false counts means we're colliding with something. | 468 | // Equal truecounts and false counts means we're colliding with something. |
469 | m_log.DebugFormat("[PHYSICS]: TrueCount:{0}, FalseCount:{1}",truecount,falsecount); | 469 | m_log.DebugFormat("[PHYSICS]: TrueCount:{0}, FalseCount:{1}",truecount,falsecount); |
470 | if (falsecount > 1.2 * truecount) | 470 | if (falsecount > 1.2 * truecount) |
471 | { | 471 | { |
472 | m_iscolliding = false; | 472 | m_iscolliding = false; |
473 | } | 473 | } |
474 | else | 474 | else |
475 | { | 475 | { |
476 | m_iscolliding = true; | 476 | m_iscolliding = true; |
477 | } | 477 | } |
478 | if (m_wascolliding != m_iscolliding) | 478 | if (m_wascolliding != m_iscolliding) |
479 | { | 479 | { |
480 | //base.SendCollisionUpdate(new CollisionEventUpdate()); | 480 | //base.SendCollisionUpdate(new CollisionEventUpdate()); |
481 | } | 481 | } |
482 | m_wascolliding = m_iscolliding; | 482 | m_wascolliding = m_iscolliding; |
483 | } | 483 | } |
484 | } | 484 | } |
485 | 485 | ||
486 | /// <summary> | 486 | /// <summary> |
487 | /// Returns if an avatar is colliding with the ground | 487 | /// Returns if an avatar is colliding with the ground |
488 | /// </summary> | 488 | /// </summary> |
489 | public override bool CollidingGround | 489 | public override bool CollidingGround |
490 | { | 490 | { |
491 | get { return m_iscollidingGround; } | 491 | get { return m_iscollidingGround; } |
492 | set | 492 | set |
493 | { | 493 | { |
494 | // Collisions against the ground are not really reliable | 494 | // Collisions against the ground are not really reliable |
495 | // So, to get a consistant value we have to average the current result over time | 495 | // So, to get a consistant value we have to average the current result over time |
496 | // Currently we use 1 second = 10 calls to this. | 496 | // Currently we use 1 second = 10 calls to this. |
497 | int i; | 497 | int i; |
498 | int truecount = 0; | 498 | int truecount = 0; |
499 | int falsecount = 0; | 499 | int falsecount = 0; |
500 | 500 | ||
501 | if (m_colliderGroundarr.Length >= 10) | 501 | if (m_colliderGroundarr.Length >= 10) |
502 | { | 502 | { |
503 | for (i = 0; i < 10; i++) | 503 | for (i = 0; i < 10; i++) |
504 | { | 504 | { |
505 | m_colliderGroundarr[i] = m_colliderGroundarr[i + 1]; | 505 | m_colliderGroundarr[i] = m_colliderGroundarr[i + 1]; |
506 | } | 506 | } |
507 | } | 507 | } |
508 | m_colliderGroundarr[10] = value; | 508 | m_colliderGroundarr[10] = value; |
509 | 509 | ||
510 | for (i = 0; i < 11; i++) | 510 | for (i = 0; i < 11; i++) |
511 | { | 511 | { |
512 | if (m_colliderGroundarr[i]) | 512 | if (m_colliderGroundarr[i]) |
513 | { | 513 | { |
514 | truecount++; | 514 | truecount++; |
515 | } | 515 | } |
516 | else | 516 | else |
517 | { | 517 | { |
518 | falsecount++; | 518 | falsecount++; |
519 | } | 519 | } |
520 | } | 520 | } |
521 | 521 | ||
522 | // Equal truecounts and false counts means we're colliding with something. | 522 | // Equal truecounts and false counts means we're colliding with something. |
523 | 523 | ||
524 | if (falsecount > 1.2 * truecount) | 524 | if (falsecount > 1.2 * truecount) |
525 | { | 525 | { |
526 | m_iscollidingGround = false; | 526 | m_iscollidingGround = false; |
527 | } | 527 | } |
528 | else | 528 | else |
529 | { | 529 | { |
530 | m_iscollidingGround = true; | 530 | m_iscollidingGround = true; |
531 | } | 531 | } |
532 | if (m_wascollidingGround != m_iscollidingGround) | 532 | if (m_wascollidingGround != m_iscollidingGround) |
533 | { | 533 | { |
534 | //base.SendCollisionUpdate(new CollisionEventUpdate()); | 534 | //base.SendCollisionUpdate(new CollisionEventUpdate()); |
535 | } | 535 | } |
536 | m_wascollidingGround = m_iscollidingGround; | 536 | m_wascollidingGround = m_iscollidingGround; |
537 | } | 537 | } |
538 | } | 538 | } |
539 | 539 | ||
540 | /// <summary> | 540 | /// <summary> |
541 | /// Returns if the avatar is colliding with an object | 541 | /// Returns if the avatar is colliding with an object |
542 | /// </summary> | 542 | /// </summary> |
543 | public override bool CollidingObj | 543 | public override bool CollidingObj |
544 | { | 544 | { |
545 | get { return m_iscollidingObj; } | 545 | get { return m_iscollidingObj; } |
546 | set | 546 | set |
547 | { | 547 | { |
548 | m_iscollidingObj = value; | 548 | m_iscollidingObj = value; |
549 | if (value) | 549 | if (value) |
550 | m_pidControllerActive = false; | 550 | m_pidControllerActive = false; |
551 | else | 551 | else |
552 | m_pidControllerActive = true; | 552 | m_pidControllerActive = true; |
553 | } | 553 | } |
554 | } | 554 | } |
555 | 555 | ||
556 | 556 | ||
557 | public override bool FloatOnWater | 557 | public override bool FloatOnWater |
558 | { | 558 | { |
559 | set { return; } | 559 | set { return; } |
560 | } | 560 | } |
561 | 561 | ||
562 | public override PhysicsVector RotationalVelocity | 562 | public override PhysicsVector RotationalVelocity |
563 | { | 563 | { |
564 | get { return m_rotationalVelocity; } | 564 | get { return m_rotationalVelocity; } |
565 | set { m_rotationalVelocity = value; } | 565 | set { m_rotationalVelocity = value; } |
566 | } | 566 | } |
567 | 567 | ||
568 | public override bool Kinematic | 568 | public override bool Kinematic |
569 | { | 569 | { |
570 | get { return false; } | 570 | get { return false; } |
571 | set { } | 571 | set { } |
572 | } | 572 | } |
573 | 573 | ||
574 | public override float Buoyancy | 574 | public override float Buoyancy |
575 | { | 575 | { |
576 | get { return m_buoyancy; } | 576 | get { return m_buoyancy; } |
577 | set { m_buoyancy = value; } | 577 | set { m_buoyancy = value; } |
578 | } | 578 | } |
579 | 579 | ||
580 | public override PhysicsVector PIDTarget { set { return; } } | 580 | public override PhysicsVector PIDTarget { set { return; } } |
581 | public override bool PIDActive { set { return; } } | 581 | public override bool PIDActive { set { return; } } |
582 | public override float PIDTau { set { return; } } | 582 | public override float PIDTau { set { return; } } |
583 | 583 | ||
584 | public override bool PIDHoverActive | 584 | public override bool PIDHoverActive |
585 | { | 585 | { |
586 | set { return; } | 586 | set { return; } |
587 | } | 587 | } |
588 | 588 | ||
589 | public override float PIDHoverHeight | 589 | public override float PIDHoverHeight |
590 | { | 590 | { |
591 | set { return; } | 591 | set { return; } |
592 | } | 592 | } |
593 | 593 | ||
594 | public override PIDHoverType PIDHoverType | 594 | public override PIDHoverType PIDHoverType |
595 | { | 595 | { |
596 | set { return; } | 596 | set { return; } |
597 | } | 597 | } |
598 | 598 | ||
599 | public override float PIDHoverTau | 599 | public override float PIDHoverTau |
600 | { | 600 | { |
601 | set { return; } | 601 | set { return; } |
602 | } | 602 | } |
603 | 603 | ||
604 | /// <summary> | 604 | /// <summary> |
605 | /// Adds the force supplied to the Target Velocity | 605 | /// Adds the force supplied to the Target Velocity |
606 | /// The PID controller takes this target velocity and tries to make it a reality | 606 | /// The PID controller takes this target velocity and tries to make it a reality |
607 | /// </summary> | 607 | /// </summary> |
608 | /// <param name="force"></param> | 608 | /// <param name="force"></param> |
609 | /// <param name="pushforce">Is this a push by a script?</param> | 609 | /// <param name="pushforce">Is this a push by a script?</param> |
610 | public override void AddForce(PhysicsVector force, bool pushforce) | 610 | public override void AddForce(PhysicsVector force, bool pushforce) |
611 | { | 611 | { |
612 | if (pushforce) | 612 | if (pushforce) |
613 | { | 613 | { |
614 | m_pidControllerActive = false; | 614 | m_pidControllerActive = false; |
615 | force *= 100f; | 615 | force *= 100f; |
616 | doForce(force, false); | 616 | doForce(force, false); |
617 | //System.Console.WriteLine("Push!"); | 617 | //System.Console.WriteLine("Push!"); |
618 | //_target_velocity.X += force.X; | 618 | //_target_velocity.X += force.X; |
619 | // _target_velocity.Y += force.Y; | 619 | // _target_velocity.Y += force.Y; |
620 | //_target_velocity.Z += force.Z; | 620 | //_target_velocity.Z += force.Z; |
621 | } | 621 | } |
622 | else | 622 | else |
623 | { | 623 | { |
624 | m_pidControllerActive = true; | 624 | m_pidControllerActive = true; |
625 | m_target_velocity.X += force.X; | 625 | m_target_velocity.X += force.X; |
626 | m_target_velocity.Y += force.Y; | 626 | m_target_velocity.Y += force.Y; |
627 | m_target_velocity.Z += force.Z; | 627 | m_target_velocity.Z += force.Z; |
628 | } | 628 | } |
629 | //m_lastUpdateSent = false; | 629 | //m_lastUpdateSent = false; |
630 | } | 630 | } |
631 | 631 | ||
632 | public void doForce(PhysicsVector force, bool now) | 632 | public void doForce(PhysicsVector force, bool now) |
633 | { | 633 | { |
634 | 634 | ||
635 | tempVector3.setValue(force.X, force.Y, force.Z); | 635 | tempVector3.setValue(force.X, force.Y, force.Z); |
636 | if (now) | 636 | if (now) |
637 | { | 637 | { |
638 | Body.applyCentralForce(tempVector3); | 638 | Body.applyCentralForce(tempVector3); |
639 | } | 639 | } |
640 | else | 640 | else |
641 | { | 641 | { |
642 | m_taintedForce += force; | 642 | m_taintedForce += force; |
643 | m_parent_scene.AddPhysicsActorTaint(this); | 643 | m_parent_scene.AddPhysicsActorTaint(this); |
644 | } | 644 | } |
645 | } | 645 | } |
646 | 646 | ||
647 | public void doImpulse(PhysicsVector force, bool now) | 647 | public void doImpulse(PhysicsVector force, bool now) |
648 | { | 648 | { |
649 | 649 | ||
650 | tempVector3.setValue(force.X, force.Y, force.Z); | 650 | tempVector3.setValue(force.X, force.Y, force.Z); |
651 | if (now) | 651 | if (now) |
652 | { | 652 | { |
653 | Body.applyCentralImpulse(tempVector3); | 653 | Body.applyCentralImpulse(tempVector3); |
654 | } | 654 | } |
655 | else | 655 | else |
656 | { | 656 | { |
657 | m_taintedForce += force; | 657 | m_taintedForce += force; |
658 | m_parent_scene.AddPhysicsActorTaint(this); | 658 | m_parent_scene.AddPhysicsActorTaint(this); |
659 | } | 659 | } |
660 | } | 660 | } |
661 | 661 | ||
662 | public override void AddAngularForce(PhysicsVector force, bool pushforce) | 662 | public override void AddAngularForce(PhysicsVector force, bool pushforce) |
663 | { | 663 | { |
664 | 664 | ||
665 | } | 665 | } |
666 | 666 | ||
667 | public override void SetMomentum(PhysicsVector momentum) | 667 | public override void SetMomentum(PhysicsVector momentum) |
668 | { | 668 | { |
669 | 669 | ||
670 | } | 670 | } |
671 | 671 | ||
672 | public override void SubscribeEvents(int ms) | 672 | public override void SubscribeEvents(int ms) |
673 | { | 673 | { |
674 | m_eventsubscription = ms; | 674 | m_eventsubscription = ms; |
675 | m_parent_scene.addCollisionEventReporting(this); | 675 | m_parent_scene.addCollisionEventReporting(this); |
676 | } | 676 | } |
677 | 677 | ||
678 | public override void UnSubscribeEvents() | 678 | public override void UnSubscribeEvents() |
679 | { | 679 | { |
680 | m_parent_scene.remCollisionEventReporting(this); | 680 | m_parent_scene.remCollisionEventReporting(this); |
681 | m_eventsubscription = 0; | 681 | m_eventsubscription = 0; |
682 | } | 682 | } |
683 | 683 | ||
684 | public override bool SubscribedEvents() | 684 | public override bool SubscribedEvents() |
685 | { | 685 | { |
686 | if (m_eventsubscription > 0) | 686 | if (m_eventsubscription > 0) |
687 | return true; | 687 | return true; |
688 | return false; | 688 | return false; |
689 | } | 689 | } |
690 | 690 | ||
691 | internal void Dispose() | 691 | internal void Dispose() |
692 | { | 692 | { |
693 | if (Body.isInWorld()) | 693 | if (Body.isInWorld()) |
694 | m_parent_scene.removeFromWorld(Body); | 694 | m_parent_scene.removeFromWorld(Body); |
695 | 695 | ||
696 | if (m_aMotor.Handle != IntPtr.Zero) | 696 | if (m_aMotor.Handle != IntPtr.Zero) |
697 | m_parent_scene.getBulletWorld().removeConstraint(m_aMotor); | 697 | m_parent_scene.getBulletWorld().removeConstraint(m_aMotor); |
698 | 698 | ||
699 | m_aMotor.Dispose(); m_aMotor = null; | 699 | m_aMotor.Dispose(); m_aMotor = null; |
700 | ClosestCastResult.Dispose(); ClosestCastResult = null; | 700 | ClosestCastResult.Dispose(); ClosestCastResult = null; |
701 | Body.Dispose(); Body = null; | 701 | Body.Dispose(); Body = null; |
702 | Shell.Dispose(); Shell = null; | 702 | Shell.Dispose(); Shell = null; |
703 | tempQuat1.Dispose(); | 703 | tempQuat1.Dispose(); |
704 | tempTrans1.Dispose(); | 704 | tempTrans1.Dispose(); |
705 | tempVector1.Dispose(); | 705 | tempVector1.Dispose(); |
706 | tempVector2.Dispose(); | 706 | tempVector2.Dispose(); |
707 | tempVector3.Dispose(); | 707 | tempVector3.Dispose(); |
708 | tempVector4.Dispose(); | 708 | tempVector4.Dispose(); |
709 | tempVector5RayCast.Dispose(); | 709 | tempVector5RayCast.Dispose(); |
710 | tempVector6RayCast.Dispose(); | 710 | tempVector6RayCast.Dispose(); |
711 | 711 | ||
712 | } | 712 | } |
713 | 713 | ||
714 | public void ProcessTaints(float timestep) | 714 | public void ProcessTaints(float timestep) |
715 | { | 715 | { |
716 | 716 | ||
717 | if (m_tainted_isPhysical != m_isPhysical) | 717 | if (m_tainted_isPhysical != m_isPhysical) |
718 | { | 718 | { |
719 | if (m_tainted_isPhysical) | 719 | if (m_tainted_isPhysical) |
720 | { | 720 | { |
721 | // Create avatar capsule and related ODE data | 721 | // Create avatar capsule and related ODE data |
722 | if (!(Shell == null && Body == null)) | 722 | if (!(Shell == null && Body == null)) |
723 | { | 723 | { |
724 | m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - " | 724 | m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - " |
725 | + (Shell != null ? "Shell " : "") | 725 | + (Shell != null ? "Shell " : "") |
726 | + (Body != null ? "Body " : "")); | 726 | + (Body != null ? "Body " : "")); |
727 | } | 727 | } |
728 | AvatarGeomAndBodyCreation(m_position.X, m_position.Y, m_position.Z); | 728 | AvatarGeomAndBodyCreation(m_position.X, m_position.Y, m_position.Z); |
729 | 729 | ||
730 | 730 | ||
731 | } | 731 | } |
732 | else | 732 | else |
733 | { | 733 | { |
734 | // destroy avatar capsule and related ODE data | 734 | // destroy avatar capsule and related ODE data |
735 | 735 | ||
736 | Dispose(); | 736 | Dispose(); |
737 | tempVector1 = new btVector3(0, 0, 0); | 737 | tempVector1 = new btVector3(0, 0, 0); |
738 | tempVector2 = new btVector3(0, 0, 0); | 738 | tempVector2 = new btVector3(0, 0, 0); |
739 | tempVector3 = new btVector3(0, 0, 0); | 739 | tempVector3 = new btVector3(0, 0, 0); |
740 | tempVector4 = new btVector3(0, 0, 0); | 740 | tempVector4 = new btVector3(0, 0, 0); |
741 | 741 | ||
742 | tempVector5RayCast = new btVector3(0, 0, 0); | 742 | tempVector5RayCast = new btVector3(0, 0, 0); |
743 | tempVector6RayCast = new btVector3(0, 0, 0); | 743 | tempVector6RayCast = new btVector3(0, 0, 0); |
744 | tempVector7RayCast = new btVector3(0, 0, 0); | 744 | tempVector7RayCast = new btVector3(0, 0, 0); |
745 | 745 | ||
746 | tempQuat1 = new btQuaternion(0, 0, 0, 1); | 746 | tempQuat1 = new btQuaternion(0, 0, 0, 1); |
747 | tempTrans1 = new btTransform(tempQuat1, tempVector1); | 747 | tempTrans1 = new btTransform(tempQuat1, tempVector1); |
748 | m_movementComparision = new PhysicsVector(0, 0, 0); | 748 | m_movementComparision = new PhysicsVector(0, 0, 0); |
749 | m_CapsuleOrientationAxis = new btVector3(1, 0, 1); | 749 | m_CapsuleOrientationAxis = new btVector3(1, 0, 1); |
750 | } | 750 | } |
751 | 751 | ||
752 | m_isPhysical = m_tainted_isPhysical; | 752 | m_isPhysical = m_tainted_isPhysical; |
753 | } | 753 | } |
754 | 754 | ||
755 | if (m_tainted_CAPSULE_LENGTH != CAPSULE_LENGTH) | 755 | if (m_tainted_CAPSULE_LENGTH != CAPSULE_LENGTH) |
756 | { | 756 | { |
757 | if (Body != null) | 757 | if (Body != null) |
758 | { | 758 | { |
759 | 759 | ||
760 | m_pidControllerActive = true; | 760 | m_pidControllerActive = true; |
761 | // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate() | 761 | // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate() |
762 | //d.JointDestroy(Amotor); | 762 | //d.JointDestroy(Amotor); |
763 | float prevCapsule = CAPSULE_LENGTH; | 763 | float prevCapsule = CAPSULE_LENGTH; |
764 | CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH; | 764 | CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH; |
765 | //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); | 765 | //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString()); |
766 | Dispose(); | 766 | Dispose(); |
767 | 767 | ||
768 | tempVector1 = new btVector3(0, 0, 0); | 768 | tempVector1 = new btVector3(0, 0, 0); |
769 | tempVector2 = new btVector3(0, 0, 0); | 769 | tempVector2 = new btVector3(0, 0, 0); |
770 | tempVector3 = new btVector3(0, 0, 0); | 770 | tempVector3 = new btVector3(0, 0, 0); |
771 | tempVector4 = new btVector3(0, 0, 0); | 771 | tempVector4 = new btVector3(0, 0, 0); |
772 | 772 | ||
773 | tempVector5RayCast = new btVector3(0, 0, 0); | 773 | tempVector5RayCast = new btVector3(0, 0, 0); |
774 | tempVector6RayCast = new btVector3(0, 0, 0); | 774 | tempVector6RayCast = new btVector3(0, 0, 0); |
775 | tempVector7RayCast = new btVector3(0, 0, 0); | 775 | tempVector7RayCast = new btVector3(0, 0, 0); |
776 | 776 | ||
777 | tempQuat1 = new btQuaternion(0, 0, 0, 1); | 777 | tempQuat1 = new btQuaternion(0, 0, 0, 1); |
778 | tempTrans1 = new btTransform(tempQuat1, tempVector1); | 778 | tempTrans1 = new btTransform(tempQuat1, tempVector1); |
779 | m_movementComparision = new PhysicsVector(0, 0, 0); | 779 | m_movementComparision = new PhysicsVector(0, 0, 0); |
780 | m_CapsuleOrientationAxis = new btVector3(1, 0, 1); | 780 | m_CapsuleOrientationAxis = new btVector3(1, 0, 1); |
781 | 781 | ||
782 | AvatarGeomAndBodyCreation(m_position.X, m_position.Y, | 782 | AvatarGeomAndBodyCreation(m_position.X, m_position.Y, |
783 | m_position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2)); | 783 | m_position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2)); |
784 | Velocity = new PhysicsVector(0f, 0f, 0f); | 784 | Velocity = new PhysicsVector(0f, 0f, 0f); |
785 | 785 | ||
786 | } | 786 | } |
787 | else | 787 | else |
788 | { | 788 | { |
789 | m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - " | 789 | m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - " |
790 | + (Shell == null ? "Shell " : "") | 790 | + (Shell == null ? "Shell " : "") |
791 | + (Body == null ? "Body " : "")); | 791 | + (Body == null ? "Body " : "")); |
792 | } | 792 | } |
793 | } | 793 | } |
794 | if (m_taintRemove) | 794 | if (m_taintRemove) |
795 | { | 795 | { |
796 | Dispose(); | 796 | Dispose(); |
797 | } | 797 | } |
798 | } | 798 | } |
799 | 799 | ||
800 | /// <summary> | 800 | /// <summary> |
801 | /// Called from Simulate | 801 | /// Called from Simulate |
802 | /// This is the avatar's movement control + PID Controller | 802 | /// This is the avatar's movement control + PID Controller |
803 | /// </summary> | 803 | /// </summary> |
804 | /// <param name="timeStep"></param> | 804 | /// <param name="timeStep"></param> |
805 | public void Move(float timeStep) | 805 | public void Move(float timeStep) |
806 | { | 806 | { |
807 | // no lock; for now it's only called from within Simulate() | 807 | // no lock; for now it's only called from within Simulate() |
808 | 808 | ||
809 | // If the PID Controller isn't active then we set our force | 809 | // If the PID Controller isn't active then we set our force |
810 | // calculating base velocity to the current position | 810 | // calculating base velocity to the current position |
811 | if (Body == null) | 811 | if (Body == null) |
812 | return; | 812 | return; |
813 | tempTrans1.Dispose(); | 813 | tempTrans1.Dispose(); |
814 | tempTrans1 = Body.getInterpolationWorldTransform(); | 814 | tempTrans1 = Body.getInterpolationWorldTransform(); |
815 | tempVector1.Dispose(); | 815 | tempVector1.Dispose(); |
816 | tempVector1 = tempTrans1.getOrigin(); | 816 | tempVector1 = tempTrans1.getOrigin(); |
817 | tempVector2.Dispose(); | 817 | tempVector2.Dispose(); |
818 | tempVector2 = Body.getInterpolationLinearVelocity(); | 818 | tempVector2 = Body.getInterpolationLinearVelocity(); |
819 | 819 | ||
820 | if (m_pidControllerActive == false) | 820 | if (m_pidControllerActive == false) |
821 | { | 821 | { |
822 | m_zeroPosition.X = tempVector1.getX(); | 822 | m_zeroPosition.X = tempVector1.getX(); |
823 | m_zeroPosition.Y = tempVector1.getY(); | 823 | m_zeroPosition.Y = tempVector1.getY(); |
824 | m_zeroPosition.Z = tempVector1.getZ(); | 824 | m_zeroPosition.Z = tempVector1.getZ(); |
825 | } | 825 | } |
826 | //PidStatus = true; | 826 | //PidStatus = true; |
827 | 827 | ||
828 | PhysicsVector vec = new PhysicsVector(); | 828 | PhysicsVector vec = new PhysicsVector(); |
829 | 829 | ||
830 | PhysicsVector vel = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ()); | 830 | PhysicsVector vel = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ()); |
831 | 831 | ||
832 | float movementdivisor = 1f; | 832 | float movementdivisor = 1f; |
833 | 833 | ||
834 | if (!m_alwaysRun) | 834 | if (!m_alwaysRun) |
835 | { | 835 | { |
836 | movementdivisor = walkDivisor; | 836 | movementdivisor = walkDivisor; |
837 | } | 837 | } |
838 | else | 838 | else |
839 | { | 839 | { |
840 | movementdivisor = runDivisor; | 840 | movementdivisor = runDivisor; |
841 | } | 841 | } |
842 | 842 | ||
843 | // if velocity is zero, use position control; otherwise, velocity control | 843 | // if velocity is zero, use position control; otherwise, velocity control |
844 | if (m_target_velocity.X == 0.0f && m_target_velocity.Y == 0.0f && m_target_velocity.Z == 0.0f && m_iscolliding) | 844 | if (m_target_velocity.X == 0.0f && m_target_velocity.Y == 0.0f && m_target_velocity.Z == 0.0f && m_iscolliding) |
845 | { | 845 | { |
846 | // keep track of where we stopped. No more slippin' & slidin' | 846 | // keep track of where we stopped. No more slippin' & slidin' |
847 | if (!m_zeroFlag) | 847 | if (!m_zeroFlag) |
848 | { | 848 | { |
849 | m_zeroFlag = true; | 849 | m_zeroFlag = true; |
850 | m_zeroPosition.X = tempVector1.getX(); | 850 | m_zeroPosition.X = tempVector1.getX(); |
851 | m_zeroPosition.Y = tempVector1.getY(); | 851 | m_zeroPosition.Y = tempVector1.getY(); |
852 | m_zeroPosition.Z = tempVector1.getZ(); | 852 | m_zeroPosition.Z = tempVector1.getZ(); |
853 | } | 853 | } |
854 | if (m_pidControllerActive) | 854 | if (m_pidControllerActive) |
855 | { | 855 | { |
856 | // We only want to deactivate the PID Controller if we think we want to have our surrogate | 856 | // We only want to deactivate the PID Controller if we think we want to have our surrogate |
857 | // react to the physics scene by moving it's position. | 857 | // react to the physics scene by moving it's position. |
858 | // Avatar to Avatar collisions | 858 | // Avatar to Avatar collisions |
859 | // Prim to avatar collisions | 859 | // Prim to avatar collisions |
860 | 860 | ||
861 | PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ()); | 861 | PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ()); |
862 | vec.X = (m_target_velocity.X - vel.X) * (PID_D) + (m_zeroPosition.X - pos.X) * (PID_P * 2); | 862 | vec.X = (m_target_velocity.X - vel.X) * (PID_D) + (m_zeroPosition.X - pos.X) * (PID_P * 2); |
863 | vec.Y = (m_target_velocity.Y - vel.Y) * (PID_D) + (m_zeroPosition.Y - pos.Y) * (PID_P * 2); | 863 | vec.Y = (m_target_velocity.Y - vel.Y) * (PID_D) + (m_zeroPosition.Y - pos.Y) * (PID_P * 2); |
864 | if (m_flying) | 864 | if (m_flying) |
865 | { | 865 | { |
866 | vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D) + (m_zeroPosition.Z - pos.Z) * PID_P; | 866 | vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D) + (m_zeroPosition.Z - pos.Z) * PID_P; |
867 | } | 867 | } |
868 | } | 868 | } |
869 | //PidStatus = true; | 869 | //PidStatus = true; |
870 | } | 870 | } |
871 | else | 871 | else |
872 | { | 872 | { |
873 | m_pidControllerActive = true; | 873 | m_pidControllerActive = true; |
874 | m_zeroFlag = false; | 874 | m_zeroFlag = false; |
875 | if (m_iscolliding && !m_flying) | 875 | if (m_iscolliding && !m_flying) |
876 | { | 876 | { |
877 | // We're standing on something | 877 | // We're standing on something |
878 | vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D); | 878 | vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D); |
879 | vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D); | 879 | vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D); |
880 | } | 880 | } |
881 | else if (m_iscolliding && m_flying) | 881 | else if (m_iscolliding && m_flying) |
882 | { | 882 | { |
883 | // We're flying and colliding with something | 883 | // We're flying and colliding with something |
884 | vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 16); | 884 | vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 16); |
885 | vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 16); | 885 | vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 16); |
886 | } | 886 | } |
887 | else if (!m_iscolliding && m_flying) | 887 | else if (!m_iscolliding && m_flying) |
888 | { | 888 | { |
889 | // we're in mid air suspended | 889 | // we're in mid air suspended |
890 | vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 6); | 890 | vec.X = ((m_target_velocity.X / movementdivisor) - vel.X) * (PID_D / 6); |
891 | vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 6); | 891 | vec.Y = ((m_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D / 6); |
892 | } | 892 | } |
893 | 893 | ||
894 | if (m_iscolliding && !m_flying && m_target_velocity.Z > 0.0f) | 894 | if (m_iscolliding && !m_flying && m_target_velocity.Z > 0.0f) |
895 | { | 895 | { |
896 | // We're colliding with something and we're not flying but we're moving | 896 | // We're colliding with something and we're not flying but we're moving |
897 | // This means we're walking or running. | 897 | // This means we're walking or running. |
898 | PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ()); | 898 | PhysicsVector pos = new PhysicsVector(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ()); |
899 | vec.Z = (m_target_velocity.Z - vel.Z) * PID_D + (m_zeroPosition.Z - pos.Z) * PID_P; | 899 | vec.Z = (m_target_velocity.Z - vel.Z) * PID_D + (m_zeroPosition.Z - pos.Z) * PID_P; |
900 | if (m_target_velocity.X > 0) | 900 | if (m_target_velocity.X > 0) |
901 | { | 901 | { |
902 | vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D; | 902 | vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D; |
903 | } | 903 | } |
904 | if (m_target_velocity.Y > 0) | 904 | if (m_target_velocity.Y > 0) |
905 | { | 905 | { |
906 | vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D; | 906 | vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D; |
907 | } | 907 | } |
908 | } | 908 | } |
909 | else if (!m_iscolliding && !m_flying) | 909 | else if (!m_iscolliding && !m_flying) |
910 | { | 910 | { |
911 | // we're not colliding and we're not flying so that means we're falling! | 911 | // we're not colliding and we're not flying so that means we're falling! |
912 | // m_iscolliding includes collisions with the ground. | 912 | // m_iscolliding includes collisions with the ground. |
913 | 913 | ||
914 | // d.Vector3 pos = d.BodyGetPosition(Body); | 914 | // d.Vector3 pos = d.BodyGetPosition(Body); |
915 | if (m_target_velocity.X > 0) | 915 | if (m_target_velocity.X > 0) |
916 | { | 916 | { |
917 | vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D; | 917 | vec.X = ((m_target_velocity.X - vel.X) / 1.2f) * PID_D; |
918 | } | 918 | } |
919 | if (m_target_velocity.Y > 0) | 919 | if (m_target_velocity.Y > 0) |
920 | { | 920 | { |
921 | vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D; | 921 | vec.Y = ((m_target_velocity.Y - vel.Y) / 1.2f) * PID_D; |
922 | } | 922 | } |
923 | } | 923 | } |
924 | 924 | ||
925 | 925 | ||
926 | if (m_flying) | 926 | if (m_flying) |
927 | { | 927 | { |
928 | vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D); | 928 | vec.Z = (m_target_velocity.Z - vel.Z) * (PID_D); |
929 | } | 929 | } |
930 | } | 930 | } |
931 | if (m_flying) | 931 | if (m_flying) |
932 | { | 932 | { |
933 | //vec.Z += ((-1 * m_parent_scene.gravityz) * m_mass); | 933 | //vec.Z += ((-1 * m_parent_scene.gravityz) * m_mass); |
934 | } | 934 | } |
935 | if (Body != null && (((m_target_velocity.X > 0.2f || m_target_velocity.X < -0.2f) || (m_target_velocity.Y > 0.2f || m_target_velocity.Y < -0.2f)))) | 935 | if (Body != null && (((m_target_velocity.X > 0.2f || m_target_velocity.X < -0.2f) || (m_target_velocity.Y > 0.2f || m_target_velocity.Y < -0.2f)))) |
936 | { | 936 | { |
937 | Body.setFriction(0.001f); | 937 | Body.setFriction(0.001f); |
938 | //m_log.DebugFormat("[PHYSICS]: Avatar force applied: {0}, Target:{1}", vec.ToString(), m_target_velocity.ToString()); | 938 | //m_log.DebugFormat("[PHYSICS]: Avatar force applied: {0}, Target:{1}", vec.ToString(), m_target_velocity.ToString()); |
939 | } | 939 | } |
940 | 940 | ||
941 | if (Body != null) | 941 | if (Body != null) |
942 | { | 942 | { |
943 | int activationstate = Body.getActivationState(); | 943 | int activationstate = Body.getActivationState(); |
944 | if (activationstate == 0) | 944 | if (activationstate == 0) |
945 | { | 945 | { |
946 | Body.forceActivationState(1); | 946 | Body.forceActivationState(1); |
947 | } | 947 | } |
948 | 948 | ||
949 | 949 | ||
950 | } | 950 | } |
951 | doImpulse(vec, true); | 951 | doImpulse(vec, true); |
952 | } | 952 | } |
953 | 953 | ||
954 | /// <summary> | 954 | /// <summary> |
955 | /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence. | 955 | /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence. |
956 | /// </summary> | 956 | /// </summary> |
957 | public void UpdatePositionAndVelocity() | 957 | public void UpdatePositionAndVelocity() |
958 | { | 958 | { |
959 | if (Body == null) | 959 | if (Body == null) |
960 | return; | 960 | return; |
961 | //int val = Environment.TickCount; | 961 | //int val = Environment.TickCount; |
962 | CheckIfStandingOnObject(); | 962 | CheckIfStandingOnObject(); |
963 | //m_log.DebugFormat("time:{0}", Environment.TickCount - val); | 963 | //m_log.DebugFormat("time:{0}", Environment.TickCount - val); |
964 | 964 | ||
965 | //IsColliding = Body.checkCollideWith(m_parent_scene.TerrainBody); | 965 | //IsColliding = Body.checkCollideWith(m_parent_scene.TerrainBody); |
966 | 966 | ||
967 | tempTrans1.Dispose(); | 967 | tempTrans1.Dispose(); |
968 | tempTrans1 = Body.getInterpolationWorldTransform(); | 968 | tempTrans1 = Body.getInterpolationWorldTransform(); |
969 | tempVector1.Dispose(); | 969 | tempVector1.Dispose(); |
970 | tempVector1 = tempTrans1.getOrigin(); | 970 | tempVector1 = tempTrans1.getOrigin(); |
971 | tempVector2.Dispose(); | 971 | tempVector2.Dispose(); |
972 | tempVector2 = Body.getInterpolationLinearVelocity(); | 972 | tempVector2 = Body.getInterpolationLinearVelocity(); |
973 | 973 | ||
974 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! | 974 | // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! |
975 | PhysicsVector vec = new PhysicsVector(tempVector1.getX(),tempVector1.getY(),tempVector1.getZ()); | 975 | PhysicsVector vec = new PhysicsVector(tempVector1.getX(),tempVector1.getY(),tempVector1.getZ()); |
976 | 976 | ||
977 | // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) | 977 | // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) |
978 | if (vec.X < 0.0f) vec.X = 0.0f; | 978 | if (vec.X < 0.0f) vec.X = 0.0f; |
979 | if (vec.Y < 0.0f) vec.Y = 0.0f; | 979 | if (vec.Y < 0.0f) vec.Y = 0.0f; |
980 | if (vec.X > (int)Constants.RegionSize - 0.2f) vec.X = (int)Constants.RegionSize - 0.2f; | 980 | if (vec.X > (int)Constants.RegionSize - 0.2f) vec.X = (int)Constants.RegionSize - 0.2f; |
981 | if (vec.Y > (int)Constants.RegionSize - 0.2f) vec.Y = (int)Constants.RegionSize - 0.2f; | 981 | if (vec.Y > (int)Constants.RegionSize - 0.2f) vec.Y = (int)Constants.RegionSize - 0.2f; |
982 | 982 | ||
983 | m_position.X = vec.X; | 983 | m_position.X = vec.X; |
984 | m_position.Y = vec.Y; | 984 | m_position.Y = vec.Y; |
985 | m_position.Z = vec.Z; | 985 | m_position.Z = vec.Z; |
986 | 986 | ||
987 | // Did we move last? = zeroflag | 987 | // Did we move last? = zeroflag |
988 | // This helps keep us from sliding all over | 988 | // This helps keep us from sliding all over |
989 | 989 | ||
990 | if (m_zeroFlag) | 990 | if (m_zeroFlag) |
991 | { | 991 | { |
992 | m_velocity.X = 0.0f; | 992 | m_velocity.X = 0.0f; |
993 | m_velocity.Y = 0.0f; | 993 | m_velocity.Y = 0.0f; |
994 | m_velocity.Z = 0.0f; | 994 | m_velocity.Z = 0.0f; |
995 | 995 | ||
996 | // Did we send out the 'stopped' message? | 996 | // Did we send out the 'stopped' message? |
997 | if (!m_lastUpdateSent) | 997 | if (!m_lastUpdateSent) |
998 | { | 998 | { |
999 | m_lastUpdateSent = true; | 999 | m_lastUpdateSent = true; |
1000 | //base.RequestPhysicsterseUpdate(); | 1000 | //base.RequestPhysicsterseUpdate(); |
1001 | 1001 | ||
1002 | } | 1002 | } |
1003 | } | 1003 | } |
1004 | else | 1004 | else |
1005 | { | 1005 | { |
1006 | m_lastUpdateSent = false; | 1006 | m_lastUpdateSent = false; |
1007 | vec = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ()); | 1007 | vec = new PhysicsVector(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ()); |
1008 | m_velocity.X = (vec.X); | 1008 | m_velocity.X = (vec.X); |
1009 | m_velocity.Y = (vec.Y); | 1009 | m_velocity.Y = (vec.Y); |
1010 | 1010 | ||
1011 | m_velocity.Z = (vec.Z); | 1011 | m_velocity.Z = (vec.Z); |
1012 | 1012 | ||
1013 | if (m_velocity.Z < -6 && !m_hackSentFall) | 1013 | if (m_velocity.Z < -6 && !m_hackSentFall) |
1014 | { | 1014 | { |
1015 | m_hackSentFall = true; | 1015 | m_hackSentFall = true; |
1016 | m_pidControllerActive = false; | 1016 | m_pidControllerActive = false; |
1017 | } | 1017 | } |
1018 | else if (m_flying && !m_hackSentFly) | 1018 | else if (m_flying && !m_hackSentFly) |
1019 | { | 1019 | { |
1020 | //m_hackSentFly = true; | 1020 | //m_hackSentFly = true; |
1021 | //base.SendCollisionUpdate(new CollisionEventUpdate()); | 1021 | //base.SendCollisionUpdate(new CollisionEventUpdate()); |
1022 | } | 1022 | } |
1023 | else | 1023 | else |
1024 | { | 1024 | { |
1025 | m_hackSentFly = false; | 1025 | m_hackSentFly = false; |
1026 | m_hackSentFall = false; | 1026 | m_hackSentFall = false; |
1027 | } | 1027 | } |
1028 | } | 1028 | } |
1029 | if (Body != null) | 1029 | if (Body != null) |
1030 | { | 1030 | { |
1031 | if (Body.getFriction() < 0.9f) | 1031 | if (Body.getFriction() < 0.9f) |
1032 | Body.setFriction(0.9f); | 1032 | Body.setFriction(0.9f); |
1033 | } | 1033 | } |
1034 | //if (Body != null) | 1034 | //if (Body != null) |
1035 | // Body.clearForces(); | 1035 | // Body.clearForces(); |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | public void CheckIfStandingOnObject() | 1038 | public void CheckIfStandingOnObject() |
1039 | { | 1039 | { |
1040 | 1040 | ||
1041 | float capsuleHalfHeight = ((CAPSULE_LENGTH + 2*CAPSULE_RADIUS)*0.5f); | 1041 | float capsuleHalfHeight = ((CAPSULE_LENGTH + 2*CAPSULE_RADIUS)*0.5f); |
1042 | 1042 | ||
1043 | tempVector5RayCast.setValue(m_position.X, m_position.Y, m_position.Z); | 1043 | tempVector5RayCast.setValue(m_position.X, m_position.Y, m_position.Z); |
1044 | tempVector6RayCast.setValue(m_position.X, m_position.Y, m_position.Z - 1 * capsuleHalfHeight * 1.1f); | 1044 | tempVector6RayCast.setValue(m_position.X, m_position.Y, m_position.Z - 1 * capsuleHalfHeight * 1.1f); |
1045 | 1045 | ||
1046 | 1046 | ||
1047 | ClosestCastResult.Dispose(); | 1047 | ClosestCastResult.Dispose(); |
1048 | ClosestCastResult = new ClosestNotMeRayResultCallback(Body); | 1048 | ClosestCastResult = new ClosestNotMeRayResultCallback(Body); |
1049 | 1049 | ||
1050 | try | 1050 | try |
1051 | { | 1051 | { |
1052 | m_parent_scene.getBulletWorld().rayTest(tempVector5RayCast, tempVector6RayCast, ClosestCastResult); | 1052 | m_parent_scene.getBulletWorld().rayTest(tempVector5RayCast, tempVector6RayCast, ClosestCastResult); |
1053 | } | 1053 | } |
1054 | catch (AccessViolationException) | 1054 | catch (AccessViolationException) |
1055 | { | 1055 | { |
1056 | m_log.Debug("BAD!"); | 1056 | m_log.Debug("BAD!"); |
1057 | } | 1057 | } |
1058 | if (ClosestCastResult.hasHit()) | 1058 | if (ClosestCastResult.hasHit()) |
1059 | { | 1059 | { |
1060 | 1060 | ||
1061 | if (tempVector7RayCast != null) | 1061 | if (tempVector7RayCast != null) |
1062 | tempVector7RayCast.Dispose(); | 1062 | tempVector7RayCast.Dispose(); |
1063 | 1063 | ||
1064 | //tempVector7RayCast = ClosestCastResult.getHitPointWorld(); | 1064 | //tempVector7RayCast = ClosestCastResult.getHitPointWorld(); |
1065 | 1065 | ||
1066 | /*if (tempVector7RayCast == null) // null == no result also | 1066 | /*if (tempVector7RayCast == null) // null == no result also |
1067 | { | 1067 | { |
1068 | CollidingObj = false; | 1068 | CollidingObj = false; |
1069 | IsColliding = false; | 1069 | IsColliding = false; |
1070 | CollidingGround = false; | 1070 | CollidingGround = false; |
1071 | 1071 | ||
1072 | return; | 1072 | return; |
1073 | } | 1073 | } |
1074 | float zVal = tempVector7RayCast.getZ(); | 1074 | float zVal = tempVector7RayCast.getZ(); |
1075 | if (zVal != 0) | 1075 | if (zVal != 0) |
1076 | m_log.Debug("[PHYSICS]: HAAAA"); | 1076 | m_log.Debug("[PHYSICS]: HAAAA"); |
1077 | if (zVal < m_position.Z && zVal > ((CAPSULE_LENGTH + 2 * CAPSULE_RADIUS) *0.5f)) | 1077 | if (zVal < m_position.Z && zVal > ((CAPSULE_LENGTH + 2 * CAPSULE_RADIUS) *0.5f)) |
1078 | { | 1078 | { |
1079 | CollidingObj = true; | 1079 | CollidingObj = true; |
1080 | IsColliding = true; | 1080 | IsColliding = true; |
1081 | } | 1081 | } |
1082 | else | 1082 | else |
1083 | { | 1083 | { |
1084 | CollidingObj = false; | 1084 | CollidingObj = false; |
1085 | IsColliding = false; | 1085 | IsColliding = false; |
1086 | CollidingGround = false; | 1086 | CollidingGround = false; |
1087 | }*/ | 1087 | }*/ |
1088 | 1088 | ||
1089 | //height+2*radius = capsule full length | 1089 | //height+2*radius = capsule full length |
1090 | //CollidingObj = true; | 1090 | //CollidingObj = true; |
1091 | //IsColliding = true; | 1091 | //IsColliding = true; |
1092 | m_iscolliding = true; | 1092 | m_iscolliding = true; |
1093 | } | 1093 | } |
1094 | else | 1094 | else |
1095 | { | 1095 | { |
1096 | //CollidingObj = false; | 1096 | //CollidingObj = false; |
1097 | //IsColliding = false; | 1097 | //IsColliding = false; |
1098 | //CollidingGround = false; | 1098 | //CollidingGround = false; |
1099 | m_iscolliding = false; | 1099 | m_iscolliding = false; |
1100 | } | 1100 | } |
1101 | } | 1101 | } |
1102 | } | 1102 | } |
1103 | 1103 | ||
1104 | } | 1104 | } |