ODECharacter.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using OpenMetaverse;
  31. using Ode.NET;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Physics.Manager;
  34. using log4net;
  35. namespace OpenSim.Region.Physics.OdePlugin
  36. {
  37. /// <summary>
  38. /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
  39. /// </summary>
  40. public enum dParam : int
  41. {
  42. LowStop = 0,
  43. HiStop = 1,
  44. Vel = 2,
  45. FMax = 3,
  46. FudgeFactor = 4,
  47. Bounce = 5,
  48. CFM = 6,
  49. StopERP = 7,
  50. StopCFM = 8,
  51. LoStop2 = 256,
  52. HiStop2 = 257,
  53. Vel2 = 258,
  54. FMax2 = 259,
  55. StopERP2 = 7 + 256,
  56. StopCFM2 = 8 + 256,
  57. LoStop3 = 512,
  58. HiStop3 = 513,
  59. Vel3 = 514,
  60. FMax3 = 515,
  61. StopERP3 = 7 + 512,
  62. StopCFM3 = 8 + 512
  63. }
  64. public class OdeCharacter : PhysicsActor
  65. {
  66. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  67. private PhysicsVector _position;
  68. private d.Vector3 _zeroPosition;
  69. // private d.Matrix3 m_StandUpRotation;
  70. private bool _zeroFlag = false;
  71. private bool m_lastUpdateSent = false;
  72. private PhysicsVector _velocity;
  73. private PhysicsVector _target_velocity;
  74. private PhysicsVector _acceleration;
  75. private PhysicsVector m_rotationalVelocity;
  76. private float m_mass = 80f;
  77. public float m_density = 60f;
  78. private bool m_pidControllerActive = true;
  79. public float PID_D = 800.0f;
  80. public float PID_P = 900.0f;
  81. //private static float POSTURE_SERVO = 10000.0f;
  82. public float CAPSULE_RADIUS = 0.37f;
  83. public float CAPSULE_LENGTH = 2.140599f;
  84. public float m_tensor = 3800000f;
  85. public float heightFudgeFactor = 0.52f;
  86. public float walkDivisor = 1.3f;
  87. public float runDivisor = 0.8f;
  88. private bool flying = false;
  89. private bool m_iscolliding = false;
  90. private bool m_iscollidingGround = false;
  91. private bool m_wascolliding = false;
  92. private bool m_wascollidingGround = false;
  93. private bool m_iscollidingObj = false;
  94. private bool m_alwaysRun = false;
  95. private bool m_hackSentFall = false;
  96. private bool m_hackSentFly = false;
  97. private PhysicsVector m_taintPosition = new PhysicsVector(0, 0, 0);
  98. public uint m_localID = 0;
  99. public bool m_returnCollisions = false;
  100. // taints and their non-tainted counterparts
  101. public bool m_isPhysical = false; // the current physical status
  102. public bool m_tainted_isPhysical = false; // set when the physical status is tainted (false=not existing in physics engine, true=existing)
  103. public float MinimumGroundFlightOffset = 3f;
  104. private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes.
  105. private float m_buoyancy = 0f;
  106. // private CollisionLocker ode;
  107. private string m_name = String.Empty;
  108. private bool[] m_colliderarr = new bool[11];
  109. private bool[] m_colliderGroundarr = new bool[11];
  110. // Default we're a Character
  111. private CollisionCategories m_collisionCategories = (CollisionCategories.Character);
  112. // Default, Collide with Other Geometries, spaces, bodies and characters.
  113. private CollisionCategories m_collisionFlags = (CollisionCategories.Geom
  114. | CollisionCategories.Space
  115. | CollisionCategories.Body
  116. | CollisionCategories.Character
  117. | CollisionCategories.Land);
  118. public IntPtr Body = IntPtr.Zero;
  119. private OdeScene _parent_scene;
  120. public IntPtr Shell = IntPtr.Zero;
  121. public IntPtr Amotor = IntPtr.Zero;
  122. public d.Mass ShellMass;
  123. public bool collidelock = false;
  124. public int m_eventsubscription = 0;
  125. private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
  126. public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos, CollisionLocker dode, PhysicsVector size, float pid_d, float pid_p, float capsule_radius, float tensor, float density, float height_fudge_factor, float walk_divisor, float rundivisor)
  127. {
  128. // ode = dode;
  129. _velocity = new PhysicsVector();
  130. _target_velocity = new PhysicsVector();
  131. if (PhysicsVector.isFinite(pos))
  132. {
  133. if (pos.Z > 9999999)
  134. {
  135. pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
  136. }
  137. if (pos.Z < -90000)
  138. {
  139. pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
  140. }
  141. _position = pos;
  142. m_taintPosition.X = pos.X;
  143. m_taintPosition.Y = pos.Y;
  144. m_taintPosition.Z = pos.Z;
  145. }
  146. else
  147. {
  148. _position = new PhysicsVector(128,128,parent_scene.GetTerrainHeightAtXY(128,128) + 10);
  149. m_taintPosition.X = _position.X;
  150. m_taintPosition.Y = _position.Y;
  151. m_taintPosition.Z = _position.Z;
  152. m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
  153. }
  154. _acceleration = new PhysicsVector();
  155. _parent_scene = parent_scene;
  156. PID_D = pid_d;
  157. PID_P = pid_p;
  158. CAPSULE_RADIUS = capsule_radius;
  159. m_tensor = tensor;
  160. m_density = density;
  161. heightFudgeFactor = height_fudge_factor;
  162. walkDivisor = walk_divisor;
  163. runDivisor = rundivisor;
  164. // m_StandUpRotation =
  165. // new d.Matrix3(0.5f, 0.7071068f, 0.5f, -0.7071068f, 0f, 0.7071068f, 0.5f, -0.7071068f,
  166. // 0.5f);
  167. for (int i = 0; i < 11; i++)
  168. {
  169. m_colliderarr[i] = false;
  170. }
  171. CAPSULE_LENGTH = (size.Z * 1.15f) - CAPSULE_RADIUS * 2.0f;
  172. //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
  173. m_tainted_CAPSULE_LENGTH = CAPSULE_LENGTH;
  174. m_isPhysical = false; // current status: no ODE information exists
  175. m_tainted_isPhysical = true; // new tainted status: need to create ODE information
  176. _parent_scene.AddPhysicsActorTaint(this);
  177. m_name = avName;
  178. }
  179. public override int PhysicsActorType
  180. {
  181. get { return (int) ActorTypes.Agent; }
  182. set { return; }
  183. }
  184. /// <summary>
  185. /// If this is set, the avatar will move faster
  186. /// </summary>
  187. public override bool SetAlwaysRun
  188. {
  189. get { return m_alwaysRun; }
  190. set { m_alwaysRun = value; }
  191. }
  192. public override uint LocalID
  193. {
  194. set { m_localID = value; }
  195. }
  196. public override bool Grabbed
  197. {
  198. set { return; }
  199. }
  200. public override bool Selected
  201. {
  202. set { return; }
  203. }
  204. public override float Buoyancy
  205. {
  206. get { return m_buoyancy; }
  207. set { m_buoyancy = value; }
  208. }
  209. public override bool FloatOnWater
  210. {
  211. set { return; }
  212. }
  213. public override bool IsPhysical
  214. {
  215. get { return false; }
  216. set { return; }
  217. }
  218. public override bool ThrottleUpdates
  219. {
  220. get { return false; }
  221. set { return; }
  222. }
  223. public override bool Flying
  224. {
  225. get { return flying; }
  226. set { flying = value; }
  227. }
  228. /// <summary>
  229. /// Returns if the avatar is colliding in general.
  230. /// This includes the ground and objects and avatar.
  231. /// </summary>
  232. public override bool IsColliding
  233. {
  234. get { return m_iscolliding; }
  235. set
  236. {
  237. int i;
  238. int truecount = 0;
  239. int falsecount = 0;
  240. if (m_colliderarr.Length >= 10)
  241. {
  242. for (i = 0; i < 10; i++)
  243. {
  244. m_colliderarr[i] = m_colliderarr[i + 1];
  245. }
  246. }
  247. m_colliderarr[10] = value;
  248. for (i = 0; i < 11; i++)
  249. {
  250. if (m_colliderarr[i])
  251. {
  252. truecount++;
  253. }
  254. else
  255. {
  256. falsecount++;
  257. }
  258. }
  259. // Equal truecounts and false counts means we're colliding with something.
  260. if (falsecount > 1.2*truecount)
  261. {
  262. m_iscolliding = false;
  263. }
  264. else
  265. {
  266. m_iscolliding = true;
  267. }
  268. if (m_wascolliding != m_iscolliding)
  269. {
  270. //base.SendCollisionUpdate(new CollisionEventUpdate());
  271. }
  272. m_wascolliding = m_iscolliding;
  273. }
  274. }
  275. /// <summary>
  276. /// Returns if an avatar is colliding with the ground
  277. /// </summary>
  278. public override bool CollidingGround
  279. {
  280. get { return m_iscollidingGround; }
  281. set
  282. {
  283. // Collisions against the ground are not really reliable
  284. // So, to get a consistant value we have to average the current result over time
  285. // Currently we use 1 second = 10 calls to this.
  286. int i;
  287. int truecount = 0;
  288. int falsecount = 0;
  289. if (m_colliderGroundarr.Length >= 10)
  290. {
  291. for (i = 0; i < 10; i++)
  292. {
  293. m_colliderGroundarr[i] = m_colliderGroundarr[i + 1];
  294. }
  295. }
  296. m_colliderGroundarr[10] = value;
  297. for (i = 0; i < 11; i++)
  298. {
  299. if (m_colliderGroundarr[i])
  300. {
  301. truecount++;
  302. }
  303. else
  304. {
  305. falsecount++;
  306. }
  307. }
  308. // Equal truecounts and false counts means we're colliding with something.
  309. if (falsecount > 1.2*truecount)
  310. {
  311. m_iscollidingGround = false;
  312. }
  313. else
  314. {
  315. m_iscollidingGround = true;
  316. }
  317. if (m_wascollidingGround != m_iscollidingGround)
  318. {
  319. //base.SendCollisionUpdate(new CollisionEventUpdate());
  320. }
  321. m_wascollidingGround = m_iscollidingGround;
  322. }
  323. }
  324. /// <summary>
  325. /// Returns if the avatar is colliding with an object
  326. /// </summary>
  327. public override bool CollidingObj
  328. {
  329. get { return m_iscollidingObj; }
  330. set
  331. {
  332. m_iscollidingObj = value;
  333. if (value)
  334. m_pidControllerActive = false;
  335. else
  336. m_pidControllerActive = true;
  337. }
  338. }
  339. /// <summary>
  340. /// turn the PID controller on or off.
  341. /// The PID Controller will turn on all by itself in many situations
  342. /// </summary>
  343. /// <param name="status"></param>
  344. public void SetPidStatus(bool status)
  345. {
  346. m_pidControllerActive = status;
  347. }
  348. public override bool Stopped
  349. {
  350. get { return _zeroFlag; }
  351. }
  352. /// <summary>
  353. /// This 'puts' an avatar somewhere in the physics space.
  354. /// Not really a good choice unless you 'know' it's a good
  355. /// spot otherwise you're likely to orbit the avatar.
  356. /// </summary>
  357. public override PhysicsVector Position
  358. {
  359. get { return _position; }
  360. set
  361. {
  362. if (Body == IntPtr.Zero || Shell == IntPtr.Zero)
  363. {
  364. if (PhysicsVector.isFinite(value))
  365. {
  366. if (value.Z > 9999999)
  367. {
  368. value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
  369. }
  370. if (value.Z < -90000)
  371. {
  372. value.Z = _parent_scene.GetTerrainHeightAtXY(127, 127) + 5;
  373. }
  374. _position.X = value.X;
  375. _position.Y = value.Y;
  376. _position.Z = value.Z;
  377. m_taintPosition.X = value.X;
  378. m_taintPosition.Y = value.Y;
  379. m_taintPosition.Z = value.Z;
  380. _parent_scene.AddPhysicsActorTaint(this);
  381. }
  382. else
  383. {
  384. m_log.Warn("[PHYSICS]: Got a NaN Position from Scene on a Character");
  385. }
  386. }
  387. }
  388. }
  389. public override PhysicsVector RotationalVelocity
  390. {
  391. get { return m_rotationalVelocity; }
  392. set { m_rotationalVelocity = value; }
  393. }
  394. /// <summary>
  395. /// This property sets the height of the avatar only. We use the height to make sure the avatar stands up straight
  396. /// and use it to offset landings properly
  397. /// </summary>
  398. public override PhysicsVector Size
  399. {
  400. get { return new PhysicsVector(CAPSULE_RADIUS*2, CAPSULE_RADIUS*2, CAPSULE_LENGTH); }
  401. set
  402. {
  403. if (PhysicsVector.isFinite(value))
  404. {
  405. m_pidControllerActive = true;
  406. PhysicsVector SetSize = value;
  407. m_tainted_CAPSULE_LENGTH = (SetSize.Z*1.15f) - CAPSULE_RADIUS*2.0f;
  408. //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
  409. Velocity = new PhysicsVector(0f, 0f, 0f);
  410. _parent_scene.AddPhysicsActorTaint(this);
  411. }
  412. else
  413. {
  414. m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
  415. }
  416. }
  417. }
  418. /// <summary>
  419. /// This creates the Avatar's physical Surrogate at the position supplied
  420. /// </summary>
  421. /// <param name="npositionX"></param>
  422. /// <param name="npositionY"></param>
  423. /// <param name="npositionZ"></param>
  424. // WARNING: This MUST NOT be called outside of ProcessTaints, else we can have unsynchronized access
  425. // to ODE internals. ProcessTaints is called from within thread-locked Simulate(), so it is the only
  426. // place that is safe to call this routine AvatarGeomAndBodyCreation.
  427. private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ, float tensor)
  428. {
  429. //CAPSULE_LENGTH = -5;
  430. //CAPSULE_RADIUS = -5;
  431. int dAMotorEuler = 1;
  432. _parent_scene.waitForSpaceUnlock(_parent_scene.space);
  433. if (CAPSULE_LENGTH <= 0)
  434. {
  435. m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
  436. CAPSULE_LENGTH = 0.01f;
  437. }
  438. if (CAPSULE_RADIUS <= 0)
  439. {
  440. m_log.Warn("[PHYSICS]: The capsule size you specified in opensim.ini is invalid! Setting it to the smallest possible size!");
  441. CAPSULE_RADIUS = 0.01f;
  442. }
  443. Shell = d.CreateCapsule(_parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH);
  444. d.GeomSetCategoryBits(Shell, (int)m_collisionCategories);
  445. d.GeomSetCollideBits(Shell, (int)m_collisionFlags);
  446. d.MassSetCapsuleTotal(out ShellMass, m_mass, 2, CAPSULE_RADIUS, CAPSULE_LENGTH);
  447. Body = d.BodyCreate(_parent_scene.world);
  448. d.BodySetPosition(Body, npositionX, npositionY, npositionZ);
  449. _position.X = npositionX;
  450. _position.Y = npositionY;
  451. _position.Z = npositionZ;
  452. m_taintPosition.X = npositionX;
  453. m_taintPosition.Y = npositionY;
  454. m_taintPosition.Z = npositionZ;
  455. d.BodySetMass(Body, ref ShellMass);
  456. d.Matrix3 m_caprot;
  457. // 90 Stand up on the cap of the capped cyllinder
  458. if (_parent_scene.IsAvCapsuleTilted)
  459. {
  460. d.RFromAxisAndAngle(out m_caprot, 1, 0, 1, (float)(Math.PI / 2));
  461. }
  462. else
  463. {
  464. d.RFromAxisAndAngle(out m_caprot, 0, 0, 1, (float)(Math.PI / 2));
  465. }
  466. d.GeomSetRotation(Shell, ref m_caprot);
  467. d.BodySetRotation(Body, ref m_caprot);
  468. d.GeomSetBody(Shell, Body);
  469. // The purpose of the AMotor here is to keep the avatar's physical
  470. // surrogate from rotating while moving
  471. Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
  472. d.JointAttach(Amotor, Body, IntPtr.Zero);
  473. d.JointSetAMotorMode(Amotor, dAMotorEuler);
  474. d.JointSetAMotorNumAxes(Amotor, 3);
  475. d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0);
  476. d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0);
  477. d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1);
  478. d.JointSetAMotorAngle(Amotor, 0, 0);
  479. d.JointSetAMotorAngle(Amotor, 1, 0);
  480. d.JointSetAMotorAngle(Amotor, 2, 0);
  481. // These lowstops and high stops are effectively (no wiggle room)
  482. if (_parent_scene.IsAvCapsuleTilted)
  483. {
  484. d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0.000000000001f);
  485. d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0.000000000001f);
  486. d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0.000000000001f);
  487. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.000000000001f);
  488. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0.000000000001f);
  489. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.000000000001f);
  490. }
  491. else
  492. {
  493. #region Documentation of capsule motor LowStop and HighStop parameters
  494. // Intentionally introduce some tilt into the capsule by setting
  495. // the motor stops to small epsilon values. This small tilt prevents
  496. // the capsule from falling into the terrain; a straight-up capsule
  497. // (with -0..0 motor stops) falls into the terrain for reasons yet
  498. // to be comprehended in their entirety.
  499. #endregion
  500. d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
  501. d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
  502. d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f);
  503. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced
  504. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
  505. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop
  506. #region Documentation of capsule motor StopERP and StopCFM parameters
  507. // In addition to the above tilt, we allow a dynamic tilt, or
  508. // wobble, to emerge as the capsule is pushed around the environment.
  509. // We do this with an experimentally determined combination of
  510. // StopERP and StopCFM which make the above motor stops soft.
  511. // The softness of the stops should be tweaked according to two
  512. // requirements:
  513. //
  514. // 1. Motor stops should be weak enough to allow enough wobble such
  515. // that the capsule can tilt slightly more when moving, to allow
  516. // "gliding" over obstacles:
  517. //
  518. //
  519. // .-.
  520. // / /
  521. // / /
  522. // _ / / _
  523. // / \ .-. / / / \
  524. // | | ----> / / / / | |
  525. // | | / / `-' | |
  526. // | | / / +------+ | |
  527. // | | / / | | | |
  528. // | | / / | | | |
  529. // \_/ `-' +------+ \_/
  530. // ----------------------------------------------------------
  531. //
  532. // Note that requirement 1 is made complicated by the ever-present
  533. // slight avatar tilt (assigned in the above code to prevent avatar
  534. // from falling through terrain), which introduces a direction-dependent
  535. // bias into the wobble (wobbling against the existing tilt is harder
  536. // than wobbling with the tilt), which makes it easier to walk over
  537. // prims from some directions. I have tried to minimize this effect by
  538. // minimizing the avatar tilt to the minimum that prevents the avatar from
  539. // falling through the terrain.
  540. //
  541. // 2. Motor stops should be strong enough to prevent the capsule
  542. // from being forced all the way to the ground; otherwise the
  543. // capsule could slip underneath obstacles like this:
  544. // _ _
  545. // / \ +------+ / \
  546. // | | ----> | | | |
  547. // | | | | | |
  548. // | | .--.___ +------+ | |
  549. // | | `--.__`--.__ | |
  550. // | | `--.__`--. | |
  551. // \_/ `--' \_/
  552. // ----------------------------------------------------------
  553. //
  554. //
  555. // It is strongly recommended you enable USE_DRAWSTUFF if you want to
  556. // tweak these values, to see how the capsule is reacting in various
  557. // situations.
  558. #endregion
  559. d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM, 0.0035f);
  560. d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM2, 0.0035f);
  561. d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM3, 0.0035f);
  562. d.JointSetAMotorParam(Amotor, (int)dParam.StopERP, 0.8f);
  563. d.JointSetAMotorParam(Amotor, (int)dParam.StopERP2, 0.8f);
  564. d.JointSetAMotorParam(Amotor, (int)dParam.StopERP3, 0.8f);
  565. }
  566. // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the
  567. // capped cyllinder will fall over
  568. d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f);
  569. d.JointSetAMotorParam(Amotor, (int)dParam.FMax, tensor);
  570. //d.Matrix3 bodyrotation = d.BodyGetRotation(Body);
  571. //d.QfromR(
  572. //d.Matrix3 checkrotation = new d.Matrix3(0.7071068,0.5, -0.7071068,
  573. //
  574. //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22);
  575. //standupStraight();
  576. }
  577. //
  578. /// <summary>
  579. /// Uses the capped cyllinder volume formula to calculate the avatar's mass.
  580. /// This may be used in calculations in the scene/scenepresence
  581. /// </summary>
  582. public override float Mass
  583. {
  584. get
  585. {
  586. float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH);
  587. return m_density*AVvolume;
  588. }
  589. }
  590. public override void link(PhysicsActor obj)
  591. {
  592. }
  593. public override void delink()
  594. {
  595. }
  596. public override void LockAngularMotion(PhysicsVector axis)
  597. {
  598. }
  599. // This code is very useful. Written by DanX0r. We're just not using it right now.
  600. // Commented out to prevent a warning.
  601. //
  602. // private void standupStraight()
  603. // {
  604. // // The purpose of this routine here is to quickly stabilize the Body while it's popped up in the air.
  605. // // The amotor needs a few seconds to stabilize so without it, the avatar shoots up sky high when you
  606. // // change appearance and when you enter the simulator
  607. // // After this routine is done, the amotor stabilizes much quicker
  608. // d.Vector3 feet;
  609. // d.Vector3 head;
  610. // d.BodyGetRelPointPos(Body, 0.0f, 0.0f, -1.0f, out feet);
  611. // d.BodyGetRelPointPos(Body, 0.0f, 0.0f, 1.0f, out head);
  612. // float posture = head.Z - feet.Z;
  613. // // restoring force proportional to lack of posture:
  614. // float servo = (2.5f - posture) * POSTURE_SERVO;
  615. // d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f);
  616. // d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f);
  617. // //d.Matrix3 bodyrotation = d.BodyGetRotation(Body);
  618. // //m_log.Info("[PHYSICSAV]: Rotation: " + bodyrotation.M00 + " : " + bodyrotation.M01 + " : " + bodyrotation.M02 + " : " + bodyrotation.M10 + " : " + bodyrotation.M11 + " : " + bodyrotation.M12 + " : " + bodyrotation.M20 + " : " + bodyrotation.M21 + " : " + bodyrotation.M22);
  619. // }
  620. public override PhysicsVector Force
  621. {
  622. get { return new PhysicsVector(_target_velocity.X, _target_velocity.Y, _target_velocity.Z); }
  623. set { return; }
  624. }
  625. public override int VehicleType
  626. {
  627. get { return 0; }
  628. set { return; }
  629. }
  630. public override void VehicleFloatParam(int param, float value)
  631. {
  632. }
  633. public override void VehicleVectorParam(int param, PhysicsVector value)
  634. {
  635. }
  636. public override void VehicleRotationParam(int param, Quaternion rotation)
  637. {
  638. }
  639. public override void SetVolumeDetect(int param)
  640. {
  641. }
  642. public override PhysicsVector CenterOfMass
  643. {
  644. get { return PhysicsVector.Zero; }
  645. }
  646. public override PhysicsVector GeometricCenter
  647. {
  648. get { return PhysicsVector.Zero; }
  649. }
  650. public override PrimitiveBaseShape Shape
  651. {
  652. set { return; }
  653. }
  654. public override PhysicsVector Velocity
  655. {
  656. get {
  657. // There's a problem with PhysicsVector.Zero! Don't Use it Here!
  658. if (_zeroFlag)
  659. return new PhysicsVector(0f, 0f, 0f);
  660. m_lastUpdateSent = false;
  661. return _velocity;
  662. }
  663. set
  664. {
  665. if (PhysicsVector.isFinite(value))
  666. {
  667. m_pidControllerActive = true;
  668. _target_velocity = value;
  669. }
  670. else
  671. {
  672. m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character");
  673. }
  674. }
  675. }
  676. public override PhysicsVector Torque
  677. {
  678. get { return PhysicsVector.Zero; }
  679. set { return; }
  680. }
  681. public override float CollisionScore
  682. {
  683. get { return 0f; }
  684. set { }
  685. }
  686. public override bool Kinematic
  687. {
  688. get { return false; }
  689. set { }
  690. }
  691. public override Quaternion Orientation
  692. {
  693. get { return Quaternion.Identity; }
  694. set {
  695. //Matrix3 or = Orientation.ToRotationMatrix();
  696. //d.Matrix3 ord = new d.Matrix3(or.m00, or.m10, or.m20, or.m01, or.m11, or.m21, or.m02, or.m12, or.m22);
  697. //d.BodySetRotation(Body, ref ord);
  698. }
  699. }
  700. public override PhysicsVector Acceleration
  701. {
  702. get { return _acceleration; }
  703. }
  704. public void SetAcceleration(PhysicsVector accel)
  705. {
  706. m_pidControllerActive = true;
  707. _acceleration = accel;
  708. }
  709. /// <summary>
  710. /// Adds the force supplied to the Target Velocity
  711. /// The PID controller takes this target velocity and tries to make it a reality
  712. /// </summary>
  713. /// <param name="force"></param>
  714. public override void AddForce(PhysicsVector force, bool pushforce)
  715. {
  716. if (PhysicsVector.isFinite(force))
  717. {
  718. if (pushforce)
  719. {
  720. m_pidControllerActive = false;
  721. force *= 100f;
  722. doForce(force);
  723. // If uncommented, things get pushed off world
  724. //
  725. // m_log.Debug("Push!");
  726. // _target_velocity.X += force.X;
  727. // _target_velocity.Y += force.Y;
  728. // _target_velocity.Z += force.Z;
  729. }
  730. else
  731. {
  732. m_pidControllerActive = true;
  733. _target_velocity.X += force.X;
  734. _target_velocity.Y += force.Y;
  735. _target_velocity.Z += force.Z;
  736. }
  737. }
  738. else
  739. {
  740. m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character");
  741. }
  742. //m_lastUpdateSent = false;
  743. }
  744. public override void AddAngularForce(PhysicsVector force, bool pushforce)
  745. {
  746. }
  747. /// <summary>
  748. /// After all of the forces add up with 'add force' we apply them with doForce
  749. /// </summary>
  750. /// <param name="force"></param>
  751. public void doForce(PhysicsVector force)
  752. {
  753. if (!collidelock)
  754. {
  755. d.BodyAddForce(Body, force.X, force.Y, force.Z);
  756. //d.BodySetRotation(Body, ref m_StandUpRotation);
  757. //standupStraight();
  758. }
  759. }
  760. public override void SetMomentum(PhysicsVector momentum)
  761. {
  762. }
  763. /// <summary>
  764. /// Called from Simulate
  765. /// This is the avatar's movement control + PID Controller
  766. /// </summary>
  767. /// <param name="timeStep"></param>
  768. public void Move(float timeStep, List<OdeCharacter> defects)
  769. {
  770. // no lock; for now it's only called from within Simulate()
  771. // If the PID Controller isn't active then we set our force
  772. // calculating base velocity to the current position
  773. if (Body == IntPtr.Zero)
  774. return;
  775. if (m_pidControllerActive == false)
  776. {
  777. _zeroPosition = d.BodyGetPosition(Body);
  778. }
  779. //PidStatus = true;
  780. d.Vector3 localpos = d.BodyGetPosition(Body);
  781. PhysicsVector localPos = new PhysicsVector(localpos.X, localpos.Y, localpos.Z);
  782. if (!PhysicsVector.isFinite(localPos))
  783. {
  784. m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
  785. defects.Add(this);
  786. // _parent_scene.RemoveCharacter(this);
  787. // destroy avatar capsule and related ODE data
  788. if (Amotor != IntPtr.Zero)
  789. {
  790. // Kill the Amotor
  791. d.JointDestroy(Amotor);
  792. Amotor = IntPtr.Zero;
  793. }
  794. //kill the Geometry
  795. _parent_scene.waitForSpaceUnlock(_parent_scene.space);
  796. if (Body != IntPtr.Zero)
  797. {
  798. //kill the body
  799. d.BodyDestroy(Body);
  800. Body = IntPtr.Zero;
  801. }
  802. if (Shell != IntPtr.Zero)
  803. {
  804. d.GeomDestroy(Shell);
  805. _parent_scene.geom_name_map.Remove(Shell);
  806. Shell = IntPtr.Zero;
  807. }
  808. return;
  809. }
  810. PhysicsVector vec = new PhysicsVector();
  811. d.Vector3 vel = d.BodyGetLinearVel(Body);
  812. float movementdivisor = 1f;
  813. if (!m_alwaysRun)
  814. {
  815. movementdivisor = walkDivisor;
  816. }
  817. else
  818. {
  819. movementdivisor = runDivisor;
  820. }
  821. // if velocity is zero, use position control; otherwise, velocity control
  822. if (_target_velocity.X == 0.0f && _target_velocity.Y == 0.0f && _target_velocity.Z == 0.0f && m_iscolliding)
  823. {
  824. // keep track of where we stopped. No more slippin' & slidin'
  825. if (!_zeroFlag)
  826. {
  827. _zeroFlag = true;
  828. _zeroPosition = d.BodyGetPosition(Body);
  829. }
  830. if (m_pidControllerActive)
  831. {
  832. // We only want to deactivate the PID Controller if we think we want to have our surrogate
  833. // react to the physics scene by moving it's position.
  834. // Avatar to Avatar collisions
  835. // Prim to avatar collisions
  836. d.Vector3 pos = d.BodyGetPosition(Body);
  837. vec.X = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2);
  838. vec.Y = (_target_velocity.Y - vel.Y)*(PID_D) + (_zeroPosition.Y - pos.Y)* (PID_P * 2);
  839. if (flying)
  840. {
  841. vec.Z = (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P;
  842. }
  843. }
  844. //PidStatus = true;
  845. }
  846. else
  847. {
  848. m_pidControllerActive = true;
  849. _zeroFlag = false;
  850. if (m_iscolliding && !flying)
  851. {
  852. // We're standing on something
  853. vec.X = ((_target_velocity.X / movementdivisor) - vel.X) * (PID_D);
  854. vec.Y = ((_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D);
  855. }
  856. else if (m_iscolliding && flying)
  857. {
  858. // We're flying and colliding with something
  859. vec.X = ((_target_velocity.X/movementdivisor) - vel.X)*(PID_D / 16);
  860. vec.Y = ((_target_velocity.Y/movementdivisor) - vel.Y)*(PID_D / 16);
  861. }
  862. else if (!m_iscolliding && flying)
  863. {
  864. // we're in mid air suspended
  865. vec.X = ((_target_velocity.X / movementdivisor) - vel.X) * (PID_D/6);
  866. vec.Y = ((_target_velocity.Y / movementdivisor) - vel.Y) * (PID_D/6);
  867. }
  868. if (m_iscolliding && !flying && _target_velocity.Z > 0.0f)
  869. {
  870. // We're colliding with something and we're not flying but we're moving
  871. // This means we're walking or running.
  872. d.Vector3 pos = d.BodyGetPosition(Body);
  873. vec.Z = (_target_velocity.Z - vel.Z)*PID_D + (_zeroPosition.Z - pos.Z)*PID_P;
  874. if (_target_velocity.X > 0)
  875. {
  876. vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D;
  877. }
  878. if (_target_velocity.Y > 0)
  879. {
  880. vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D;
  881. }
  882. }
  883. else if (!m_iscolliding && !flying)
  884. {
  885. // we're not colliding and we're not flying so that means we're falling!
  886. // m_iscolliding includes collisions with the ground.
  887. // d.Vector3 pos = d.BodyGetPosition(Body);
  888. if (_target_velocity.X > 0)
  889. {
  890. vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D;
  891. }
  892. if (_target_velocity.Y > 0)
  893. {
  894. vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D;
  895. }
  896. }
  897. if (flying)
  898. {
  899. vec.Z = (_target_velocity.Z - vel.Z) * (PID_D);
  900. }
  901. }
  902. if (flying)
  903. {
  904. vec.Z += ((-1 * _parent_scene.gravityz)*m_mass);
  905. //Added for auto fly height. Kitto Flora
  906. //d.Vector3 pos = d.BodyGetPosition(Body);
  907. float target_altitude = _parent_scene.GetTerrainHeightAtXY(_position.X, _position.Y) + MinimumGroundFlightOffset;
  908. if (_position.Z < target_altitude)
  909. {
  910. vec.Z += (target_altitude - _position.Z) * PID_P * 5.0f;
  911. }
  912. // end add Kitto Flora
  913. }
  914. if (PhysicsVector.isFinite(vec))
  915. {
  916. doForce(vec);
  917. }
  918. else
  919. {
  920. m_log.Warn("[PHYSICS]: Got a NaN force vector in Move()");
  921. m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
  922. defects.Add(this);
  923. // _parent_scene.RemoveCharacter(this);
  924. // destroy avatar capsule and related ODE data
  925. if (Amotor != IntPtr.Zero)
  926. {
  927. // Kill the Amotor
  928. d.JointDestroy(Amotor);
  929. Amotor = IntPtr.Zero;
  930. }
  931. //kill the Geometry
  932. _parent_scene.waitForSpaceUnlock(_parent_scene.space);
  933. if (Body != IntPtr.Zero)
  934. {
  935. //kill the body
  936. d.BodyDestroy(Body);
  937. Body = IntPtr.Zero;
  938. }
  939. if (Shell != IntPtr.Zero)
  940. {
  941. d.GeomDestroy(Shell);
  942. _parent_scene.geom_name_map.Remove(Shell);
  943. Shell = IntPtr.Zero;
  944. }
  945. return;
  946. }
  947. }
  948. /// <summary>
  949. /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence.
  950. /// </summary>
  951. public void UpdatePositionAndVelocity()
  952. {
  953. // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
  954. d.Vector3 vec = d.BodyGetPosition(Body);
  955. // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
  956. if (vec.X < 0.0f) vec.X = 0.0f;
  957. if (vec.Y < 0.0f) vec.Y = 0.0f;
  958. if (vec.X > 255.95f) vec.X = 255.95f;
  959. if (vec.Y > 255.95f) vec.Y = 255.95f;
  960. _position.X = vec.X;
  961. _position.Y = vec.Y;
  962. _position.Z = vec.Z;
  963. // Did we move last? = zeroflag
  964. // This helps keep us from sliding all over
  965. if (_zeroFlag)
  966. {
  967. _velocity.X = 0.0f;
  968. _velocity.Y = 0.0f;
  969. _velocity.Z = 0.0f;
  970. // Did we send out the 'stopped' message?
  971. if (!m_lastUpdateSent)
  972. {
  973. m_lastUpdateSent = true;
  974. //base.RequestPhysicsterseUpdate();
  975. }
  976. }
  977. else
  978. {
  979. m_lastUpdateSent = false;
  980. vec = d.BodyGetLinearVel(Body);
  981. _velocity.X = (vec.X);
  982. _velocity.Y = (vec.Y);
  983. _velocity.Z = (vec.Z);
  984. if (_velocity.Z < -6 && !m_hackSentFall)
  985. {
  986. m_hackSentFall = true;
  987. m_pidControllerActive = false;
  988. }
  989. else if (flying && !m_hackSentFly)
  990. {
  991. //m_hackSentFly = true;
  992. //base.SendCollisionUpdate(new CollisionEventUpdate());
  993. }
  994. else
  995. {
  996. m_hackSentFly = false;
  997. m_hackSentFall = false;
  998. }
  999. }
  1000. }
  1001. /// <summary>
  1002. /// Cleanup the things we use in the scene.
  1003. /// </summary>
  1004. public void Destroy()
  1005. {
  1006. m_tainted_isPhysical = false;
  1007. _parent_scene.AddPhysicsActorTaint(this);
  1008. }
  1009. public override void CrossingFailure()
  1010. {
  1011. }
  1012. public override PhysicsVector PIDTarget { set { return; } }
  1013. public override bool PIDActive { set { return; } }
  1014. public override float PIDTau { set { return; } }
  1015. public override float PIDHoverHeight { set { return; } }
  1016. public override bool PIDHoverActive { set { return; } }
  1017. public override PIDHoverType PIDHoverType { set { return; } }
  1018. public override float PIDHoverTau { set { return; } }
  1019. public override void SubscribeEvents(int ms)
  1020. {
  1021. m_eventsubscription = ms;
  1022. _parent_scene.addCollisionEventReporting(this);
  1023. }
  1024. public override void UnSubscribeEvents()
  1025. {
  1026. _parent_scene.remCollisionEventReporting(this);
  1027. m_eventsubscription = 0;
  1028. }
  1029. public void AddCollisionEvent(uint CollidedWith, float depth)
  1030. {
  1031. if (m_eventsubscription > 0)
  1032. CollisionEventsThisFrame.addCollider(CollidedWith,depth);
  1033. }
  1034. public void SendCollisions()
  1035. {
  1036. if (m_eventsubscription > 0)
  1037. {
  1038. base.SendCollisionUpdate(CollisionEventsThisFrame);
  1039. CollisionEventsThisFrame = new CollisionEventUpdate();
  1040. }
  1041. }
  1042. public override bool SubscribedEvents()
  1043. {
  1044. if (m_eventsubscription > 0)
  1045. return true;
  1046. return false;
  1047. }
  1048. public void ProcessTaints(float timestep)
  1049. {
  1050. if (m_tainted_isPhysical != m_isPhysical)
  1051. {
  1052. if (m_tainted_isPhysical)
  1053. {
  1054. // Create avatar capsule and related ODE data
  1055. if (!(Shell == IntPtr.Zero && Body == IntPtr.Zero && Amotor == IntPtr.Zero))
  1056. {
  1057. m_log.Warn("[PHYSICS]: re-creating the following avatar ODE data, even though it already exists - "
  1058. + (Shell!=IntPtr.Zero ? "Shell ":"")
  1059. + (Body!=IntPtr.Zero ? "Body ":"")
  1060. + (Amotor!=IntPtr.Zero ? "Amotor ":""));
  1061. }
  1062. AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z, m_tensor);
  1063. _parent_scene.geom_name_map[Shell] = m_name;
  1064. _parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
  1065. _parent_scene.AddCharacter(this);
  1066. }
  1067. else
  1068. {
  1069. _parent_scene.RemoveCharacter(this);
  1070. // destroy avatar capsule and related ODE data
  1071. if (Amotor != IntPtr.Zero)
  1072. {
  1073. // Kill the Amotor
  1074. d.JointDestroy(Amotor);
  1075. Amotor = IntPtr.Zero;
  1076. }
  1077. //kill the Geometry
  1078. _parent_scene.waitForSpaceUnlock(_parent_scene.space);
  1079. if (Body != IntPtr.Zero)
  1080. {
  1081. //kill the body
  1082. d.BodyDestroy(Body);
  1083. Body = IntPtr.Zero;
  1084. }
  1085. if (Shell != IntPtr.Zero)
  1086. {
  1087. d.GeomDestroy(Shell);
  1088. _parent_scene.geom_name_map.Remove(Shell);
  1089. Shell = IntPtr.Zero;
  1090. }
  1091. }
  1092. m_isPhysical = m_tainted_isPhysical;
  1093. }
  1094. if (m_tainted_CAPSULE_LENGTH != CAPSULE_LENGTH)
  1095. {
  1096. if (Shell != IntPtr.Zero && Body != IntPtr.Zero && Amotor != IntPtr.Zero)
  1097. {
  1098. m_pidControllerActive = true;
  1099. // no lock needed on _parent_scene.OdeLock because we are called from within the thread lock in OdePlugin's simulate()
  1100. d.JointDestroy(Amotor);
  1101. float prevCapsule = CAPSULE_LENGTH;
  1102. CAPSULE_LENGTH = m_tainted_CAPSULE_LENGTH;
  1103. //m_log.Info("[SIZE]: " + CAPSULE_LENGTH.ToString());
  1104. d.BodyDestroy(Body);
  1105. d.GeomDestroy(Shell);
  1106. AvatarGeomAndBodyCreation(_position.X, _position.Y,
  1107. _position.Z + (Math.Abs(CAPSULE_LENGTH - prevCapsule) * 2), m_tensor);
  1108. Velocity = new PhysicsVector(0f, 0f, 0f);
  1109. _parent_scene.geom_name_map[Shell] = m_name;
  1110. _parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
  1111. }
  1112. else
  1113. {
  1114. m_log.Warn("[PHYSICS]: trying to change capsule size, but the following ODE data is missing - "
  1115. + (Shell==IntPtr.Zero ? "Shell ":"")
  1116. + (Body==IntPtr.Zero ? "Body ":"")
  1117. + (Amotor==IntPtr.Zero ? "Amotor ":""));
  1118. }
  1119. }
  1120. if (!m_taintPosition.IsIdentical(_position, 0.05f))
  1121. {
  1122. if (Body != IntPtr.Zero)
  1123. {
  1124. d.BodySetPosition(Body, m_taintPosition.X, m_taintPosition.Y, m_taintPosition.Z);
  1125. _position.X = m_taintPosition.X;
  1126. _position.Y = m_taintPosition.Y;
  1127. _position.Z = m_taintPosition.Z;
  1128. }
  1129. }
  1130. }
  1131. }
  1132. }