PhysXCharacter.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. using System;
  28. using System.Collections.Generic;
  29. using Nini.Config;
  30. using OpenSim.Framework;
  31. using OpenSim.Region.Physics.Manager;
  32. using PhysXWrapper;
  33. using Quaternion=OpenMetaverse.Quaternion;
  34. using System.Reflection;
  35. using log4net;
  36. using OpenMetaverse;
  37. namespace OpenSim.Region.Physics.PhysXPlugin
  38. {
  39. public class PhysXCharacter : PhysicsActor
  40. {
  41. private Vector3 _position;
  42. private Vector3 _velocity;
  43. private Vector3 m_rotationalVelocity = Vector3.Zero;
  44. private Vector3 _acceleration;
  45. private NxCharacter _character;
  46. private bool flying;
  47. private bool iscolliding = false;
  48. private float gravityAccel;
  49. public PhysXCharacter(NxCharacter character)
  50. {
  51. _character = character;
  52. }
  53. public override int PhysicsActorType
  54. {
  55. get { return (int) ActorTypes.Agent; }
  56. set { return; }
  57. }
  58. public override bool SetAlwaysRun
  59. {
  60. get { return false; }
  61. set { return; }
  62. }
  63. public override uint LocalID
  64. {
  65. set { return; }
  66. }
  67. public override bool Grabbed
  68. {
  69. set { return; }
  70. }
  71. public override bool Selected
  72. {
  73. set { return; }
  74. }
  75. public override float Buoyancy
  76. {
  77. get { return 0f; }
  78. set { return; }
  79. }
  80. public override bool FloatOnWater
  81. {
  82. set { return; }
  83. }
  84. public override bool IsPhysical
  85. {
  86. get { return false; }
  87. set { return; }
  88. }
  89. public override bool ThrottleUpdates
  90. {
  91. get { return false; }
  92. set { return; }
  93. }
  94. public override bool Flying
  95. {
  96. get { return flying; }
  97. set { flying = value; }
  98. }
  99. public override bool IsColliding
  100. {
  101. get { return iscolliding; }
  102. set { iscolliding = value; }
  103. }
  104. public override bool CollidingGround
  105. {
  106. get { return false; }
  107. set { return; }
  108. }
  109. public override bool CollidingObj
  110. {
  111. get { return false; }
  112. set { return; }
  113. }
  114. public override Vector3 RotationalVelocity
  115. {
  116. get { return m_rotationalVelocity; }
  117. set { m_rotationalVelocity = value; }
  118. }
  119. public override bool Stopped
  120. {
  121. get { return false; }
  122. }
  123. public override Vector3 Position
  124. {
  125. get { return _position; }
  126. set
  127. {
  128. _position = value;
  129. Vec3 ps = new Vec3();
  130. ps.X = value.X;
  131. ps.Y = value.Y;
  132. ps.Z = value.Z;
  133. _character.Position = ps;
  134. }
  135. }
  136. public override Vector3 Size
  137. {
  138. get { return Vector3.Zero; }
  139. set { }
  140. }
  141. public override float Mass
  142. {
  143. get { return 0f; }
  144. }
  145. public override Vector3 Force
  146. {
  147. get { return Vector3.Zero; }
  148. set { return; }
  149. }
  150. public override int VehicleType
  151. {
  152. get { return 0; }
  153. set { return; }
  154. }
  155. public override void VehicleFloatParam(int param, float value)
  156. {
  157. }
  158. public override void VehicleVectorParam(int param, Vector3 value)
  159. {
  160. }
  161. public override void VehicleRotationParam(int param, Quaternion rotation)
  162. {
  163. }
  164. public override void VehicleFlags(int param, bool remove)
  165. {
  166. }
  167. public override void SetVolumeDetect(int param)
  168. {
  169. }
  170. public override Vector3 CenterOfMass
  171. {
  172. get { return Vector3.Zero; }
  173. }
  174. public override Vector3 GeometricCenter
  175. {
  176. get { return Vector3.Zero; }
  177. }
  178. public override Vector3 Velocity
  179. {
  180. get { return _velocity; }
  181. set { _velocity = value; }
  182. }
  183. public override float CollisionScore
  184. {
  185. get { return 0f; }
  186. set { }
  187. }
  188. public override bool Kinematic
  189. {
  190. get { return false; }
  191. set { }
  192. }
  193. public override Quaternion Orientation
  194. {
  195. get { return Quaternion.Identity; }
  196. set { }
  197. }
  198. public override Vector3 Acceleration
  199. {
  200. get { return _acceleration; }
  201. }
  202. public void SetAcceleration(Vector3 accel)
  203. {
  204. _acceleration = accel;
  205. }
  206. public override void AddForce(Vector3 force, bool pushforce)
  207. {
  208. }
  209. public override Vector3 Torque
  210. {
  211. get { return Vector3.Zero; }
  212. set { return; }
  213. }
  214. public override void AddAngularForce(Vector3 force, bool pushforce)
  215. {
  216. }
  217. public override void link(PhysicsActor obj)
  218. {
  219. }
  220. public override void delink()
  221. {
  222. }
  223. public override void LockAngularMotion(Vector3 axis)
  224. {
  225. }
  226. public override void SetMomentum(Vector3 momentum)
  227. {
  228. }
  229. public void Move(float timeStep)
  230. {
  231. Vec3 vec = new Vec3();
  232. vec.X = _velocity.X*timeStep;
  233. vec.Y = _velocity.Y*timeStep;
  234. if (flying)
  235. {
  236. vec.Z = (_velocity.Z)*timeStep;
  237. }
  238. else
  239. {
  240. gravityAccel += -9.8f;
  241. vec.Z = (gravityAccel + _velocity.Z)*timeStep;
  242. }
  243. int res = _character.Move(vec);
  244. if (res == 1)
  245. {
  246. gravityAccel = 0;
  247. }
  248. }
  249. public override PrimitiveBaseShape Shape
  250. {
  251. set { return; }
  252. }
  253. public void UpdatePosition()
  254. {
  255. Vec3 vec = _character.Position;
  256. _position.X = vec.X;
  257. _position.Y = vec.Y;
  258. _position.Z = vec.Z;
  259. }
  260. public override void CrossingFailure()
  261. {
  262. }
  263. public override Vector3 PIDTarget { set { return; } }
  264. public override bool PIDActive { set { return; } }
  265. public override float PIDTau { set { return; } }
  266. public override float PIDHoverHeight { set { return; } }
  267. public override bool PIDHoverActive { set { return; } }
  268. public override PIDHoverType PIDHoverType { set { return; } }
  269. public override float PIDHoverTau { set { return; } }
  270. public override Quaternion APIDTarget
  271. {
  272. set { return; }
  273. }
  274. public override bool APIDActive
  275. {
  276. set { return; }
  277. }
  278. public override float APIDStrength
  279. {
  280. set { return; }
  281. }
  282. public override float APIDDamping
  283. {
  284. set { return; }
  285. }
  286. public override void SubscribeEvents(int ms)
  287. {
  288. }
  289. public override void UnSubscribeEvents()
  290. {
  291. }
  292. public override bool SubscribedEvents()
  293. {
  294. return false;
  295. }
  296. }
  297. }