ODECharacter.cs 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239
  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. // Revision by Ubit 2011/12
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.PhysicsModules.SharedBase;
  34. using log4net;
  35. namespace OpenSim.Region.PhysicsModule.ubOde
  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 Vector3 _position;
  68. private Vector3 _zeroPosition;
  69. private Vector3 _velocity;
  70. private Vector3 _target_velocity;
  71. private Vector3 _acceleration;
  72. private Vector3 m_rotationalVelocity;
  73. private Vector3 m_size;
  74. private Vector3 m_collideNormal;
  75. private Vector3 m_lastFallVel;
  76. private Quaternion m_orientation;
  77. private Quaternion m_orientation2D;
  78. private float m_mass = 80f;
  79. public float m_density = 60f;
  80. private bool m_pidControllerActive = true;
  81. public int m_bodydisablecontrol = 0;
  82. const float basePID_D = 0.55f; // scaled for unit mass unit time (2200 /(50*80))
  83. const float basePID_P = 0.225f; // scaled for unit mass unit time (900 /(50*80))
  84. public float PID_D;
  85. public float PID_P;
  86. private float timeStep;
  87. private float invtimeStep;
  88. private float m_feetOffset = 0;
  89. private float feetOff = 0;
  90. private float boneOff = 0;
  91. private float AvaAvaSizeXsq = 0.3f;
  92. private float AvaAvaSizeYsq = 0.2f;
  93. public float walkDivisor = 1.3f;
  94. public float runDivisor = 0.8f;
  95. private bool m_flying = false;
  96. private bool m_iscolliding = false;
  97. private bool m_iscollidingGround = false;
  98. private bool m_iscollidingObj = false;
  99. private bool m_alwaysRun = false;
  100. private bool _zeroFlag = false;
  101. private bool m_haveLastFallVel = false;
  102. private uint m_localID = 0;
  103. public bool m_returnCollisions = false;
  104. // taints and their non-tainted counterparts
  105. public bool m_isPhysical = false; // the current physical status
  106. public float MinimumGroundFlightOffset = 3f;
  107. private float m_buoyancy = 0f;
  108. private bool m_freemove = false;
  109. // private string m_name = String.Empty;
  110. // other filter control
  111. int m_colliderfilter = 0;
  112. int m_colliderGroundfilter = 0;
  113. int m_colliderObjectfilter = 0;
  114. // Default we're a Character
  115. private CollisionCategories m_collisionCategories = (CollisionCategories.Character);
  116. // Default, Collide with Other Geometries, spaces, bodies and characters.
  117. private CollisionCategories m_collisionFlags = (CollisionCategories.Character
  118. | CollisionCategories.Geom
  119. | CollisionCategories.VolumeDtc
  120. );
  121. // we do land collisions not ode | CollisionCategories.Land);
  122. public IntPtr Body = IntPtr.Zero;
  123. private ODEScene m_parent_scene;
  124. private IntPtr capsule = IntPtr.Zero;
  125. public IntPtr collider = IntPtr.Zero;
  126. public IntPtr Amotor = IntPtr.Zero;
  127. internal SafeNativeMethods.Mass ShellMass;
  128. public int m_eventsubscription = 0;
  129. private int m_cureventsubscription = 0;
  130. private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
  131. private bool SentEmptyCollisionsEvent;
  132. // unique UUID of this character object
  133. public UUID m_uuid;
  134. public bool bad = false;
  135. float mu;
  136. // HoverHeight control
  137. private float m_PIDHoverHeight;
  138. private float m_PIDHoverTau;
  139. private bool m_useHoverPID;
  140. private PIDHoverType m_PIDHoverType;
  141. private float m_targetHoverHeight;
  142. public OdeCharacter(uint localID,String avName,ODEScene parent_scene,Vector3 pos,Vector3 pSize,float pfeetOffset,float density,float walk_divisor,float rundivisor)
  143. {
  144. m_uuid = UUID.Random();
  145. m_localID = localID;
  146. m_parent_scene = parent_scene;
  147. timeStep = parent_scene.ODE_STEPSIZE;
  148. invtimeStep = 1 / timeStep;
  149. if(pos.IsFinite())
  150. {
  151. if(pos.Z > 99999f)
  152. {
  153. pos.Z = parent_scene.GetTerrainHeightAtXY(127,127) + 5;
  154. }
  155. if(pos.Z < -100f) // shouldn't this be 0 ?
  156. {
  157. pos.Z = parent_scene.GetTerrainHeightAtXY(127,127) + 5;
  158. }
  159. _position = pos;
  160. }
  161. else
  162. {
  163. _position = new Vector3(((float)m_parent_scene.WorldExtents.X * 0.5f),((float)m_parent_scene.WorldExtents.Y * 0.5f),parent_scene.GetTerrainHeightAtXY(128f,128f) + 10f);
  164. m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
  165. }
  166. m_size.X = pSize.X;
  167. m_size.Y = pSize.Y;
  168. m_size.Z = pSize.Z;
  169. if(m_size.X <0.01f)
  170. m_size.X = 0.01f;
  171. if(m_size.Y <0.01f)
  172. m_size.Y = 0.01f;
  173. if(m_size.Z <0.01f)
  174. m_size.Z = 0.01f;
  175. m_feetOffset = pfeetOffset;
  176. m_orientation = Quaternion.Identity;
  177. m_orientation2D = Quaternion.Identity;
  178. m_density = density;
  179. // force lower density for testing
  180. m_density = 3.0f;
  181. mu = m_parent_scene.AvatarFriction;
  182. walkDivisor = walk_divisor;
  183. runDivisor = rundivisor;
  184. m_mass = m_density * m_size.X * m_size.Y * m_size.Z;
  185. ; // sure we have a default
  186. PID_D = basePID_D * m_mass * invtimeStep;
  187. PID_P = basePID_P * m_mass * invtimeStep;
  188. m_isPhysical = false; // current status: no ODE information exists
  189. Name = avName;
  190. AddChange(changes.Add,null);
  191. }
  192. public override int PhysicsActorType
  193. {
  194. get
  195. {
  196. return (int)ActorTypes.Agent;
  197. }
  198. set
  199. {
  200. return;
  201. }
  202. }
  203. public override void getContactData(ref ContactData cdata)
  204. {
  205. cdata.mu = mu;
  206. cdata.bounce = 0;
  207. cdata.softcolide = false;
  208. }
  209. public override bool Building
  210. {
  211. get; set;
  212. }
  213. /// <summary>
  214. /// If this is set, the avatar will move faster
  215. /// </summary>
  216. public override bool SetAlwaysRun
  217. {
  218. get
  219. {
  220. return m_alwaysRun;
  221. }
  222. set
  223. {
  224. m_alwaysRun = value;
  225. }
  226. }
  227. public override uint LocalID
  228. {
  229. get
  230. {
  231. return m_localID;
  232. }
  233. set
  234. {
  235. m_localID = value;
  236. }
  237. }
  238. public override PhysicsActor ParentActor
  239. {
  240. get
  241. {
  242. return (PhysicsActor)this;
  243. }
  244. }
  245. public override bool Grabbed
  246. {
  247. set
  248. {
  249. return;
  250. }
  251. }
  252. public override bool Selected
  253. {
  254. set
  255. {
  256. return;
  257. }
  258. }
  259. public override float Buoyancy
  260. {
  261. get
  262. {
  263. return m_buoyancy;
  264. }
  265. set
  266. {
  267. m_buoyancy = value;
  268. }
  269. }
  270. public override bool FloatOnWater
  271. {
  272. set
  273. {
  274. return;
  275. }
  276. }
  277. public override bool IsPhysical
  278. {
  279. get
  280. {
  281. return m_isPhysical;
  282. }
  283. set
  284. {
  285. return;
  286. }
  287. }
  288. public override bool ThrottleUpdates
  289. {
  290. get
  291. {
  292. return false;
  293. }
  294. set
  295. {
  296. return;
  297. }
  298. }
  299. public override bool Flying
  300. {
  301. get
  302. {
  303. return m_flying;
  304. }
  305. set
  306. {
  307. m_flying = value;
  308. // m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying);
  309. }
  310. }
  311. /// <summary>
  312. /// Returns if the avatar is colliding in general.
  313. /// This includes the ground and objects and avatar.
  314. /// </summary>
  315. public override bool IsColliding
  316. {
  317. get
  318. {
  319. return (m_iscolliding || m_iscollidingGround);
  320. }
  321. set
  322. {
  323. if(value)
  324. {
  325. m_colliderfilter += 3;
  326. if(m_colliderfilter > 3)
  327. m_colliderfilter = 3;
  328. }
  329. else
  330. {
  331. m_colliderfilter--;
  332. if(m_colliderfilter < 0)
  333. m_colliderfilter = 0;
  334. }
  335. if(m_colliderfilter == 0)
  336. m_iscolliding = false;
  337. else
  338. {
  339. m_pidControllerActive = true;
  340. m_iscolliding = true;
  341. m_freemove = false;
  342. }
  343. }
  344. }
  345. /// <summary>
  346. /// Returns if an avatar is colliding with the ground
  347. /// </summary>
  348. public override bool CollidingGround
  349. {
  350. get
  351. {
  352. return m_iscollidingGround;
  353. }
  354. set
  355. {
  356. /* we now control this
  357. if (value)
  358. {
  359. m_colliderGroundfilter += 2;
  360. if (m_colliderGroundfilter > 2)
  361. m_colliderGroundfilter = 2;
  362. }
  363. else
  364. {
  365. m_colliderGroundfilter--;
  366. if (m_colliderGroundfilter < 0)
  367. m_colliderGroundfilter = 0;
  368. }
  369. if (m_colliderGroundfilter == 0)
  370. m_iscollidingGround = false;
  371. else
  372. m_iscollidingGround = true;
  373. */
  374. }
  375. }
  376. /// <summary>
  377. /// Returns if the avatar is colliding with an object
  378. /// </summary>
  379. public override bool CollidingObj
  380. {
  381. get
  382. {
  383. return m_iscollidingObj;
  384. }
  385. set
  386. {
  387. // Ubit filter this also
  388. if(value)
  389. {
  390. m_colliderObjectfilter += 2;
  391. if(m_colliderObjectfilter > 2)
  392. m_colliderObjectfilter = 2;
  393. }
  394. else
  395. {
  396. m_colliderObjectfilter--;
  397. if(m_colliderObjectfilter < 0)
  398. m_colliderObjectfilter = 0;
  399. }
  400. if(m_colliderObjectfilter == 0)
  401. m_iscollidingObj = false;
  402. else
  403. m_iscollidingObj = true;
  404. // m_iscollidingObj = value;
  405. if(m_iscollidingObj)
  406. m_pidControllerActive = false;
  407. else
  408. m_pidControllerActive = true;
  409. }
  410. }
  411. /// <summary>
  412. /// turn the PID controller on or off.
  413. /// The PID Controller will turn on all by itself in many situations
  414. /// </summary>
  415. /// <param name="status"></param>
  416. public void SetPidStatus(bool status)
  417. {
  418. m_pidControllerActive = status;
  419. }
  420. public override bool Stopped
  421. {
  422. get
  423. {
  424. return _zeroFlag;
  425. }
  426. }
  427. /// <summary>
  428. /// This 'puts' an avatar somewhere in the physics space.
  429. /// Not really a good choice unless you 'know' it's a good
  430. /// spot otherwise you're likely to orbit the avatar.
  431. /// </summary>
  432. public override Vector3 Position
  433. {
  434. get
  435. {
  436. return _position;
  437. }
  438. set
  439. {
  440. if(value.IsFinite())
  441. {
  442. if(value.Z > 9999999f)
  443. {
  444. value.Z = m_parent_scene.GetTerrainHeightAtXY(127,127) + 5;
  445. }
  446. if(value.Z < -100f)
  447. {
  448. value.Z = m_parent_scene.GetTerrainHeightAtXY(127,127) + 5;
  449. }
  450. AddChange(changes.Position,value);
  451. }
  452. else
  453. {
  454. m_log.Warn("[PHYSICS]: Got a NaN Position from Scene on a Character");
  455. }
  456. }
  457. }
  458. public override Vector3 RotationalVelocity
  459. {
  460. get
  461. {
  462. return m_rotationalVelocity;
  463. }
  464. set
  465. {
  466. m_rotationalVelocity = value;
  467. }
  468. }
  469. /// <summary>
  470. /// This property sets the height of the avatar only. We use the height to make sure the avatar stands up straight
  471. /// and use it to offset landings properly
  472. /// </summary>
  473. public override Vector3 Size
  474. {
  475. get
  476. {
  477. return m_size;
  478. }
  479. set
  480. {
  481. if(value.IsFinite())
  482. {
  483. if(value.X <0.01f)
  484. value.X = 0.01f;
  485. if(value.Y <0.01f)
  486. value.Y = 0.01f;
  487. if(value.Z <0.01f)
  488. value.Z = 0.01f;
  489. AddChange(changes.Size,value);
  490. }
  491. else
  492. {
  493. m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
  494. }
  495. }
  496. }
  497. public override void setAvatarSize(Vector3 size,float feetOffset)
  498. {
  499. if(size.IsFinite())
  500. {
  501. if(size.X < 0.01f)
  502. size.X = 0.01f;
  503. if(size.Y < 0.01f)
  504. size.Y = 0.01f;
  505. if(size.Z < 0.01f)
  506. size.Z = 0.01f;
  507. strAvatarSize st = new strAvatarSize();
  508. st.size = size;
  509. st.offset = feetOffset;
  510. AddChange(changes.AvatarSize,st);
  511. }
  512. else
  513. {
  514. m_log.Warn("[PHYSICS]: Got a NaN AvatarSize from Scene on a Character");
  515. }
  516. }
  517. /// <summary>
  518. /// This creates the Avatar's physical Surrogate at the position supplied
  519. /// </summary>
  520. /// <param name="npositionX"></param>
  521. /// <param name="npositionY"></param>
  522. /// <param name="npositionZ"></param>
  523. //
  524. /// <summary>
  525. /// Uses the capped cyllinder volume formula to calculate the avatar's mass.
  526. /// This may be used in calculations in the scene/scenepresence
  527. /// </summary>
  528. public override float Mass
  529. {
  530. get
  531. {
  532. return m_mass;
  533. }
  534. }
  535. public override void link(PhysicsActor obj)
  536. {
  537. }
  538. public override void delink()
  539. {
  540. }
  541. public override void LockAngularMotion(byte axislocks)
  542. {
  543. }
  544. public override Vector3 Force
  545. {
  546. get
  547. {
  548. return _target_velocity;
  549. }
  550. set
  551. {
  552. return;
  553. }
  554. }
  555. public override int VehicleType
  556. {
  557. get
  558. {
  559. return 0;
  560. }
  561. set
  562. {
  563. return;
  564. }
  565. }
  566. public override void VehicleFloatParam(int param,float value)
  567. {
  568. }
  569. public override void VehicleVectorParam(int param,Vector3 value)
  570. {
  571. }
  572. public override void VehicleRotationParam(int param,Quaternion rotation)
  573. {
  574. }
  575. public override void VehicleFlags(int param,bool remove)
  576. {
  577. }
  578. public override void SetVolumeDetect(int param)
  579. {
  580. }
  581. public override Vector3 CenterOfMass
  582. {
  583. get
  584. {
  585. Vector3 pos = _position;
  586. return pos;
  587. }
  588. }
  589. public override Vector3 GeometricCenter
  590. {
  591. get
  592. {
  593. Vector3 pos = _position;
  594. return pos;
  595. }
  596. }
  597. public override PrimitiveBaseShape Shape
  598. {
  599. set
  600. {
  601. return;
  602. }
  603. }
  604. public override Vector3 rootVelocity
  605. {
  606. get
  607. {
  608. return _velocity;
  609. }
  610. }
  611. public override Vector3 Velocity
  612. {
  613. get
  614. {
  615. return _velocity;
  616. }
  617. set
  618. {
  619. if(value.IsFinite())
  620. {
  621. AddChange(changes.Velocity,value);
  622. }
  623. else
  624. {
  625. m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character");
  626. }
  627. }
  628. }
  629. public override Vector3 TargetVelocity
  630. {
  631. get
  632. {
  633. return m_targetVelocity;
  634. }
  635. set
  636. {
  637. if(value.IsFinite())
  638. {
  639. AddChange(changes.TargetVelocity,value);
  640. }
  641. else
  642. {
  643. m_log.Warn("[PHYSICS]: Got a NaN velocity from Scene in a Character");
  644. }
  645. }
  646. }
  647. public override Vector3 Torque
  648. {
  649. get
  650. {
  651. return Vector3.Zero;
  652. }
  653. set
  654. {
  655. return;
  656. }
  657. }
  658. public override float CollisionScore
  659. {
  660. get
  661. {
  662. return 0f;
  663. }
  664. set
  665. {
  666. }
  667. }
  668. public override bool Kinematic
  669. {
  670. get
  671. {
  672. return false;
  673. }
  674. set
  675. {
  676. }
  677. }
  678. public override Quaternion Orientation
  679. {
  680. get
  681. {
  682. return m_orientation;
  683. }
  684. set
  685. {
  686. // fakeori = value;
  687. // givefakeori++;
  688. value.Normalize();
  689. AddChange(changes.Orientation,value);
  690. }
  691. }
  692. public override Vector3 Acceleration
  693. {
  694. get
  695. {
  696. return _acceleration;
  697. }
  698. set
  699. {
  700. }
  701. }
  702. public void SetAcceleration(Vector3 accel)
  703. {
  704. m_pidControllerActive = true;
  705. _acceleration = accel;
  706. if (Body != IntPtr.Zero)
  707. SafeNativeMethods.BodyEnable(Body);
  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(Vector3 force,bool pushforce)
  715. {
  716. if(force.IsFinite())
  717. {
  718. if(pushforce)
  719. {
  720. AddChange(changes.Force,force * m_density / (m_parent_scene.ODE_STEPSIZE * 28f));
  721. }
  722. else
  723. {
  724. AddChange(changes.TargetVelocity,force);
  725. }
  726. }
  727. else
  728. {
  729. m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character");
  730. }
  731. //m_lastUpdateSent = false;
  732. }
  733. public override void AddAngularForce(Vector3 force,bool pushforce)
  734. {
  735. }
  736. public override void SetMomentum(Vector3 momentum)
  737. {
  738. if(momentum.IsFinite())
  739. AddChange(changes.Momentum,momentum);
  740. }
  741. private void AvatarGeomAndBodyCreation(float npositionX,float npositionY,float npositionZ)
  742. {
  743. // sizes one day should came from visual parameters
  744. float sx = m_size.X;
  745. float sy = m_size.Y;
  746. float sz = m_size.Z;
  747. float bot = -sz * 0.5f + m_feetOffset;
  748. boneOff = bot + 0.3f;
  749. float feetsz = sz * 0.45f;
  750. if(feetsz > 0.6f)
  751. feetsz = 0.6f;
  752. feetOff = bot + feetsz;
  753. AvaAvaSizeXsq = 0.4f * sx;
  754. AvaAvaSizeXsq *= AvaAvaSizeXsq;
  755. AvaAvaSizeYsq = 0.5f * sy;
  756. AvaAvaSizeYsq *= AvaAvaSizeYsq;
  757. m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace);
  758. collider = SafeNativeMethods.SimpleSpaceCreate(m_parent_scene.CharsSpace);
  759. SafeNativeMethods.SpaceSetSublevel(collider,3);
  760. SafeNativeMethods.SpaceSetCleanup(collider,false);
  761. SafeNativeMethods.GeomSetCategoryBits(collider,(uint)m_collisionCategories);
  762. SafeNativeMethods.GeomSetCollideBits(collider,(uint)m_collisionFlags);
  763. float r = m_size.X;
  764. if(m_size.Y > r)
  765. r = m_size.Y;
  766. float l = m_size.Z - r;
  767. r *= 0.5f;
  768. capsule = SafeNativeMethods.CreateCapsule(collider,r,l);
  769. m_mass = m_density * m_size.X * m_size.Y * m_size.Z; // update mass
  770. SafeNativeMethods.MassSetBoxTotal(out ShellMass,m_mass,m_size.X,m_size.Y,m_size.Z);
  771. PID_D = basePID_D * m_mass / m_parent_scene.ODE_STEPSIZE;
  772. PID_P = basePID_P * m_mass / m_parent_scene.ODE_STEPSIZE;
  773. Body = SafeNativeMethods.BodyCreate(m_parent_scene.world);
  774. _zeroFlag = false;
  775. m_pidControllerActive = true;
  776. m_freemove = false;
  777. _velocity = Vector3.Zero;
  778. // SafeNativeMethods.BodySetAutoDisableFlag(Body,false);
  779. SafeNativeMethods.BodySetAutoDisableFlag(Body, true);
  780. m_bodydisablecontrol = 0;
  781. SafeNativeMethods.BodySetPosition(Body,npositionX,npositionY,npositionZ);
  782. _position.X = npositionX;
  783. _position.Y = npositionY;
  784. _position.Z = npositionZ;
  785. SafeNativeMethods.BodySetMass(Body,ref ShellMass);
  786. SafeNativeMethods.GeomSetBody(capsule,Body);
  787. // The purpose of the AMotor here is to keep the avatar's physical
  788. // surrogate from rotating while moving
  789. Amotor = SafeNativeMethods.JointCreateAMotor(m_parent_scene.world,IntPtr.Zero);
  790. SafeNativeMethods.JointAttach(Amotor,Body,IntPtr.Zero);
  791. SafeNativeMethods.JointSetAMotorMode(Amotor,0);
  792. SafeNativeMethods.JointSetAMotorNumAxes(Amotor,3);
  793. SafeNativeMethods.JointSetAMotorAxis(Amotor,0,0,1,0,0);
  794. SafeNativeMethods.JointSetAMotorAxis(Amotor,1,0,0,1,0);
  795. SafeNativeMethods.JointSetAMotorAxis(Amotor,2,0,0,0,1);
  796. SafeNativeMethods.JointSetAMotorAngle(Amotor,0,0);
  797. SafeNativeMethods.JointSetAMotorAngle(Amotor,1,0);
  798. SafeNativeMethods.JointSetAMotorAngle(Amotor,2,0);
  799. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM,0f); // make it HARD
  800. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM2,0f);
  801. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM3,0f);
  802. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP,0.8f);
  803. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP2,0.8f);
  804. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP3,0.8f);
  805. // These lowstops and high stops are effectively (no wiggle room)
  806. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LowStop,-1e-5f);
  807. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop,1e-5f);
  808. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LoStop2,-1e-5f);
  809. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop2,1e-5f);
  810. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LoStop3,-1e-5f);
  811. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop3,1e-5f);
  812. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel,0);
  813. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel2,0);
  814. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel3,0);
  815. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax,5e8f);
  816. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax2,5e8f);
  817. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax3,5e8f);
  818. }
  819. /// <summary>
  820. /// Destroys the avatar body and geom
  821. private void AvatarGeomAndBodyDestroy()
  822. {
  823. // Kill the Amotor
  824. if(Amotor != IntPtr.Zero)
  825. {
  826. SafeNativeMethods.JointDestroy(Amotor);
  827. Amotor = IntPtr.Zero;
  828. }
  829. if(Body != IntPtr.Zero)
  830. {
  831. //kill the body
  832. SafeNativeMethods.BodyDestroy(Body);
  833. Body = IntPtr.Zero;
  834. }
  835. //kill the Geoms
  836. if(capsule != IntPtr.Zero)
  837. {
  838. m_parent_scene.actor_name_map.Remove(capsule);
  839. m_parent_scene.waitForSpaceUnlock(collider);
  840. SafeNativeMethods.GeomDestroy(capsule);
  841. capsule = IntPtr.Zero;
  842. }
  843. if(collider != IntPtr.Zero)
  844. {
  845. SafeNativeMethods.SpaceDestroy(collider);
  846. collider = IntPtr.Zero;
  847. }
  848. }
  849. //in place 2D rotation around Z assuming rot is normalised and is a rotation around Z
  850. public void RotateXYonZ(ref float x,ref float y,ref Quaternion rot)
  851. {
  852. float sin = 2.0f * rot.Z * rot.W;
  853. float cos = rot.W * rot.W - rot.Z * rot.Z;
  854. float tx = x;
  855. x = tx * cos - y * sin;
  856. y = tx * sin + y * cos;
  857. }
  858. public void RotateXYonZ(ref float x,ref float y,ref float sin,ref float cos)
  859. {
  860. float tx = x;
  861. x = tx * cos - y * sin;
  862. y = tx * sin + y * cos;
  863. }
  864. public void invRotateXYonZ(ref float x,ref float y,ref float sin,ref float cos)
  865. {
  866. float tx = x;
  867. x = tx * cos + y * sin;
  868. y = -tx * sin + y * cos;
  869. }
  870. public void invRotateXYonZ(ref float x,ref float y,ref Quaternion rot)
  871. {
  872. float sin = -2.0f * rot.Z * rot.W;
  873. float cos = rot.W * rot.W - rot.Z * rot.Z;
  874. float tx = x;
  875. x = tx * cos - y * sin;
  876. y = tx * sin + y * cos;
  877. }
  878. internal bool Collide(IntPtr me,IntPtr other,bool reverse,ref SafeNativeMethods.ContactGeom contact,
  879. ref SafeNativeMethods.ContactGeom altContact,ref bool useAltcontact,ref bool feetcollision)
  880. {
  881. feetcollision = false;
  882. useAltcontact = false;
  883. if(me == capsule)
  884. {
  885. Vector3 offset;
  886. float h = contact.pos.Z - _position.Z;
  887. offset.Z = h - feetOff;
  888. offset.X = contact.pos.X - _position.X;
  889. offset.Y = contact.pos.Y - _position.Y;
  890. SafeNativeMethods.GeomClassID gtype = SafeNativeMethods.GeomGetClass(other);
  891. if(gtype == SafeNativeMethods.GeomClassID.CapsuleClass)
  892. {
  893. Vector3 roff = offset * Quaternion.Inverse(m_orientation2D);
  894. float r = roff.X *roff.X / AvaAvaSizeXsq;
  895. r += (roff.Y * roff.Y) / AvaAvaSizeYsq;
  896. if(r > 1.0f)
  897. return false;
  898. float dp = 1.0f -(float)Math.Sqrt((double)r);
  899. if(dp > 0.05f)
  900. dp = 0.05f;
  901. contact.depth = dp;
  902. if(offset.Z < 0)
  903. {
  904. feetcollision = true;
  905. if(h < boneOff)
  906. {
  907. m_collideNormal.X = contact.normal.X;
  908. m_collideNormal.Y = contact.normal.Y;
  909. m_collideNormal.Z = contact.normal.Z;
  910. IsColliding = true;
  911. }
  912. }
  913. return true;
  914. }
  915. if(gtype == SafeNativeMethods.GeomClassID.SphereClass && SafeNativeMethods.GeomGetBody(other) != IntPtr.Zero)
  916. {
  917. if(SafeNativeMethods.GeomSphereGetRadius(other) < 0.5)
  918. return true;
  919. }
  920. if(offset.Z > 0 || contact.normal.Z > 0.35f)
  921. {
  922. if(offset.Z <= 0)
  923. {
  924. feetcollision = true;
  925. if(h < boneOff)
  926. {
  927. m_collideNormal.X = contact.normal.X;
  928. m_collideNormal.Y = contact.normal.Y;
  929. m_collideNormal.Z = contact.normal.Z;
  930. IsColliding = true;
  931. }
  932. }
  933. return true;
  934. }
  935. if(m_flying)
  936. return true;
  937. feetcollision = true;
  938. if(h < boneOff)
  939. {
  940. m_collideNormal.X = contact.normal.X;
  941. m_collideNormal.Y = contact.normal.Y;
  942. m_collideNormal.Z = contact.normal.Z;
  943. IsColliding = true;
  944. }
  945. altContact = contact;
  946. useAltcontact = true;
  947. offset.Z -= 0.2f;
  948. offset.Normalize();
  949. float tdp = contact.depth;
  950. float t = offset.X;
  951. t = Math.Abs(t);
  952. if(t > 1e-6)
  953. {
  954. tdp /= t;
  955. tdp *= contact.normal.X;
  956. }
  957. else
  958. tdp *= 10;
  959. if(tdp > 0.25f)
  960. tdp = 0.25f;
  961. altContact.depth = tdp;
  962. if(reverse)
  963. {
  964. altContact.normal.X = offset.X;
  965. altContact.normal.Y = offset.Y;
  966. altContact.normal.Z = offset.Z;
  967. }
  968. else
  969. {
  970. altContact.normal.X = -offset.X;
  971. altContact.normal.Y = -offset.Y;
  972. altContact.normal.Z = -offset.Z;
  973. }
  974. return true;
  975. }
  976. return false;
  977. }
  978. /// <summary>
  979. /// Called from Simulate
  980. /// This is the avatar's movement control + PID Controller
  981. /// </summary>
  982. /// <param name="timeStep"></param>
  983. public void Move()
  984. {
  985. if(Body == IntPtr.Zero)
  986. return;
  987. if (!SafeNativeMethods.BodyIsEnabled(Body))
  988. {
  989. if (++m_bodydisablecontrol < 50)
  990. return;
  991. // clear residuals
  992. SafeNativeMethods.BodySetAngularVel(Body, 0f, 0f, 0f);
  993. SafeNativeMethods.BodySetLinearVel(Body, 0f, 0f, 0f);
  994. _zeroFlag = true;
  995. SafeNativeMethods.BodyEnable(Body);
  996. }
  997. m_bodydisablecontrol = 0;
  998. SafeNativeMethods.Vector3 dtmp = SafeNativeMethods.BodyGetPosition(Body);
  999. Vector3 localpos = new Vector3(dtmp.X,dtmp.Y,dtmp.Z);
  1000. // the Amotor still lets avatar rotation to drift during colisions
  1001. // so force it back to identity
  1002. SafeNativeMethods.Quaternion qtmp;
  1003. qtmp.W = m_orientation2D.W;
  1004. qtmp.X = m_orientation2D.X;
  1005. qtmp.Y = m_orientation2D.Y;
  1006. qtmp.Z = m_orientation2D.Z;
  1007. SafeNativeMethods.BodySetQuaternion(Body,ref qtmp);
  1008. if(m_pidControllerActive == false)
  1009. {
  1010. _zeroPosition = localpos;
  1011. }
  1012. // check outbounds forcing to be in world
  1013. bool fixbody = false;
  1014. float tmp = localpos.X;
  1015. if ((Single.IsNaN(tmp) || Single.IsInfinity(tmp)))
  1016. {
  1017. fixbody = true;
  1018. localpos.X = 128f;
  1019. }
  1020. else if (tmp < 0.0f)
  1021. {
  1022. fixbody = true;
  1023. localpos.X = 0.1f;
  1024. }
  1025. else if (tmp > m_parent_scene.WorldExtents.X - 0.1f)
  1026. {
  1027. fixbody = true;
  1028. localpos.X = m_parent_scene.WorldExtents.X - 0.1f;
  1029. }
  1030. tmp = localpos.Y;
  1031. if ((Single.IsNaN(tmp) || Single.IsInfinity(tmp)))
  1032. {
  1033. fixbody = true;
  1034. localpos.X = 128f;
  1035. }
  1036. else if (tmp < 0.0f)
  1037. {
  1038. fixbody = true;
  1039. localpos.Y = 0.1f;
  1040. }
  1041. else if(tmp > m_parent_scene.WorldExtents.Y - 0.1)
  1042. {
  1043. fixbody = true;
  1044. localpos.Y = m_parent_scene.WorldExtents.Y - 0.1f;
  1045. }
  1046. tmp = localpos.Z;
  1047. if ((Single.IsNaN(tmp) || Single.IsInfinity(tmp)))
  1048. {
  1049. fixbody = true;
  1050. localpos.Z = 128f;
  1051. }
  1052. if (fixbody)
  1053. {
  1054. m_freemove = false;
  1055. SafeNativeMethods.BodySetPosition(Body,localpos.X,localpos.Y,localpos.Z);
  1056. }
  1057. float breakfactor;
  1058. Vector3 vec = Vector3.Zero;
  1059. dtmp = SafeNativeMethods.BodyGetLinearVel(Body);
  1060. Vector3 vel = new Vector3(dtmp.X,dtmp.Y,dtmp.Z);
  1061. float velLengthSquared = vel.LengthSquared();
  1062. Vector3 ctz = _target_velocity;
  1063. float movementdivisor = 1f;
  1064. //Ubit change divisions into multiplications below
  1065. if(!m_alwaysRun)
  1066. movementdivisor = 1 / walkDivisor;
  1067. else
  1068. movementdivisor = 1 / runDivisor;
  1069. ctz.X *= movementdivisor;
  1070. ctz.Y *= movementdivisor;
  1071. //******************************************
  1072. // colide with land
  1073. SafeNativeMethods.AABB aabb;
  1074. // d.GeomGetAABB(feetbox, out aabb);
  1075. SafeNativeMethods.GeomGetAABB(capsule,out aabb);
  1076. float chrminZ = aabb.MinZ; // move up a bit
  1077. Vector3 posch = localpos;
  1078. float ftmp;
  1079. if(m_flying)
  1080. {
  1081. ftmp = timeStep;
  1082. posch.X += vel.X * ftmp;
  1083. posch.Y += vel.Y * ftmp;
  1084. }
  1085. float terrainheight = m_parent_scene.GetTerrainHeightAtXY(posch.X,posch.Y);
  1086. if(chrminZ < terrainheight)
  1087. {
  1088. if(ctz.Z < 0)
  1089. ctz.Z = 0;
  1090. if(!m_haveLastFallVel)
  1091. {
  1092. m_lastFallVel = vel;
  1093. m_haveLastFallVel = true;
  1094. }
  1095. Vector3 n = m_parent_scene.GetTerrainNormalAtXY(posch.X,posch.Y);
  1096. float depth = terrainheight - chrminZ;
  1097. vec.Z = depth * PID_P * 50;
  1098. if(!m_flying)
  1099. {
  1100. vec.Z += -vel.Z * PID_D;
  1101. if(n.Z < 0.4f)
  1102. {
  1103. vec.X = depth * PID_P * 50 - vel.X * PID_D;
  1104. vec.X *= n.X;
  1105. vec.Y = depth * PID_P * 50 - vel.Y * PID_D;
  1106. vec.Y *= n.Y;
  1107. vec.Z *= n.Z;
  1108. if(n.Z < 0.1f)
  1109. {
  1110. // cancel the slope pose
  1111. n.X = 0f;
  1112. n.Y = 0f;
  1113. n.Z = 1.0f;
  1114. }
  1115. }
  1116. }
  1117. if(depth < 0.2f)
  1118. {
  1119. m_colliderGroundfilter++;
  1120. if(m_colliderGroundfilter > 2)
  1121. {
  1122. m_iscolliding = true;
  1123. m_colliderfilter = 2;
  1124. if(m_colliderGroundfilter > 10)
  1125. {
  1126. m_colliderGroundfilter = 10;
  1127. m_freemove = false;
  1128. }
  1129. m_collideNormal.X = n.X;
  1130. m_collideNormal.Y = n.Y;
  1131. m_collideNormal.Z = n.Z;
  1132. m_iscollidingGround = true;
  1133. ContactPoint contact = new ContactPoint();
  1134. contact.PenetrationDepth = depth;
  1135. contact.Position.X = localpos.X;
  1136. contact.Position.Y = localpos.Y;
  1137. contact.Position.Z = terrainheight;
  1138. contact.SurfaceNormal.X = -n.X;
  1139. contact.SurfaceNormal.Y = -n.Y;
  1140. contact.SurfaceNormal.Z = -n.Z;
  1141. contact.RelativeSpeed = Vector3.Dot(m_lastFallVel,n);
  1142. contact.CharacterFeet = true;
  1143. AddCollisionEvent(0,contact);
  1144. m_lastFallVel = vel;
  1145. // vec.Z *= 0.5f;
  1146. }
  1147. }
  1148. else
  1149. {
  1150. m_colliderGroundfilter -= 5;
  1151. if(m_colliderGroundfilter <= 0)
  1152. {
  1153. m_colliderGroundfilter = 0;
  1154. m_iscollidingGround = false;
  1155. }
  1156. }
  1157. }
  1158. else
  1159. {
  1160. m_haveLastFallVel = false;
  1161. m_colliderGroundfilter -= 5;
  1162. if(m_colliderGroundfilter <= 0)
  1163. {
  1164. m_colliderGroundfilter = 0;
  1165. m_iscollidingGround = false;
  1166. }
  1167. }
  1168. bool hoverPIDActive = false;
  1169. if(m_useHoverPID && m_PIDHoverTau != 0 && m_PIDHoverHeight != 0)
  1170. {
  1171. hoverPIDActive = true;
  1172. switch(m_PIDHoverType)
  1173. {
  1174. case PIDHoverType.Ground:
  1175. m_targetHoverHeight = terrainheight + m_PIDHoverHeight;
  1176. break;
  1177. case PIDHoverType.GroundAndWater:
  1178. float waterHeight = m_parent_scene.GetWaterLevel();
  1179. if(terrainheight > waterHeight)
  1180. m_targetHoverHeight = terrainheight + m_PIDHoverHeight;
  1181. else
  1182. m_targetHoverHeight = waterHeight + m_PIDHoverHeight;
  1183. break;
  1184. } // end switch (m_PIDHoverType)
  1185. // don't go underground
  1186. if(m_targetHoverHeight > terrainheight + 0.5f * (aabb.MaxZ - aabb.MinZ))
  1187. {
  1188. float fz = (m_targetHoverHeight - localpos.Z);
  1189. // if error is zero, use position control; otherwise, velocity control
  1190. if(Math.Abs(fz) < 0.01f)
  1191. {
  1192. ctz.Z = 0;
  1193. }
  1194. else
  1195. {
  1196. _zeroFlag = false;
  1197. fz /= m_PIDHoverTau;
  1198. tmp = Math.Abs(fz);
  1199. if(tmp > 50)
  1200. fz = 50 * Math.Sign(fz);
  1201. else if(tmp < 0.1)
  1202. fz = 0.1f * Math.Sign(fz);
  1203. ctz.Z = fz;
  1204. }
  1205. }
  1206. }
  1207. //******************************************
  1208. if(!m_iscolliding)
  1209. m_collideNormal.Z = 0;
  1210. bool tviszero = (ctz.X == 0.0f && ctz.Y == 0.0f && ctz.Z == 0.0f);
  1211. if(!tviszero)
  1212. {
  1213. m_freemove = false;
  1214. // movement relative to surface if moving on it
  1215. // dont disturbe vertical movement, ie jumps
  1216. if(m_iscolliding && !m_flying && ctz.Z == 0 && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f)
  1217. {
  1218. float p = ctz.X * m_collideNormal.X + ctz.Y * m_collideNormal.Y;
  1219. ctz.X *= (float)Math.Sqrt(1 - m_collideNormal.X * m_collideNormal.X);
  1220. ctz.Y *= (float)Math.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y);
  1221. ctz.Z -= p;
  1222. if(ctz.Z < 0)
  1223. ctz.Z *= 2;
  1224. }
  1225. }
  1226. if(!m_freemove)
  1227. {
  1228. // if velocity is zero, use position control; otherwise, velocity control
  1229. if(tviszero)
  1230. {
  1231. if(m_iscolliding || m_flying)
  1232. {
  1233. // keep track of where we stopped. No more slippin' & slidin'
  1234. if (!_zeroFlag)
  1235. {
  1236. _zeroFlag = true;
  1237. _zeroPosition = localpos;
  1238. }
  1239. if(m_pidControllerActive)
  1240. {
  1241. // We only want to deactivate the PID Controller if we think we want to have our surrogate
  1242. // react to the physics scene by moving it's position.
  1243. // Avatar to Avatar collisions
  1244. // Prim to avatar collisions
  1245. vec.X = -vel.X * PID_D * 2f + (_zeroPosition.X - localpos.X) * (PID_P * 5);
  1246. vec.Y = -vel.Y * PID_D * 2f + (_zeroPosition.Y - localpos.Y) * (PID_P * 5);
  1247. if(vel.Z > 0)
  1248. vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P;
  1249. else
  1250. vec.Z += (-vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P) * 0.2f;
  1251. }
  1252. }
  1253. else
  1254. {
  1255. _zeroFlag = false;
  1256. vec.X += (ctz.X - vel.X) * PID_D * 0.833f;
  1257. vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f;
  1258. // hack for breaking on fall
  1259. if (ctz.Z == -9999f)
  1260. vec.Z += -vel.Z * PID_D - m_parent_scene.gravityz * m_mass;
  1261. }
  1262. }
  1263. else
  1264. {
  1265. m_pidControllerActive = true;
  1266. _zeroFlag = false;
  1267. if(m_iscolliding)
  1268. {
  1269. if(!m_flying)
  1270. {
  1271. // we are on a surface
  1272. if(ctz.Z > 0f)
  1273. {
  1274. // moving up or JUMPING
  1275. vec.Z += (ctz.Z - vel.Z) * PID_D * 2f;
  1276. vec.X += (ctz.X - vel.X) * (PID_D);
  1277. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1278. }
  1279. else
  1280. {
  1281. // we are moving down on a surface
  1282. if(ctz.Z == 0)
  1283. {
  1284. if(vel.Z > 0)
  1285. vec.Z -= vel.Z * PID_D * 2f;
  1286. vec.X += (ctz.X - vel.X) * (PID_D);
  1287. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1288. }
  1289. // intencionally going down
  1290. else
  1291. {
  1292. if(ctz.Z < vel.Z)
  1293. vec.Z += (ctz.Z - vel.Z) * PID_D;
  1294. else
  1295. {
  1296. }
  1297. if(Math.Abs(ctz.X) > Math.Abs(vel.X))
  1298. vec.X += (ctz.X - vel.X) * (PID_D);
  1299. if(Math.Abs(ctz.Y) > Math.Abs(vel.Y))
  1300. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1301. }
  1302. }
  1303. // We're standing on something
  1304. }
  1305. else
  1306. {
  1307. // We're flying and colliding with something
  1308. vec.X += (ctz.X - vel.X) * (PID_D * 0.0625f);
  1309. vec.Y += (ctz.Y - vel.Y) * (PID_D * 0.0625f);
  1310. vec.Z += (ctz.Z - vel.Z) * (PID_D * 0.0625f);
  1311. }
  1312. }
  1313. else // ie not colliding
  1314. {
  1315. if(m_flying || hoverPIDActive) //(!m_iscolliding && flying)
  1316. {
  1317. // we're in mid air suspended
  1318. vec.X += (ctz.X - vel.X) * (PID_D);
  1319. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1320. vec.Z += (ctz.Z - vel.Z) * (PID_D);
  1321. }
  1322. else
  1323. {
  1324. // we're not colliding and we're not flying so that means we're falling!
  1325. // m_iscolliding includes collisions with the ground.
  1326. // d.Vector3 pos = d.BodyGetPosition(Body);
  1327. vec.X += (ctz.X - vel.X) * PID_D * 0.833f;
  1328. vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f;
  1329. // hack for breaking on fall
  1330. if (ctz.Z == -9999f)
  1331. vec.Z += -vel.Z * PID_D - m_parent_scene.gravityz * m_mass;
  1332. }
  1333. }
  1334. }
  1335. if(velLengthSquared > 2500.0f) // 50m/s apply breaks
  1336. {
  1337. breakfactor = 0.16f * m_mass;
  1338. vec.X -= breakfactor * vel.X;
  1339. vec.Y -= breakfactor * vel.Y;
  1340. vec.Z -= breakfactor * vel.Z;
  1341. }
  1342. }
  1343. else
  1344. {
  1345. breakfactor = m_mass;
  1346. vec.X -= breakfactor * vel.X;
  1347. vec.Y -= breakfactor * vel.Y;
  1348. if(m_flying)
  1349. vec.Z -= 0.5f * breakfactor * vel.Z;
  1350. else
  1351. vec.Z -= .16f* m_mass * vel.Z;
  1352. }
  1353. if(m_flying || hoverPIDActive)
  1354. {
  1355. vec.Z -= m_parent_scene.gravityz * m_mass;
  1356. if(!hoverPIDActive)
  1357. {
  1358. //Added for auto fly height. Kitto Flora
  1359. float target_altitude = terrainheight + MinimumGroundFlightOffset;
  1360. if(localpos.Z < target_altitude)
  1361. {
  1362. vec.Z += (target_altitude - localpos.Z) * PID_P * 5.0f;
  1363. }
  1364. // end add Kitto Flora
  1365. }
  1366. }
  1367. if(vec.IsFinite())
  1368. {
  1369. if((vec.X != 0 || vec.Y !=0 || vec.Z !=0))
  1370. SafeNativeMethods.BodyAddForce(Body,vec.X,vec.Y,vec.Z);
  1371. }
  1372. // update our local ideia of position velocity and aceleration
  1373. // _position = localpos;
  1374. _position = localpos;
  1375. if(_zeroFlag)
  1376. {
  1377. _velocity = Vector3.Zero;
  1378. _acceleration = Vector3.Zero;
  1379. m_rotationalVelocity = Vector3.Zero;
  1380. }
  1381. else
  1382. {
  1383. Vector3 a = _velocity; // previous velocity
  1384. SetSmooth(ref _velocity,ref vel,2);
  1385. a = (_velocity - a) * invtimeStep;
  1386. SetSmooth(ref _acceleration,ref a,2);
  1387. dtmp = SafeNativeMethods.BodyGetAngularVel(Body);
  1388. m_rotationalVelocity.X = 0f;
  1389. m_rotationalVelocity.Y = 0f;
  1390. m_rotationalVelocity.Z = dtmp.Z;
  1391. Math.Round(m_rotationalVelocity.Z,3);
  1392. }
  1393. }
  1394. public void round(ref Vector3 v,int digits)
  1395. {
  1396. v.X = (float)Math.Round(v.X,digits);
  1397. v.Y = (float)Math.Round(v.Y,digits);
  1398. v.Z = (float)Math.Round(v.Z,digits);
  1399. }
  1400. public void SetSmooth(ref Vector3 dst,ref Vector3 value)
  1401. {
  1402. dst.X = 0.1f * dst.X + 0.9f * value.X;
  1403. dst.Y = 0.1f * dst.Y + 0.9f * value.Y;
  1404. dst.Z = 0.1f * dst.Z + 0.9f * value.Z;
  1405. }
  1406. public void SetSmooth(ref Vector3 dst,ref Vector3 value,int rounddigits)
  1407. {
  1408. dst.X = 0.4f * dst.X + 0.6f * value.X;
  1409. dst.X = (float)Math.Round(dst.X,rounddigits);
  1410. dst.Y = 0.4f * dst.Y + 0.6f * value.Y;
  1411. dst.Y = (float)Math.Round(dst.Y,rounddigits);
  1412. dst.Z = 0.4f * dst.Z + 0.6f * value.Z;
  1413. dst.Z = (float)Math.Round(dst.Z,rounddigits);
  1414. }
  1415. /// <summary>
  1416. /// Updates the reported position and velocity.
  1417. /// Used to copy variables from unmanaged space at heartbeat rate and also trigger scene updates acording
  1418. /// also outbounds checking
  1419. /// copy and outbounds now done in move(..) at ode rate
  1420. ///
  1421. /// </summary>
  1422. public void UpdatePositionAndVelocity()
  1423. {
  1424. return;
  1425. // if (Body == IntPtr.Zero)
  1426. // return;
  1427. }
  1428. /// <summary>
  1429. /// Cleanup the things we use in the scene.
  1430. /// </summary>
  1431. public void Destroy()
  1432. {
  1433. AddChange(changes.Remove,null);
  1434. }
  1435. public override void CrossingFailure()
  1436. {
  1437. }
  1438. public override Vector3 PIDTarget
  1439. {
  1440. set
  1441. {
  1442. return;
  1443. }
  1444. }
  1445. public override bool PIDActive
  1446. {
  1447. get
  1448. {
  1449. return m_pidControllerActive;
  1450. }
  1451. set
  1452. {
  1453. return;
  1454. }
  1455. }
  1456. public override float PIDTau
  1457. {
  1458. set
  1459. {
  1460. return;
  1461. }
  1462. }
  1463. public override float PIDHoverHeight
  1464. {
  1465. set
  1466. {
  1467. AddChange(changes.PIDHoverHeight,value);
  1468. }
  1469. }
  1470. public override bool PIDHoverActive
  1471. {
  1472. get
  1473. {
  1474. return m_useHoverPID;
  1475. }
  1476. set
  1477. {
  1478. AddChange(changes.PIDHoverActive,value);
  1479. }
  1480. }
  1481. public override PIDHoverType PIDHoverType
  1482. {
  1483. set
  1484. {
  1485. AddChange(changes.PIDHoverType,value);
  1486. }
  1487. }
  1488. public override float PIDHoverTau
  1489. {
  1490. set
  1491. {
  1492. float tmp = 0;
  1493. if(value > 0)
  1494. {
  1495. float mint = (0.05f > timeStep ? 0.05f : timeStep);
  1496. if(value < mint)
  1497. tmp = mint;
  1498. else
  1499. tmp = value;
  1500. }
  1501. AddChange(changes.PIDHoverTau,tmp);
  1502. }
  1503. }
  1504. public override Quaternion APIDTarget
  1505. {
  1506. set
  1507. {
  1508. return;
  1509. }
  1510. }
  1511. public override bool APIDActive
  1512. {
  1513. set
  1514. {
  1515. return;
  1516. }
  1517. }
  1518. public override float APIDStrength
  1519. {
  1520. set
  1521. {
  1522. return;
  1523. }
  1524. }
  1525. public override float APIDDamping
  1526. {
  1527. set
  1528. {
  1529. return;
  1530. }
  1531. }
  1532. public override void SubscribeEvents(int ms)
  1533. {
  1534. m_eventsubscription = ms;
  1535. m_cureventsubscription = 0;
  1536. CollisionEventsThisFrame.Clear();
  1537. SentEmptyCollisionsEvent = false;
  1538. }
  1539. public override void UnSubscribeEvents()
  1540. {
  1541. m_eventsubscription = 0;
  1542. m_parent_scene.RemoveCollisionEventReporting(this);
  1543. lock(CollisionEventsThisFrame)
  1544. CollisionEventsThisFrame.Clear();
  1545. }
  1546. public override void AddCollisionEvent(uint CollidedWith,ContactPoint contact)
  1547. {
  1548. lock(CollisionEventsThisFrame)
  1549. CollisionEventsThisFrame.AddCollider(CollidedWith,contact);
  1550. m_parent_scene.AddCollisionEventReporting(this);
  1551. }
  1552. public void SendCollisions(int timestep)
  1553. {
  1554. if(m_cureventsubscription < 50000)
  1555. m_cureventsubscription += timestep;
  1556. if(m_cureventsubscription < m_eventsubscription)
  1557. return;
  1558. if(Body != IntPtr.Zero && !SafeNativeMethods.BodyIsEnabled(Body))
  1559. return;
  1560. lock(CollisionEventsThisFrame)
  1561. {
  1562. int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
  1563. if(!SentEmptyCollisionsEvent || ncolisions > 0)
  1564. {
  1565. base.SendCollisionUpdate(CollisionEventsThisFrame);
  1566. m_cureventsubscription = 0;
  1567. if(ncolisions == 0)
  1568. {
  1569. SentEmptyCollisionsEvent = true;
  1570. // _parent_scene.RemoveCollisionEventReporting(this);
  1571. }
  1572. else
  1573. {
  1574. SentEmptyCollisionsEvent = false;
  1575. CollisionEventsThisFrame.Clear();
  1576. }
  1577. }
  1578. }
  1579. }
  1580. public override bool SubscribedEvents()
  1581. {
  1582. if(m_eventsubscription > 0)
  1583. return true;
  1584. return false;
  1585. }
  1586. private void changePhysicsStatus(bool NewStatus)
  1587. {
  1588. if(NewStatus != m_isPhysical)
  1589. {
  1590. if(NewStatus)
  1591. {
  1592. AvatarGeomAndBodyDestroy();
  1593. AvatarGeomAndBodyCreation(_position.X,_position.Y,_position.Z);
  1594. m_parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
  1595. m_parent_scene.AddCharacter(this);
  1596. }
  1597. else
  1598. {
  1599. m_parent_scene.RemoveCollisionEventReporting(this);
  1600. m_parent_scene.RemoveCharacter(this);
  1601. // destroy avatar capsule and related ODE data
  1602. AvatarGeomAndBodyDestroy();
  1603. }
  1604. m_freemove = false;
  1605. m_isPhysical = NewStatus;
  1606. }
  1607. }
  1608. private void changeAdd()
  1609. {
  1610. changePhysicsStatus(true);
  1611. }
  1612. private void changeRemove()
  1613. {
  1614. changePhysicsStatus(false);
  1615. }
  1616. private void changeShape(PrimitiveBaseShape arg)
  1617. {
  1618. }
  1619. private void changeAvatarSize(strAvatarSize st)
  1620. {
  1621. m_feetOffset = st.offset;
  1622. changeSize(st.size);
  1623. }
  1624. private void changeSize(Vector3 pSize)
  1625. {
  1626. if(pSize.IsFinite())
  1627. {
  1628. // for now only look to Z changes since viewers also don't change X and Y
  1629. if(pSize.Z != m_size.Z)
  1630. {
  1631. AvatarGeomAndBodyDestroy();
  1632. float oldsz = m_size.Z;
  1633. m_size = pSize;
  1634. AvatarGeomAndBodyCreation(_position.X,_position.Y,
  1635. _position.Z + (m_size.Z - oldsz) * 0.5f);
  1636. // Velocity = Vector3.Zero;
  1637. m_targetVelocity = Vector3.Zero;
  1638. m_parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
  1639. }
  1640. m_freemove = false;
  1641. m_pidControllerActive = true;
  1642. }
  1643. else
  1644. {
  1645. m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
  1646. }
  1647. }
  1648. private void changePosition(Vector3 newPos)
  1649. {
  1650. if(Body != IntPtr.Zero)
  1651. {
  1652. SafeNativeMethods.BodySetPosition(Body, newPos.X, newPos.Y, newPos.Z);
  1653. SafeNativeMethods.BodyEnable(Body);
  1654. }
  1655. _position = newPos;
  1656. m_freemove = false;
  1657. _zeroFlag = false;
  1658. m_pidControllerActive = true;
  1659. }
  1660. private void changeOrientation(Quaternion newOri)
  1661. {
  1662. if(m_orientation != newOri)
  1663. {
  1664. m_orientation = newOri; // keep a copy for core use
  1665. // but only use rotations around Z
  1666. m_orientation2D.W = newOri.W;
  1667. m_orientation2D.Z = newOri.Z;
  1668. float t = m_orientation2D.W * m_orientation2D.W + m_orientation2D.Z * m_orientation2D.Z;
  1669. if(t > 0)
  1670. {
  1671. t = 1.0f / (float)Math.Sqrt(t);
  1672. m_orientation2D.W *= t;
  1673. m_orientation2D.Z *= t;
  1674. }
  1675. else
  1676. {
  1677. m_orientation2D.W = 1.0f;
  1678. m_orientation2D.Z = 0f;
  1679. }
  1680. m_orientation2D.Y = 0f;
  1681. m_orientation2D.X = 0f;
  1682. if (Body != IntPtr.Zero)
  1683. {
  1684. SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
  1685. myrot.X = m_orientation2D.X;
  1686. myrot.Y = m_orientation2D.Y;
  1687. myrot.Z = m_orientation2D.Z;
  1688. myrot.W = m_orientation2D.W;
  1689. SafeNativeMethods.BodySetQuaternion(Body,ref myrot);
  1690. SafeNativeMethods.BodyEnable(Body);
  1691. }
  1692. }
  1693. }
  1694. private void changeVelocity(Vector3 newVel)
  1695. {
  1696. _velocity = newVel;
  1697. setFreeMove();
  1698. if (Body != IntPtr.Zero)
  1699. {
  1700. SafeNativeMethods.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
  1701. SafeNativeMethods.BodyEnable(Body);
  1702. }
  1703. }
  1704. private void changeTargetVelocity(Vector3 newVel)
  1705. {
  1706. //m_pidControllerActive = true;
  1707. //m_freemove = false;
  1708. _target_velocity = newVel;
  1709. if (Body != IntPtr.Zero)
  1710. SafeNativeMethods.BodyEnable(Body);
  1711. }
  1712. private void changeSetTorque(Vector3 newTorque)
  1713. {
  1714. }
  1715. private void changeAddForce(Vector3 newForce)
  1716. {
  1717. }
  1718. private void changeAddAngularForce(Vector3 arg)
  1719. {
  1720. }
  1721. private void changeAngularLock(byte arg)
  1722. {
  1723. }
  1724. private void changeFloatOnWater(bool arg)
  1725. {
  1726. }
  1727. private void changeVolumedetetion(bool arg)
  1728. {
  1729. }
  1730. private void changeSelectedStatus(bool arg)
  1731. {
  1732. }
  1733. private void changeDisable(bool arg)
  1734. {
  1735. }
  1736. private void changeBuilding(bool arg)
  1737. {
  1738. }
  1739. private void setFreeMove()
  1740. {
  1741. m_pidControllerActive = true;
  1742. _zeroFlag = false;
  1743. _target_velocity = Vector3.Zero;
  1744. m_freemove = true;
  1745. m_colliderfilter = -1;
  1746. m_colliderObjectfilter = -1;
  1747. m_colliderGroundfilter = -1;
  1748. m_iscolliding = false;
  1749. m_iscollidingGround = false;
  1750. m_iscollidingObj = false;
  1751. CollisionEventsThisFrame.Clear();
  1752. }
  1753. private void changeForce(Vector3 newForce)
  1754. {
  1755. setFreeMove();
  1756. if(Body != IntPtr.Zero)
  1757. {
  1758. if(newForce.X != 0f || newForce.Y != 0f || newForce.Z != 0)
  1759. SafeNativeMethods.BodyAddForce(Body,newForce.X,newForce.Y,newForce.Z);
  1760. SafeNativeMethods.BodyEnable(Body);
  1761. }
  1762. }
  1763. // for now momentum is actually velocity
  1764. private void changeMomentum(Vector3 newmomentum)
  1765. {
  1766. _velocity = newmomentum;
  1767. setFreeMove();
  1768. if(Body != IntPtr.Zero)
  1769. {
  1770. SafeNativeMethods.BodySetLinearVel(Body,newmomentum.X,newmomentum.Y,newmomentum.Z);
  1771. SafeNativeMethods.BodyEnable(Body);
  1772. }
  1773. }
  1774. private void changePIDHoverHeight(float val)
  1775. {
  1776. m_PIDHoverHeight = val;
  1777. if(val == 0)
  1778. m_useHoverPID = false;
  1779. }
  1780. private void changePIDHoverType(PIDHoverType type)
  1781. {
  1782. m_PIDHoverType = type;
  1783. }
  1784. private void changePIDHoverTau(float tau)
  1785. {
  1786. m_PIDHoverTau = tau;
  1787. }
  1788. private void changePIDHoverActive(bool active)
  1789. {
  1790. m_useHoverPID = active;
  1791. }
  1792. private void donullchange()
  1793. {
  1794. }
  1795. public bool DoAChange(changes what,object arg)
  1796. {
  1797. if(collider == IntPtr.Zero && what != changes.Add && what != changes.Remove)
  1798. {
  1799. return false;
  1800. }
  1801. // nasty switch
  1802. switch(what)
  1803. {
  1804. case changes.Add:
  1805. changeAdd();
  1806. break;
  1807. case changes.Remove:
  1808. changeRemove();
  1809. break;
  1810. case changes.Position:
  1811. changePosition((Vector3)arg);
  1812. break;
  1813. case changes.Orientation:
  1814. changeOrientation((Quaternion)arg);
  1815. break;
  1816. case changes.PosOffset:
  1817. donullchange();
  1818. break;
  1819. case changes.OriOffset:
  1820. donullchange();
  1821. break;
  1822. case changes.Velocity:
  1823. changeVelocity((Vector3)arg);
  1824. break;
  1825. case changes.TargetVelocity:
  1826. changeTargetVelocity((Vector3)arg);
  1827. break;
  1828. // case changes.Acceleration:
  1829. // changeacceleration((Vector3)arg);
  1830. // break;
  1831. // case changes.AngVelocity:
  1832. // changeangvelocity((Vector3)arg);
  1833. // break;
  1834. case changes.Force:
  1835. changeForce((Vector3)arg);
  1836. break;
  1837. case changes.Torque:
  1838. changeSetTorque((Vector3)arg);
  1839. break;
  1840. case changes.AddForce:
  1841. changeAddForce((Vector3)arg);
  1842. break;
  1843. case changes.AddAngForce:
  1844. changeAddAngularForce((Vector3)arg);
  1845. break;
  1846. case changes.AngLock:
  1847. changeAngularLock((byte)arg);
  1848. break;
  1849. case changes.Size:
  1850. changeSize((Vector3)arg);
  1851. break;
  1852. case changes.AvatarSize:
  1853. changeAvatarSize((strAvatarSize)arg);
  1854. break;
  1855. case changes.Momentum:
  1856. changeMomentum((Vector3)arg);
  1857. break;
  1858. case changes.PIDHoverHeight:
  1859. changePIDHoverHeight((float)arg);
  1860. break;
  1861. case changes.PIDHoverType:
  1862. changePIDHoverType((PIDHoverType)arg);
  1863. break;
  1864. case changes.PIDHoverTau:
  1865. changePIDHoverTau((float)arg);
  1866. break;
  1867. case changes.PIDHoverActive:
  1868. changePIDHoverActive((bool)arg);
  1869. break;
  1870. /* not in use for now
  1871. case changes.Shape:
  1872. changeShape((PrimitiveBaseShape)arg);
  1873. break;
  1874. case changes.CollidesWater:
  1875. changeFloatOnWater((bool)arg);
  1876. break;
  1877. case changes.VolumeDtc:
  1878. changeVolumedetetion((bool)arg);
  1879. break;
  1880. case changes.Physical:
  1881. changePhysicsStatus((bool)arg);
  1882. break;
  1883. case changes.Selected:
  1884. changeSelectedStatus((bool)arg);
  1885. break;
  1886. case changes.disabled:
  1887. changeDisable((bool)arg);
  1888. break;
  1889. case changes.building:
  1890. changeBuilding((bool)arg);
  1891. break;
  1892. */
  1893. case changes.Null:
  1894. donullchange();
  1895. break;
  1896. default:
  1897. donullchange();
  1898. break;
  1899. }
  1900. return false;
  1901. }
  1902. public void AddChange(changes what,object arg)
  1903. {
  1904. m_parent_scene.AddChange((PhysicsActor)this,what,arg);
  1905. }
  1906. private struct strAvatarSize
  1907. {
  1908. public Vector3 size;
  1909. public float offset;
  1910. }
  1911. }
  1912. }