ODECharacter.cs 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238
  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; // previus 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. m_pidControllerActive = true;
  1658. }
  1659. private void changeOrientation(Quaternion newOri)
  1660. {
  1661. if(m_orientation != newOri)
  1662. {
  1663. m_orientation = newOri; // keep a copy for core use
  1664. // but only use rotations around Z
  1665. m_orientation2D.W = newOri.W;
  1666. m_orientation2D.Z = newOri.Z;
  1667. float t = m_orientation2D.W * m_orientation2D.W + m_orientation2D.Z * m_orientation2D.Z;
  1668. if(t > 0)
  1669. {
  1670. t = 1.0f / (float)Math.Sqrt(t);
  1671. m_orientation2D.W *= t;
  1672. m_orientation2D.Z *= t;
  1673. }
  1674. else
  1675. {
  1676. m_orientation2D.W = 1.0f;
  1677. m_orientation2D.Z = 0f;
  1678. }
  1679. m_orientation2D.Y = 0f;
  1680. m_orientation2D.X = 0f;
  1681. if (Body != IntPtr.Zero)
  1682. {
  1683. SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
  1684. myrot.X = m_orientation2D.X;
  1685. myrot.Y = m_orientation2D.Y;
  1686. myrot.Z = m_orientation2D.Z;
  1687. myrot.W = m_orientation2D.W;
  1688. SafeNativeMethods.BodySetQuaternion(Body,ref myrot);
  1689. SafeNativeMethods.BodyEnable(Body);
  1690. }
  1691. }
  1692. }
  1693. private void changeVelocity(Vector3 newVel)
  1694. {
  1695. _velocity = newVel;
  1696. setFreeMove();
  1697. if (Body != IntPtr.Zero)
  1698. {
  1699. SafeNativeMethods.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
  1700. SafeNativeMethods.BodyEnable(Body);
  1701. }
  1702. }
  1703. private void changeTargetVelocity(Vector3 newVel)
  1704. {
  1705. m_pidControllerActive = true;
  1706. m_freemove = false;
  1707. _target_velocity = newVel;
  1708. if (Body != IntPtr.Zero)
  1709. SafeNativeMethods.BodyEnable(Body);
  1710. }
  1711. private void changeSetTorque(Vector3 newTorque)
  1712. {
  1713. }
  1714. private void changeAddForce(Vector3 newForce)
  1715. {
  1716. }
  1717. private void changeAddAngularForce(Vector3 arg)
  1718. {
  1719. }
  1720. private void changeAngularLock(byte arg)
  1721. {
  1722. }
  1723. private void changeFloatOnWater(bool arg)
  1724. {
  1725. }
  1726. private void changeVolumedetetion(bool arg)
  1727. {
  1728. }
  1729. private void changeSelectedStatus(bool arg)
  1730. {
  1731. }
  1732. private void changeDisable(bool arg)
  1733. {
  1734. }
  1735. private void changeBuilding(bool arg)
  1736. {
  1737. }
  1738. private void setFreeMove()
  1739. {
  1740. m_pidControllerActive = true;
  1741. _zeroFlag = false;
  1742. _target_velocity = Vector3.Zero;
  1743. m_freemove = true;
  1744. m_colliderfilter = -1;
  1745. m_colliderObjectfilter = -1;
  1746. m_colliderGroundfilter = -1;
  1747. m_iscolliding = false;
  1748. m_iscollidingGround = false;
  1749. m_iscollidingObj = false;
  1750. CollisionEventsThisFrame.Clear();
  1751. }
  1752. private void changeForce(Vector3 newForce)
  1753. {
  1754. setFreeMove();
  1755. if(Body != IntPtr.Zero)
  1756. {
  1757. if(newForce.X != 0f || newForce.Y != 0f || newForce.Z != 0)
  1758. SafeNativeMethods.BodyAddForce(Body,newForce.X,newForce.Y,newForce.Z);
  1759. SafeNativeMethods.BodyEnable(Body);
  1760. }
  1761. }
  1762. // for now momentum is actually velocity
  1763. private void changeMomentum(Vector3 newmomentum)
  1764. {
  1765. _velocity = newmomentum;
  1766. setFreeMove();
  1767. if(Body != IntPtr.Zero)
  1768. {
  1769. SafeNativeMethods.BodySetLinearVel(Body,newmomentum.X,newmomentum.Y,newmomentum.Z);
  1770. SafeNativeMethods.BodyEnable(Body);
  1771. }
  1772. }
  1773. private void changePIDHoverHeight(float val)
  1774. {
  1775. m_PIDHoverHeight = val;
  1776. if(val == 0)
  1777. m_useHoverPID = false;
  1778. }
  1779. private void changePIDHoverType(PIDHoverType type)
  1780. {
  1781. m_PIDHoverType = type;
  1782. }
  1783. private void changePIDHoverTau(float tau)
  1784. {
  1785. m_PIDHoverTau = tau;
  1786. }
  1787. private void changePIDHoverActive(bool active)
  1788. {
  1789. m_useHoverPID = active;
  1790. }
  1791. private void donullchange()
  1792. {
  1793. }
  1794. public bool DoAChange(changes what,object arg)
  1795. {
  1796. if(collider == IntPtr.Zero && what != changes.Add && what != changes.Remove)
  1797. {
  1798. return false;
  1799. }
  1800. // nasty switch
  1801. switch(what)
  1802. {
  1803. case changes.Add:
  1804. changeAdd();
  1805. break;
  1806. case changes.Remove:
  1807. changeRemove();
  1808. break;
  1809. case changes.Position:
  1810. changePosition((Vector3)arg);
  1811. break;
  1812. case changes.Orientation:
  1813. changeOrientation((Quaternion)arg);
  1814. break;
  1815. case changes.PosOffset:
  1816. donullchange();
  1817. break;
  1818. case changes.OriOffset:
  1819. donullchange();
  1820. break;
  1821. case changes.Velocity:
  1822. changeVelocity((Vector3)arg);
  1823. break;
  1824. case changes.TargetVelocity:
  1825. changeTargetVelocity((Vector3)arg);
  1826. break;
  1827. // case changes.Acceleration:
  1828. // changeacceleration((Vector3)arg);
  1829. // break;
  1830. // case changes.AngVelocity:
  1831. // changeangvelocity((Vector3)arg);
  1832. // break;
  1833. case changes.Force:
  1834. changeForce((Vector3)arg);
  1835. break;
  1836. case changes.Torque:
  1837. changeSetTorque((Vector3)arg);
  1838. break;
  1839. case changes.AddForce:
  1840. changeAddForce((Vector3)arg);
  1841. break;
  1842. case changes.AddAngForce:
  1843. changeAddAngularForce((Vector3)arg);
  1844. break;
  1845. case changes.AngLock:
  1846. changeAngularLock((byte)arg);
  1847. break;
  1848. case changes.Size:
  1849. changeSize((Vector3)arg);
  1850. break;
  1851. case changes.AvatarSize:
  1852. changeAvatarSize((strAvatarSize)arg);
  1853. break;
  1854. case changes.Momentum:
  1855. changeMomentum((Vector3)arg);
  1856. break;
  1857. case changes.PIDHoverHeight:
  1858. changePIDHoverHeight((float)arg);
  1859. break;
  1860. case changes.PIDHoverType:
  1861. changePIDHoverType((PIDHoverType)arg);
  1862. break;
  1863. case changes.PIDHoverTau:
  1864. changePIDHoverTau((float)arg);
  1865. break;
  1866. case changes.PIDHoverActive:
  1867. changePIDHoverActive((bool)arg);
  1868. break;
  1869. /* not in use for now
  1870. case changes.Shape:
  1871. changeShape((PrimitiveBaseShape)arg);
  1872. break;
  1873. case changes.CollidesWater:
  1874. changeFloatOnWater((bool)arg);
  1875. break;
  1876. case changes.VolumeDtc:
  1877. changeVolumedetetion((bool)arg);
  1878. break;
  1879. case changes.Physical:
  1880. changePhysicsStatus((bool)arg);
  1881. break;
  1882. case changes.Selected:
  1883. changeSelectedStatus((bool)arg);
  1884. break;
  1885. case changes.disabled:
  1886. changeDisable((bool)arg);
  1887. break;
  1888. case changes.building:
  1889. changeBuilding((bool)arg);
  1890. break;
  1891. */
  1892. case changes.Null:
  1893. donullchange();
  1894. break;
  1895. default:
  1896. donullchange();
  1897. break;
  1898. }
  1899. return false;
  1900. }
  1901. public void AddChange(changes what,object arg)
  1902. {
  1903. m_parent_scene.AddChange((PhysicsActor)this,what,arg);
  1904. }
  1905. private struct strAvatarSize
  1906. {
  1907. public Vector3 size;
  1908. public float offset;
  1909. }
  1910. }
  1911. }