PECharacter.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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 copyrightD
  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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Physics.Manager;
  34. using OpenSim.Region.CoreModules.RegionSync.RegionSyncModule;
  35. namespace OpenSim.Region.Physics.PEPlugin
  36. {
  37. public class PECharacter : PhysicsActor
  38. {
  39. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  40. private bool _stopped;
  41. private Vector3 _size;
  42. private PrimitiveBaseShape _pbs;
  43. private uint _localID = 0;
  44. private bool _grabbed;
  45. private bool _selected;
  46. private Vector3 _position;
  47. private float _mass = 80f;
  48. public float _density = 60f;
  49. public float CAPSULE_RADIUS = 0.37f;
  50. public float CAPSULE_LENGTH = 2.140599f;
  51. private Vector3 _force;
  52. private Vector3 _velocity;
  53. private Vector3 _torque;
  54. private float _collisionScore;
  55. private Vector3 _acceleration;
  56. private Quaternion _orientation;
  57. private int _physicsActorType;
  58. private bool _isPhysical;
  59. private bool _flying;
  60. private bool _setAlwaysRun;
  61. private bool _throttleUpdates;
  62. private bool _isColliding;
  63. private bool _collidingGround;
  64. private bool _collidingObj;
  65. private bool _floatOnWater;
  66. private Vector3 _rotationalVelocity;
  67. private bool _kinematic;
  68. private float _buoyancy;
  69. private Vector3 _PIDTarget;
  70. private bool _usePID;
  71. private float _PIDTau;
  72. private bool _useHoverPID;
  73. private float _PIDHoverHeight;
  74. private PIDHoverType _PIDHoverType;
  75. private float _PIDHoverTao;
  76. public PECharacter(String avName, PEScene parent_scene, Vector3 pos,
  77. CollisionLocker dode, Vector3 size, float pid_d, float pid_p,
  78. float capsule_radius, float tensor, float density, float height_fudge_factor,
  79. float walk_divisor, float rundivisor)
  80. {
  81. _position = pos;
  82. _size = size;
  83. _density = density;
  84. base.ChangingActorID = RegionSyncServerModule.ActorID;
  85. return;
  86. }
  87. public override void RequestPhysicsterseUpdate()
  88. {
  89. if (PhysEngineToSceneConnectorModule.IsPhysEngineActorS)
  90. {
  91. // if the values have changed and it was I who changed them, send an update
  92. if (this.lastValues.Changed(this) && ChangingActorID == RegionSyncServerModule.ActorID)
  93. {
  94. // m_log.DebugFormat("[ODE CHARACTER]: Sending terse update for {0}", LocalID);
  95. PhysEngineToSceneConnectorModule.RouteUpdate(this);
  96. }
  97. }
  98. else
  99. {
  100. base.RequestPhysicsterseUpdate();
  101. }
  102. }
  103. public override bool Stopped {
  104. get { return _stopped; }
  105. }
  106. public override Vector3 Size {
  107. get { return _size; }
  108. set { _size = value;
  109. }
  110. }
  111. public override PrimitiveBaseShape Shape {
  112. set { _pbs = value;
  113. }
  114. }
  115. public override uint LocalID {
  116. set { _localID = value;
  117. }
  118. get { return _localID; }
  119. }
  120. public override bool Grabbed {
  121. set { _grabbed = value;
  122. // m_log.Debug("[RPE] PEChar set Grabbed");
  123. }
  124. }
  125. public override bool Selected {
  126. set { _selected = value;
  127. // m_log.Debug("[RPE] PEChar set Selected");
  128. }
  129. }
  130. public override void CrossingFailure() { return; }
  131. public override void link(PhysicsActor obj) { return; }
  132. public override void delink() { return; }
  133. public override void LockAngularMotion(Vector3 axis) { return; }
  134. public override Vector3 Position {
  135. get { return _position; }
  136. set { _position = value;
  137. base.ChangingActorID = RegionSyncServerModule.ActorID;
  138. }
  139. }
  140. public override float Mass {
  141. get {
  142. float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH);
  143. _mass = _density*AVvolume;
  144. return _mass;
  145. }
  146. }
  147. public override Vector3 Force {
  148. get { return _force; }
  149. set { _force = value;
  150. base.ChangingActorID = RegionSyncServerModule.ActorID;
  151. }
  152. }
  153. public override int VehicleType {
  154. get { return 0; }
  155. set { return; }
  156. }
  157. public override void VehicleFloatParam(int param, float value) { }
  158. public override void VehicleVectorParam(int param, Vector3 value) {}
  159. public override void VehicleRotationParam(int param, Quaternion rotation) { }
  160. public override void VehicleFlags(int param, bool remove) { }
  161. // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more
  162. public override void SetVolumeDetect(int param) { return; }
  163. public override Vector3 GeometricCenter { get { return Vector3.Zero; } }
  164. public override Vector3 CenterOfMass { get { return Vector3.Zero; } }
  165. public override Vector3 Velocity {
  166. get { return _velocity; }
  167. set { _velocity = value;
  168. base.ChangingActorID = RegionSyncServerModule.ActorID;
  169. }
  170. }
  171. public override Vector3 Torque {
  172. get { return _torque; }
  173. set { _torque = value;
  174. }
  175. }
  176. public override float CollisionScore {
  177. get { return _collisionScore; }
  178. set { _collisionScore = value;
  179. }
  180. }
  181. public override Vector3 Acceleration {
  182. get { return _acceleration; }
  183. }
  184. public override Quaternion Orientation {
  185. get { return _orientation; }
  186. set { _orientation = value;
  187. base.ChangingActorID = RegionSyncServerModule.ActorID;
  188. }
  189. }
  190. public override int PhysicsActorType {
  191. get { return _physicsActorType; }
  192. set { _physicsActorType = value;
  193. }
  194. }
  195. public override bool IsPhysical {
  196. get { return _isPhysical; }
  197. set { _isPhysical = value;
  198. }
  199. }
  200. public override bool Flying {
  201. get { return _flying; }
  202. set { _flying = value;
  203. }
  204. }
  205. public override bool
  206. SetAlwaysRun {
  207. get { return _setAlwaysRun; }
  208. set { _setAlwaysRun = value; }
  209. }
  210. public override bool ThrottleUpdates {
  211. get { return _throttleUpdates; }
  212. set { _throttleUpdates = value; }
  213. }
  214. public override bool IsColliding {
  215. get { return _isColliding; }
  216. set { _isColliding = value; }
  217. }
  218. public override bool CollidingGround {
  219. get { return _collidingGround; }
  220. set { _collidingGround = value; }
  221. }
  222. public override bool CollidingObj {
  223. get { return _collidingObj; }
  224. set { _collidingObj = value; }
  225. }
  226. public override bool FloatOnWater {
  227. set { _floatOnWater = value; }
  228. }
  229. public override Vector3 RotationalVelocity {
  230. get { return _rotationalVelocity; }
  231. set { _rotationalVelocity = value; }
  232. }
  233. public override bool Kinematic {
  234. get { return _kinematic; }
  235. set { _kinematic = value; }
  236. }
  237. public override float Buoyancy {
  238. get { return _buoyancy; }
  239. set { _buoyancy = value; }
  240. }
  241. // Used for MoveTo
  242. public override Vector3 PIDTarget {
  243. set { _PIDTarget = value; }
  244. }
  245. public override bool PIDActive {
  246. set { _usePID = value; }
  247. }
  248. public override float PIDTau {
  249. set { _PIDTau = value; }
  250. }
  251. // Used for llSetHoverHeight and maybe vehicle height
  252. // Hover Height will override MoveTo target's Z
  253. public override bool PIDHoverActive {
  254. set { _useHoverPID = value; }
  255. }
  256. public override float PIDHoverHeight {
  257. set { _PIDHoverHeight = value; }
  258. }
  259. public override PIDHoverType PIDHoverType {
  260. set { _PIDHoverType = value; }
  261. }
  262. public override float PIDHoverTau {
  263. set { _PIDHoverTao = value; }
  264. }
  265. // For RotLookAt
  266. public override Quaternion APIDTarget { set { return; } }
  267. public override bool APIDActive { set { return; } }
  268. public override float APIDStrength { set { return; } }
  269. public override float APIDDamping { set { return; } }
  270. public override void AddForce(Vector3 force, bool pushforce) {
  271. if (force.IsFinite())
  272. {
  273. // base.ChangingActorID = RegionSyncServerModule.ActorID;
  274. _velocity.X += force.X;
  275. _velocity.Y += force.Y;
  276. _velocity.Z += force.Z;
  277. }
  278. else
  279. {
  280. m_log.Warn("[PHYSICS]: Got a NaN force applied to a Character");
  281. }
  282. //m_lastUpdateSent = false;
  283. }
  284. public override void AddAngularForce(Vector3 force, bool pushforce) {
  285. }
  286. public override void SetMomentum(Vector3 momentum) {
  287. }
  288. public override void SubscribeEvents(int ms) {
  289. }
  290. public override void UnSubscribeEvents() {
  291. }
  292. public override bool SubscribedEvents() {
  293. return false;
  294. }
  295. }
  296. }