ODECharacter.cs 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266
  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 > Constants.MaxSimulationHeight)
  152. {
  153. pos.Z = parent_scene.GetTerrainHeightAtXY(127,127) + 5;
  154. }
  155. if(pos.Z < Constants.MinSimulationHeight) // 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. float sx = m_size.X;
  744. float sy = m_size.Y;
  745. float sz = m_size.Z;
  746. float bot = -sz * 0.5f + m_feetOffset;
  747. boneOff = bot + 0.3f;
  748. float feetsz = sz * 0.45f;
  749. if(feetsz > 0.6f)
  750. feetsz = 0.6f;
  751. feetOff = bot + feetsz;
  752. AvaAvaSizeXsq = 0.4f * sx;
  753. AvaAvaSizeXsq *= AvaAvaSizeXsq;
  754. AvaAvaSizeYsq = 0.5f * sy;
  755. AvaAvaSizeYsq *= AvaAvaSizeYsq;
  756. m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace);
  757. collider = SafeNativeMethods.SimpleSpaceCreate(m_parent_scene.CharsSpace);
  758. SafeNativeMethods.SpaceSetSublevel(collider,3);
  759. SafeNativeMethods.SpaceSetCleanup(collider,false);
  760. SafeNativeMethods.GeomSetCategoryBits(collider,(uint)m_collisionCategories);
  761. SafeNativeMethods.GeomSetCollideBits(collider,(uint)m_collisionFlags);
  762. float r = sx;
  763. if(sy > r)
  764. r = sy;
  765. float l = sz - r;
  766. r *= 0.5f;
  767. capsule = SafeNativeMethods.CreateCapsule(collider, r, l);
  768. m_mass = m_density * sx * sy * sz; // update mass
  769. SafeNativeMethods.MassSetBoxTotal(out ShellMass, m_mass, sx, sy, sz);
  770. PID_D = basePID_D * m_mass / m_parent_scene.ODE_STEPSIZE;
  771. PID_P = basePID_P * m_mass / m_parent_scene.ODE_STEPSIZE;
  772. Body = SafeNativeMethods.BodyCreate(m_parent_scene.world);
  773. _zeroFlag = false;
  774. m_pidControllerActive = true;
  775. m_freemove = false;
  776. _velocity = Vector3.Zero;
  777. // SafeNativeMethods.BodySetAutoDisableFlag(Body,false);
  778. SafeNativeMethods.BodySetAutoDisableFlag(Body, true);
  779. m_bodydisablecontrol = 0;
  780. SafeNativeMethods.BodySetPosition(Body, npositionX, npositionY, npositionZ);
  781. _position.X = npositionX;
  782. _position.Y = npositionY;
  783. _position.Z = npositionZ;
  784. SafeNativeMethods.BodySetMass(Body,ref ShellMass);
  785. SafeNativeMethods.GeomSetBody(capsule,Body);
  786. // The purpose of the AMotor here is to keep the avatar's physical
  787. // surrogate from rotating while moving
  788. Amotor = SafeNativeMethods.JointCreateAMotor(m_parent_scene.world,IntPtr.Zero);
  789. SafeNativeMethods.JointAttach(Amotor,Body,IntPtr.Zero);
  790. SafeNativeMethods.JointSetAMotorMode(Amotor,0);
  791. SafeNativeMethods.JointSetAMotorNumAxes(Amotor,3);
  792. SafeNativeMethods.JointSetAMotorAxis(Amotor,0,0,1,0,0);
  793. SafeNativeMethods.JointSetAMotorAxis(Amotor,1,0,0,1,0);
  794. SafeNativeMethods.JointSetAMotorAxis(Amotor,2,0,0,0,1);
  795. SafeNativeMethods.JointSetAMotorAngle(Amotor,0,0);
  796. SafeNativeMethods.JointSetAMotorAngle(Amotor,1,0);
  797. SafeNativeMethods.JointSetAMotorAngle(Amotor,2,0);
  798. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM,0f); // make it HARD
  799. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM2,0f);
  800. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM3,0f);
  801. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP,0.8f);
  802. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP2,0.8f);
  803. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP3,0.8f);
  804. // These lowstops and high stops are effectively (no wiggle room)
  805. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LowStop,-1e-5f);
  806. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop,1e-5f);
  807. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LoStop2,-1e-5f);
  808. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop2,1e-5f);
  809. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LoStop3,-1e-5f);
  810. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop3,1e-5f);
  811. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel,0);
  812. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel2,0);
  813. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel3,0);
  814. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax,5e8f);
  815. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax2,5e8f);
  816. SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax3,5e8f);
  817. }
  818. /// <summary>
  819. /// Destroys the avatar body and geom
  820. private void AvatarGeomAndBodyDestroy()
  821. {
  822. // Kill the Amotor
  823. if(Amotor != IntPtr.Zero)
  824. {
  825. SafeNativeMethods.JointDestroy(Amotor);
  826. Amotor = IntPtr.Zero;
  827. }
  828. if(Body != IntPtr.Zero)
  829. {
  830. //kill the body
  831. SafeNativeMethods.BodyDestroy(Body);
  832. Body = IntPtr.Zero;
  833. }
  834. //kill the Geoms
  835. if(capsule != IntPtr.Zero)
  836. {
  837. m_parent_scene.actor_name_map.Remove(capsule);
  838. m_parent_scene.waitForSpaceUnlock(collider);
  839. SafeNativeMethods.GeomDestroy(capsule);
  840. capsule = IntPtr.Zero;
  841. }
  842. if(collider != IntPtr.Zero)
  843. {
  844. SafeNativeMethods.SpaceDestroy(collider);
  845. collider = IntPtr.Zero;
  846. }
  847. }
  848. //in place 2D rotation around Z assuming rot is normalised and is a rotation around Z
  849. public void RotateXYonZ(ref float x,ref float y,ref Quaternion rot)
  850. {
  851. float sin = 2.0f * rot.Z * rot.W;
  852. float cos = rot.W * rot.W - rot.Z * rot.Z;
  853. float tx = x;
  854. x = tx * cos - y * sin;
  855. y = tx * sin + y * cos;
  856. }
  857. public void RotateXYonZ(ref float x,ref float y,ref float sin,ref float cos)
  858. {
  859. float tx = x;
  860. x = tx * cos - y * sin;
  861. y = tx * sin + y * cos;
  862. }
  863. public void invRotateXYonZ(ref float x,ref float y,ref float sin,ref float cos)
  864. {
  865. float tx = x;
  866. x = tx * cos + y * sin;
  867. y = -tx * sin + y * cos;
  868. }
  869. public void invRotateXYonZ(ref float x,ref float y,ref Quaternion rot)
  870. {
  871. float sin = -2.0f * rot.Z * rot.W;
  872. float cos = rot.W * rot.W - rot.Z * rot.Z;
  873. float tx = x;
  874. x = tx * cos - y * sin;
  875. y = tx * sin + y * cos;
  876. }
  877. internal bool Collide(IntPtr me,IntPtr other,bool reverse,ref SafeNativeMethods.ContactGeom contact,
  878. ref SafeNativeMethods.ContactGeom altContact,ref bool useAltcontact,ref bool feetcollision)
  879. {
  880. feetcollision = false;
  881. useAltcontact = false;
  882. if(me == capsule)
  883. {
  884. Vector3 offset;
  885. float h = contact.pos.Z - _position.Z;
  886. offset.Z = h - feetOff;
  887. offset.X = contact.pos.X - _position.X;
  888. offset.Y = contact.pos.Y - _position.Y;
  889. SafeNativeMethods.GeomClassID gtype = SafeNativeMethods.GeomGetClass(other);
  890. if(gtype == SafeNativeMethods.GeomClassID.CapsuleClass)
  891. {
  892. Vector3 roff = offset * Quaternion.Inverse(m_orientation2D);
  893. float r = roff.X *roff.X / AvaAvaSizeXsq;
  894. r += (roff.Y * roff.Y) / AvaAvaSizeYsq;
  895. if(r > 1.0f)
  896. return false;
  897. float dp = 1.0f -(float)Math.Sqrt((double)r);
  898. if(dp > 0.05f)
  899. dp = 0.05f;
  900. contact.depth = dp;
  901. if(offset.Z < 0)
  902. {
  903. feetcollision = true;
  904. if(h < boneOff)
  905. {
  906. m_collideNormal.X = contact.normal.X;
  907. m_collideNormal.Y = contact.normal.Y;
  908. m_collideNormal.Z = contact.normal.Z;
  909. IsColliding = true;
  910. }
  911. }
  912. return true;
  913. }
  914. if(gtype == SafeNativeMethods.GeomClassID.SphereClass && SafeNativeMethods.GeomGetBody(other) != IntPtr.Zero)
  915. {
  916. if(SafeNativeMethods.GeomSphereGetRadius(other) < 0.5)
  917. return true;
  918. }
  919. if(offset.Z > 0 || contact.normal.Z > 0.35f)
  920. {
  921. if(offset.Z <= 0)
  922. {
  923. feetcollision = true;
  924. if(h < boneOff)
  925. {
  926. m_collideNormal.X = contact.normal.X;
  927. m_collideNormal.Y = contact.normal.Y;
  928. m_collideNormal.Z = contact.normal.Z;
  929. IsColliding = true;
  930. }
  931. }
  932. return true;
  933. }
  934. if(m_flying)
  935. return true;
  936. feetcollision = true;
  937. if(h < boneOff)
  938. {
  939. m_collideNormal.X = contact.normal.X;
  940. m_collideNormal.Y = contact.normal.Y;
  941. m_collideNormal.Z = contact.normal.Z;
  942. IsColliding = true;
  943. }
  944. altContact = contact;
  945. useAltcontact = true;
  946. offset.Z -= 0.2f;
  947. offset.Normalize();
  948. float tdp = contact.depth;
  949. float t = offset.X;
  950. t = Math.Abs(t);
  951. if(t > 1e-6)
  952. {
  953. tdp /= t;
  954. tdp *= contact.normal.X;
  955. }
  956. else
  957. tdp *= 10;
  958. if(tdp > 0.25f)
  959. tdp = 0.25f;
  960. altContact.depth = tdp;
  961. if(reverse)
  962. {
  963. altContact.normal.X = offset.X;
  964. altContact.normal.Y = offset.Y;
  965. altContact.normal.Z = offset.Z;
  966. }
  967. else
  968. {
  969. altContact.normal.X = -offset.X;
  970. altContact.normal.Y = -offset.Y;
  971. altContact.normal.Z = -offset.Z;
  972. }
  973. return true;
  974. }
  975. return false;
  976. }
  977. /// <summary>
  978. /// Called from Simulate
  979. /// This is the avatar's movement control + PID Controller
  980. /// </summary>
  981. /// <param name="timeStep"></param>
  982. public void Move()
  983. {
  984. if(Body == IntPtr.Zero)
  985. return;
  986. if (!SafeNativeMethods.BodyIsEnabled(Body))
  987. {
  988. if (++m_bodydisablecontrol < 50)
  989. return;
  990. // clear residuals
  991. SafeNativeMethods.BodySetAngularVel(Body, 0f, 0f, 0f);
  992. SafeNativeMethods.BodySetLinearVel(Body, 0f, 0f, 0f);
  993. _zeroFlag = true;
  994. SafeNativeMethods.BodyEnable(Body);
  995. }
  996. m_bodydisablecontrol = 0;
  997. SafeNativeMethods.Vector3 dtmp = SafeNativeMethods.BodyGetPosition(Body);
  998. Vector3 localpos = new Vector3(dtmp.X,dtmp.Y,dtmp.Z);
  999. // the Amotor still lets avatar rotation to drift during colisions
  1000. // so force it back to identity
  1001. SafeNativeMethods.Quaternion qtmp;
  1002. qtmp.W = m_orientation2D.W;
  1003. qtmp.X = m_orientation2D.X;
  1004. qtmp.Y = m_orientation2D.Y;
  1005. qtmp.Z = m_orientation2D.Z;
  1006. SafeNativeMethods.BodySetQuaternion(Body,ref qtmp);
  1007. if(m_pidControllerActive == false)
  1008. {
  1009. _zeroPosition = localpos;
  1010. }
  1011. // check outbounds forcing to be in world
  1012. bool fixbody = false;
  1013. float tmp = localpos.X;
  1014. if ((Single.IsNaN(tmp) || Single.IsInfinity(tmp)))
  1015. {
  1016. fixbody = true;
  1017. localpos.X = 128f;
  1018. }
  1019. else if (tmp < 0.0f)
  1020. {
  1021. fixbody = true;
  1022. localpos.X = 0.1f;
  1023. }
  1024. else if (tmp > m_parent_scene.WorldExtents.X - 0.1f)
  1025. {
  1026. fixbody = true;
  1027. localpos.X = m_parent_scene.WorldExtents.X - 0.1f;
  1028. }
  1029. tmp = localpos.Y;
  1030. if ((Single.IsNaN(tmp) || Single.IsInfinity(tmp)))
  1031. {
  1032. fixbody = true;
  1033. localpos.X = 128f;
  1034. }
  1035. else if (tmp < 0.0f)
  1036. {
  1037. fixbody = true;
  1038. localpos.Y = 0.1f;
  1039. }
  1040. else if(tmp > m_parent_scene.WorldExtents.Y - 0.1)
  1041. {
  1042. fixbody = true;
  1043. localpos.Y = m_parent_scene.WorldExtents.Y - 0.1f;
  1044. }
  1045. tmp = localpos.Z;
  1046. if ((Single.IsNaN(tmp) || Single.IsInfinity(tmp)))
  1047. {
  1048. fixbody = true;
  1049. localpos.Z = 128f;
  1050. }
  1051. if (fixbody)
  1052. {
  1053. m_freemove = false;
  1054. SafeNativeMethods.BodySetPosition(Body,localpos.X,localpos.Y,localpos.Z);
  1055. }
  1056. float breakfactor;
  1057. Vector3 vec = Vector3.Zero;
  1058. dtmp = SafeNativeMethods.BodyGetLinearVel(Body);
  1059. Vector3 vel = new Vector3(dtmp.X,dtmp.Y,dtmp.Z);
  1060. float velLengthSquared = vel.LengthSquared();
  1061. Vector3 ctz = _target_velocity;
  1062. float movementdivisor = 1f;
  1063. //Ubit change divisions into multiplications below
  1064. if(!m_alwaysRun)
  1065. movementdivisor = 1 / walkDivisor;
  1066. else
  1067. movementdivisor = 1 / runDivisor;
  1068. ctz.X *= movementdivisor;
  1069. ctz.Y *= movementdivisor;
  1070. //******************************************
  1071. // colide with land
  1072. SafeNativeMethods.AABB aabb;
  1073. // d.GeomGetAABB(feetbox, out aabb);
  1074. SafeNativeMethods.GeomGetAABB(capsule,out aabb);
  1075. float chrminZ = aabb.MinZ; // move up a bit
  1076. Vector3 posch = localpos;
  1077. float ftmp;
  1078. if(m_flying)
  1079. {
  1080. ftmp = timeStep;
  1081. posch.X += vel.X * ftmp;
  1082. posch.Y += vel.Y * ftmp;
  1083. }
  1084. float terrainheight = m_parent_scene.GetTerrainHeightAtXY(posch.X,posch.Y);
  1085. if(chrminZ < terrainheight)
  1086. {
  1087. if(ctz.Z < 0)
  1088. ctz.Z = 0;
  1089. if(!m_haveLastFallVel)
  1090. {
  1091. m_lastFallVel = vel;
  1092. m_haveLastFallVel = true;
  1093. }
  1094. Vector3 n = m_parent_scene.GetTerrainNormalAtXY(posch.X,posch.Y);
  1095. float depth = terrainheight - chrminZ;
  1096. vec.Z = depth * PID_P * 50;
  1097. if(!m_flying)
  1098. {
  1099. vec.Z += -vel.Z * PID_D;
  1100. if(n.Z < 0.4f)
  1101. {
  1102. vec.X = depth * PID_P * 50 - vel.X * PID_D;
  1103. vec.X *= n.X;
  1104. vec.Y = depth * PID_P * 50 - vel.Y * PID_D;
  1105. vec.Y *= n.Y;
  1106. vec.Z *= n.Z;
  1107. if(n.Z < 0.1f)
  1108. {
  1109. // cancel the slope pose
  1110. n.X = 0f;
  1111. n.Y = 0f;
  1112. n.Z = 1.0f;
  1113. }
  1114. }
  1115. }
  1116. if(depth < 0.2f)
  1117. {
  1118. m_colliderGroundfilter++;
  1119. if(m_colliderGroundfilter > 2)
  1120. {
  1121. m_iscolliding = true;
  1122. m_colliderfilter = 2;
  1123. if(m_colliderGroundfilter > 10)
  1124. {
  1125. m_colliderGroundfilter = 10;
  1126. m_freemove = false;
  1127. }
  1128. m_collideNormal.X = n.X;
  1129. m_collideNormal.Y = n.Y;
  1130. m_collideNormal.Z = n.Z;
  1131. m_iscollidingGround = true;
  1132. ContactPoint contact = new ContactPoint();
  1133. contact.PenetrationDepth = depth;
  1134. contact.Position.X = localpos.X;
  1135. contact.Position.Y = localpos.Y;
  1136. contact.Position.Z = terrainheight;
  1137. contact.SurfaceNormal.X = -n.X;
  1138. contact.SurfaceNormal.Y = -n.Y;
  1139. contact.SurfaceNormal.Z = -n.Z;
  1140. contact.RelativeSpeed = Vector3.Dot(m_lastFallVel,n);
  1141. contact.CharacterFeet = true;
  1142. AddCollisionEvent(0,contact);
  1143. m_lastFallVel = vel;
  1144. // vec.Z *= 0.5f;
  1145. }
  1146. }
  1147. else
  1148. {
  1149. m_colliderGroundfilter -= 5;
  1150. if(m_colliderGroundfilter <= 0)
  1151. {
  1152. m_colliderGroundfilter = 0;
  1153. m_iscollidingGround = false;
  1154. }
  1155. }
  1156. }
  1157. else
  1158. {
  1159. m_haveLastFallVel = false;
  1160. m_colliderGroundfilter -= 5;
  1161. if(m_colliderGroundfilter <= 0)
  1162. {
  1163. m_colliderGroundfilter = 0;
  1164. m_iscollidingGround = false;
  1165. }
  1166. }
  1167. bool hoverPIDActive = false;
  1168. if(m_useHoverPID && m_PIDHoverTau != 0 && m_PIDHoverHeight != 0)
  1169. {
  1170. hoverPIDActive = true;
  1171. switch(m_PIDHoverType)
  1172. {
  1173. case PIDHoverType.Ground:
  1174. m_targetHoverHeight = terrainheight + m_PIDHoverHeight;
  1175. break;
  1176. case PIDHoverType.GroundAndWater:
  1177. float waterHeight = m_parent_scene.GetWaterLevel();
  1178. if(terrainheight > waterHeight)
  1179. m_targetHoverHeight = terrainheight + m_PIDHoverHeight;
  1180. else
  1181. m_targetHoverHeight = waterHeight + m_PIDHoverHeight;
  1182. break;
  1183. } // end switch (m_PIDHoverType)
  1184. // don't go underground
  1185. if(m_targetHoverHeight > terrainheight + 0.5f * (aabb.MaxZ - aabb.MinZ))
  1186. {
  1187. float fz = (m_targetHoverHeight - localpos.Z);
  1188. // if error is zero, use position control; otherwise, velocity control
  1189. if(Math.Abs(fz) < 0.01f)
  1190. {
  1191. ctz.Z = 0;
  1192. }
  1193. else
  1194. {
  1195. _zeroFlag = false;
  1196. fz /= m_PIDHoverTau;
  1197. tmp = Math.Abs(fz);
  1198. if(tmp > 50)
  1199. fz = 50 * Math.Sign(fz);
  1200. else if(tmp < 0.1)
  1201. fz = 0.1f * Math.Sign(fz);
  1202. ctz.Z = fz;
  1203. }
  1204. }
  1205. }
  1206. //******************************************
  1207. if(!m_iscolliding)
  1208. m_collideNormal.Z = 0;
  1209. bool tviszero = (ctz.X == 0.0f && ctz.Y == 0.0f && ctz.Z == 0.0f);
  1210. if(!tviszero)
  1211. {
  1212. m_freemove = false;
  1213. // movement relative to surface if moving on it
  1214. // dont disturbe vertical movement, ie jumps
  1215. if(m_iscolliding && !m_flying && ctz.Z == 0 && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f)
  1216. {
  1217. float p = ctz.X * m_collideNormal.X + ctz.Y * m_collideNormal.Y;
  1218. ctz.X *= (float)Math.Sqrt(1 - m_collideNormal.X * m_collideNormal.X);
  1219. ctz.Y *= (float)Math.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y);
  1220. ctz.Z -= p;
  1221. if(ctz.Z < 0)
  1222. ctz.Z *= 2;
  1223. }
  1224. }
  1225. if(!m_freemove)
  1226. {
  1227. // if velocity is zero, use position control; otherwise, velocity control
  1228. if(tviszero)
  1229. {
  1230. if(m_iscolliding || m_flying)
  1231. {
  1232. // keep track of where we stopped. No more slippin' & slidin'
  1233. if (!_zeroFlag)
  1234. {
  1235. _zeroFlag = true;
  1236. _zeroPosition = localpos;
  1237. }
  1238. if(m_pidControllerActive)
  1239. {
  1240. // We only want to deactivate the PID Controller if we think we want to have our surrogate
  1241. // react to the physics scene by moving it's position.
  1242. // Avatar to Avatar collisions
  1243. // Prim to avatar collisions
  1244. vec.X = -vel.X * PID_D * 2f + (_zeroPosition.X - localpos.X) * (PID_P * 5);
  1245. vec.Y = -vel.Y * PID_D * 2f + (_zeroPosition.Y - localpos.Y) * (PID_P * 5);
  1246. if(vel.Z > 0)
  1247. vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P;
  1248. else
  1249. vec.Z += (-vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P) * 0.2f;
  1250. }
  1251. }
  1252. else
  1253. {
  1254. _zeroFlag = false;
  1255. vec.X += (ctz.X - vel.X) * PID_D * 0.833f;
  1256. vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f;
  1257. // hack for breaking on fall
  1258. if (ctz.Z == -9999f)
  1259. vec.Z += -vel.Z * PID_D - m_parent_scene.gravityz * m_mass;
  1260. }
  1261. }
  1262. else
  1263. {
  1264. m_pidControllerActive = true;
  1265. _zeroFlag = false;
  1266. if(m_iscolliding)
  1267. {
  1268. if(!m_flying)
  1269. {
  1270. // we are on a surface
  1271. if(ctz.Z > 0f)
  1272. {
  1273. // moving up or JUMPING
  1274. vec.Z += (ctz.Z - vel.Z) * PID_D * 2f;
  1275. vec.X += (ctz.X - vel.X) * (PID_D);
  1276. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1277. }
  1278. else
  1279. {
  1280. // we are moving down on a surface
  1281. if(ctz.Z == 0)
  1282. {
  1283. if(vel.Z > 0)
  1284. vec.Z -= vel.Z * PID_D * 2f;
  1285. vec.X += (ctz.X - vel.X) * (PID_D);
  1286. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1287. }
  1288. // intencionally going down
  1289. else
  1290. {
  1291. if(ctz.Z < vel.Z)
  1292. vec.Z += (ctz.Z - vel.Z) * PID_D;
  1293. else
  1294. {
  1295. }
  1296. if(Math.Abs(ctz.X) > Math.Abs(vel.X))
  1297. vec.X += (ctz.X - vel.X) * (PID_D);
  1298. if(Math.Abs(ctz.Y) > Math.Abs(vel.Y))
  1299. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1300. }
  1301. }
  1302. // We're standing on something
  1303. }
  1304. else
  1305. {
  1306. // We're flying and colliding with something
  1307. vec.X += (ctz.X - vel.X) * (PID_D * 0.0625f);
  1308. vec.Y += (ctz.Y - vel.Y) * (PID_D * 0.0625f);
  1309. vec.Z += (ctz.Z - vel.Z) * (PID_D * 0.0625f);
  1310. }
  1311. }
  1312. else // ie not colliding
  1313. {
  1314. if(m_flying || hoverPIDActive) //(!m_iscolliding && flying)
  1315. {
  1316. // we're in mid air suspended
  1317. vec.X += (ctz.X - vel.X) * (PID_D);
  1318. vec.Y += (ctz.Y - vel.Y) * (PID_D);
  1319. vec.Z += (ctz.Z - vel.Z) * (PID_D);
  1320. }
  1321. else
  1322. {
  1323. // we're not colliding and we're not flying so that means we're falling!
  1324. // m_iscolliding includes collisions with the ground.
  1325. // d.Vector3 pos = d.BodyGetPosition(Body);
  1326. vec.X += (ctz.X - vel.X) * PID_D * 0.833f;
  1327. vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f;
  1328. // hack for breaking on fall
  1329. if (ctz.Z == -9999f)
  1330. vec.Z += -vel.Z * PID_D - m_parent_scene.gravityz * m_mass;
  1331. }
  1332. }
  1333. }
  1334. if(velLengthSquared > 2500.0f) // 50m/s apply breaks
  1335. {
  1336. breakfactor = 0.16f * m_mass;
  1337. vec.X -= breakfactor * vel.X;
  1338. vec.Y -= breakfactor * vel.Y;
  1339. vec.Z -= breakfactor * vel.Z;
  1340. }
  1341. }
  1342. else
  1343. {
  1344. breakfactor = m_mass;
  1345. vec.X -= breakfactor * vel.X;
  1346. vec.Y -= breakfactor * vel.Y;
  1347. if(m_flying)
  1348. vec.Z -= 0.5f * breakfactor * vel.Z;
  1349. else
  1350. vec.Z -= .16f* m_mass * vel.Z;
  1351. }
  1352. if(m_flying || hoverPIDActive)
  1353. {
  1354. vec.Z -= m_parent_scene.gravityz * m_mass;
  1355. if(!hoverPIDActive)
  1356. {
  1357. //Added for auto fly height. Kitto Flora
  1358. float target_altitude = terrainheight + MinimumGroundFlightOffset;
  1359. if(localpos.Z < target_altitude)
  1360. {
  1361. vec.Z += (target_altitude - localpos.Z) * PID_P * 5.0f;
  1362. }
  1363. // end add Kitto Flora
  1364. }
  1365. }
  1366. if(vec.IsFinite())
  1367. {
  1368. if((vec.X != 0 || vec.Y !=0 || vec.Z !=0))
  1369. SafeNativeMethods.BodyAddForce(Body,vec.X,vec.Y,vec.Z);
  1370. }
  1371. // update our local ideia of position velocity and aceleration
  1372. // _position = localpos;
  1373. _position = localpos;
  1374. if(_zeroFlag)
  1375. {
  1376. _velocity = Vector3.Zero;
  1377. _acceleration = Vector3.Zero;
  1378. m_rotationalVelocity = Vector3.Zero;
  1379. }
  1380. else
  1381. {
  1382. Vector3 a = _velocity; // previous velocity
  1383. SetSmooth(ref _velocity,ref vel,2);
  1384. a = (_velocity - a) * invtimeStep;
  1385. SetSmooth(ref _acceleration,ref a,2);
  1386. dtmp = SafeNativeMethods.BodyGetAngularVel(Body);
  1387. m_rotationalVelocity.X = 0f;
  1388. m_rotationalVelocity.Y = 0f;
  1389. m_rotationalVelocity.Z = dtmp.Z;
  1390. Math.Round(m_rotationalVelocity.Z,3);
  1391. }
  1392. }
  1393. public void round(ref Vector3 v,int digits)
  1394. {
  1395. v.X = (float)Math.Round(v.X,digits);
  1396. v.Y = (float)Math.Round(v.Y,digits);
  1397. v.Z = (float)Math.Round(v.Z,digits);
  1398. }
  1399. public void SetSmooth(ref Vector3 dst,ref Vector3 value)
  1400. {
  1401. dst.X = 0.1f * dst.X + 0.9f * value.X;
  1402. dst.Y = 0.1f * dst.Y + 0.9f * value.Y;
  1403. dst.Z = 0.1f * dst.Z + 0.9f * value.Z;
  1404. }
  1405. public void SetSmooth(ref Vector3 dst,ref Vector3 value,int rounddigits)
  1406. {
  1407. dst.X = 0.4f * dst.X + 0.6f * value.X;
  1408. dst.X = (float)Math.Round(dst.X,rounddigits);
  1409. dst.Y = 0.4f * dst.Y + 0.6f * value.Y;
  1410. dst.Y = (float)Math.Round(dst.Y,rounddigits);
  1411. dst.Z = 0.4f * dst.Z + 0.6f * value.Z;
  1412. dst.Z = (float)Math.Round(dst.Z,rounddigits);
  1413. }
  1414. /// <summary>
  1415. /// Updates the reported position and velocity.
  1416. /// Used to copy variables from unmanaged space at heartbeat rate and also trigger scene updates acording
  1417. /// also outbounds checking
  1418. /// copy and outbounds now done in move(..) at ode rate
  1419. ///
  1420. /// </summary>
  1421. public void UpdatePositionAndVelocity()
  1422. {
  1423. return;
  1424. // if (Body == IntPtr.Zero)
  1425. // return;
  1426. }
  1427. /// <summary>
  1428. /// Cleanup the things we use in the scene.
  1429. /// </summary>
  1430. public void Destroy()
  1431. {
  1432. AddChange(changes.Remove,null);
  1433. }
  1434. public override void CrossingFailure()
  1435. {
  1436. }
  1437. public override Vector3 PIDTarget
  1438. {
  1439. set
  1440. {
  1441. return;
  1442. }
  1443. }
  1444. public override bool PIDActive
  1445. {
  1446. get
  1447. {
  1448. return m_pidControllerActive;
  1449. }
  1450. set
  1451. {
  1452. return;
  1453. }
  1454. }
  1455. public override float PIDTau
  1456. {
  1457. set
  1458. {
  1459. return;
  1460. }
  1461. }
  1462. public override float PIDHoverHeight
  1463. {
  1464. set
  1465. {
  1466. AddChange(changes.PIDHoverHeight,value);
  1467. }
  1468. }
  1469. public override bool PIDHoverActive
  1470. {
  1471. get
  1472. {
  1473. return m_useHoverPID;
  1474. }
  1475. set
  1476. {
  1477. AddChange(changes.PIDHoverActive,value);
  1478. }
  1479. }
  1480. public override PIDHoverType PIDHoverType
  1481. {
  1482. set
  1483. {
  1484. AddChange(changes.PIDHoverType,value);
  1485. }
  1486. }
  1487. public override float PIDHoverTau
  1488. {
  1489. set
  1490. {
  1491. float tmp = 0;
  1492. if(value > 0)
  1493. {
  1494. float mint = (0.05f > timeStep ? 0.05f : timeStep);
  1495. if(value < mint)
  1496. tmp = mint;
  1497. else
  1498. tmp = value;
  1499. }
  1500. AddChange(changes.PIDHoverTau,tmp);
  1501. }
  1502. }
  1503. public override Quaternion APIDTarget
  1504. {
  1505. set
  1506. {
  1507. return;
  1508. }
  1509. }
  1510. public override bool APIDActive
  1511. {
  1512. set
  1513. {
  1514. return;
  1515. }
  1516. }
  1517. public override float APIDStrength
  1518. {
  1519. set
  1520. {
  1521. return;
  1522. }
  1523. }
  1524. public override float APIDDamping
  1525. {
  1526. set
  1527. {
  1528. return;
  1529. }
  1530. }
  1531. public override void SubscribeEvents(int ms)
  1532. {
  1533. m_eventsubscription = ms;
  1534. m_cureventsubscription = 0;
  1535. CollisionEventsThisFrame.Clear();
  1536. SentEmptyCollisionsEvent = false;
  1537. }
  1538. public override void UnSubscribeEvents()
  1539. {
  1540. m_eventsubscription = 0;
  1541. m_parent_scene.RemoveCollisionEventReporting(this);
  1542. lock(CollisionEventsThisFrame)
  1543. CollisionEventsThisFrame.Clear();
  1544. }
  1545. public override void AddCollisionEvent(uint CollidedWith,ContactPoint contact)
  1546. {
  1547. lock(CollisionEventsThisFrame)
  1548. CollisionEventsThisFrame.AddCollider(CollidedWith,contact);
  1549. m_parent_scene.AddCollisionEventReporting(this);
  1550. }
  1551. public void SendCollisions(int timestep)
  1552. {
  1553. if(m_cureventsubscription < 50000)
  1554. m_cureventsubscription += timestep;
  1555. if(m_cureventsubscription < m_eventsubscription)
  1556. return;
  1557. if(Body != IntPtr.Zero && !SafeNativeMethods.BodyIsEnabled(Body))
  1558. return;
  1559. lock(CollisionEventsThisFrame)
  1560. {
  1561. int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
  1562. if(!SentEmptyCollisionsEvent || ncolisions > 0)
  1563. {
  1564. base.SendCollisionUpdate(CollisionEventsThisFrame);
  1565. m_cureventsubscription = 0;
  1566. if(ncolisions == 0)
  1567. {
  1568. SentEmptyCollisionsEvent = true;
  1569. // _parent_scene.RemoveCollisionEventReporting(this);
  1570. }
  1571. else
  1572. {
  1573. SentEmptyCollisionsEvent = false;
  1574. CollisionEventsThisFrame.Clear();
  1575. }
  1576. }
  1577. }
  1578. }
  1579. public override bool SubscribedEvents()
  1580. {
  1581. if(m_eventsubscription > 0)
  1582. return true;
  1583. return false;
  1584. }
  1585. private void changePhysicsStatus(bool NewStatus)
  1586. {
  1587. if(NewStatus != m_isPhysical)
  1588. {
  1589. if(NewStatus)
  1590. {
  1591. AvatarGeomAndBodyDestroy();
  1592. AvatarGeomAndBodyCreation(_position.X,_position.Y,_position.Z);
  1593. m_parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
  1594. m_parent_scene.AddCharacter(this);
  1595. }
  1596. else
  1597. {
  1598. m_parent_scene.RemoveCollisionEventReporting(this);
  1599. m_parent_scene.RemoveCharacter(this);
  1600. // destroy avatar capsule and related ODE data
  1601. AvatarGeomAndBodyDestroy();
  1602. }
  1603. m_freemove = false;
  1604. m_isPhysical = NewStatus;
  1605. }
  1606. }
  1607. private void changeAdd()
  1608. {
  1609. changePhysicsStatus(true);
  1610. }
  1611. private void changeRemove()
  1612. {
  1613. changePhysicsStatus(false);
  1614. }
  1615. private void changeShape(PrimitiveBaseShape arg)
  1616. {
  1617. }
  1618. private void changeAvatarSize(strAvatarSize st)
  1619. {
  1620. m_feetOffset = st.offset;
  1621. changeSize(st.size);
  1622. }
  1623. private void changeSize(Vector3 pSize)
  1624. {
  1625. if(pSize.IsFinite())
  1626. {
  1627. // for now only look to Z changes since viewers also don't change X and Y
  1628. if(pSize.Z != m_size.Z)
  1629. {
  1630. float oldsz = m_size.Z;
  1631. m_size = pSize;
  1632. float sz = m_size.Z;
  1633. float bot = -sz * 0.5f + m_feetOffset;
  1634. boneOff = bot + 0.3f;
  1635. float feetsz = sz * 0.45f;
  1636. if (feetsz > 0.6f)
  1637. feetsz = 0.6f;
  1638. feetOff = bot + feetsz;
  1639. float sx = m_size.X;
  1640. AvaAvaSizeXsq = 0.4f * sx;
  1641. AvaAvaSizeXsq *= AvaAvaSizeXsq;
  1642. float sy = m_size.Y;
  1643. AvaAvaSizeYsq = 0.5f * sy;
  1644. AvaAvaSizeYsq *= AvaAvaSizeYsq;
  1645. float r = sx;
  1646. if (sy > r)
  1647. r = sy;
  1648. float l = sz - r;
  1649. r *= 0.5f;
  1650. SafeNativeMethods.GeomCapsuleSetParams(capsule, r, l);
  1651. m_mass = m_density * sx * sy * sz; // update mass
  1652. PID_D = basePID_D * m_mass / m_parent_scene.ODE_STEPSIZE;
  1653. PID_P = basePID_P * m_mass / m_parent_scene.ODE_STEPSIZE;
  1654. SafeNativeMethods.MassSetBoxTotal(out ShellMass, m_mass, sx, sy, sz);
  1655. SafeNativeMethods.BodySetMass(Body, ref ShellMass);
  1656. _position.Z += (sz - oldsz) * 0.5f;
  1657. SafeNativeMethods.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
  1658. m_bodydisablecontrol = 0;
  1659. _zeroFlag = false;
  1660. _velocity = Vector3.Zero;
  1661. m_targetVelocity = Vector3.Zero;
  1662. }
  1663. m_freemove = false;
  1664. m_pidControllerActive = true;
  1665. }
  1666. else
  1667. {
  1668. m_log.Warn("[PHYSICS]: Got a NaN Size from Scene on a Character");
  1669. }
  1670. }
  1671. private void changePosition(Vector3 newPos)
  1672. {
  1673. if(Body != IntPtr.Zero)
  1674. {
  1675. SafeNativeMethods.BodySetPosition(Body, newPos.X, newPos.Y, newPos.Z);
  1676. SafeNativeMethods.BodyEnable(Body);
  1677. }
  1678. _position = newPos;
  1679. m_freemove = false;
  1680. _zeroFlag = false;
  1681. m_pidControllerActive = true;
  1682. }
  1683. private void changeOrientation(Quaternion newOri)
  1684. {
  1685. if(m_orientation != newOri)
  1686. {
  1687. m_orientation = newOri; // keep a copy for core use
  1688. // but only use rotations around Z
  1689. m_orientation2D.W = newOri.W;
  1690. m_orientation2D.Z = newOri.Z;
  1691. float t = m_orientation2D.W * m_orientation2D.W + m_orientation2D.Z * m_orientation2D.Z;
  1692. if(t > 0)
  1693. {
  1694. t = 1.0f / (float)Math.Sqrt(t);
  1695. m_orientation2D.W *= t;
  1696. m_orientation2D.Z *= t;
  1697. }
  1698. else
  1699. {
  1700. m_orientation2D.W = 1.0f;
  1701. m_orientation2D.Z = 0f;
  1702. }
  1703. m_orientation2D.Y = 0f;
  1704. m_orientation2D.X = 0f;
  1705. if (Body != IntPtr.Zero)
  1706. {
  1707. SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
  1708. myrot.X = m_orientation2D.X;
  1709. myrot.Y = m_orientation2D.Y;
  1710. myrot.Z = m_orientation2D.Z;
  1711. myrot.W = m_orientation2D.W;
  1712. SafeNativeMethods.BodySetQuaternion(Body,ref myrot);
  1713. SafeNativeMethods.BodyEnable(Body);
  1714. }
  1715. }
  1716. }
  1717. private void changeVelocity(Vector3 newVel)
  1718. {
  1719. _velocity = newVel;
  1720. setFreeMove();
  1721. if (Body != IntPtr.Zero)
  1722. {
  1723. SafeNativeMethods.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z);
  1724. SafeNativeMethods.BodyEnable(Body);
  1725. }
  1726. }
  1727. private void changeTargetVelocity(Vector3 newVel)
  1728. {
  1729. //m_pidControllerActive = true;
  1730. //m_freemove = false;
  1731. _target_velocity = newVel;
  1732. if (Body != IntPtr.Zero)
  1733. SafeNativeMethods.BodyEnable(Body);
  1734. }
  1735. private void changeSetTorque(Vector3 newTorque)
  1736. {
  1737. }
  1738. private void changeAddForce(Vector3 newForce)
  1739. {
  1740. }
  1741. private void changeAddAngularForce(Vector3 arg)
  1742. {
  1743. }
  1744. private void changeAngularLock(byte arg)
  1745. {
  1746. }
  1747. private void changeFloatOnWater(bool arg)
  1748. {
  1749. }
  1750. private void changeVolumedetetion(bool arg)
  1751. {
  1752. }
  1753. private void changeSelectedStatus(bool arg)
  1754. {
  1755. }
  1756. private void changeDisable(bool arg)
  1757. {
  1758. }
  1759. private void changeBuilding(bool arg)
  1760. {
  1761. }
  1762. private void setFreeMove()
  1763. {
  1764. m_pidControllerActive = true;
  1765. _zeroFlag = false;
  1766. _target_velocity = Vector3.Zero;
  1767. m_freemove = true;
  1768. m_colliderfilter = -1;
  1769. m_colliderObjectfilter = -1;
  1770. m_colliderGroundfilter = -1;
  1771. m_iscolliding = false;
  1772. m_iscollidingGround = false;
  1773. m_iscollidingObj = false;
  1774. CollisionEventsThisFrame.Clear();
  1775. }
  1776. private void changeForce(Vector3 newForce)
  1777. {
  1778. setFreeMove();
  1779. if(Body != IntPtr.Zero)
  1780. {
  1781. if(newForce.X != 0f || newForce.Y != 0f || newForce.Z != 0)
  1782. SafeNativeMethods.BodyAddForce(Body,newForce.X,newForce.Y,newForce.Z);
  1783. SafeNativeMethods.BodyEnable(Body);
  1784. }
  1785. }
  1786. // for now momentum is actually velocity
  1787. private void changeMomentum(Vector3 newmomentum)
  1788. {
  1789. _velocity = newmomentum;
  1790. setFreeMove();
  1791. if(Body != IntPtr.Zero)
  1792. {
  1793. SafeNativeMethods.BodySetLinearVel(Body,newmomentum.X,newmomentum.Y,newmomentum.Z);
  1794. SafeNativeMethods.BodyEnable(Body);
  1795. }
  1796. }
  1797. private void changePIDHoverHeight(float val)
  1798. {
  1799. m_PIDHoverHeight = val;
  1800. if(val == 0)
  1801. m_useHoverPID = false;
  1802. }
  1803. private void changePIDHoverType(PIDHoverType type)
  1804. {
  1805. m_PIDHoverType = type;
  1806. }
  1807. private void changePIDHoverTau(float tau)
  1808. {
  1809. m_PIDHoverTau = tau;
  1810. }
  1811. private void changePIDHoverActive(bool active)
  1812. {
  1813. m_useHoverPID = active;
  1814. }
  1815. private void donullchange()
  1816. {
  1817. }
  1818. public bool DoAChange(changes what,object arg)
  1819. {
  1820. if(collider == IntPtr.Zero && what != changes.Add && what != changes.Remove)
  1821. {
  1822. return false;
  1823. }
  1824. // nasty switch
  1825. switch(what)
  1826. {
  1827. case changes.Add:
  1828. changeAdd();
  1829. break;
  1830. case changes.Remove:
  1831. changeRemove();
  1832. break;
  1833. case changes.Position:
  1834. changePosition((Vector3)arg);
  1835. break;
  1836. case changes.Orientation:
  1837. changeOrientation((Quaternion)arg);
  1838. break;
  1839. case changes.PosOffset:
  1840. donullchange();
  1841. break;
  1842. case changes.OriOffset:
  1843. donullchange();
  1844. break;
  1845. case changes.Velocity:
  1846. changeVelocity((Vector3)arg);
  1847. break;
  1848. case changes.TargetVelocity:
  1849. changeTargetVelocity((Vector3)arg);
  1850. break;
  1851. // case changes.Acceleration:
  1852. // changeacceleration((Vector3)arg);
  1853. // break;
  1854. // case changes.AngVelocity:
  1855. // changeangvelocity((Vector3)arg);
  1856. // break;
  1857. case changes.Force:
  1858. changeForce((Vector3)arg);
  1859. break;
  1860. case changes.Torque:
  1861. changeSetTorque((Vector3)arg);
  1862. break;
  1863. case changes.AddForce:
  1864. changeAddForce((Vector3)arg);
  1865. break;
  1866. case changes.AddAngForce:
  1867. changeAddAngularForce((Vector3)arg);
  1868. break;
  1869. case changes.AngLock:
  1870. changeAngularLock((byte)arg);
  1871. break;
  1872. case changes.Size:
  1873. changeSize((Vector3)arg);
  1874. break;
  1875. case changes.AvatarSize:
  1876. changeAvatarSize((strAvatarSize)arg);
  1877. break;
  1878. case changes.Momentum:
  1879. changeMomentum((Vector3)arg);
  1880. break;
  1881. case changes.PIDHoverHeight:
  1882. changePIDHoverHeight((float)arg);
  1883. break;
  1884. case changes.PIDHoverType:
  1885. changePIDHoverType((PIDHoverType)arg);
  1886. break;
  1887. case changes.PIDHoverTau:
  1888. changePIDHoverTau((float)arg);
  1889. break;
  1890. case changes.PIDHoverActive:
  1891. changePIDHoverActive((bool)arg);
  1892. break;
  1893. /* not in use for now
  1894. case changes.Shape:
  1895. changeShape((PrimitiveBaseShape)arg);
  1896. break;
  1897. case changes.CollidesWater:
  1898. changeFloatOnWater((bool)arg);
  1899. break;
  1900. case changes.VolumeDtc:
  1901. changeVolumedetetion((bool)arg);
  1902. break;
  1903. case changes.Physical:
  1904. changePhysicsStatus((bool)arg);
  1905. break;
  1906. case changes.Selected:
  1907. changeSelectedStatus((bool)arg);
  1908. break;
  1909. case changes.disabled:
  1910. changeDisable((bool)arg);
  1911. break;
  1912. case changes.building:
  1913. changeBuilding((bool)arg);
  1914. break;
  1915. */
  1916. case changes.Null:
  1917. donullchange();
  1918. break;
  1919. default:
  1920. donullchange();
  1921. break;
  1922. }
  1923. return false;
  1924. }
  1925. public void AddChange(changes what,object arg)
  1926. {
  1927. m_parent_scene.AddChange((PhysicsActor)this,what,arg);
  1928. }
  1929. private struct strAvatarSize
  1930. {
  1931. public Vector3 size;
  1932. public float offset;
  1933. }
  1934. }
  1935. }