ODEPrim.cs 115 KB

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