ODEPrim.cs 118 KB

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