BSDynamics.cs 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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. /* RA: June 14, 2011. Copied from ODEDynamics.cs and converted to
  28. * call the BulletSim system.
  29. */
  30. /* Revised Aug, Sept 2009 by Kitto Flora. ODEDynamics.cs replaces
  31. * ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
  32. * ODEPrim.cs contains methods dealing with Prim editing, Prim
  33. * characteristics and Kinetic motion.
  34. * ODEDynamics.cs contains methods dealing with Prim Physical motion
  35. * (dynamics) and the associated settings. Old Linear and angular
  36. * motors for dynamic motion have been replace with MoveLinear()
  37. * and MoveAngular(); 'Physical' is used only to switch ODE dynamic
  38. * simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
  39. * switch between 'VEHICLE' parameter use and general dynamics
  40. * settings use.
  41. */
  42. using System;
  43. using System.Collections.Generic;
  44. using System.Reflection;
  45. using System.Runtime.InteropServices;
  46. using log4net;
  47. using OpenMetaverse;
  48. using OpenSim.Framework;
  49. using OpenSim.Region.Physics.Manager;
  50. namespace OpenSim.Region.Physics.BulletSPlugin
  51. {
  52. public sealed class BSDynamics
  53. {
  54. private BSScene PhysicsScene { get; set; }
  55. // the prim this dynamic controller belongs to
  56. private BSPrim Prim { get; set; }
  57. // Vehicle properties
  58. public Vehicle Type { get; set; }
  59. // private Quaternion m_referenceFrame = Quaternion.Identity; // Axis modifier
  60. private VehicleFlag m_flags = (VehicleFlag) 0; // Boolean settings:
  61. // HOVER_TERRAIN_ONLY
  62. // HOVER_GLOBAL_HEIGHT
  63. // NO_DEFLECTION_UP
  64. // HOVER_WATER_ONLY
  65. // HOVER_UP_ONLY
  66. // LIMIT_MOTOR_UP
  67. // LIMIT_ROLL_ONLY
  68. private Vector3 m_BlockingEndPoint = Vector3.Zero;
  69. private Quaternion m_RollreferenceFrame = Quaternion.Identity;
  70. private Quaternion m_referenceFrame = Quaternion.Identity;
  71. // Linear properties
  72. private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
  73. private Vector3 m_linearMotorOffset = Vector3.Zero; // the point of force can be offset from the center
  74. private Vector3 m_linearMotorDirectionLASTSET = Vector3.Zero; // velocity requested by LSL
  75. private Vector3 m_newVelocity = Vector3.Zero; // velocity computed to be applied to body
  76. private Vector3 m_linearFrictionTimescale = Vector3.Zero;
  77. private float m_linearMotorDecayTimescale = 0;
  78. private float m_linearMotorTimescale = 0;
  79. private Vector3 m_lastLinearVelocityVector = Vector3.Zero;
  80. private Vector3 m_lastPositionVector = Vector3.Zero;
  81. // private bool m_LinearMotorSetLastFrame = false;
  82. // private Vector3 m_linearMotorOffset = Vector3.Zero;
  83. //Angular properties
  84. private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
  85. private int m_angularMotorApply = 0; // application frame counter
  86. private Vector3 m_angularMotorVelocity = Vector3.Zero; // current angular motor velocity
  87. private float m_angularMotorTimescale = 0; // motor angular velocity ramp up rate
  88. private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate
  89. private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate
  90. private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body
  91. private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body
  92. //Deflection properties
  93. private float m_angularDeflectionEfficiency = 0;
  94. private float m_angularDeflectionTimescale = 0;
  95. private float m_linearDeflectionEfficiency = 0;
  96. private float m_linearDeflectionTimescale = 0;
  97. //Banking properties
  98. private float m_bankingEfficiency = 0;
  99. private float m_bankingMix = 0;
  100. private float m_bankingTimescale = 0;
  101. //Hover and Buoyancy properties
  102. private float m_VhoverHeight = 0f;
  103. private float m_VhoverEfficiency = 0f;
  104. private float m_VhoverTimescale = 0f;
  105. private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height
  106. private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle.
  107. // Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity)
  108. // KF: So far I have found no good method to combine a script-requested .Z velocity and gravity.
  109. // Therefore only m_VehicleBuoyancy=1 (0g) will use the script-requested .Z velocity.
  110. //Attractor properties
  111. private float m_verticalAttractionEfficiency = 1.0f; // damped
  112. private float m_verticalAttractionTimescale = 500f; // Timescale > 300 means no vert attractor.
  113. public BSDynamics(BSScene myScene, BSPrim myPrim)
  114. {
  115. PhysicsScene = myScene;
  116. Prim = myPrim;
  117. Type = Vehicle.TYPE_NONE;
  118. }
  119. // Return 'true' if this vehicle is doing vehicle things
  120. public bool IsActive
  121. {
  122. get { return Type != Vehicle.TYPE_NONE; }
  123. }
  124. internal void ProcessFloatVehicleParam(Vehicle pParam, float pValue)
  125. {
  126. VDetailLog("{0},ProcessFloatVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue);
  127. switch (pParam)
  128. {
  129. case Vehicle.ANGULAR_DEFLECTION_EFFICIENCY:
  130. m_angularDeflectionEfficiency = Math.Max(pValue, 0.01f);
  131. break;
  132. case Vehicle.ANGULAR_DEFLECTION_TIMESCALE:
  133. m_angularDeflectionTimescale = Math.Max(pValue, 0.01f);
  134. break;
  135. case Vehicle.ANGULAR_MOTOR_DECAY_TIMESCALE:
  136. m_angularMotorDecayTimescale = Math.Max(pValue, 0.01f);
  137. break;
  138. case Vehicle.ANGULAR_MOTOR_TIMESCALE:
  139. m_angularMotorTimescale = Math.Max(pValue, 0.01f);
  140. break;
  141. case Vehicle.BANKING_EFFICIENCY:
  142. m_bankingEfficiency = Math.Max(-1f, Math.Min(pValue, 1f));
  143. break;
  144. case Vehicle.BANKING_MIX:
  145. m_bankingMix = Math.Max(pValue, 0.01f);
  146. break;
  147. case Vehicle.BANKING_TIMESCALE:
  148. m_bankingTimescale = Math.Max(pValue, 0.01f);
  149. break;
  150. case Vehicle.BUOYANCY:
  151. m_VehicleBuoyancy = Math.Max(-1f, Math.Min(pValue, 1f));
  152. break;
  153. case Vehicle.HOVER_EFFICIENCY:
  154. m_VhoverEfficiency = Math.Max(0f, Math.Min(pValue, 1f));
  155. break;
  156. case Vehicle.HOVER_HEIGHT:
  157. m_VhoverHeight = pValue;
  158. break;
  159. case Vehicle.HOVER_TIMESCALE:
  160. m_VhoverTimescale = Math.Max(pValue, 0.01f);
  161. break;
  162. case Vehicle.LINEAR_DEFLECTION_EFFICIENCY:
  163. m_linearDeflectionEfficiency = Math.Max(pValue, 0.01f);
  164. break;
  165. case Vehicle.LINEAR_DEFLECTION_TIMESCALE:
  166. m_linearDeflectionTimescale = Math.Max(pValue, 0.01f);
  167. break;
  168. case Vehicle.LINEAR_MOTOR_DECAY_TIMESCALE:
  169. m_linearMotorDecayTimescale = Math.Max(pValue, 0.01f);
  170. break;
  171. case Vehicle.LINEAR_MOTOR_TIMESCALE:
  172. m_linearMotorTimescale = Math.Max(pValue, 0.01f);
  173. break;
  174. case Vehicle.VERTICAL_ATTRACTION_EFFICIENCY:
  175. m_verticalAttractionEfficiency = Math.Max(0.1f, Math.Min(pValue, 1f));
  176. break;
  177. case Vehicle.VERTICAL_ATTRACTION_TIMESCALE:
  178. m_verticalAttractionTimescale = Math.Max(pValue, 0.01f);
  179. break;
  180. // These are vector properties but the engine lets you use a single float value to
  181. // set all of the components to the same value
  182. case Vehicle.ANGULAR_FRICTION_TIMESCALE:
  183. m_angularFrictionTimescale = new Vector3(pValue, pValue, pValue);
  184. break;
  185. case Vehicle.ANGULAR_MOTOR_DIRECTION:
  186. m_angularMotorDirection = new Vector3(pValue, pValue, pValue);
  187. m_angularMotorApply = 100;
  188. break;
  189. case Vehicle.LINEAR_FRICTION_TIMESCALE:
  190. m_linearFrictionTimescale = new Vector3(pValue, pValue, pValue);
  191. break;
  192. case Vehicle.LINEAR_MOTOR_DIRECTION:
  193. m_linearMotorDirection = new Vector3(pValue, pValue, pValue);
  194. m_linearMotorDirectionLASTSET = new Vector3(pValue, pValue, pValue);
  195. break;
  196. case Vehicle.LINEAR_MOTOR_OFFSET:
  197. m_linearMotorOffset = new Vector3(pValue, pValue, pValue);
  198. break;
  199. }
  200. }//end ProcessFloatVehicleParam
  201. internal void ProcessVectorVehicleParam(Vehicle pParam, Vector3 pValue)
  202. {
  203. VDetailLog("{0},ProcessVectorVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue);
  204. switch (pParam)
  205. {
  206. case Vehicle.ANGULAR_FRICTION_TIMESCALE:
  207. m_angularFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
  208. break;
  209. case Vehicle.ANGULAR_MOTOR_DIRECTION:
  210. // Limit requested angular speed to 2 rps= 4 pi rads/sec
  211. pValue.X = Math.Max(-12.56f, Math.Min(pValue.X, 12.56f));
  212. pValue.Y = Math.Max(-12.56f, Math.Min(pValue.Y, 12.56f));
  213. pValue.Z = Math.Max(-12.56f, Math.Min(pValue.Z, 12.56f));
  214. m_angularMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
  215. m_angularMotorApply = 100;
  216. break;
  217. case Vehicle.LINEAR_FRICTION_TIMESCALE:
  218. m_linearFrictionTimescale = new Vector3(pValue.X, pValue.Y, pValue.Z);
  219. break;
  220. case Vehicle.LINEAR_MOTOR_DIRECTION:
  221. m_linearMotorDirection = new Vector3(pValue.X, pValue.Y, pValue.Z);
  222. m_linearMotorDirectionLASTSET = new Vector3(pValue.X, pValue.Y, pValue.Z);
  223. break;
  224. case Vehicle.LINEAR_MOTOR_OFFSET:
  225. m_linearMotorOffset = new Vector3(pValue.X, pValue.Y, pValue.Z);
  226. break;
  227. case Vehicle.BLOCK_EXIT:
  228. m_BlockingEndPoint = new Vector3(pValue.X, pValue.Y, pValue.Z);
  229. break;
  230. }
  231. }//end ProcessVectorVehicleParam
  232. internal void ProcessRotationVehicleParam(Vehicle pParam, Quaternion pValue)
  233. {
  234. VDetailLog("{0},ProcessRotationalVehicleParam,param={1},val={2}", Prim.LocalID, pParam, pValue);
  235. switch (pParam)
  236. {
  237. case Vehicle.REFERENCE_FRAME:
  238. m_referenceFrame = pValue;
  239. break;
  240. case Vehicle.ROLL_FRAME:
  241. m_RollreferenceFrame = pValue;
  242. break;
  243. }
  244. }//end ProcessRotationVehicleParam
  245. internal void ProcessVehicleFlags(int pParam, bool remove)
  246. {
  247. VDetailLog("{0},ProcessVehicleFlags,param={1},remove={2}", Prim.LocalID, pParam, remove);
  248. VehicleFlag parm = (VehicleFlag)pParam;
  249. if (pParam == -1)
  250. m_flags = (VehicleFlag)0;
  251. else
  252. {
  253. if (remove)
  254. m_flags &= ~parm;
  255. else
  256. m_flags |= parm;
  257. }
  258. }
  259. internal void ProcessTypeChange(Vehicle pType)
  260. {
  261. VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType);
  262. // Set Defaults For Type
  263. Type = pType;
  264. switch (pType)
  265. {
  266. case Vehicle.TYPE_NONE:
  267. m_linearMotorDirection = Vector3.Zero;
  268. m_linearMotorTimescale = 0;
  269. m_linearMotorDecayTimescale = 0;
  270. m_linearFrictionTimescale = new Vector3(0, 0, 0);
  271. m_angularMotorDirection = Vector3.Zero;
  272. m_angularMotorDecayTimescale = 0;
  273. m_angularMotorTimescale = 0;
  274. m_angularFrictionTimescale = new Vector3(0, 0, 0);
  275. m_VhoverHeight = 0;
  276. m_VhoverEfficiency = 0;
  277. m_VhoverTimescale = 0;
  278. m_VehicleBuoyancy = 0;
  279. m_linearDeflectionEfficiency = 1;
  280. m_linearDeflectionTimescale = 1;
  281. m_angularDeflectionEfficiency = 0;
  282. m_angularDeflectionTimescale = 1000;
  283. m_verticalAttractionEfficiency = 0;
  284. m_verticalAttractionTimescale = 0;
  285. m_bankingEfficiency = 0;
  286. m_bankingTimescale = 1000;
  287. m_bankingMix = 1;
  288. m_referenceFrame = Quaternion.Identity;
  289. m_flags = (VehicleFlag)0;
  290. break;
  291. case Vehicle.TYPE_SLED:
  292. m_linearMotorDirection = Vector3.Zero;
  293. m_linearMotorTimescale = 1000;
  294. m_linearMotorDecayTimescale = 120;
  295. m_linearFrictionTimescale = new Vector3(30, 1, 1000);
  296. m_angularMotorDirection = Vector3.Zero;
  297. m_angularMotorTimescale = 1000;
  298. m_angularMotorDecayTimescale = 120;
  299. m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
  300. m_VhoverHeight = 0;
  301. m_VhoverEfficiency = 10; // TODO: this looks wrong!!
  302. m_VhoverTimescale = 10;
  303. m_VehicleBuoyancy = 0;
  304. m_linearDeflectionEfficiency = 1;
  305. m_linearDeflectionTimescale = 1;
  306. m_angularDeflectionEfficiency = 1;
  307. m_angularDeflectionTimescale = 1000;
  308. m_verticalAttractionEfficiency = 0;
  309. m_verticalAttractionTimescale = 0;
  310. m_bankingEfficiency = 0;
  311. m_bankingTimescale = 10;
  312. m_bankingMix = 1;
  313. m_referenceFrame = Quaternion.Identity;
  314. m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | VehicleFlag.LIMIT_MOTOR_UP);
  315. m_flags &=
  316. ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY |
  317. VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY);
  318. break;
  319. case Vehicle.TYPE_CAR:
  320. m_linearMotorDirection = Vector3.Zero;
  321. m_linearMotorTimescale = 1;
  322. m_linearMotorDecayTimescale = 60;
  323. m_linearFrictionTimescale = new Vector3(100, 2, 1000);
  324. m_angularMotorDirection = Vector3.Zero;
  325. m_angularMotorTimescale = 1;
  326. m_angularMotorDecayTimescale = 0.8f;
  327. m_angularFrictionTimescale = new Vector3(1000, 1000, 1000);
  328. m_VhoverHeight = 0;
  329. m_VhoverEfficiency = 0;
  330. m_VhoverTimescale = 1000;
  331. m_VehicleBuoyancy = 0;
  332. m_linearDeflectionEfficiency = 1;
  333. m_linearDeflectionTimescale = 2;
  334. m_angularDeflectionEfficiency = 0;
  335. m_angularDeflectionTimescale = 10;
  336. m_verticalAttractionEfficiency = 1f;
  337. m_verticalAttractionTimescale = 10f;
  338. m_bankingEfficiency = -0.2f;
  339. m_bankingMix = 1;
  340. m_bankingTimescale = 1;
  341. m_referenceFrame = Quaternion.Identity;
  342. m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
  343. | VehicleFlag.HOVER_TERRAIN_ONLY
  344. | VehicleFlag.HOVER_GLOBAL_HEIGHT);
  345. m_flags |= (VehicleFlag.NO_DEFLECTION_UP
  346. | VehicleFlag.LIMIT_ROLL_ONLY
  347. | VehicleFlag.LIMIT_MOTOR_UP
  348. | VehicleFlag.HOVER_UP_ONLY);
  349. break;
  350. case Vehicle.TYPE_BOAT:
  351. m_linearMotorDirection = Vector3.Zero;
  352. m_linearMotorTimescale = 5;
  353. m_linearMotorDecayTimescale = 60;
  354. m_linearFrictionTimescale = new Vector3(10, 3, 2);
  355. m_angularMotorDirection = Vector3.Zero;
  356. m_angularMotorTimescale = 4;
  357. m_angularMotorDecayTimescale = 4;
  358. m_angularFrictionTimescale = new Vector3(10,10,10);
  359. m_VhoverHeight = 0;
  360. m_VhoverEfficiency = 0.5f;
  361. m_VhoverTimescale = 2;
  362. m_VehicleBuoyancy = 1;
  363. m_linearDeflectionEfficiency = 0.5f;
  364. m_linearDeflectionTimescale = 3;
  365. m_angularDeflectionEfficiency = 0.5f;
  366. m_angularDeflectionTimescale = 5;
  367. m_verticalAttractionEfficiency = 0.5f;
  368. m_verticalAttractionTimescale = 5f;
  369. m_bankingEfficiency = -0.3f;
  370. m_bankingMix = 0.8f;
  371. m_bankingTimescale = 1;
  372. m_referenceFrame = Quaternion.Identity;
  373. m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY
  374. | VehicleFlag.HOVER_GLOBAL_HEIGHT
  375. | VehicleFlag.LIMIT_ROLL_ONLY
  376. | VehicleFlag.HOVER_UP_ONLY);
  377. m_flags |= (VehicleFlag.NO_DEFLECTION_UP
  378. | VehicleFlag.LIMIT_MOTOR_UP
  379. | VehicleFlag.HOVER_WATER_ONLY);
  380. break;
  381. case Vehicle.TYPE_AIRPLANE:
  382. m_linearMotorDirection = Vector3.Zero;
  383. m_linearMotorTimescale = 2;
  384. m_linearMotorDecayTimescale = 60;
  385. m_linearFrictionTimescale = new Vector3(200, 10, 5);
  386. m_angularMotorDirection = Vector3.Zero;
  387. m_angularMotorTimescale = 4;
  388. m_angularMotorDecayTimescale = 4;
  389. m_angularFrictionTimescale = new Vector3(20, 20, 20);
  390. m_VhoverHeight = 0;
  391. m_VhoverEfficiency = 0.5f;
  392. m_VhoverTimescale = 1000;
  393. m_VehicleBuoyancy = 0;
  394. m_linearDeflectionEfficiency = 0.5f;
  395. m_linearDeflectionTimescale = 3;
  396. m_angularDeflectionEfficiency = 1;
  397. m_angularDeflectionTimescale = 2;
  398. m_verticalAttractionEfficiency = 0.9f;
  399. m_verticalAttractionTimescale = 2f;
  400. m_bankingEfficiency = 1;
  401. m_bankingMix = 0.7f;
  402. m_bankingTimescale = 2;
  403. m_referenceFrame = Quaternion.Identity;
  404. m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
  405. | VehicleFlag.HOVER_TERRAIN_ONLY
  406. | VehicleFlag.HOVER_GLOBAL_HEIGHT
  407. | VehicleFlag.HOVER_UP_ONLY
  408. | VehicleFlag.NO_DEFLECTION_UP
  409. | VehicleFlag.LIMIT_MOTOR_UP);
  410. m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY);
  411. break;
  412. case Vehicle.TYPE_BALLOON:
  413. m_linearMotorDirection = Vector3.Zero;
  414. m_linearMotorTimescale = 5;
  415. m_linearFrictionTimescale = new Vector3(5, 5, 5);
  416. m_linearMotorDecayTimescale = 60;
  417. m_angularMotorDirection = Vector3.Zero;
  418. m_angularMotorTimescale = 6;
  419. m_angularFrictionTimescale = new Vector3(10, 10, 10);
  420. m_angularMotorDecayTimescale = 10;
  421. m_VhoverHeight = 5;
  422. m_VhoverEfficiency = 0.8f;
  423. m_VhoverTimescale = 10;
  424. m_VehicleBuoyancy = 1;
  425. m_linearDeflectionEfficiency = 0;
  426. m_linearDeflectionTimescale = 5;
  427. m_angularDeflectionEfficiency = 0;
  428. m_angularDeflectionTimescale = 5;
  429. m_verticalAttractionEfficiency = 1f;
  430. m_verticalAttractionTimescale = 100f;
  431. m_bankingEfficiency = 0;
  432. m_bankingMix = 0.7f;
  433. m_bankingTimescale = 5;
  434. m_referenceFrame = Quaternion.Identity;
  435. m_referenceFrame = Quaternion.Identity;
  436. m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY
  437. | VehicleFlag.HOVER_TERRAIN_ONLY
  438. | VehicleFlag.HOVER_UP_ONLY
  439. | VehicleFlag.NO_DEFLECTION_UP
  440. | VehicleFlag.LIMIT_MOTOR_UP);
  441. m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY
  442. | VehicleFlag.HOVER_GLOBAL_HEIGHT);
  443. break;
  444. }
  445. }
  446. // Some of the properties of this prim may have changed.
  447. // Do any updating needed for a vehicle
  448. public void Refresh()
  449. {
  450. /*
  451. * Doesnt work unless BSDynamics senses and corrects for all collisions
  452. if (IsActive)
  453. BulletSimAPI.AddToCollisionFlags2(Prim.BSBody.ptr, CollisionFlags.CF_KINEMATIC_OBJECT);
  454. else
  455. BulletSimAPI.RemoveFromCollisionFlags2(Prim.BSBody.ptr, CollisionFlags.CF_KINEMATIC_OBJECT);
  456. */
  457. /*
  458. * Doesn't work because with zero inertia, Bullet will not apply any forces to the object.
  459. if (IsActive)
  460. {
  461. BulletSimAPI.SetMassProps2(Prim.BSBody.ptr, Prim.MassRaw, Vector3.Zero);
  462. BulletSimAPI.UpdateInertiaTensor2(Prim.BSBody.ptr);
  463. }
  464. */
  465. }
  466. // One step of the vehicle properties for the next 'pTimestep' seconds.
  467. internal void Step(float pTimestep)
  468. {
  469. if (!IsActive) return;
  470. MoveLinear(pTimestep);
  471. MoveAngular(pTimestep);
  472. LimitRotation(pTimestep);
  473. /* Experimental
  474. // Wonder if Bullet could handle collision penetration while this applies the forces.
  475. // Apply the computed forces on the vehicle
  476. Prim.ForcePosition += Prim.ForceVelocity * Prim.MassRaw * pTimestep;
  477. if (Prim.ForceRotationalVelocity != Vector3.Zero)
  478. {
  479. Quaternion newOrientation = Prim.ForceOrientation;
  480. newOrientation.Normalize();
  481. Quaternion appliedRotation = new Quaternion((Prim.ForceRotationalVelocity * pTimestep), 0f);
  482. newOrientation += (appliedRotation * newOrientation) * 0.5f;
  483. newOrientation.Normalize();
  484. Prim.ForceOrientation = newOrientation;
  485. }
  486. */
  487. // remember the position so next step we can limit absolute movement effects
  488. m_lastPositionVector = Prim.ForcePosition;
  489. VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}",
  490. Prim.LocalID, Prim.ForcePosition, Prim.Force, Prim.ForceVelocity, Prim.RotationalVelocity);
  491. }// end Step
  492. // Apply the effect of the linear motor.
  493. // Also does hover and float.
  494. private void MoveLinear(float pTimestep)
  495. {
  496. // m_linearMotorDirection is the target direction we are moving relative to the vehicle coordinates
  497. // m_lastLinearVelocityVector is the current speed we are moving in that direction
  498. if (m_linearMotorDirection.LengthSquared() > 0.001f)
  499. {
  500. Vector3 origDir = m_linearMotorDirection;
  501. Vector3 origVel = m_lastLinearVelocityVector;
  502. // add drive to body
  503. Vector3 addAmount = (m_linearMotorDirection - m_lastLinearVelocityVector)/(m_linearMotorTimescale / pTimestep);
  504. // lastLinearVelocityVector is the current body velocity vector
  505. m_lastLinearVelocityVector += addAmount;
  506. float keepfraction = 1.0f - (1.0f / (m_linearMotorDecayTimescale / pTimestep));
  507. m_linearMotorDirection *= keepfraction;
  508. VDetailLog("{0},MoveLinear,nonZero,origdir={1},origvel={2},add={3},notDecay={4},dir={5},vel={6}",
  509. Prim.LocalID, origDir, origVel, addAmount, keepfraction, m_linearMotorDirection, m_lastLinearVelocityVector);
  510. // convert requested object velocity to object relative vector
  511. m_newVelocity = m_lastLinearVelocityVector * Prim.ForceOrientation;
  512. }
  513. else
  514. {
  515. // if what remains of direction is very small, zero it.
  516. m_linearMotorDirection = Vector3.Zero;
  517. m_lastLinearVelocityVector = Vector3.Zero;
  518. m_newVelocity = Vector3.Zero;
  519. VDetailLog("{0},MoveLinear,zeroed", Prim.LocalID);
  520. }
  521. // m_newVelocity is velocity computed from linear motor
  522. // Add the various forces into m_dir which will be our new direction vector (velocity)
  523. // add Gravity and Buoyancy
  524. // There is some gravity, make a gravity force vector that is applied after object velocity.
  525. // m_VehicleBuoyancy: -1=2g; 0=1g; 1=0g;
  526. // Vector3 grav = Prim.PhysicsScene.DefaultGravity * (Prim.Linkset.LinksetMass * (1f - m_VehicleBuoyancy));
  527. Vector3 grav = Prim.PhysicsScene.DefaultGravity * (1f - m_VehicleBuoyancy);
  528. /*
  529. * RA: Not sure why one would do this
  530. // Preserve the current Z velocity
  531. Vector3 vel_now = m_prim.Velocity;
  532. m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity
  533. */
  534. Vector3 pos = Prim.ForcePosition;
  535. // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f);
  536. // If below the terrain, move us above the ground a little.
  537. float terrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos);
  538. // Taking the rotated size doesn't work here because m_prim.Size is the size of the root prim and not the linkset.
  539. // Need to add a m_prim.LinkSet.Size similar to m_prim.LinkSet.Mass.
  540. // Vector3 rotatedSize = m_prim.Size * m_prim.ForceOrientation;
  541. // if (rotatedSize.Z < terrainHeight)
  542. if (pos.Z < terrainHeight)
  543. {
  544. pos.Z = terrainHeight + 2;
  545. Prim.ForcePosition = pos;
  546. VDetailLog("{0},MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, terrainHeight, pos);
  547. }
  548. // Check if hovering
  549. // m_VhoverEfficiency: 0=bouncy, 1=totally damped
  550. // m_VhoverTimescale: time to achieve height
  551. if ((m_flags & (VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT)) != 0)
  552. {
  553. // We should hover, get the target height
  554. if ((m_flags & VehicleFlag.HOVER_WATER_ONLY) != 0)
  555. {
  556. m_VhoverTargetHeight = Prim.PhysicsScene.GetWaterLevelAtXYZ(pos) + m_VhoverHeight;
  557. }
  558. if ((m_flags & VehicleFlag.HOVER_TERRAIN_ONLY) != 0)
  559. {
  560. m_VhoverTargetHeight = terrainHeight + m_VhoverHeight;
  561. }
  562. if ((m_flags & VehicleFlag.HOVER_GLOBAL_HEIGHT) != 0)
  563. {
  564. m_VhoverTargetHeight = m_VhoverHeight;
  565. }
  566. if ((m_flags & VehicleFlag.HOVER_UP_ONLY) != 0)
  567. {
  568. // If body is aready heigher, use its height as target height
  569. if (pos.Z > m_VhoverTargetHeight) m_VhoverTargetHeight = pos.Z;
  570. }
  571. if ((m_flags & VehicleFlag.LOCK_HOVER_HEIGHT) != 0)
  572. {
  573. if ((pos.Z - m_VhoverTargetHeight) > .2 || (pos.Z - m_VhoverTargetHeight) < -.2)
  574. {
  575. Prim.ForcePosition = pos;
  576. }
  577. }
  578. else
  579. {
  580. float horizontalError = pos.Z - m_VhoverTargetHeight;
  581. // RA: where does the 50 come from>
  582. float horizontalCorrectionVelocity = ((horizontalError * 50.0f) / (m_VhoverTimescale / pTimestep));
  583. // Replace Vertical speed with correction figure if significant
  584. if (Math.Abs(horizontalError) > 0.01f)
  585. {
  586. m_newVelocity.Z += horizontalCorrectionVelocity;
  587. //KF: m_VhoverEfficiency is not yet implemented
  588. }
  589. else if (horizontalError < -0.01)
  590. {
  591. m_newVelocity.Z -= horizontalCorrectionVelocity;
  592. }
  593. else
  594. {
  595. m_newVelocity.Z = 0f;
  596. }
  597. }
  598. VDetailLog("{0},MoveLinear,hover,pos={1},dir={2},height={3},target={4}", Prim.LocalID, pos, m_newVelocity, m_VhoverHeight, m_VhoverTargetHeight);
  599. }
  600. Vector3 posChange = pos - m_lastPositionVector;
  601. if (m_BlockingEndPoint != Vector3.Zero)
  602. {
  603. bool changed = false;
  604. if (pos.X >= (m_BlockingEndPoint.X - (float)1))
  605. {
  606. pos.X -= posChange.X + 1;
  607. changed = true;
  608. }
  609. if (pos.Y >= (m_BlockingEndPoint.Y - (float)1))
  610. {
  611. pos.Y -= posChange.Y + 1;
  612. changed = true;
  613. }
  614. if (pos.Z >= (m_BlockingEndPoint.Z - (float)1))
  615. {
  616. pos.Z -= posChange.Z + 1;
  617. changed = true;
  618. }
  619. if (pos.X <= 0)
  620. {
  621. pos.X += posChange.X + 1;
  622. changed = true;
  623. }
  624. if (pos.Y <= 0)
  625. {
  626. pos.Y += posChange.Y + 1;
  627. changed = true;
  628. }
  629. if (changed)
  630. {
  631. Prim.ForcePosition = pos;
  632. VDetailLog("{0},MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}",
  633. Prim.LocalID, m_BlockingEndPoint, posChange, pos);
  634. }
  635. }
  636. // Limit absolute vertical change
  637. float Zchange = Math.Abs(posChange.Z);
  638. if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0)
  639. {
  640. if (Zchange > .3)
  641. grav.Z = (float)(grav.Z * 3);
  642. if (Zchange > .15)
  643. grav.Z = (float)(grav.Z * 2);
  644. if (Zchange > .75)
  645. grav.Z = (float)(grav.Z * 1.5);
  646. if (Zchange > .05)
  647. grav.Z = (float)(grav.Z * 1.25);
  648. if (Zchange > .025)
  649. grav.Z = (float)(grav.Z * 1.125);
  650. float postemp = (pos.Z - terrainHeight);
  651. if (postemp > 2.5f)
  652. grav.Z = (float)(grav.Z * 1.037125);
  653. VDetailLog("{0},MoveLinear,limitMotorUp,grav={1}", Prim.LocalID, grav);
  654. }
  655. // If not changing some axis, reduce out velocity
  656. if ((m_flags & (VehicleFlag.NO_X)) != 0)
  657. m_newVelocity.X = 0;
  658. if ((m_flags & (VehicleFlag.NO_Y)) != 0)
  659. m_newVelocity.Y = 0;
  660. if ((m_flags & (VehicleFlag.NO_Z)) != 0)
  661. m_newVelocity.Z = 0;
  662. // Apply friction
  663. Vector3 keepFraction = Vector3.One - (Vector3.One / (m_linearFrictionTimescale / pTimestep));
  664. m_lastLinearVelocityVector *= keepFraction;
  665. // Apply velocity
  666. // Prim.ForceVelocity = m_newVelocity;
  667. Prim.AddForce(m_newVelocity, false);
  668. VDetailLog("{0},MoveLinear,done,lmDir={1},lmVel={2},newVel={3},grav={4},1Mdecay={5}",
  669. Prim.LocalID, m_linearMotorDirection, m_lastLinearVelocityVector, m_newVelocity, grav, keepFraction);
  670. } // end MoveLinear()
  671. // Apply the effect of the angular motor.
  672. private void MoveAngular(float pTimestep)
  673. {
  674. // m_angularMotorDirection // angular velocity requested by LSL motor
  675. // m_angularMotorApply // application frame counter
  676. // m_angularMotorVelocity // current angular motor velocity (ramps up and down)
  677. // m_angularMotorTimescale // motor angular velocity ramp up rate
  678. // m_angularMotorDecayTimescale // motor angular velocity decay rate
  679. // m_angularFrictionTimescale // body angular velocity decay rate
  680. // m_lastAngularVelocity // what was last applied to body
  681. // Get what the body is doing, this includes 'external' influences
  682. Vector3 angularVelocity = Prim.ForceRotationalVelocity;
  683. if (m_angularMotorApply > 0)
  684. {
  685. // Rather than snapping the angular motor velocity from the old value to
  686. // a newly set velocity, this routine steps the value from the previous
  687. // value (m_angularMotorVelocity) to the requested value (m_angularMotorDirection).
  688. // There are m_angularMotorApply steps.
  689. Vector3 origVel = m_angularMotorVelocity;
  690. Vector3 origDir = m_angularMotorDirection;
  691. // ramp up to new value
  692. // new velocity += error / ( time to get there / step interval)
  693. // requested speed - last motor speed
  694. m_angularMotorVelocity += (m_angularMotorDirection - m_angularMotorVelocity) / (m_angularMotorTimescale / pTimestep);
  695. VDetailLog("{0},MoveAngular,angularMotorApply,apply={1},angTScale={2},timeStep={3},origvel={4},origDir={5},vel={6}",
  696. Prim.LocalID, m_angularMotorApply, m_angularMotorTimescale, pTimestep, origVel, origDir, m_angularMotorVelocity);
  697. m_angularMotorApply--;
  698. }
  699. else
  700. {
  701. // No motor recently applied, keep the body velocity
  702. // and decay the velocity
  703. if (m_angularMotorVelocity.LengthSquared() < 0.0001)
  704. m_angularMotorVelocity = Vector3.Zero;
  705. else
  706. m_angularMotorVelocity -= m_angularMotorVelocity / (m_angularMotorDecayTimescale / pTimestep);
  707. } // end motor section
  708. #region Vertical attactor
  709. Vector3 vertattr = Vector3.Zero;
  710. Vector3 deflection = Vector3.Zero;
  711. Vector3 banking = Vector3.Zero;
  712. if (m_verticalAttractionTimescale < 300 && m_lastAngularVelocity != Vector3.Zero)
  713. {
  714. float VAservo = 0.2f;
  715. if (Prim.Linkset.LinksetIsColliding)
  716. VAservo = 0.05f / (m_verticalAttractionTimescale / pTimestep);
  717. VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency);
  718. // get present body rotation
  719. Quaternion rotq = Prim.ForceOrientation;
  720. // vector pointing up
  721. Vector3 verticalError = Vector3.UnitZ;
  722. // rotate it to Body Angle
  723. verticalError = verticalError * rotq;
  724. // verticalError.X and .Y are the World error amounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1.
  725. // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go
  726. // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body.
  727. // Error is 0 (no error) to +/- 2 (max error)
  728. if (verticalError.Z < 0.0f)
  729. {
  730. verticalError.X = 2.0f - verticalError.X;
  731. verticalError.Y = 2.0f - verticalError.Y;
  732. }
  733. // scale it by VAservo
  734. verticalError = verticalError * VAservo;
  735. // As the body rotates around the X axis, then verticalError.Y increases; Rotated around Y then .X increases, so
  736. // Change Body angular velocity X based on Y, and Y based on X. Z is not changed.
  737. vertattr.X = verticalError.Y;
  738. vertattr.Y = - verticalError.X;
  739. vertattr.Z = 0f;
  740. // scaling appears better usingsquare-law
  741. float bounce = 1.0f - (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency);
  742. vertattr.X += bounce * angularVelocity.X;
  743. vertattr.Y += bounce * angularVelocity.Y;
  744. VDetailLog("{0},MoveAngular,verticalAttraction,verticalError={1},bounce={2},vertattr={3}",
  745. Prim.LocalID, verticalError, bounce, vertattr);
  746. }
  747. #endregion // Vertical attactor
  748. #region Deflection
  749. //Forward is the prefered direction, but if the reference frame has changed, we need to take this into account as well
  750. Vector3 PreferredAxisOfMotion =
  751. new Vector3((10*(m_angularDeflectionEfficiency/m_angularDeflectionTimescale)), 0, 0);
  752. PreferredAxisOfMotion *= Quaternion.Add(Prim.ForceOrientation, m_referenceFrame);
  753. //Multiply it so that it scales linearly
  754. //deflection = PreferredAxisOfMotion;
  755. //deflection = ((PreferredAxisOfMotion * m_angularDeflectionEfficiency) / (m_angularDeflectionTimescale / pTimestep));
  756. #endregion
  757. #region Banking
  758. if (m_bankingEfficiency != 0)
  759. {
  760. Vector3 dir = Vector3.One * Prim.ForceOrientation;
  761. float mult = (m_bankingMix*m_bankingMix)*-1*(m_bankingMix < 0 ? -1 : 1);
  762. //Changes which way it banks in and out of turns
  763. //Use the square of the efficiency, as it looks much more how SL banking works
  764. float effSquared = (m_bankingEfficiency*m_bankingEfficiency);
  765. if (m_bankingEfficiency < 0)
  766. effSquared *= -1; //Keep the negative!
  767. float mix = Math.Abs(m_bankingMix);
  768. if (m_angularMotorVelocity.X == 0)
  769. {
  770. /*if (!parent.Orientation.ApproxEquals(this.m_referenceFrame, 0.25f))
  771. {
  772. Vector3 axisAngle;
  773. float angle;
  774. parent.Orientation.GetAxisAngle(out axisAngle, out angle);
  775. Vector3 rotatedVel = parent.Velocity * parent.Orientation;
  776. if ((rotatedVel.X < 0 && axisAngle.Y > 0) || (rotatedVel.X > 0 && axisAngle.Y < 0))
  777. m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (1f) * 10;
  778. else
  779. m_angularMotorVelocity.X += (effSquared * (mult * mix)) * (-1f) * 10;
  780. }*/
  781. }
  782. else
  783. banking.Z += (effSquared*(mult*mix))*(m_angularMotorVelocity.X) * 4;
  784. if (!Prim.Linkset.LinksetIsColliding && Math.Abs(m_angularMotorVelocity.X) > mix)
  785. //If they are colliding, we probably shouldn't shove the prim around... probably
  786. {
  787. float angVelZ = m_angularMotorVelocity.X*-1;
  788. /*if(angVelZ > mix)
  789. angVelZ = mix;
  790. else if(angVelZ < -mix)
  791. angVelZ = -mix;*/
  792. //This controls how fast and how far the banking occurs
  793. Vector3 bankingRot = new Vector3(angVelZ*(effSquared*mult), 0, 0);
  794. if (bankingRot.X > 3)
  795. bankingRot.X = 3;
  796. else if (bankingRot.X < -3)
  797. bankingRot.X = -3;
  798. bankingRot *= Prim.ForceOrientation;
  799. banking += bankingRot;
  800. }
  801. m_angularMotorVelocity.X *= m_bankingEfficiency == 1 ? 0.0f : 1 - m_bankingEfficiency;
  802. }
  803. #endregion
  804. m_lastVertAttractor = vertattr;
  805. // Bank section tba
  806. // Deflection section tba
  807. // Sum velocities
  808. m_lastAngularVelocity = m_angularMotorVelocity + vertattr; // + bank + deflection
  809. if ((m_flags & (VehicleFlag.NO_DEFLECTION_UP)) != 0)
  810. {
  811. m_lastAngularVelocity.X = 0;
  812. m_lastAngularVelocity.Y = 0;
  813. VDetailLog("{0},MoveAngular,noDeflectionUp,lastAngular={1}", Prim.LocalID, m_lastAngularVelocity);
  814. }
  815. if (m_lastAngularVelocity.ApproxEquals(Vector3.Zero, 0.01f))
  816. {
  817. m_lastAngularVelocity = Vector3.Zero; // Reduce small value to zero.
  818. VDetailLog("{0},MoveAngular,zeroSmallValues,lastAngular={1}", Prim.LocalID, m_lastAngularVelocity);
  819. }
  820. // apply friction
  821. Vector3 decayamount = Vector3.One / (m_angularFrictionTimescale / pTimestep);
  822. m_lastAngularVelocity -= m_lastAngularVelocity * decayamount;
  823. // Apply to the body
  824. // Prim.ForceRotationalVelocity = m_lastAngularVelocity;
  825. Prim.AddAngularForce(m_lastAngularVelocity, false);
  826. VDetailLog("{0},MoveAngular,done,decay={1},lastAngular={2}", Prim.LocalID, decayamount, m_lastAngularVelocity);
  827. } //end MoveAngular
  828. internal void LimitRotation(float timestep)
  829. {
  830. Quaternion rotq = Prim.ForceOrientation;
  831. Quaternion m_rot = rotq;
  832. if (m_RollreferenceFrame != Quaternion.Identity)
  833. {
  834. if (rotq.X >= m_RollreferenceFrame.X)
  835. {
  836. m_rot.X = rotq.X - (m_RollreferenceFrame.X / 2);
  837. }
  838. if (rotq.Y >= m_RollreferenceFrame.Y)
  839. {
  840. m_rot.Y = rotq.Y - (m_RollreferenceFrame.Y / 2);
  841. }
  842. if (rotq.X <= -m_RollreferenceFrame.X)
  843. {
  844. m_rot.X = rotq.X + (m_RollreferenceFrame.X / 2);
  845. }
  846. if (rotq.Y <= -m_RollreferenceFrame.Y)
  847. {
  848. m_rot.Y = rotq.Y + (m_RollreferenceFrame.Y / 2);
  849. }
  850. }
  851. if ((m_flags & VehicleFlag.LOCK_ROTATION) != 0)
  852. {
  853. m_rot.X = 0;
  854. m_rot.Y = 0;
  855. }
  856. if (rotq != m_rot)
  857. {
  858. Prim.ForceOrientation = m_rot;
  859. VDetailLog("{0},LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot);
  860. }
  861. }
  862. // Invoke the detailed logger and output something if it's enabled.
  863. private void VDetailLog(string msg, params Object[] args)
  864. {
  865. if (Prim.PhysicsScene.VehicleLoggingEnabled)
  866. Prim.PhysicsScene.DetailLog(msg, args);
  867. }
  868. }
  869. }