ODEPrim.cs 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231
  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. /*
  28. * Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
  29. * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
  30. * ODEPrim.cs contains methods dealing with Prim editing, Prim
  31. * characteristics and Kinetic motion.
  32. * ODEDynamics.cs contains methods dealing with Prim Physical motion
  33. * (dynamics) and the associated settings. Old Linear and angular
  34. * motors for dynamic motion have been replace with MoveLinear()
  35. * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
  36. * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
  37. * switch between 'VEHICLE' parameter use and general dynamics
  38. * settings use.
  39. */
  40. //#define SPAM
  41. using System;
  42. using System.Collections.Generic;
  43. using System.Reflection;
  44. using System.Runtime.InteropServices;
  45. using System.Threading;
  46. using log4net;
  47. using OpenMetaverse;
  48. using Ode.NET;
  49. using OpenSim.Framework;
  50. using OpenSim.Region.Physics.Manager;
  51. namespace OpenSim.Region.Physics.OdePlugin
  52. {
  53. /// <summary>
  54. /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
  55. /// </summary>
  56. public class OdePrim : PhysicsActor
  57. {
  58. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  59. private bool m_isphysical;
  60. /// <summary>
  61. /// Is this prim subject to physics? Even if not, it's still solid for collision purposes.
  62. /// </summary>
  63. public override bool IsPhysical
  64. {
  65. get { return m_isphysical; }
  66. set
  67. {
  68. m_isphysical = value;
  69. if (!m_isphysical) // Zero the remembered last velocity
  70. m_lastVelocity = Vector3.Zero;
  71. }
  72. }
  73. private Vector3 _position;
  74. private Vector3 _velocity;
  75. private Vector3 _torque;
  76. private Vector3 m_lastVelocity;
  77. private Vector3 m_lastposition;
  78. private Quaternion m_lastorientation = new Quaternion();
  79. private Vector3 m_rotationalVelocity;
  80. private Vector3 _size;
  81. private Vector3 _acceleration;
  82. // private d.Vector3 _zeroPosition = new d.Vector3(0.0f, 0.0f, 0.0f);
  83. private Quaternion _orientation;
  84. private Vector3 m_taintposition;
  85. private Vector3 m_taintsize;
  86. private Vector3 m_taintVelocity;
  87. private Vector3 m_taintTorque;
  88. private Quaternion m_taintrot;
  89. private Vector3 m_angularlock = Vector3.One;
  90. private Vector3 m_taintAngularLock = Vector3.One;
  91. private IntPtr Amotor = IntPtr.Zero;
  92. private Vector3 m_PIDTarget;
  93. private float m_PIDTau;
  94. private float PID_D = 35f;
  95. private float PID_G = 25f;
  96. private bool m_usePID;
  97. // KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau),
  98. // and are for non-VEHICLES only.
  99. private float m_PIDHoverHeight;
  100. private float m_PIDHoverTau;
  101. private bool m_useHoverPID;
  102. private PIDHoverType m_PIDHoverType = PIDHoverType.Ground;
  103. private float m_targetHoverHeight;
  104. private float m_groundHeight;
  105. private float m_waterHeight;
  106. private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
  107. // private float m_tensor = 5f;
  108. private int body_autodisable_frames = 20;
  109. private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom
  110. | CollisionCategories.Space
  111. | CollisionCategories.Body
  112. | CollisionCategories.Character
  113. );
  114. private bool m_taintshape;
  115. private bool m_taintPhysics;
  116. private bool m_collidesLand = true;
  117. private bool m_collidesWater;
  118. // Default we're a Geometry
  119. private CollisionCategories m_collisionCategories = (CollisionCategories.Geom);
  120. // Default, Collide with Other Geometries, spaces and Bodies
  121. private CollisionCategories m_collisionFlags = m_default_collisionFlags;
  122. public bool m_taintremove { get; private set; }
  123. public bool m_taintdisable { get; private set; }
  124. internal bool m_disabled;
  125. public bool m_taintadd { get; private set; }
  126. public bool m_taintselected { get; private set; }
  127. public bool m_taintCollidesWater { get; private set; }
  128. public uint m_localID { get; private set; }
  129. private bool m_taintforce = false;
  130. private bool m_taintaddangularforce = false;
  131. private Vector3 m_force;
  132. private List<Vector3> m_forcelist = new List<Vector3>();
  133. private List<Vector3> m_angularforcelist = new List<Vector3>();
  134. private PrimitiveBaseShape _pbs;
  135. private OdeScene _parent_scene;
  136. /// <summary>
  137. /// The physics space which contains prim geometries
  138. /// </summary>
  139. public IntPtr m_targetSpace = IntPtr.Zero;
  140. public IntPtr prim_geom { get; private set; }
  141. public IntPtr _triMeshData { get; private set; }
  142. private IntPtr _linkJointGroup = IntPtr.Zero;
  143. private PhysicsActor _parent;
  144. private PhysicsActor m_taintparent;
  145. private List<OdePrim> childrenPrim = new List<OdePrim>();
  146. private bool iscolliding;
  147. private bool m_isSelected;
  148. internal bool m_isVolumeDetect; // If true, this prim only detects collisions but doesn't collide actively
  149. private bool m_throttleUpdates;
  150. private int throttleCounter;
  151. public int m_interpenetrationcount { get; private set; }
  152. internal float m_collisionscore;
  153. public int m_roundsUnderMotionThreshold { get; private set; }
  154. private int m_crossingfailures;
  155. public bool outofBounds { get; private set; }
  156. private float m_density = 10.000006836f; // Aluminum g/cm3;
  157. public bool _zeroFlag { get; private set; }
  158. private bool m_lastUpdateSent;
  159. public IntPtr Body = IntPtr.Zero;
  160. private Vector3 _target_velocity;
  161. private d.Mass pMass;
  162. private int m_eventsubscription;
  163. private CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
  164. /// <summary>
  165. /// Signal whether there were collisions on the previous frame, so we know if we need to send the
  166. /// empty CollisionEventsThisFrame to the prim so that it can detect the end of a collision.
  167. /// </summary>
  168. /// <remarks>
  169. /// This is probably a temporary measure, pending storing this information consistently in CollisionEventUpdate itself.
  170. /// </remarks>
  171. private bool m_collisionsOnPreviousFrame;
  172. private IntPtr m_linkJoint = IntPtr.Zero;
  173. internal volatile bool childPrim;
  174. private ODEDynamics m_vehicle;
  175. internal int m_material = (int)Material.Wood;
  176. public OdePrim(
  177. String primName, OdeScene parent_scene, Vector3 pos, Vector3 size,
  178. Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical)
  179. {
  180. Name = primName;
  181. m_vehicle = new ODEDynamics();
  182. //gc = GCHandle.Alloc(prim_geom, GCHandleType.Pinned);
  183. if (!pos.IsFinite())
  184. {
  185. pos = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f),
  186. parent_scene.GetTerrainHeightAtXY(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f)) + 0.5f);
  187. m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Position for {0}", Name);
  188. }
  189. _position = pos;
  190. m_taintposition = pos;
  191. PID_D = parent_scene.bodyPIDD;
  192. PID_G = parent_scene.bodyPIDG;
  193. m_density = parent_scene.geomDefaultDensity;
  194. // m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
  195. body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
  196. prim_geom = IntPtr.Zero;
  197. if (!pos.IsFinite())
  198. {
  199. size = new Vector3(0.5f, 0.5f, 0.5f);
  200. m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Size for {0}", Name);
  201. }
  202. if (size.X <= 0) size.X = 0.01f;
  203. if (size.Y <= 0) size.Y = 0.01f;
  204. if (size.Z <= 0) size.Z = 0.01f;
  205. _size = size;
  206. m_taintsize = _size;
  207. if (!QuaternionIsFinite(rotation))
  208. {
  209. rotation = Quaternion.Identity;
  210. m_log.WarnFormat("[PHYSICS]: Got nonFinite Object create Rotation for {0}", Name);
  211. }
  212. _orientation = rotation;
  213. m_taintrot = _orientation;
  214. _pbs = pbs;
  215. _parent_scene = parent_scene;
  216. m_targetSpace = (IntPtr)0;
  217. if (pos.Z < 0)
  218. {
  219. IsPhysical = false;
  220. }
  221. else
  222. {
  223. IsPhysical = pisPhysical;
  224. // If we're physical, we need to be in the master space for now.
  225. // linksets *should* be in a space together.. but are not currently
  226. if (IsPhysical)
  227. m_targetSpace = _parent_scene.space;
  228. }
  229. m_taintadd = true;
  230. _parent_scene.AddPhysicsActorTaint(this);
  231. }
  232. public override int PhysicsActorType
  233. {
  234. get { return (int) ActorTypes.Prim; }
  235. set { return; }
  236. }
  237. public override bool SetAlwaysRun
  238. {
  239. get { return false; }
  240. set { return; }
  241. }
  242. public override uint LocalID
  243. {
  244. set {
  245. //m_log.Info("[PHYSICS]: Setting TrackerID: " + value);
  246. m_localID = value; }
  247. }
  248. public override bool Grabbed
  249. {
  250. set { return; }
  251. }
  252. public override bool Selected
  253. {
  254. set
  255. {
  256. // This only makes the object not collidable if the object
  257. // is physical or the object is modified somehow *IN THE FUTURE*
  258. // without this, if an avatar selects prim, they can walk right
  259. // through it while it's selected
  260. m_collisionscore = 0;
  261. if ((IsPhysical && !_zeroFlag) || !value)
  262. {
  263. m_taintselected = value;
  264. _parent_scene.AddPhysicsActorTaint(this);
  265. }
  266. else
  267. {
  268. m_taintselected = value;
  269. m_isSelected = value;
  270. }
  271. if (m_isSelected)
  272. disableBodySoft();
  273. }
  274. }
  275. /// <summary>
  276. /// Set a new geometry for this prim.
  277. /// </summary>
  278. /// <param name="geom"></param>
  279. private void SetGeom(IntPtr geom)
  280. {
  281. prim_geom = geom;
  282. //Console.WriteLine("SetGeom to " + prim_geom + " for " + Name);
  283. if (prim_geom != IntPtr.Zero)
  284. {
  285. d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
  286. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  287. _parent_scene.geom_name_map[prim_geom] = Name;
  288. _parent_scene.actor_name_map[prim_geom] = this;
  289. }
  290. if (childPrim)
  291. {
  292. if (_parent != null && _parent is OdePrim)
  293. {
  294. OdePrim parent = (OdePrim)_parent;
  295. //Console.WriteLine("SetGeom calls ChildSetGeom");
  296. parent.ChildSetGeom(this);
  297. }
  298. }
  299. //m_log.Warn("Setting Geom to: " + prim_geom);
  300. }
  301. private void enableBodySoft()
  302. {
  303. if (!childPrim)
  304. {
  305. if (IsPhysical && Body != IntPtr.Zero)
  306. {
  307. d.BodyEnable(Body);
  308. if (m_vehicle.Type != Vehicle.TYPE_NONE)
  309. m_vehicle.Enable(Body, _parent_scene);
  310. }
  311. m_disabled = false;
  312. }
  313. }
  314. private void disableBodySoft()
  315. {
  316. m_disabled = true;
  317. if (IsPhysical && Body != IntPtr.Zero)
  318. {
  319. d.BodyDisable(Body);
  320. }
  321. }
  322. /// <summary>
  323. /// Make a prim subject to physics.
  324. /// </summary>
  325. private void enableBody()
  326. {
  327. // Don't enable this body if we're a child prim
  328. // this should be taken care of in the parent function not here
  329. if (!childPrim)
  330. {
  331. // Sets the geom to a body
  332. Body = d.BodyCreate(_parent_scene.world);
  333. setMass();
  334. d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
  335. d.Quaternion myrot = new d.Quaternion();
  336. myrot.X = _orientation.X;
  337. myrot.Y = _orientation.Y;
  338. myrot.Z = _orientation.Z;
  339. myrot.W = _orientation.W;
  340. d.BodySetQuaternion(Body, ref myrot);
  341. d.GeomSetBody(prim_geom, Body);
  342. m_collisionCategories |= CollisionCategories.Body;
  343. m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
  344. d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
  345. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  346. d.BodySetAutoDisableFlag(Body, true);
  347. d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
  348. // disconnect from world gravity so we can apply buoyancy
  349. d.BodySetGravityMode (Body, false);
  350. m_interpenetrationcount = 0;
  351. m_collisionscore = 0;
  352. m_disabled = false;
  353. // The body doesn't already have a finite rotation mode set here
  354. if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0.0f)) && _parent == null)
  355. {
  356. createAMotor(m_angularlock);
  357. }
  358. if (m_vehicle.Type != Vehicle.TYPE_NONE)
  359. {
  360. m_vehicle.Enable(Body, _parent_scene);
  361. }
  362. _parent_scene.ActivatePrim(this);
  363. }
  364. }
  365. #region Mass Calculation
  366. private float CalculateMass()
  367. {
  368. float volume = _size.X * _size.Y * _size.Z; // default
  369. float tmp;
  370. float returnMass = 0;
  371. float hollowAmount = (float)_pbs.ProfileHollow * 2.0e-5f;
  372. float hollowVolume = hollowAmount * hollowAmount;
  373. switch (_pbs.ProfileShape)
  374. {
  375. case ProfileShape.Square:
  376. // default box
  377. if (_pbs.PathCurve == (byte)Extrusion.Straight)
  378. {
  379. if (hollowAmount > 0.0)
  380. {
  381. switch (_pbs.HollowShape)
  382. {
  383. case HollowShape.Square:
  384. case HollowShape.Same:
  385. break;
  386. case HollowShape.Circle:
  387. hollowVolume *= 0.78539816339f;
  388. break;
  389. case HollowShape.Triangle:
  390. hollowVolume *= (0.5f * .5f);
  391. break;
  392. default:
  393. hollowVolume = 0;
  394. break;
  395. }
  396. volume *= (1.0f - hollowVolume);
  397. }
  398. }
  399. else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
  400. {
  401. //a tube
  402. volume *= 0.78539816339e-2f * (float)(200 - _pbs.PathScaleX);
  403. tmp= 1.0f -2.0e-2f * (float)(200 - _pbs.PathScaleY);
  404. volume -= volume*tmp*tmp;
  405. if (hollowAmount > 0.0)
  406. {
  407. hollowVolume *= hollowAmount;
  408. switch (_pbs.HollowShape)
  409. {
  410. case HollowShape.Square:
  411. case HollowShape.Same:
  412. break;
  413. case HollowShape.Circle:
  414. hollowVolume *= 0.78539816339f;;
  415. break;
  416. case HollowShape.Triangle:
  417. hollowVolume *= 0.5f * 0.5f;
  418. break;
  419. default:
  420. hollowVolume = 0;
  421. break;
  422. }
  423. volume *= (1.0f - hollowVolume);
  424. }
  425. }
  426. break;
  427. case ProfileShape.Circle:
  428. if (_pbs.PathCurve == (byte)Extrusion.Straight)
  429. {
  430. volume *= 0.78539816339f; // elipse base
  431. if (hollowAmount > 0.0)
  432. {
  433. switch (_pbs.HollowShape)
  434. {
  435. case HollowShape.Same:
  436. case HollowShape.Circle:
  437. break;
  438. case HollowShape.Square:
  439. hollowVolume *= 0.5f * 2.5984480504799f;
  440. break;
  441. case HollowShape.Triangle:
  442. hollowVolume *= .5f * 1.27323954473516f;
  443. break;
  444. default:
  445. hollowVolume = 0;
  446. break;
  447. }
  448. volume *= (1.0f - hollowVolume);
  449. }
  450. }
  451. else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
  452. {
  453. volume *= 0.61685027506808491367715568749226e-2f * (float)(200 - _pbs.PathScaleX);
  454. tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
  455. volume *= (1.0f - tmp * tmp);
  456. if (hollowAmount > 0.0)
  457. {
  458. // calculate the hollow volume by it's shape compared to the prim shape
  459. hollowVolume *= hollowAmount;
  460. switch (_pbs.HollowShape)
  461. {
  462. case HollowShape.Same:
  463. case HollowShape.Circle:
  464. break;
  465. case HollowShape.Square:
  466. hollowVolume *= 0.5f * 2.5984480504799f;
  467. break;
  468. case HollowShape.Triangle:
  469. hollowVolume *= .5f * 1.27323954473516f;
  470. break;
  471. default:
  472. hollowVolume = 0;
  473. break;
  474. }
  475. volume *= (1.0f - hollowVolume);
  476. }
  477. }
  478. break;
  479. case ProfileShape.HalfCircle:
  480. if (_pbs.PathCurve == (byte)Extrusion.Curve1)
  481. {
  482. volume *= 0.52359877559829887307710723054658f;
  483. }
  484. break;
  485. case ProfileShape.EquilateralTriangle:
  486. if (_pbs.PathCurve == (byte)Extrusion.Straight)
  487. {
  488. volume *= 0.32475953f;
  489. if (hollowAmount > 0.0)
  490. {
  491. // calculate the hollow volume by it's shape compared to the prim shape
  492. switch (_pbs.HollowShape)
  493. {
  494. case HollowShape.Same:
  495. case HollowShape.Triangle:
  496. hollowVolume *= .25f;
  497. break;
  498. case HollowShape.Square:
  499. hollowVolume *= 0.499849f * 3.07920140172638f;
  500. break;
  501. case HollowShape.Circle:
  502. // Hollow shape is a perfect cyllinder in respect to the cube's scale
  503. // Cyllinder hollow volume calculation
  504. hollowVolume *= 0.1963495f * 3.07920140172638f;
  505. break;
  506. default:
  507. hollowVolume = 0;
  508. break;
  509. }
  510. volume *= (1.0f - hollowVolume);
  511. }
  512. }
  513. else if (_pbs.PathCurve == (byte)Extrusion.Curve1)
  514. {
  515. volume *= 0.32475953f;
  516. volume *= 0.01f * (float)(200 - _pbs.PathScaleX);
  517. tmp = 1.0f - .02f * (float)(200 - _pbs.PathScaleY);
  518. volume *= (1.0f - tmp * tmp);
  519. if (hollowAmount > 0.0)
  520. {
  521. hollowVolume *= hollowAmount;
  522. switch (_pbs.HollowShape)
  523. {
  524. case HollowShape.Same:
  525. case HollowShape.Triangle:
  526. hollowVolume *= .25f;
  527. break;
  528. case HollowShape.Square:
  529. hollowVolume *= 0.499849f * 3.07920140172638f;
  530. break;
  531. case HollowShape.Circle:
  532. hollowVolume *= 0.1963495f * 3.07920140172638f;
  533. break;
  534. default:
  535. hollowVolume = 0;
  536. break;
  537. }
  538. volume *= (1.0f - hollowVolume);
  539. }
  540. }
  541. break;
  542. default:
  543. break;
  544. }
  545. float taperX1;
  546. float taperY1;
  547. float taperX;
  548. float taperY;
  549. float pathBegin;
  550. float pathEnd;
  551. float profileBegin;
  552. float profileEnd;
  553. if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible)
  554. {
  555. taperX1 = _pbs.PathScaleX * 0.01f;
  556. if (taperX1 > 1.0f)
  557. taperX1 = 2.0f - taperX1;
  558. taperX = 1.0f - taperX1;
  559. taperY1 = _pbs.PathScaleY * 0.01f;
  560. if (taperY1 > 1.0f)
  561. taperY1 = 2.0f - taperY1;
  562. taperY = 1.0f - taperY1;
  563. }
  564. else
  565. {
  566. taperX = _pbs.PathTaperX * 0.01f;
  567. if (taperX < 0.0f)
  568. taperX = -taperX;
  569. taperX1 = 1.0f - taperX;
  570. taperY = _pbs.PathTaperY * 0.01f;
  571. if (taperY < 0.0f)
  572. taperY = -taperY;
  573. taperY1 = 1.0f - taperY;
  574. }
  575. volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
  576. pathBegin = (float)_pbs.PathBegin * 2.0e-5f;
  577. pathEnd = 1.0f - (float)_pbs.PathEnd * 2.0e-5f;
  578. volume *= (pathEnd - pathBegin);
  579. // this is crude aproximation
  580. profileBegin = (float)_pbs.ProfileBegin * 2.0e-5f;
  581. profileEnd = 1.0f - (float)_pbs.ProfileEnd * 2.0e-5f;
  582. volume *= (profileEnd - profileBegin);
  583. returnMass = m_density * volume;
  584. if (returnMass <= 0)
  585. returnMass = 0.0001f;//ckrinke: Mass must be greater then zero.
  586. // else if (returnMass > _parent_scene.maximumMassObject)
  587. // returnMass = _parent_scene.maximumMassObject;
  588. // Recursively calculate mass
  589. bool HasChildPrim = false;
  590. lock (childrenPrim)
  591. {
  592. if (childrenPrim.Count > 0)
  593. {
  594. HasChildPrim = true;
  595. }
  596. }
  597. if (HasChildPrim)
  598. {
  599. OdePrim[] childPrimArr = new OdePrim[0];
  600. lock (childrenPrim)
  601. childPrimArr = childrenPrim.ToArray();
  602. for (int i = 0; i < childPrimArr.Length; i++)
  603. {
  604. if (childPrimArr[i] != null && !childPrimArr[i].m_taintremove)
  605. returnMass += childPrimArr[i].CalculateMass();
  606. // failsafe, this shouldn't happen but with OpenSim, you never know :)
  607. if (i > 256)
  608. break;
  609. }
  610. }
  611. if (returnMass > _parent_scene.maximumMassObject)
  612. returnMass = _parent_scene.maximumMassObject;
  613. return returnMass;
  614. }
  615. #endregion
  616. private void setMass()
  617. {
  618. if (Body != (IntPtr) 0)
  619. {
  620. float newmass = CalculateMass();
  621. //m_log.Info("[PHYSICS]: New Mass: " + newmass.ToString());
  622. d.MassSetBoxTotal(out pMass, newmass, _size.X, _size.Y, _size.Z);
  623. d.BodySetMass(Body, ref pMass);
  624. }
  625. }
  626. /// <summary>
  627. /// Stop a prim from being subject to physics.
  628. /// </summary>
  629. internal void disableBody()
  630. {
  631. //this kills the body so things like 'mesh' can re-create it.
  632. lock (this)
  633. {
  634. if (!childPrim)
  635. {
  636. if (Body != IntPtr.Zero)
  637. {
  638. _parent_scene.DeactivatePrim(this);
  639. m_collisionCategories &= ~CollisionCategories.Body;
  640. m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
  641. if (prim_geom != IntPtr.Zero)
  642. {
  643. d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
  644. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  645. }
  646. d.BodyDestroy(Body);
  647. lock (childrenPrim)
  648. {
  649. if (childrenPrim.Count > 0)
  650. {
  651. foreach (OdePrim prm in childrenPrim)
  652. {
  653. _parent_scene.DeactivatePrim(prm);
  654. prm.Body = IntPtr.Zero;
  655. }
  656. }
  657. }
  658. Body = IntPtr.Zero;
  659. }
  660. }
  661. else
  662. {
  663. _parent_scene.DeactivatePrim(this);
  664. m_collisionCategories &= ~CollisionCategories.Body;
  665. m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
  666. if (prim_geom != IntPtr.Zero)
  667. {
  668. d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
  669. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  670. }
  671. Body = IntPtr.Zero;
  672. }
  673. }
  674. m_disabled = true;
  675. m_collisionscore = 0;
  676. }
  677. private static Dictionary<IMesh, IntPtr> m_MeshToTriMeshMap = new Dictionary<IMesh, IntPtr>();
  678. private void setMesh(OdeScene parent_scene, IMesh mesh)
  679. {
  680. // m_log.DebugFormat("[ODE PRIM]: Setting mesh on {0} to {1}", Name, mesh);
  681. // This sleeper is there to moderate how long it takes between
  682. // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object
  683. //Thread.Sleep(10);
  684. //Kill Body so that mesh can re-make the geom
  685. if (IsPhysical && Body != IntPtr.Zero)
  686. {
  687. if (childPrim)
  688. {
  689. if (_parent != null)
  690. {
  691. OdePrim parent = (OdePrim)_parent;
  692. parent.ChildDelink(this);
  693. }
  694. }
  695. else
  696. {
  697. disableBody();
  698. }
  699. }
  700. IntPtr vertices, indices;
  701. int vertexCount, indexCount;
  702. int vertexStride, triStride;
  703. mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount); // Note, that vertices are fixed in unmanaged heap
  704. mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
  705. mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
  706. if (m_MeshToTriMeshMap.ContainsKey(mesh))
  707. {
  708. _triMeshData = m_MeshToTriMeshMap[mesh];
  709. }
  710. else
  711. {
  712. _triMeshData = d.GeomTriMeshDataCreate();
  713. d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
  714. d.GeomTriMeshDataPreprocess(_triMeshData);
  715. m_MeshToTriMeshMap[mesh] = _triMeshData;
  716. }
  717. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  718. try
  719. {
  720. if (prim_geom == IntPtr.Zero)
  721. {
  722. SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
  723. }
  724. }
  725. catch (AccessViolationException)
  726. {
  727. m_log.ErrorFormat("[PHYSICS]: MESH LOCKED FOR {0}", Name);
  728. return;
  729. }
  730. // if (IsPhysical && Body == (IntPtr) 0)
  731. // {
  732. // Recreate the body
  733. // m_interpenetrationcount = 0;
  734. // m_collisionscore = 0;
  735. // enableBody();
  736. // }
  737. }
  738. internal void ProcessTaints()
  739. {
  740. #if SPAM
  741. Console.WriteLine("ZProcessTaints for " + Name);
  742. #endif
  743. if (m_taintadd)
  744. {
  745. changeadd();
  746. }
  747. if (prim_geom != IntPtr.Zero)
  748. {
  749. if (!_position.ApproxEquals(m_taintposition, 0f))
  750. changemove();
  751. if (m_taintrot != _orientation)
  752. {
  753. if (childPrim && IsPhysical) // For physical child prim...
  754. {
  755. rotate();
  756. // KF: ODE will also rotate the parent prim!
  757. // so rotate the root back to where it was
  758. OdePrim parent = (OdePrim)_parent;
  759. parent.rotate();
  760. }
  761. else
  762. {
  763. //Just rotate the prim
  764. rotate();
  765. }
  766. }
  767. if (m_taintPhysics != IsPhysical && !(m_taintparent != _parent))
  768. changePhysicsStatus();
  769. if (!_size.ApproxEquals(m_taintsize, 0f))
  770. changesize();
  771. if (m_taintshape)
  772. changeshape();
  773. if (m_taintforce)
  774. changeAddForce();
  775. if (m_taintaddangularforce)
  776. changeAddAngularForce();
  777. if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f))
  778. changeSetTorque();
  779. if (m_taintdisable)
  780. changedisable();
  781. if (m_taintselected != m_isSelected)
  782. changeSelectedStatus();
  783. if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f))
  784. changevelocity();
  785. if (m_taintparent != _parent)
  786. changelink();
  787. if (m_taintCollidesWater != m_collidesWater)
  788. changefloatonwater();
  789. if (!m_angularlock.ApproxEquals(m_taintAngularLock,0f))
  790. changeAngularLock();
  791. }
  792. else
  793. {
  794. m_log.ErrorFormat("[PHYSICS]: The scene reused a disposed PhysActor for {0}! *waves finger*, Don't be evil. A couple of things can cause this. An improper prim breakdown(be sure to set prim_geom to zero after d.GeomDestroy! An improper buildup (creating the geom failed). Or, the Scene Reused a physics actor after disposing it.)", Name);
  795. }
  796. }
  797. /// <summary>
  798. /// Change prim in response to an angular lock taint.
  799. /// </summary>
  800. private void changeAngularLock()
  801. {
  802. // do we have a Physical object?
  803. if (Body != IntPtr.Zero)
  804. {
  805. //Check that we have a Parent
  806. //If we have a parent then we're not authorative here
  807. if (_parent == null)
  808. {
  809. if (!m_taintAngularLock.ApproxEquals(Vector3.One, 0f))
  810. {
  811. //d.BodySetFiniteRotationMode(Body, 0);
  812. //d.BodySetFiniteRotationAxis(Body,m_taintAngularLock.X,m_taintAngularLock.Y,m_taintAngularLock.Z);
  813. createAMotor(m_taintAngularLock);
  814. }
  815. else
  816. {
  817. if (Amotor != IntPtr.Zero)
  818. {
  819. d.JointDestroy(Amotor);
  820. Amotor = IntPtr.Zero;
  821. }
  822. }
  823. }
  824. }
  825. // Store this for later in case we get turned into a separate body
  826. m_angularlock = m_taintAngularLock;
  827. }
  828. /// <summary>
  829. /// Change prim in response to a link taint.
  830. /// </summary>
  831. private void changelink()
  832. {
  833. // If the newly set parent is not null
  834. // create link
  835. if (_parent == null && m_taintparent != null)
  836. {
  837. if (m_taintparent.PhysicsActorType == (int)ActorTypes.Prim)
  838. {
  839. OdePrim obj = (OdePrim)m_taintparent;
  840. //obj.disableBody();
  841. //Console.WriteLine("changelink calls ParentPrim");
  842. obj.AddChildPrim(this);
  843. /*
  844. if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body)
  845. {
  846. _linkJointGroup = d.JointGroupCreate(0);
  847. m_linkJoint = d.JointCreateFixed(_parent_scene.world, _linkJointGroup);
  848. d.JointAttach(m_linkJoint, obj.Body, Body);
  849. d.JointSetFixed(m_linkJoint);
  850. }
  851. */
  852. }
  853. }
  854. // If the newly set parent is null
  855. // destroy link
  856. else if (_parent != null && m_taintparent == null)
  857. {
  858. //Console.WriteLine(" changelink B");
  859. if (_parent is OdePrim)
  860. {
  861. OdePrim obj = (OdePrim)_parent;
  862. obj.ChildDelink(this);
  863. childPrim = false;
  864. //_parent = null;
  865. }
  866. /*
  867. if (Body != (IntPtr)0 && _linkJointGroup != (IntPtr)0)
  868. d.JointGroupDestroy(_linkJointGroup);
  869. _linkJointGroup = (IntPtr)0;
  870. m_linkJoint = (IntPtr)0;
  871. */
  872. }
  873. _parent = m_taintparent;
  874. m_taintPhysics = IsPhysical;
  875. }
  876. /// <summary>
  877. /// Add a child prim to this parent prim.
  878. /// </summary>
  879. /// <param name="prim">Child prim</param>
  880. private void AddChildPrim(OdePrim prim)
  881. {
  882. //Console.WriteLine("AddChildPrim " + Name);
  883. if (this.m_localID != prim.m_localID)
  884. {
  885. if (Body == IntPtr.Zero)
  886. {
  887. Body = d.BodyCreate(_parent_scene.world);
  888. setMass();
  889. }
  890. if (Body != IntPtr.Zero)
  891. {
  892. lock (childrenPrim)
  893. {
  894. if (!childrenPrim.Contains(prim))
  895. {
  896. //Console.WriteLine("childrenPrim.Add " + prim);
  897. childrenPrim.Add(prim);
  898. foreach (OdePrim prm in childrenPrim)
  899. {
  900. d.Mass m2;
  901. d.MassSetZero(out m2);
  902. d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
  903. d.Quaternion quat = new d.Quaternion();
  904. quat.W = prm._orientation.W;
  905. quat.X = prm._orientation.X;
  906. quat.Y = prm._orientation.Y;
  907. quat.Z = prm._orientation.Z;
  908. d.Matrix3 mat = new d.Matrix3();
  909. d.RfromQ(out mat, ref quat);
  910. d.MassRotate(ref m2, ref mat);
  911. d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
  912. d.MassAdd(ref pMass, ref m2);
  913. }
  914. foreach (OdePrim prm in childrenPrim)
  915. {
  916. prm.m_collisionCategories |= CollisionCategories.Body;
  917. prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
  918. if (prm.prim_geom == IntPtr.Zero)
  919. {
  920. m_log.WarnFormat(
  921. "[PHYSICS]: Unable to link one of the linkset elements {0} for parent {1}. No geom yet",
  922. prm.Name, prim.Name);
  923. continue;
  924. }
  925. //Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name);
  926. d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
  927. d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
  928. d.Quaternion quat = new d.Quaternion();
  929. quat.W = prm._orientation.W;
  930. quat.X = prm._orientation.X;
  931. quat.Y = prm._orientation.Y;
  932. quat.Z = prm._orientation.Z;
  933. d.Matrix3 mat = new d.Matrix3();
  934. d.RfromQ(out mat, ref quat);
  935. if (Body != IntPtr.Zero)
  936. {
  937. d.GeomSetBody(prm.prim_geom, Body);
  938. prm.childPrim = true;
  939. d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
  940. //d.GeomSetOffsetPosition(prim.prim_geom,
  941. // (Position.X - prm.Position.X) - pMass.c.X,
  942. // (Position.Y - prm.Position.Y) - pMass.c.Y,
  943. // (Position.Z - prm.Position.Z) - pMass.c.Z);
  944. d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
  945. //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
  946. d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
  947. d.BodySetMass(Body, ref pMass);
  948. }
  949. else
  950. {
  951. m_log.DebugFormat("[PHYSICS]: {0} ain't got no boooooooooddy, no body", Name);
  952. }
  953. prm.m_interpenetrationcount = 0;
  954. prm.m_collisionscore = 0;
  955. prm.m_disabled = false;
  956. // The body doesn't already have a finite rotation mode set here
  957. if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
  958. {
  959. prm.createAMotor(m_angularlock);
  960. }
  961. prm.Body = Body;
  962. _parent_scene.ActivatePrim(prm);
  963. }
  964. m_collisionCategories |= CollisionCategories.Body;
  965. m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
  966. //Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name);
  967. d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
  968. //Console.WriteLine(" Post GeomSetCategoryBits 2");
  969. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  970. d.Quaternion quat2 = new d.Quaternion();
  971. quat2.W = _orientation.W;
  972. quat2.X = _orientation.X;
  973. quat2.Y = _orientation.Y;
  974. quat2.Z = _orientation.Z;
  975. d.Matrix3 mat2 = new d.Matrix3();
  976. d.RfromQ(out mat2, ref quat2);
  977. d.GeomSetBody(prim_geom, Body);
  978. d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
  979. //d.GeomSetOffsetPosition(prim.prim_geom,
  980. // (Position.X - prm.Position.X) - pMass.c.X,
  981. // (Position.Y - prm.Position.Y) - pMass.c.Y,
  982. // (Position.Z - prm.Position.Z) - pMass.c.Z);
  983. //d.GeomSetOffsetRotation(prim_geom, ref mat2);
  984. d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
  985. d.BodySetMass(Body, ref pMass);
  986. d.BodySetAutoDisableFlag(Body, true);
  987. d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
  988. m_interpenetrationcount = 0;
  989. m_collisionscore = 0;
  990. m_disabled = false;
  991. // The body doesn't already have a finite rotation mode set here
  992. if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
  993. {
  994. createAMotor(m_angularlock);
  995. }
  996. d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
  997. if (m_vehicle.Type != Vehicle.TYPE_NONE)
  998. m_vehicle.Enable(Body, _parent_scene);
  999. _parent_scene.ActivatePrim(this);
  1000. }
  1001. }
  1002. }
  1003. }
  1004. }
  1005. private void ChildSetGeom(OdePrim odePrim)
  1006. {
  1007. //if (IsPhysical && Body != IntPtr.Zero)
  1008. lock (childrenPrim)
  1009. {
  1010. foreach (OdePrim prm in childrenPrim)
  1011. {
  1012. //prm.childPrim = true;
  1013. prm.disableBody();
  1014. //prm.m_taintparent = null;
  1015. //prm._parent = null;
  1016. //prm.m_taintPhysics = false;
  1017. //prm.m_disabled = true;
  1018. //prm.childPrim = false;
  1019. }
  1020. }
  1021. disableBody();
  1022. if (Body != IntPtr.Zero)
  1023. {
  1024. _parent_scene.DeactivatePrim(this);
  1025. }
  1026. lock (childrenPrim)
  1027. {
  1028. foreach (OdePrim prm in childrenPrim)
  1029. {
  1030. //Console.WriteLine("ChildSetGeom calls ParentPrim");
  1031. AddChildPrim(prm);
  1032. }
  1033. }
  1034. }
  1035. private void ChildDelink(OdePrim odePrim)
  1036. {
  1037. // Okay, we have a delinked child.. need to rebuild the body.
  1038. lock (childrenPrim)
  1039. {
  1040. foreach (OdePrim prm in childrenPrim)
  1041. {
  1042. prm.childPrim = true;
  1043. prm.disableBody();
  1044. //prm.m_taintparent = null;
  1045. //prm._parent = null;
  1046. //prm.m_taintPhysics = false;
  1047. //prm.m_disabled = true;
  1048. //prm.childPrim = false;
  1049. }
  1050. }
  1051. disableBody();
  1052. lock (childrenPrim)
  1053. {
  1054. //Console.WriteLine("childrenPrim.Remove " + odePrim);
  1055. childrenPrim.Remove(odePrim);
  1056. }
  1057. if (Body != IntPtr.Zero)
  1058. {
  1059. _parent_scene.DeactivatePrim(this);
  1060. }
  1061. lock (childrenPrim)
  1062. {
  1063. foreach (OdePrim prm in childrenPrim)
  1064. {
  1065. //Console.WriteLine("ChildDelink calls ParentPrim");
  1066. AddChildPrim(prm);
  1067. }
  1068. }
  1069. }
  1070. /// <summary>
  1071. /// Change prim in response to a selection taint.
  1072. /// </summary>
  1073. private void changeSelectedStatus()
  1074. {
  1075. if (m_taintselected)
  1076. {
  1077. m_collisionCategories = CollisionCategories.Selected;
  1078. m_collisionFlags = (CollisionCategories.Sensor | CollisionCategories.Space);
  1079. // We do the body disable soft twice because 'in theory' a collision could have happened
  1080. // in between the disabling and the collision properties setting
  1081. // which would wake the physical body up from a soft disabling and potentially cause it to fall
  1082. // through the ground.
  1083. // NOTE FOR JOINTS: this doesn't always work for jointed assemblies because if you select
  1084. // just one part of the assembly, the rest of the assembly is non-selected and still simulating,
  1085. // so that causes the selected part to wake up and continue moving.
  1086. // even if you select all parts of a jointed assembly, it is not guaranteed that the entire
  1087. // assembly will stop simulating during the selection, because of the lack of atomicity
  1088. // of select operations (their processing could be interrupted by a thread switch, causing
  1089. // simulation to continue before all of the selected object notifications trickle down to
  1090. // the physics engine).
  1091. // e.g. we select 100 prims that are connected by joints. non-atomically, the first 50 are
  1092. // selected and disabled. then, due to a thread switch, the selection processing is
  1093. // interrupted and the physics engine continues to simulate, so the last 50 items, whose
  1094. // selection was not yet processed, continues to simulate. this wakes up ALL of the
  1095. // first 50 again. then the last 50 are disabled. then the first 50, which were just woken
  1096. // up, start simulating again, which in turn wakes up the last 50.
  1097. if (IsPhysical)
  1098. {
  1099. disableBodySoft();
  1100. }
  1101. if (prim_geom != IntPtr.Zero)
  1102. {
  1103. d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
  1104. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  1105. }
  1106. if (IsPhysical)
  1107. {
  1108. disableBodySoft();
  1109. }
  1110. }
  1111. else
  1112. {
  1113. m_collisionCategories = CollisionCategories.Geom;
  1114. if (IsPhysical)
  1115. m_collisionCategories |= CollisionCategories.Body;
  1116. m_collisionFlags = m_default_collisionFlags;
  1117. if (m_collidesLand)
  1118. m_collisionFlags |= CollisionCategories.Land;
  1119. if (m_collidesWater)
  1120. m_collisionFlags |= CollisionCategories.Water;
  1121. if (prim_geom != IntPtr.Zero)
  1122. {
  1123. d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
  1124. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  1125. }
  1126. if (IsPhysical)
  1127. {
  1128. if (Body != IntPtr.Zero)
  1129. {
  1130. d.BodySetLinearVel(Body, 0f, 0f, 0f);
  1131. d.BodySetForce(Body, 0, 0, 0);
  1132. enableBodySoft();
  1133. }
  1134. }
  1135. }
  1136. resetCollisionAccounting();
  1137. m_isSelected = m_taintselected;
  1138. }//end changeSelectedStatus
  1139. internal void ResetTaints()
  1140. {
  1141. m_taintposition = _position;
  1142. m_taintrot = _orientation;
  1143. m_taintPhysics = IsPhysical;
  1144. m_taintselected = m_isSelected;
  1145. m_taintsize = _size;
  1146. m_taintshape = false;
  1147. m_taintforce = false;
  1148. m_taintdisable = false;
  1149. m_taintVelocity = Vector3.Zero;
  1150. }
  1151. /// <summary>
  1152. /// Create a geometry for the given mesh in the given target space.
  1153. /// </summary>
  1154. /// <param name="m_targetSpace"></param>
  1155. /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
  1156. private void CreateGeom(IntPtr m_targetSpace, IMesh mesh)
  1157. {
  1158. #if SPAM
  1159. Console.WriteLine("CreateGeom:");
  1160. #endif
  1161. if (mesh != null)
  1162. {
  1163. setMesh(_parent_scene, mesh);
  1164. }
  1165. else
  1166. {
  1167. if (_pbs.ProfileShape == ProfileShape.HalfCircle && _pbs.PathCurve == (byte)Extrusion.Curve1)
  1168. {
  1169. if (_size.X == _size.Y && _size.Y == _size.Z && _size.X == _size.Z)
  1170. {
  1171. if (((_size.X / 2f) > 0f))
  1172. {
  1173. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1174. try
  1175. {
  1176. //Console.WriteLine(" CreateGeom 1");
  1177. SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
  1178. }
  1179. catch (AccessViolationException)
  1180. {
  1181. m_log.WarnFormat("[PHYSICS]: Unable to create physics proxy for object {0}", Name);
  1182. return;
  1183. }
  1184. }
  1185. else
  1186. {
  1187. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1188. try
  1189. {
  1190. //Console.WriteLine(" CreateGeom 2");
  1191. SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
  1192. }
  1193. catch (AccessViolationException)
  1194. {
  1195. m_log.WarnFormat("[PHYSICS]: Unable to create physics proxy for object {0}", Name);
  1196. return;
  1197. }
  1198. }
  1199. }
  1200. else
  1201. {
  1202. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1203. try
  1204. {
  1205. //Console.WriteLine(" CreateGeom 3");
  1206. SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
  1207. }
  1208. catch (AccessViolationException)
  1209. {
  1210. m_log.WarnFormat("[PHYSICS]: Unable to create physics proxy for object {0}", Name);
  1211. return;
  1212. }
  1213. }
  1214. }
  1215. else
  1216. {
  1217. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1218. try
  1219. {
  1220. //Console.WriteLine(" CreateGeom 4");
  1221. SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
  1222. }
  1223. catch (AccessViolationException)
  1224. {
  1225. m_log.WarnFormat("[PHYSICS]: Unable to create physics proxy for object {0}", Name);
  1226. return;
  1227. }
  1228. }
  1229. }
  1230. }
  1231. /// <summary>
  1232. /// Remove the existing geom from this prim.
  1233. /// </summary>
  1234. /// <param name="m_targetSpace"></param>
  1235. /// <param name="mesh">If null, then a mesh is used that is based on the profile shape data.</param>
  1236. /// <returns>true if the geom was successfully removed, false if it was already gone or the remove failed.</returns>
  1237. internal bool RemoveGeom()
  1238. {
  1239. if (prim_geom != IntPtr.Zero)
  1240. {
  1241. try
  1242. {
  1243. _parent_scene.geom_name_map.Remove(prim_geom);
  1244. _parent_scene.actor_name_map.Remove(prim_geom);
  1245. d.GeomDestroy(prim_geom);
  1246. prim_geom = IntPtr.Zero;
  1247. }
  1248. catch (System.AccessViolationException)
  1249. {
  1250. prim_geom = IntPtr.Zero;
  1251. m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
  1252. return false;
  1253. }
  1254. return true;
  1255. }
  1256. else
  1257. {
  1258. return false;
  1259. }
  1260. }
  1261. /// <summary>
  1262. /// Add prim in response to an add taint.
  1263. /// </summary>
  1264. private void changeadd()
  1265. {
  1266. int[] iprimspaceArrItem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
  1267. IntPtr targetspace = _parent_scene.calculateSpaceForGeom(_position);
  1268. if (targetspace == IntPtr.Zero)
  1269. targetspace = _parent_scene.createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
  1270. m_targetSpace = targetspace;
  1271. IMesh mesh = null;
  1272. if (_parent_scene.needsMeshing(_pbs))
  1273. {
  1274. // Don't need to re-enable body.. it's done in SetMesh
  1275. mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
  1276. // createmesh returns null when it's a shape that isn't a cube.
  1277. // m_log.Debug(m_localID);
  1278. }
  1279. #if SPAM
  1280. Console.WriteLine("changeadd 1");
  1281. #endif
  1282. CreateGeom(m_targetSpace, mesh);
  1283. if (prim_geom != IntPtr.Zero)
  1284. {
  1285. d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
  1286. d.Quaternion myrot = new d.Quaternion();
  1287. myrot.X = _orientation.X;
  1288. myrot.Y = _orientation.Y;
  1289. myrot.Z = _orientation.Z;
  1290. myrot.W = _orientation.W;
  1291. d.GeomSetQuaternion(prim_geom, ref myrot);
  1292. }
  1293. if (IsPhysical && Body == IntPtr.Zero)
  1294. enableBody();
  1295. changeSelectedStatus();
  1296. m_taintadd = false;
  1297. }
  1298. /// <summary>
  1299. /// Move prim in response to a move taint.
  1300. /// </summary>
  1301. private void changemove()
  1302. {
  1303. if (IsPhysical)
  1304. {
  1305. if (!m_disabled && !m_taintremove && !childPrim)
  1306. {
  1307. if (Body == IntPtr.Zero)
  1308. enableBody();
  1309. //Prim auto disable after 20 frames,
  1310. //if you move it, re-enable the prim manually.
  1311. if (_parent != null)
  1312. {
  1313. if (m_linkJoint != IntPtr.Zero)
  1314. {
  1315. d.JointDestroy(m_linkJoint);
  1316. m_linkJoint = IntPtr.Zero;
  1317. }
  1318. }
  1319. if (Body != IntPtr.Zero)
  1320. {
  1321. d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
  1322. if (_parent != null)
  1323. {
  1324. OdePrim odParent = (OdePrim)_parent;
  1325. if (Body != (IntPtr)0 && odParent.Body != (IntPtr)0 && Body != odParent.Body)
  1326. {
  1327. // KF: Fixed Joints were removed? Anyway - this Console.WriteLine does not show up, so routine is not used??
  1328. Console.WriteLine(" JointCreateFixed");
  1329. m_linkJoint = d.JointCreateFixed(_parent_scene.world, _linkJointGroup);
  1330. d.JointAttach(m_linkJoint, Body, odParent.Body);
  1331. d.JointSetFixed(m_linkJoint);
  1332. }
  1333. }
  1334. d.BodyEnable(Body);
  1335. if (m_vehicle.Type != Vehicle.TYPE_NONE)
  1336. {
  1337. m_vehicle.Enable(Body, _parent_scene);
  1338. }
  1339. }
  1340. else
  1341. {
  1342. m_log.WarnFormat("[PHYSICS]: Body for {0} still null after enableBody(). This is a crash scenario.", Name);
  1343. }
  1344. }
  1345. //else
  1346. // {
  1347. //m_log.Debug("[BUG]: race!");
  1348. //}
  1349. }
  1350. else
  1351. {
  1352. // string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
  1353. // int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
  1354. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1355. IntPtr tempspace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
  1356. m_targetSpace = tempspace;
  1357. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1358. if (prim_geom != IntPtr.Zero)
  1359. {
  1360. d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
  1361. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1362. d.SpaceAdd(m_targetSpace, prim_geom);
  1363. }
  1364. }
  1365. changeSelectedStatus();
  1366. resetCollisionAccounting();
  1367. m_taintposition = _position;
  1368. }
  1369. internal void Move(float timestep)
  1370. {
  1371. float fx = 0;
  1372. float fy = 0;
  1373. float fz = 0;
  1374. if (IsPhysical && (Body != IntPtr.Zero) && !m_isSelected && !childPrim) // KF: Only move root prims.
  1375. {
  1376. if (m_vehicle.Type != Vehicle.TYPE_NONE)
  1377. {
  1378. // 'VEHICLES' are dealt with in ODEDynamics.cs
  1379. m_vehicle.Step(timestep, _parent_scene);
  1380. }
  1381. else
  1382. {
  1383. //Console.WriteLine("Move " + Name);
  1384. if (!d.BodyIsEnabled (Body)) d.BodyEnable (Body); // KF add 161009
  1385. // NON-'VEHICLES' are dealt with here
  1386. // if (d.BodyIsEnabled(Body) && !m_angularlock.ApproxEquals(Vector3.Zero, 0.003f))
  1387. // {
  1388. // d.Vector3 avel2 = d.BodyGetAngularVel(Body);
  1389. // /*
  1390. // if (m_angularlock.X == 1)
  1391. // avel2.X = 0;
  1392. // if (m_angularlock.Y == 1)
  1393. // avel2.Y = 0;
  1394. // if (m_angularlock.Z == 1)
  1395. // avel2.Z = 0;
  1396. // d.BodySetAngularVel(Body, avel2.X, avel2.Y, avel2.Z);
  1397. // */
  1398. // }
  1399. //float PID_P = 900.0f;
  1400. float m_mass = CalculateMass();
  1401. // fz = 0f;
  1402. //m_log.Info(m_collisionFlags.ToString());
  1403. //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
  1404. // would come from SceneObjectPart.cs, public void SetBuoyancy(float fvalue) , PhysActor.Buoyancy = fvalue; ??
  1405. // m_buoyancy: (unlimited value) <0=Falls fast; 0=1g; 1=0g; >1 = floats up
  1406. // gravityz multiplier = 1 - m_buoyancy
  1407. fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass;
  1408. if (m_usePID)
  1409. {
  1410. //Console.WriteLine("PID " + Name);
  1411. // KF - this is for object move? eg. llSetPos() ?
  1412. //if (!d.BodyIsEnabled(Body))
  1413. //d.BodySetForce(Body, 0f, 0f, 0f);
  1414. // If we're using the PID controller, then we have no gravity
  1415. //fz = (-1 * _parent_scene.gravityz) * m_mass; //KF: ?? Prims have no global gravity,so simply...
  1416. fz = 0f;
  1417. // no lock; for now it's only called from within Simulate()
  1418. // If the PID Controller isn't active then we set our force
  1419. // calculating base velocity to the current position
  1420. if ((m_PIDTau < 1) && (m_PIDTau != 0))
  1421. {
  1422. //PID_G = PID_G / m_PIDTau;
  1423. m_PIDTau = 1;
  1424. }
  1425. if ((PID_G - m_PIDTau) <= 0)
  1426. {
  1427. PID_G = m_PIDTau + 1;
  1428. }
  1429. //PidStatus = true;
  1430. // PhysicsVector vec = new PhysicsVector();
  1431. d.Vector3 vel = d.BodyGetLinearVel(Body);
  1432. d.Vector3 pos = d.BodyGetPosition(Body);
  1433. _target_velocity =
  1434. new Vector3(
  1435. (m_PIDTarget.X - pos.X) * ((PID_G - m_PIDTau) * timestep),
  1436. (m_PIDTarget.Y - pos.Y) * ((PID_G - m_PIDTau) * timestep),
  1437. (m_PIDTarget.Z - pos.Z) * ((PID_G - m_PIDTau) * timestep)
  1438. );
  1439. // if velocity is zero, use position control; otherwise, velocity control
  1440. if (_target_velocity.ApproxEquals(Vector3.Zero,0.1f))
  1441. {
  1442. // keep track of where we stopped. No more slippin' & slidin'
  1443. // We only want to deactivate the PID Controller if we think we want to have our surrogate
  1444. // react to the physics scene by moving it's position.
  1445. // Avatar to Avatar collisions
  1446. // Prim to avatar collisions
  1447. //fx = (_target_velocity.X - vel.X) * (PID_D) + (_zeroPosition.X - pos.X) * (PID_P * 2);
  1448. //fy = (_target_velocity.Y - vel.Y) * (PID_D) + (_zeroPosition.Y - pos.Y) * (PID_P * 2);
  1449. //fz = fz + (_target_velocity.Z - vel.Z) * (PID_D) + (_zeroPosition.Z - pos.Z) * PID_P;
  1450. d.BodySetPosition(Body, m_PIDTarget.X, m_PIDTarget.Y, m_PIDTarget.Z);
  1451. d.BodySetLinearVel(Body, 0, 0, 0);
  1452. d.BodyAddForce(Body, 0, 0, fz);
  1453. return;
  1454. }
  1455. else
  1456. {
  1457. _zeroFlag = false;
  1458. // We're flying and colliding with something
  1459. fx = ((_target_velocity.X) - vel.X) * (PID_D);
  1460. fy = ((_target_velocity.Y) - vel.Y) * (PID_D);
  1461. // vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P;
  1462. fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass);
  1463. }
  1464. } // end if (m_usePID)
  1465. // Hover PID Controller needs to be mutually exlusive to MoveTo PID controller
  1466. if (m_useHoverPID && !m_usePID)
  1467. {
  1468. //Console.WriteLine("Hover " + Name);
  1469. // If we're using the PID controller, then we have no gravity
  1470. fz = (-1 * _parent_scene.gravityz) * m_mass;
  1471. // no lock; for now it's only called from within Simulate()
  1472. // If the PID Controller isn't active then we set our force
  1473. // calculating base velocity to the current position
  1474. if ((m_PIDTau < 1))
  1475. {
  1476. PID_G = PID_G / m_PIDTau;
  1477. }
  1478. if ((PID_G - m_PIDTau) <= 0)
  1479. {
  1480. PID_G = m_PIDTau + 1;
  1481. }
  1482. // Where are we, and where are we headed?
  1483. d.Vector3 pos = d.BodyGetPosition(Body);
  1484. d.Vector3 vel = d.BodyGetLinearVel(Body);
  1485. // Non-Vehicles have a limited set of Hover options.
  1486. // determine what our target height really is based on HoverType
  1487. switch (m_PIDHoverType)
  1488. {
  1489. case PIDHoverType.Ground:
  1490. m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
  1491. m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
  1492. break;
  1493. case PIDHoverType.GroundAndWater:
  1494. m_groundHeight = _parent_scene.GetTerrainHeightAtXY(pos.X, pos.Y);
  1495. m_waterHeight = _parent_scene.GetWaterLevel();
  1496. if (m_groundHeight > m_waterHeight)
  1497. {
  1498. m_targetHoverHeight = m_groundHeight + m_PIDHoverHeight;
  1499. }
  1500. else
  1501. {
  1502. m_targetHoverHeight = m_waterHeight + m_PIDHoverHeight;
  1503. }
  1504. break;
  1505. } // end switch (m_PIDHoverType)
  1506. _target_velocity =
  1507. new Vector3(0.0f, 0.0f,
  1508. (m_targetHoverHeight - pos.Z) * ((PID_G - m_PIDHoverTau) * timestep)
  1509. );
  1510. // if velocity is zero, use position control; otherwise, velocity control
  1511. if (_target_velocity.ApproxEquals(Vector3.Zero, 0.1f))
  1512. {
  1513. // keep track of where we stopped. No more slippin' & slidin'
  1514. // We only want to deactivate the PID Controller if we think we want to have our surrogate
  1515. // react to the physics scene by moving it's position.
  1516. // Avatar to Avatar collisions
  1517. // Prim to avatar collisions
  1518. d.BodySetPosition(Body, pos.X, pos.Y, m_targetHoverHeight);
  1519. d.BodySetLinearVel(Body, vel.X, vel.Y, 0);
  1520. d.BodyAddForce(Body, 0, 0, fz);
  1521. return;
  1522. }
  1523. else
  1524. {
  1525. _zeroFlag = false;
  1526. // We're flying and colliding with something
  1527. fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass);
  1528. }
  1529. }
  1530. fx *= m_mass;
  1531. fy *= m_mass;
  1532. //fz *= m_mass;
  1533. fx += m_force.X;
  1534. fy += m_force.Y;
  1535. fz += m_force.Z;
  1536. //m_log.Info("[OBJPID]: X:" + fx.ToString() + " Y:" + fy.ToString() + " Z:" + fz.ToString());
  1537. if (fx != 0 || fy != 0 || fz != 0)
  1538. {
  1539. //m_taintdisable = true;
  1540. //base.RaiseOutOfBounds(Position);
  1541. //d.BodySetLinearVel(Body, fx, fy, 0f);
  1542. if (!d.BodyIsEnabled(Body))
  1543. {
  1544. // A physical body at rest on a surface will auto-disable after a while,
  1545. // this appears to re-enable it incase the surface it is upon vanishes,
  1546. // and the body should fall again.
  1547. d.BodySetLinearVel(Body, 0f, 0f, 0f);
  1548. d.BodySetForce(Body, 0, 0, 0);
  1549. enableBodySoft();
  1550. }
  1551. // 35x10 = 350n times the mass per second applied maximum.
  1552. float nmax = 35f * m_mass;
  1553. float nmin = -35f * m_mass;
  1554. if (fx > nmax)
  1555. fx = nmax;
  1556. if (fx < nmin)
  1557. fx = nmin;
  1558. if (fy > nmax)
  1559. fy = nmax;
  1560. if (fy < nmin)
  1561. fy = nmin;
  1562. d.BodyAddForce(Body, fx, fy, fz);
  1563. //Console.WriteLine("AddForce " + fx + "," + fy + "," + fz);
  1564. }
  1565. }
  1566. }
  1567. else
  1568. { // is not physical, or is not a body or is selected
  1569. // _zeroPosition = d.BodyGetPosition(Body);
  1570. return;
  1571. //Console.WriteLine("Nothing " + Name);
  1572. }
  1573. }
  1574. private void rotate()
  1575. {
  1576. d.Quaternion myrot = new d.Quaternion();
  1577. myrot.X = _orientation.X;
  1578. myrot.Y = _orientation.Y;
  1579. myrot.Z = _orientation.Z;
  1580. myrot.W = _orientation.W;
  1581. if (Body != IntPtr.Zero)
  1582. {
  1583. // KF: If this is a root prim do BodySet
  1584. d.BodySetQuaternion(Body, ref myrot);
  1585. if (IsPhysical)
  1586. {
  1587. if (!m_angularlock.ApproxEquals(Vector3.One, 0f))
  1588. createAMotor(m_angularlock);
  1589. }
  1590. }
  1591. else
  1592. {
  1593. // daughter prim, do Geom set
  1594. d.GeomSetQuaternion(prim_geom, ref myrot);
  1595. }
  1596. resetCollisionAccounting();
  1597. m_taintrot = _orientation;
  1598. }
  1599. private void resetCollisionAccounting()
  1600. {
  1601. m_collisionscore = 0;
  1602. m_interpenetrationcount = 0;
  1603. m_disabled = false;
  1604. }
  1605. /// <summary>
  1606. /// Change prim in response to a disable taint.
  1607. /// </summary>
  1608. private void changedisable()
  1609. {
  1610. m_disabled = true;
  1611. if (Body != IntPtr.Zero)
  1612. {
  1613. d.BodyDisable(Body);
  1614. Body = IntPtr.Zero;
  1615. }
  1616. m_taintdisable = false;
  1617. }
  1618. /// <summary>
  1619. /// Change prim in response to a physics status taint
  1620. /// </summary>
  1621. private void changePhysicsStatus()
  1622. {
  1623. if (IsPhysical)
  1624. {
  1625. if (Body == IntPtr.Zero)
  1626. {
  1627. if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
  1628. {
  1629. changeshape();
  1630. }
  1631. else
  1632. {
  1633. enableBody();
  1634. }
  1635. }
  1636. }
  1637. else
  1638. {
  1639. if (Body != IntPtr.Zero)
  1640. {
  1641. if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
  1642. {
  1643. RemoveGeom();
  1644. //Console.WriteLine("changePhysicsStatus for " + Name);
  1645. changeadd();
  1646. }
  1647. if (childPrim)
  1648. {
  1649. if (_parent != null)
  1650. {
  1651. OdePrim parent = (OdePrim)_parent;
  1652. parent.ChildDelink(this);
  1653. }
  1654. }
  1655. else
  1656. {
  1657. disableBody();
  1658. }
  1659. }
  1660. }
  1661. changeSelectedStatus();
  1662. resetCollisionAccounting();
  1663. m_taintPhysics = IsPhysical;
  1664. }
  1665. /// <summary>
  1666. /// Change prim in response to a size taint.
  1667. /// </summary>
  1668. private void changesize()
  1669. {
  1670. #if SPAM
  1671. m_log.DebugFormat("[ODE PRIM]: Called changesize");
  1672. #endif
  1673. if (_size.X <= 0) _size.X = 0.01f;
  1674. if (_size.Y <= 0) _size.Y = 0.01f;
  1675. if (_size.Z <= 0) _size.Z = 0.01f;
  1676. //kill body to rebuild
  1677. if (IsPhysical && Body != IntPtr.Zero)
  1678. {
  1679. if (childPrim)
  1680. {
  1681. if (_parent != null)
  1682. {
  1683. OdePrim parent = (OdePrim)_parent;
  1684. parent.ChildDelink(this);
  1685. }
  1686. }
  1687. else
  1688. {
  1689. disableBody();
  1690. }
  1691. }
  1692. if (d.SpaceQuery(m_targetSpace, prim_geom))
  1693. {
  1694. // _parent_scene.waitForSpaceUnlock(m_targetSpace);
  1695. d.SpaceRemove(m_targetSpace, prim_geom);
  1696. }
  1697. RemoveGeom();
  1698. // we don't need to do space calculation because the client sends a position update also.
  1699. IMesh mesh = null;
  1700. // Construction of new prim
  1701. if (_parent_scene.needsMeshing(_pbs))
  1702. {
  1703. float meshlod = _parent_scene.meshSculptLOD;
  1704. if (IsPhysical)
  1705. meshlod = _parent_scene.MeshSculptphysicalLOD;
  1706. // Don't need to re-enable body.. it's done in SetMesh
  1707. if (_parent_scene.needsMeshing(_pbs))
  1708. mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical);
  1709. }
  1710. CreateGeom(m_targetSpace, mesh);
  1711. d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
  1712. d.Quaternion myrot = new d.Quaternion();
  1713. myrot.X = _orientation.X;
  1714. myrot.Y = _orientation.Y;
  1715. myrot.Z = _orientation.Z;
  1716. myrot.W = _orientation.W;
  1717. d.GeomSetQuaternion(prim_geom, ref myrot);
  1718. //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
  1719. if (IsPhysical && Body == IntPtr.Zero && !childPrim)
  1720. {
  1721. // Re creates body on size.
  1722. // EnableBody also does setMass()
  1723. enableBody();
  1724. d.BodyEnable(Body);
  1725. }
  1726. changeSelectedStatus();
  1727. if (childPrim)
  1728. {
  1729. if (_parent is OdePrim)
  1730. {
  1731. OdePrim parent = (OdePrim)_parent;
  1732. parent.ChildSetGeom(this);
  1733. }
  1734. }
  1735. resetCollisionAccounting();
  1736. m_taintsize = _size;
  1737. }
  1738. /// <summary>
  1739. /// Change prim in response to a float on water taint.
  1740. /// </summary>
  1741. /// <param name="timestep"></param>
  1742. private void changefloatonwater()
  1743. {
  1744. m_collidesWater = m_taintCollidesWater;
  1745. if (prim_geom != IntPtr.Zero)
  1746. {
  1747. if (m_collidesWater)
  1748. {
  1749. m_collisionFlags |= CollisionCategories.Water;
  1750. }
  1751. else
  1752. {
  1753. m_collisionFlags &= ~CollisionCategories.Water;
  1754. }
  1755. d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
  1756. }
  1757. }
  1758. /// <summary>
  1759. /// Change prim in response to a shape taint.
  1760. /// </summary>
  1761. private void changeshape()
  1762. {
  1763. // Cleanup of old prim geometry and Bodies
  1764. if (IsPhysical && Body != IntPtr.Zero)
  1765. {
  1766. if (childPrim)
  1767. {
  1768. if (_parent != null)
  1769. {
  1770. OdePrim parent = (OdePrim)_parent;
  1771. parent.ChildDelink(this);
  1772. }
  1773. }
  1774. else
  1775. {
  1776. disableBody();
  1777. }
  1778. }
  1779. RemoveGeom();
  1780. // we don't need to do space calculation because the client sends a position update also.
  1781. if (_size.X <= 0) _size.X = 0.01f;
  1782. if (_size.Y <= 0) _size.Y = 0.01f;
  1783. if (_size.Z <= 0) _size.Z = 0.01f;
  1784. // Construction of new prim
  1785. IMesh mesh = null;
  1786. if (_parent_scene.needsMeshing(_pbs))
  1787. {
  1788. // Don't need to re-enable body.. it's done in CreateMesh
  1789. float meshlod = _parent_scene.meshSculptLOD;
  1790. if (IsPhysical)
  1791. meshlod = _parent_scene.MeshSculptphysicalLOD;
  1792. // createmesh returns null when it doesn't mesh.
  1793. mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical);
  1794. }
  1795. CreateGeom(m_targetSpace, mesh);
  1796. d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
  1797. d.Quaternion myrot = new d.Quaternion();
  1798. //myrot.W = _orientation.w;
  1799. myrot.W = _orientation.W;
  1800. myrot.X = _orientation.X;
  1801. myrot.Y = _orientation.Y;
  1802. myrot.Z = _orientation.Z;
  1803. d.GeomSetQuaternion(prim_geom, ref myrot);
  1804. //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
  1805. if (IsPhysical && Body == IntPtr.Zero)
  1806. {
  1807. // Re creates body on size.
  1808. // EnableBody also does setMass()
  1809. enableBody();
  1810. if (Body != IntPtr.Zero)
  1811. {
  1812. d.BodyEnable(Body);
  1813. }
  1814. }
  1815. changeSelectedStatus();
  1816. if (childPrim)
  1817. {
  1818. if (_parent is OdePrim)
  1819. {
  1820. OdePrim parent = (OdePrim)_parent;
  1821. parent.ChildSetGeom(this);
  1822. }
  1823. }
  1824. resetCollisionAccounting();
  1825. m_taintshape = false;
  1826. }
  1827. /// <summary>
  1828. /// Change prim in response to an add force taint.
  1829. /// </summary>
  1830. private void changeAddForce()
  1831. {
  1832. if (!m_isSelected)
  1833. {
  1834. lock (m_forcelist)
  1835. {
  1836. //m_log.Info("[PHYSICS]: dequeing forcelist");
  1837. if (IsPhysical)
  1838. {
  1839. Vector3 iforce = Vector3.Zero;
  1840. int i = 0;
  1841. try
  1842. {
  1843. for (i = 0; i < m_forcelist.Count; i++)
  1844. {
  1845. iforce = iforce + (m_forcelist[i] * 100);
  1846. }
  1847. }
  1848. catch (IndexOutOfRangeException)
  1849. {
  1850. m_forcelist = new List<Vector3>();
  1851. m_collisionscore = 0;
  1852. m_interpenetrationcount = 0;
  1853. m_taintforce = false;
  1854. return;
  1855. }
  1856. catch (ArgumentOutOfRangeException)
  1857. {
  1858. m_forcelist = new List<Vector3>();
  1859. m_collisionscore = 0;
  1860. m_interpenetrationcount = 0;
  1861. m_taintforce = false;
  1862. return;
  1863. }
  1864. d.BodyEnable(Body);
  1865. d.BodyAddForce(Body, iforce.X, iforce.Y, iforce.Z);
  1866. }
  1867. m_forcelist.Clear();
  1868. }
  1869. m_collisionscore = 0;
  1870. m_interpenetrationcount = 0;
  1871. }
  1872. m_taintforce = false;
  1873. }
  1874. /// <summary>
  1875. /// Change prim in response to a torque taint.
  1876. /// </summary>
  1877. private void changeSetTorque()
  1878. {
  1879. if (!m_isSelected)
  1880. {
  1881. if (IsPhysical && Body != IntPtr.Zero)
  1882. {
  1883. d.BodySetTorque(Body, m_taintTorque.X, m_taintTorque.Y, m_taintTorque.Z);
  1884. }
  1885. }
  1886. m_taintTorque = Vector3.Zero;
  1887. }
  1888. /// <summary>
  1889. /// Change prim in response to an angular force taint.
  1890. /// </summary>
  1891. private void changeAddAngularForce()
  1892. {
  1893. if (!m_isSelected)
  1894. {
  1895. lock (m_angularforcelist)
  1896. {
  1897. //m_log.Info("[PHYSICS]: dequeing forcelist");
  1898. if (IsPhysical)
  1899. {
  1900. Vector3 iforce = Vector3.Zero;
  1901. for (int i = 0; i < m_angularforcelist.Count; i++)
  1902. {
  1903. iforce = iforce + (m_angularforcelist[i] * 100);
  1904. }
  1905. d.BodyEnable(Body);
  1906. d.BodyAddTorque(Body, iforce.X, iforce.Y, iforce.Z);
  1907. }
  1908. m_angularforcelist.Clear();
  1909. }
  1910. m_collisionscore = 0;
  1911. m_interpenetrationcount = 0;
  1912. }
  1913. m_taintaddangularforce = false;
  1914. }
  1915. /// <summary>
  1916. /// Change prim in response to a velocity taint.
  1917. /// </summary>
  1918. private void changevelocity()
  1919. {
  1920. if (!m_isSelected)
  1921. {
  1922. Thread.Sleep(20);
  1923. if (IsPhysical)
  1924. {
  1925. if (Body != IntPtr.Zero)
  1926. {
  1927. d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
  1928. }
  1929. }
  1930. //resetCollisionAccounting();
  1931. }
  1932. m_taintVelocity = Vector3.Zero;
  1933. }
  1934. internal void setPrimForRemoval()
  1935. {
  1936. m_taintremove = true;
  1937. }
  1938. public override bool Flying
  1939. {
  1940. // no flying prims for you
  1941. get { return false; }
  1942. set { }
  1943. }
  1944. public override bool IsColliding
  1945. {
  1946. get { return iscolliding; }
  1947. set { iscolliding = value; }
  1948. }
  1949. public override bool CollidingGround
  1950. {
  1951. get { return false; }
  1952. set { return; }
  1953. }
  1954. public override bool CollidingObj
  1955. {
  1956. get { return false; }
  1957. set { return; }
  1958. }
  1959. public override bool ThrottleUpdates
  1960. {
  1961. get { return m_throttleUpdates; }
  1962. set { m_throttleUpdates = value; }
  1963. }
  1964. public override bool Stopped
  1965. {
  1966. get { return _zeroFlag; }
  1967. }
  1968. public override Vector3 Position
  1969. {
  1970. get { return _position; }
  1971. set { _position = value;
  1972. //m_log.Info("[PHYSICS]: " + _position.ToString());
  1973. }
  1974. }
  1975. public override Vector3 Size
  1976. {
  1977. get { return _size; }
  1978. set
  1979. {
  1980. if (value.IsFinite())
  1981. {
  1982. _size = value;
  1983. // m_log.DebugFormat("[PHYSICS]: Set size on {0} to {1}", Name, value);
  1984. }
  1985. else
  1986. {
  1987. m_log.WarnFormat("[PHYSICS]: Got NaN Size on object {0}", Name);
  1988. }
  1989. }
  1990. }
  1991. public override float Mass
  1992. {
  1993. get { return CalculateMass(); }
  1994. }
  1995. public override Vector3 Force
  1996. {
  1997. //get { return Vector3.Zero; }
  1998. get { return m_force; }
  1999. set
  2000. {
  2001. if (value.IsFinite())
  2002. {
  2003. m_force = value;
  2004. }
  2005. else
  2006. {
  2007. m_log.WarnFormat("[PHYSICS]: NaN in Force Applied to an Object {0}", Name);
  2008. }
  2009. }
  2010. }
  2011. public override int VehicleType
  2012. {
  2013. get { return (int)m_vehicle.Type; }
  2014. set { m_vehicle.ProcessTypeChange((Vehicle)value); }
  2015. }
  2016. public override void VehicleFloatParam(int param, float value)
  2017. {
  2018. m_vehicle.ProcessFloatVehicleParam((Vehicle) param, value);
  2019. }
  2020. public override void VehicleVectorParam(int param, Vector3 value)
  2021. {
  2022. m_vehicle.ProcessVectorVehicleParam((Vehicle) param, value);
  2023. }
  2024. public override void VehicleRotationParam(int param, Quaternion rotation)
  2025. {
  2026. m_vehicle.ProcessRotationVehicleParam((Vehicle) param, rotation);
  2027. }
  2028. public override void VehicleFlags(int param, bool remove)
  2029. {
  2030. m_vehicle.ProcessVehicleFlags(param, remove);
  2031. }
  2032. public override void SetVolumeDetect(int param)
  2033. {
  2034. // We have to lock the scene here so that an entire simulate loop either uses volume detect for all
  2035. // possible collisions with this prim or for none of them.
  2036. lock (_parent_scene.OdeLock)
  2037. {
  2038. m_isVolumeDetect = (param != 0);
  2039. }
  2040. }
  2041. public override Vector3 CenterOfMass
  2042. {
  2043. get { return Vector3.Zero; }
  2044. }
  2045. public override Vector3 GeometricCenter
  2046. {
  2047. get { return Vector3.Zero; }
  2048. }
  2049. public override PrimitiveBaseShape Shape
  2050. {
  2051. set
  2052. {
  2053. _pbs = value;
  2054. m_taintshape = true;
  2055. }
  2056. }
  2057. public override Vector3 Velocity
  2058. {
  2059. get
  2060. {
  2061. // Averate previous velocity with the new one so
  2062. // client object interpolation works a 'little' better
  2063. if (_zeroFlag)
  2064. return Vector3.Zero;
  2065. Vector3 returnVelocity = Vector3.Zero;
  2066. returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2;
  2067. returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2;
  2068. returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2;
  2069. return returnVelocity;
  2070. }
  2071. set
  2072. {
  2073. if (value.IsFinite())
  2074. {
  2075. _velocity = value;
  2076. m_taintVelocity = value;
  2077. _parent_scene.AddPhysicsActorTaint(this);
  2078. }
  2079. else
  2080. {
  2081. m_log.WarnFormat("[PHYSICS]: Got NaN Velocity in Object {0}", Name);
  2082. }
  2083. }
  2084. }
  2085. public override Vector3 Torque
  2086. {
  2087. get
  2088. {
  2089. if (!IsPhysical || Body == IntPtr.Zero)
  2090. return Vector3.Zero;
  2091. return _torque;
  2092. }
  2093. set
  2094. {
  2095. if (value.IsFinite())
  2096. {
  2097. m_taintTorque = value;
  2098. _parent_scene.AddPhysicsActorTaint(this);
  2099. }
  2100. else
  2101. {
  2102. m_log.WarnFormat("[PHYSICS]: Got NaN Torque in Object {0}", Name);
  2103. }
  2104. }
  2105. }
  2106. public override float CollisionScore
  2107. {
  2108. get { return m_collisionscore; }
  2109. set { m_collisionscore = value; }
  2110. }
  2111. public override bool Kinematic
  2112. {
  2113. get { return false; }
  2114. set { }
  2115. }
  2116. public override Quaternion Orientation
  2117. {
  2118. get { return _orientation; }
  2119. set
  2120. {
  2121. if (QuaternionIsFinite(value))
  2122. _orientation = value;
  2123. else
  2124. m_log.WarnFormat("[PHYSICS]: Got NaN quaternion Orientation from Scene in Object {0}", Name);
  2125. }
  2126. }
  2127. private static bool QuaternionIsFinite(Quaternion q)
  2128. {
  2129. if (Single.IsNaN(q.X) || Single.IsInfinity(q.X))
  2130. return false;
  2131. if (Single.IsNaN(q.Y) || Single.IsInfinity(q.Y))
  2132. return false;
  2133. if (Single.IsNaN(q.Z) || Single.IsInfinity(q.Z))
  2134. return false;
  2135. if (Single.IsNaN(q.W) || Single.IsInfinity(q.W))
  2136. return false;
  2137. return true;
  2138. }
  2139. public override Vector3 Acceleration
  2140. {
  2141. get { return _acceleration; }
  2142. set { _acceleration = value; }
  2143. }
  2144. public override void AddForce(Vector3 force, bool pushforce)
  2145. {
  2146. if (force.IsFinite())
  2147. {
  2148. lock (m_forcelist)
  2149. m_forcelist.Add(force);
  2150. m_taintforce = true;
  2151. }
  2152. else
  2153. {
  2154. m_log.WarnFormat("[PHYSICS]: Got Invalid linear force vector from Scene in Object {0}", Name);
  2155. }
  2156. //m_log.Info("[PHYSICS]: Added Force:" + force.ToString() + " to prim at " + Position.ToString());
  2157. }
  2158. public override void AddAngularForce(Vector3 force, bool pushforce)
  2159. {
  2160. if (force.IsFinite())
  2161. {
  2162. m_angularforcelist.Add(force);
  2163. m_taintaddangularforce = true;
  2164. }
  2165. else
  2166. {
  2167. m_log.WarnFormat("[PHYSICS]: Got Invalid Angular force vector from Scene in Object {0}", Name);
  2168. }
  2169. }
  2170. public override Vector3 RotationalVelocity
  2171. {
  2172. get
  2173. {
  2174. Vector3 pv = Vector3.Zero;
  2175. if (_zeroFlag)
  2176. return pv;
  2177. m_lastUpdateSent = false;
  2178. if (m_rotationalVelocity.ApproxEquals(pv, 0.2f))
  2179. return pv;
  2180. return m_rotationalVelocity;
  2181. }
  2182. set
  2183. {
  2184. if (value.IsFinite())
  2185. {
  2186. m_rotationalVelocity = value;
  2187. }
  2188. else
  2189. {
  2190. m_log.WarnFormat("[PHYSICS]: Got NaN RotationalVelocity in Object {0}", Name);
  2191. }
  2192. }
  2193. }
  2194. public override void CrossingFailure()
  2195. {
  2196. m_crossingfailures++;
  2197. if (m_crossingfailures > _parent_scene.geomCrossingFailuresBeforeOutofbounds)
  2198. {
  2199. base.RaiseOutOfBounds(_position);
  2200. return;
  2201. }
  2202. else if (m_crossingfailures == _parent_scene.geomCrossingFailuresBeforeOutofbounds)
  2203. {
  2204. m_log.Warn("[PHYSICS]: Too many crossing failures for: " + Name);
  2205. }
  2206. }
  2207. public override float Buoyancy
  2208. {
  2209. get { return m_buoyancy; }
  2210. set { m_buoyancy = value; }
  2211. }
  2212. public override void link(PhysicsActor obj)
  2213. {
  2214. m_taintparent = obj;
  2215. }
  2216. public override void delink()
  2217. {
  2218. m_taintparent = null;
  2219. }
  2220. public override void LockAngularMotion(Vector3 axis)
  2221. {
  2222. // reverse the zero/non zero values for ODE.
  2223. if (axis.IsFinite())
  2224. {
  2225. axis.X = (axis.X > 0) ? 1f : 0f;
  2226. axis.Y = (axis.Y > 0) ? 1f : 0f;
  2227. axis.Z = (axis.Z > 0) ? 1f : 0f;
  2228. m_log.DebugFormat("[axislock]: <{0},{1},{2}>", axis.X, axis.Y, axis.Z);
  2229. m_taintAngularLock = axis;
  2230. }
  2231. else
  2232. {
  2233. m_log.WarnFormat("[PHYSICS]: Got NaN locking axis from Scene on Object {0}", Name);
  2234. }
  2235. }
  2236. internal void UpdatePositionAndVelocity()
  2237. {
  2238. // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
  2239. if (_parent == null)
  2240. {
  2241. Vector3 pv = Vector3.Zero;
  2242. bool lastZeroFlag = _zeroFlag;
  2243. if (Body != (IntPtr)0) // FIXME -> or if it is a joint
  2244. {
  2245. d.Vector3 vec = d.BodyGetPosition(Body);
  2246. d.Quaternion ori = d.BodyGetQuaternion(Body);
  2247. d.Vector3 vel = d.BodyGetLinearVel(Body);
  2248. d.Vector3 rotvel = d.BodyGetAngularVel(Body);
  2249. d.Vector3 torque = d.BodyGetTorque(Body);
  2250. _torque = new Vector3(torque.X, torque.Y, torque.Z);
  2251. Vector3 l_position = Vector3.Zero;
  2252. Quaternion l_orientation = Quaternion.Identity;
  2253. // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!)
  2254. //if (vec.X < 0.0f) { vec.X = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
  2255. //if (vec.Y < 0.0f) { vec.Y = 0.0f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
  2256. //if (vec.X > 255.95f) { vec.X = 255.95f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
  2257. //if (vec.Y > 255.95f) { vec.Y = 255.95f; if (Body != (IntPtr)0) d.BodySetAngularVel(Body, 0, 0, 0); }
  2258. m_lastposition = _position;
  2259. m_lastorientation = _orientation;
  2260. l_position.X = vec.X;
  2261. l_position.Y = vec.Y;
  2262. l_position.Z = vec.Z;
  2263. l_orientation.X = ori.X;
  2264. l_orientation.Y = ori.Y;
  2265. l_orientation.Z = ori.Z;
  2266. l_orientation.W = ori.W;
  2267. if (l_position.X > ((int)_parent_scene.WorldExtents.X - 0.05f) || l_position.X < 0f || l_position.Y > ((int)_parent_scene.WorldExtents.Y - 0.05f) || l_position.Y < 0f)
  2268. {
  2269. //base.RaiseOutOfBounds(l_position);
  2270. if (m_crossingfailures < _parent_scene.geomCrossingFailuresBeforeOutofbounds)
  2271. {
  2272. _position = l_position;
  2273. //_parent_scene.remActivePrim(this);
  2274. if (_parent == null)
  2275. base.RequestPhysicsterseUpdate();
  2276. return;
  2277. }
  2278. else
  2279. {
  2280. if (_parent == null)
  2281. base.RaiseOutOfBounds(l_position);
  2282. return;
  2283. }
  2284. }
  2285. if (l_position.Z < 0)
  2286. {
  2287. // This is so prim that get lost underground don't fall forever and suck up
  2288. //
  2289. // Sim resources and memory.
  2290. // Disables the prim's movement physics....
  2291. // It's a hack and will generate a console message if it fails.
  2292. //IsPhysical = false;
  2293. if (_parent == null)
  2294. base.RaiseOutOfBounds(_position);
  2295. _acceleration.X = 0;
  2296. _acceleration.Y = 0;
  2297. _acceleration.Z = 0;
  2298. _velocity.X = 0;
  2299. _velocity.Y = 0;
  2300. _velocity.Z = 0;
  2301. m_rotationalVelocity.X = 0;
  2302. m_rotationalVelocity.Y = 0;
  2303. m_rotationalVelocity.Z = 0;
  2304. if (_parent == null)
  2305. base.RequestPhysicsterseUpdate();
  2306. m_throttleUpdates = false;
  2307. throttleCounter = 0;
  2308. _zeroFlag = true;
  2309. //outofBounds = true;
  2310. }
  2311. //float Adiff = 1.0f - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation));
  2312. //Console.WriteLine("Adiff " + Name + " = " + Adiff);
  2313. if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02)
  2314. && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02)
  2315. && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02)
  2316. // && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.01))
  2317. && (1.0 - Math.Abs(Quaternion.Dot(m_lastorientation, l_orientation)) < 0.0001)) // KF 0.01 is far to large
  2318. {
  2319. _zeroFlag = true;
  2320. //Console.WriteLine("ZFT 2");
  2321. m_throttleUpdates = false;
  2322. }
  2323. else
  2324. {
  2325. //m_log.Debug(Math.Abs(m_lastposition.X - l_position.X).ToString());
  2326. _zeroFlag = false;
  2327. m_lastUpdateSent = false;
  2328. //m_throttleUpdates = false;
  2329. }
  2330. if (_zeroFlag)
  2331. {
  2332. _velocity.X = 0.0f;
  2333. _velocity.Y = 0.0f;
  2334. _velocity.Z = 0.0f;
  2335. _acceleration.X = 0;
  2336. _acceleration.Y = 0;
  2337. _acceleration.Z = 0;
  2338. //_orientation.w = 0f;
  2339. //_orientation.X = 0f;
  2340. //_orientation.Y = 0f;
  2341. //_orientation.Z = 0f;
  2342. m_rotationalVelocity.X = 0;
  2343. m_rotationalVelocity.Y = 0;
  2344. m_rotationalVelocity.Z = 0;
  2345. if (!m_lastUpdateSent)
  2346. {
  2347. m_throttleUpdates = false;
  2348. throttleCounter = 0;
  2349. m_rotationalVelocity = pv;
  2350. if (_parent == null)
  2351. {
  2352. base.RequestPhysicsterseUpdate();
  2353. }
  2354. m_lastUpdateSent = true;
  2355. }
  2356. }
  2357. else
  2358. {
  2359. if (lastZeroFlag != _zeroFlag)
  2360. {
  2361. if (_parent == null)
  2362. {
  2363. base.RequestPhysicsterseUpdate();
  2364. }
  2365. }
  2366. m_lastVelocity = _velocity;
  2367. _position = l_position;
  2368. _velocity.X = vel.X;
  2369. _velocity.Y = vel.Y;
  2370. _velocity.Z = vel.Z;
  2371. _acceleration = ((_velocity - m_lastVelocity) / 0.1f);
  2372. _acceleration = new Vector3(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f);
  2373. //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
  2374. if (_velocity.ApproxEquals(pv, 0.5f))
  2375. {
  2376. m_rotationalVelocity = pv;
  2377. }
  2378. else
  2379. {
  2380. m_rotationalVelocity = new Vector3(rotvel.X, rotvel.Y, rotvel.Z);
  2381. }
  2382. //m_log.Debug("ODE: " + m_rotationalVelocity.ToString());
  2383. _orientation.X = ori.X;
  2384. _orientation.Y = ori.Y;
  2385. _orientation.Z = ori.Z;
  2386. _orientation.W = ori.W;
  2387. m_lastUpdateSent = false;
  2388. if (!m_throttleUpdates || throttleCounter > _parent_scene.geomUpdatesPerThrottledUpdate)
  2389. {
  2390. if (_parent == null)
  2391. {
  2392. base.RequestPhysicsterseUpdate();
  2393. }
  2394. }
  2395. else
  2396. {
  2397. throttleCounter++;
  2398. }
  2399. }
  2400. m_lastposition = l_position;
  2401. }
  2402. else
  2403. {
  2404. // Not a body.. so Make sure the client isn't interpolating
  2405. _velocity.X = 0;
  2406. _velocity.Y = 0;
  2407. _velocity.Z = 0;
  2408. _acceleration.X = 0;
  2409. _acceleration.Y = 0;
  2410. _acceleration.Z = 0;
  2411. m_rotationalVelocity.X = 0;
  2412. m_rotationalVelocity.Y = 0;
  2413. m_rotationalVelocity.Z = 0;
  2414. _zeroFlag = true;
  2415. }
  2416. }
  2417. }
  2418. public override bool FloatOnWater
  2419. {
  2420. set {
  2421. m_taintCollidesWater = value;
  2422. _parent_scene.AddPhysicsActorTaint(this);
  2423. }
  2424. }
  2425. public override void SetMomentum(Vector3 momentum)
  2426. {
  2427. }
  2428. public override Vector3 PIDTarget
  2429. {
  2430. set
  2431. {
  2432. if (value.IsFinite())
  2433. {
  2434. m_PIDTarget = value;
  2435. }
  2436. else
  2437. m_log.WarnFormat("[PHYSICS]: Got NaN PIDTarget from Scene on Object {0}", Name);
  2438. }
  2439. }
  2440. public override bool PIDActive { set { m_usePID = value; } }
  2441. public override float PIDTau { set { m_PIDTau = value; } }
  2442. public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } }
  2443. public override bool PIDHoverActive { set { m_useHoverPID = value; } }
  2444. public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } }
  2445. public override float PIDHoverTau { set { m_PIDHoverTau = value; } }
  2446. public override Quaternion APIDTarget{ set { return; } }
  2447. public override bool APIDActive{ set { return; } }
  2448. public override float APIDStrength{ set { return; } }
  2449. public override float APIDDamping{ set { return; } }
  2450. private void createAMotor(Vector3 axis)
  2451. {
  2452. if (Body == IntPtr.Zero)
  2453. return;
  2454. if (Amotor != IntPtr.Zero)
  2455. {
  2456. d.JointDestroy(Amotor);
  2457. Amotor = IntPtr.Zero;
  2458. }
  2459. float axisnum = 3;
  2460. axisnum = (axisnum - (axis.X + axis.Y + axis.Z));
  2461. // PhysicsVector totalSize = new PhysicsVector(_size.X, _size.Y, _size.Z);
  2462. // Inverse Inertia Matrix, set the X, Y, and/r Z inertia to 0 then invert it again.
  2463. d.Mass objMass;
  2464. d.MassSetZero(out objMass);
  2465. DMassCopy(ref pMass, ref objMass);
  2466. //m_log.DebugFormat("1-{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, ", objMass.I.M00, objMass.I.M01, objMass.I.M02, objMass.I.M10, objMass.I.M11, objMass.I.M12, objMass.I.M20, objMass.I.M21, objMass.I.M22);
  2467. Matrix4 dMassMat = FromDMass(objMass);
  2468. Matrix4 mathmat = Inverse(dMassMat);
  2469. /*
  2470. //m_log.DebugFormat("2-{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, ", mathmat[0, 0], mathmat[0, 1], mathmat[0, 2], mathmat[1, 0], mathmat[1, 1], mathmat[1, 2], mathmat[2, 0], mathmat[2, 1], mathmat[2, 2]);
  2471. mathmat = Inverse(mathmat);
  2472. objMass = FromMatrix4(mathmat, ref objMass);
  2473. //m_log.DebugFormat("3-{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, ", objMass.I.M00, objMass.I.M01, objMass.I.M02, objMass.I.M10, objMass.I.M11, objMass.I.M12, objMass.I.M20, objMass.I.M21, objMass.I.M22);
  2474. mathmat = Inverse(mathmat);
  2475. */
  2476. if (axis.X == 0)
  2477. {
  2478. mathmat.M33 = 50.0000001f;
  2479. //objMass.I.M22 = 0;
  2480. }
  2481. if (axis.Y == 0)
  2482. {
  2483. mathmat.M22 = 50.0000001f;
  2484. //objMass.I.M11 = 0;
  2485. }
  2486. if (axis.Z == 0)
  2487. {
  2488. mathmat.M11 = 50.0000001f;
  2489. //objMass.I.M00 = 0;
  2490. }
  2491. mathmat = Inverse(mathmat);
  2492. objMass = FromMatrix4(mathmat, ref objMass);
  2493. //m_log.DebugFormat("4-{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, ", objMass.I.M00, objMass.I.M01, objMass.I.M02, objMass.I.M10, objMass.I.M11, objMass.I.M12, objMass.I.M20, objMass.I.M21, objMass.I.M22);
  2494. //return;
  2495. if (d.MassCheck(ref objMass))
  2496. {
  2497. d.BodySetMass(Body, ref objMass);
  2498. }
  2499. else
  2500. {
  2501. //m_log.Debug("[PHYSICS]: Mass invalid, ignoring");
  2502. }
  2503. if (axisnum <= 0)
  2504. return;
  2505. // int dAMotorEuler = 1;
  2506. Amotor = d.JointCreateAMotor(_parent_scene.world, IntPtr.Zero);
  2507. d.JointAttach(Amotor, Body, IntPtr.Zero);
  2508. d.JointSetAMotorMode(Amotor, 0);
  2509. d.JointSetAMotorNumAxes(Amotor,(int)axisnum);
  2510. int i = 0;
  2511. if (axis.X == 0)
  2512. {
  2513. d.JointSetAMotorAxis(Amotor, i, 0, 1, 0, 0);
  2514. i++;
  2515. }
  2516. if (axis.Y == 0)
  2517. {
  2518. d.JointSetAMotorAxis(Amotor, i, 0, 0, 1, 0);
  2519. i++;
  2520. }
  2521. if (axis.Z == 0)
  2522. {
  2523. d.JointSetAMotorAxis(Amotor, i, 0, 0, 0, 1);
  2524. i++;
  2525. }
  2526. for (int j = 0; j < (int)axisnum; j++)
  2527. {
  2528. //d.JointSetAMotorAngle(Amotor, j, 0);
  2529. }
  2530. //d.JointSetAMotorAngle(Amotor, 1, 0);
  2531. //d.JointSetAMotorAngle(Amotor, 2, 0);
  2532. // These lowstops and high stops are effectively (no wiggle room)
  2533. d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -0f);
  2534. d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
  2535. d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -0f);
  2536. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0f);
  2537. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f);
  2538. d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0f);
  2539. //d.JointSetAMotorParam(Amotor, (int) dParam.Vel, 9000f);
  2540. d.JointSetAMotorParam(Amotor, (int)dParam.FudgeFactor, 0f);
  2541. d.JointSetAMotorParam(Amotor, (int)dParam.FMax, Mass * 50f);//
  2542. }
  2543. private Matrix4 FromDMass(d.Mass pMass)
  2544. {
  2545. Matrix4 obj;
  2546. obj.M11 = pMass.I.M00;
  2547. obj.M12 = pMass.I.M01;
  2548. obj.M13 = pMass.I.M02;
  2549. obj.M14 = 0;
  2550. obj.M21 = pMass.I.M10;
  2551. obj.M22 = pMass.I.M11;
  2552. obj.M23 = pMass.I.M12;
  2553. obj.M24 = 0;
  2554. obj.M31 = pMass.I.M20;
  2555. obj.M32 = pMass.I.M21;
  2556. obj.M33 = pMass.I.M22;
  2557. obj.M34 = 0;
  2558. obj.M41 = 0;
  2559. obj.M42 = 0;
  2560. obj.M43 = 0;
  2561. obj.M44 = 1;
  2562. return obj;
  2563. }
  2564. private d.Mass FromMatrix4(Matrix4 pMat, ref d.Mass obj)
  2565. {
  2566. obj.I.M00 = pMat[0, 0];
  2567. obj.I.M01 = pMat[0, 1];
  2568. obj.I.M02 = pMat[0, 2];
  2569. obj.I.M10 = pMat[1, 0];
  2570. obj.I.M11 = pMat[1, 1];
  2571. obj.I.M12 = pMat[1, 2];
  2572. obj.I.M20 = pMat[2, 0];
  2573. obj.I.M21 = pMat[2, 1];
  2574. obj.I.M22 = pMat[2, 2];
  2575. return obj;
  2576. }
  2577. public override void SubscribeEvents(int ms)
  2578. {
  2579. m_eventsubscription = ms;
  2580. _parent_scene.AddCollisionEventReporting(this);
  2581. }
  2582. public override void UnSubscribeEvents()
  2583. {
  2584. _parent_scene.RemoveCollisionEventReporting(this);
  2585. m_eventsubscription = 0;
  2586. }
  2587. public void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
  2588. {
  2589. CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
  2590. }
  2591. public void SendCollisions()
  2592. {
  2593. if (m_collisionsOnPreviousFrame || CollisionEventsThisFrame.Count > 0)
  2594. {
  2595. base.SendCollisionUpdate(CollisionEventsThisFrame);
  2596. if (CollisionEventsThisFrame.Count > 0)
  2597. {
  2598. m_collisionsOnPreviousFrame = true;
  2599. CollisionEventsThisFrame.Clear();
  2600. }
  2601. else
  2602. {
  2603. m_collisionsOnPreviousFrame = false;
  2604. }
  2605. }
  2606. }
  2607. public override bool SubscribedEvents()
  2608. {
  2609. if (m_eventsubscription > 0)
  2610. return true;
  2611. return false;
  2612. }
  2613. public static Matrix4 Inverse(Matrix4 pMat)
  2614. {
  2615. if (determinant3x3(pMat) == 0)
  2616. {
  2617. return Matrix4.Identity; // should probably throw an error. singluar matrix inverse not possible
  2618. }
  2619. return (Adjoint(pMat) / determinant3x3(pMat));
  2620. }
  2621. public static Matrix4 Adjoint(Matrix4 pMat)
  2622. {
  2623. Matrix4 adjointMatrix = new Matrix4();
  2624. for (int i=0; i<4; i++)
  2625. {
  2626. for (int j=0; j<4; j++)
  2627. {
  2628. Matrix4SetValue(ref adjointMatrix, i, j, (float)(Math.Pow(-1, i + j) * (determinant3x3(Minor(pMat, i, j)))));
  2629. }
  2630. }
  2631. adjointMatrix = Transpose(adjointMatrix);
  2632. return adjointMatrix;
  2633. }
  2634. public static Matrix4 Minor(Matrix4 matrix, int iRow, int iCol)
  2635. {
  2636. Matrix4 minor = new Matrix4();
  2637. int m = 0, n = 0;
  2638. for (int i = 0; i < 4; i++)
  2639. {
  2640. if (i == iRow)
  2641. continue;
  2642. n = 0;
  2643. for (int j = 0; j < 4; j++)
  2644. {
  2645. if (j == iCol)
  2646. continue;
  2647. Matrix4SetValue(ref minor, m,n, matrix[i, j]);
  2648. n++;
  2649. }
  2650. m++;
  2651. }
  2652. return minor;
  2653. }
  2654. public static Matrix4 Transpose(Matrix4 pMat)
  2655. {
  2656. Matrix4 transposeMatrix = new Matrix4();
  2657. for (int i = 0; i < 4; i++)
  2658. for (int j = 0; j < 4; j++)
  2659. Matrix4SetValue(ref transposeMatrix, i, j, pMat[j, i]);
  2660. return transposeMatrix;
  2661. }
  2662. public static void Matrix4SetValue(ref Matrix4 pMat, int r, int c, float val)
  2663. {
  2664. switch (r)
  2665. {
  2666. case 0:
  2667. switch (c)
  2668. {
  2669. case 0:
  2670. pMat.M11 = val;
  2671. break;
  2672. case 1:
  2673. pMat.M12 = val;
  2674. break;
  2675. case 2:
  2676. pMat.M13 = val;
  2677. break;
  2678. case 3:
  2679. pMat.M14 = val;
  2680. break;
  2681. }
  2682. break;
  2683. case 1:
  2684. switch (c)
  2685. {
  2686. case 0:
  2687. pMat.M21 = val;
  2688. break;
  2689. case 1:
  2690. pMat.M22 = val;
  2691. break;
  2692. case 2:
  2693. pMat.M23 = val;
  2694. break;
  2695. case 3:
  2696. pMat.M24 = val;
  2697. break;
  2698. }
  2699. break;
  2700. case 2:
  2701. switch (c)
  2702. {
  2703. case 0:
  2704. pMat.M31 = val;
  2705. break;
  2706. case 1:
  2707. pMat.M32 = val;
  2708. break;
  2709. case 2:
  2710. pMat.M33 = val;
  2711. break;
  2712. case 3:
  2713. pMat.M34 = val;
  2714. break;
  2715. }
  2716. break;
  2717. case 3:
  2718. switch (c)
  2719. {
  2720. case 0:
  2721. pMat.M41 = val;
  2722. break;
  2723. case 1:
  2724. pMat.M42 = val;
  2725. break;
  2726. case 2:
  2727. pMat.M43 = val;
  2728. break;
  2729. case 3:
  2730. pMat.M44 = val;
  2731. break;
  2732. }
  2733. break;
  2734. }
  2735. }
  2736. private static float determinant3x3(Matrix4 pMat)
  2737. {
  2738. float det = 0;
  2739. float diag1 = pMat[0, 0]*pMat[1, 1]*pMat[2, 2];
  2740. float diag2 = pMat[0, 1]*pMat[2, 1]*pMat[2, 0];
  2741. float diag3 = pMat[0, 2]*pMat[1, 0]*pMat[2, 1];
  2742. float diag4 = pMat[2, 0]*pMat[1, 1]*pMat[0, 2];
  2743. float diag5 = pMat[2, 1]*pMat[1, 2]*pMat[0, 0];
  2744. float diag6 = pMat[2, 2]*pMat[1, 0]*pMat[0, 1];
  2745. det = diag1 + diag2 + diag3 - (diag4 + diag5 + diag6);
  2746. return det;
  2747. }
  2748. private static void DMassCopy(ref d.Mass src, ref d.Mass dst)
  2749. {
  2750. dst.c.W = src.c.W;
  2751. dst.c.X = src.c.X;
  2752. dst.c.Y = src.c.Y;
  2753. dst.c.Z = src.c.Z;
  2754. dst.mass = src.mass;
  2755. dst.I.M00 = src.I.M00;
  2756. dst.I.M01 = src.I.M01;
  2757. dst.I.M02 = src.I.M02;
  2758. dst.I.M10 = src.I.M10;
  2759. dst.I.M11 = src.I.M11;
  2760. dst.I.M12 = src.I.M12;
  2761. dst.I.M20 = src.I.M20;
  2762. dst.I.M21 = src.I.M21;
  2763. dst.I.M22 = src.I.M22;
  2764. }
  2765. public override void SetMaterial(int pMaterial)
  2766. {
  2767. m_material = pMaterial;
  2768. }
  2769. }
  2770. }