Annotation of /trunk/NewtonPlugin/NewtonPrim.cs
Parent Directory
|
Revision Log
Revision 17 - (view) (download)
| 1 : | adjohn | 2 | /* |
| 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 OpenSim 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 : | using System; | ||
| 29 : | using System.Collections.Generic; | ||
| 30 : | chi11ken | 9 | using OpenMetaverse; |
| 31 : | adjohn | 2 | using Nini.Config; |
| 32 : | using OpenSim.Framework; | ||
| 33 : | using OpenSim.Region.Physics.Manager; | ||
| 34 : | rknop | 15 | using System.Reflection; |
| 35 : | using log4net; | ||
| 36 : | adjohn | 2 | |
| 37 : | namespace OpenSim.Region.Physics.NewtonPlugin | ||
| 38 : | { | ||
| 39 : | public class NewtonPrim : PhysicsActor | ||
| 40 : | { | ||
| 41 : | rknop | 15 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 42 : | chi11ken | 10 | private float _mass; |
| 43 : | private PhysicsVector _position; | ||
| 44 : | adjohn | 2 | private PhysicsVector _velocity; |
| 45 : | private PhysicsVector _oldPosition; | ||
| 46 : | private PhysicsVector _oldVelocity; | ||
| 47 : | private PhysicsVector _acceleration; | ||
| 48 : | private PhysicsVector _oldAcceleration; | ||
| 49 : | private PhysicsVector _jerk; | ||
| 50 : | private PhysicsVector _oldJerk; | ||
| 51 : | private PhysicsVector _size; | ||
| 52 : | chi11ken | 10 | |
| 53 : | private PhysicsVector _a0; | ||
| 54 : | private PhysicsVector _j0; | ||
| 55 : | private PhysicsVector _a1; | ||
| 56 : | private PhysicsVector _a2; | ||
| 57 : | private PhysicsVector _j2; | ||
| 58 : | private bool _firstStep; | ||
| 59 : | private float _hOld; | ||
| 60 : | |||
| 61 : | adjohn | 2 | private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; |
| 62 : | private Quaternion _orientation; | ||
| 63 : | private bool iscolliding; | ||
| 64 : | private bool isPhysical; | ||
| 65 : | |||
| 66 : | public NewtonPrim() | ||
| 67 : | { | ||
| 68 : | chi11ken | 10 | _mass = 1.0f; |
| 69 : | adjohn | 2 | _velocity = new PhysicsVector(); |
| 70 : | _position = new PhysicsVector(); | ||
| 71 : | _acceleration = new PhysicsVector(); | ||
| 72 : | _jerk = new PhysicsVector(); | ||
| 73 : | _oldPosition = new PhysicsVector(); | ||
| 74 : | _oldVelocity = new PhysicsVector(); | ||
| 75 : | _oldAcceleration = new PhysicsVector(); | ||
| 76 : | _oldJerk = new PhysicsVector(); | ||
| 77 : | chi11ken | 10 | |
| 78 : | _a0 = new PhysicsVector(); | ||
| 79 : | _j0 = new PhysicsVector(); | ||
| 80 : | _a1 = new PhysicsVector(); | ||
| 81 : | _a2 = new PhysicsVector(); | ||
| 82 : | _j2 = new PhysicsVector(); | ||
| 83 : | _firstStep = true; | ||
| 84 : | adjohn | 2 | } |
| 85 : | |||
| 86 : | public override int PhysicsActorType | ||
| 87 : | { | ||
| 88 : | get { return (int) ActorTypes.Prim; } | ||
| 89 : | set { return; } | ||
| 90 : | } | ||
| 91 : | |||
| 92 : | public override PhysicsVector RotationalVelocity | ||
| 93 : | { | ||
| 94 : | get { return m_rotationalVelocity; } | ||
| 95 : | set { m_rotationalVelocity = value; } | ||
| 96 : | } | ||
| 97 : | |||
| 98 : | public override bool IsPhysical | ||
| 99 : | { | ||
| 100 : | get { return isPhysical; } | ||
| 101 : | set { isPhysical = value; } | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | public override bool ThrottleUpdates | ||
| 105 : | { | ||
| 106 : | get { return false; } | ||
| 107 : | set { return; } | ||
| 108 : | } | ||
| 109 : | |||
| 110 : | public override bool IsColliding | ||
| 111 : | { | ||
| 112 : | get { return iscolliding; } | ||
| 113 : | set { iscolliding = value; } | ||
| 114 : | } | ||
| 115 : | |||
| 116 : | public override bool CollidingGround | ||
| 117 : | { | ||
| 118 : | get { return false; } | ||
| 119 : | set { return; } | ||
| 120 : | } | ||
| 121 : | |||
| 122 : | public override bool CollidingObj | ||
| 123 : | { | ||
| 124 : | get { return false; } | ||
| 125 : | set { return; } | ||
| 126 : | } | ||
| 127 : | |||
| 128 : | public override bool Stopped | ||
| 129 : | { | ||
| 130 : | get { return false; } | ||
| 131 : | } | ||
| 132 : | |||
| 133 : | public PhysicsVector OldPosition | ||
| 134 : | { | ||
| 135 : | get { return _oldPosition; } | ||
| 136 : | set { _oldPosition = value; } | ||
| 137 : | } | ||
| 138 : | |||
| 139 : | public override PhysicsVector Position | ||
| 140 : | { | ||
| 141 : | get { return _position; } | ||
| 142 : | rknop | 17 | set { |
| 143 : | // m_log.InfoFormat("[NEWTONPRIM] Somebody set our position to {0}", value); | ||
| 144 : | _position = value; | ||
| 145 : | } | ||
| 146 : | adjohn | 2 | } |
| 147 : | |||
| 148 : | public override PhysicsVector Size | ||
| 149 : | { | ||
| 150 : | get { return _size; } | ||
| 151 : | set { _size = value; } | ||
| 152 : | } | ||
| 153 : | |||
| 154 : | public override float Mass | ||
| 155 : | { | ||
| 156 : | get { return _mass; } | ||
| 157 : | rknop | 17 | // set { |
| 158 : | // m_log.InfoFormat("[NEWTONPRIM] Somebody tried to set mass to {0}, ignored.", | ||
| 159 : | // value); | ||
| 160 : | // } | ||
| 161 : | chi11ken | 10 | } |
| 162 : | adjohn | 2 | |
| 163 : | rknop | 17 | // We're the Physics Engine, we control mass!!! |
| 164 : | // (More to the point : I don't know how to ask | ||
| 165 : | // for the out-of-engine mass, and it was getting | ||
| 166 : | // set after the object had been enabled physical, | ||
| 167 : | // which led to inconsistencies and scariness | ||
| 168 : | // with AddForce) | ||
| 169 : | |||
| 170 : | chi11ken | 10 | public void SetMass(float mass) |
| 171 : | { | ||
| 172 : | rknop | 17 | // m_log.InfoFormat("[NEWTONPRIM] Somebody tried to set mass to {0}, ignored.",mass); |
| 173 : | adjohn | 2 | } |
| 174 : | |||
| 175 : | chi11ken | 10 | public override PhysicsVector Force |
| 176 : | adjohn | 2 | { |
| 177 : | get { return PhysicsVector.Zero; } | ||
| 178 : | chi11ken | 3 | set { return; } |
| 179 : | adjohn | 2 | } |
| 180 : | |||
| 181 : | chi11ken | 9 | public override int VehicleType |
| 182 : | { | ||
| 183 : | get { return 0; } | ||
| 184 : | set { return; } | ||
| 185 : | } | ||
| 186 : | |||
| 187 : | public override void VehicleFloatParam(int param, float value) | ||
| 188 : | { | ||
| 189 : | } | ||
| 190 : | |||
| 191 : | public override void VehicleVectorParam(int param, PhysicsVector value) | ||
| 192 : | { | ||
| 193 : | } | ||
| 194 : | |||
| 195 : | public override void VehicleRotationParam(int param, Quaternion rotation) | ||
| 196 : | { | ||
| 197 : | } | ||
| 198 : | |||
| 199 : | public override void SetVolumeDetect(int param) | ||
| 200 : | { | ||
| 201 : | } | ||
| 202 : | |||
| 203 : | adjohn | 2 | public override PhysicsVector CenterOfMass |
| 204 : | { | ||
| 205 : | get { return PhysicsVector.Zero; } | ||
| 206 : | } | ||
| 207 : | |||
| 208 : | public override PhysicsVector GeometricCenter | ||
| 209 : | { | ||
| 210 : | get { return PhysicsVector.Zero; } | ||
| 211 : | } | ||
| 212 : | |||
| 213 : | public override PrimitiveBaseShape Shape | ||
| 214 : | { | ||
| 215 : | set { return; } | ||
| 216 : | } | ||
| 217 : | |||
| 218 : | public override float Buoyancy | ||
| 219 : | { | ||
| 220 : | get { return 0f; } | ||
| 221 : | set { return; } | ||
| 222 : | } | ||
| 223 : | |||
| 224 : | public override bool FloatOnWater | ||
| 225 : | { | ||
| 226 : | set { return; } | ||
| 227 : | } | ||
| 228 : | |||
| 229 : | public PhysicsVector OldVelocity | ||
| 230 : | { | ||
| 231 : | get { return _oldVelocity; } | ||
| 232 : | set { _oldVelocity = value; } | ||
| 233 : | } | ||
| 234 : | |||
| 235 : | public override PhysicsVector Velocity | ||
| 236 : | { | ||
| 237 : | get { return _velocity; } | ||
| 238 : | set { _velocity = value; } | ||
| 239 : | } | ||
| 240 : | |||
| 241 : | chi11ken | 10 | public override PhysicsVector Torque |
| 242 : | { | ||
| 243 : | get { return PhysicsVector.Zero; } | ||
| 244 : | set { return; } | ||
| 245 : | } | ||
| 246 : | |||
| 247 : | adjohn | 2 | public override float CollisionScore |
| 248 : | { | ||
| 249 : | get { return 0f; } | ||
| 250 : | set { } | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | public override Quaternion Orientation | ||
| 254 : | { | ||
| 255 : | get { return _orientation; } | ||
| 256 : | set { _orientation = value; } | ||
| 257 : | } | ||
| 258 : | |||
| 259 : | public PhysicsVector OldAcceleration | ||
| 260 : | { | ||
| 261 : | get { return _oldAcceleration; } | ||
| 262 : | set { _oldAcceleration = value; } | ||
| 263 : | } | ||
| 264 : | |||
| 265 : | rknop | 15 | // set commented out because PhysicsActor.Acceleration doesn't have |
| 266 : | // a set! | ||
| 267 : | adjohn | 2 | public override PhysicsVector Acceleration |
| 268 : | { | ||
| 269 : | get { return _acceleration; } | ||
| 270 : | rknop | 15 | // set { _acceleration = value; } |
| 271 : | adjohn | 2 | } |
| 272 : | |||
| 273 : | public PhysicsVector Jerk | ||
| 274 : | { | ||
| 275 : | chi11ken | 10 | get { return _jerk; } |
| 276 : | set { _jerk = value; } | ||
| 277 : | adjohn | 2 | } |
| 278 : | |||
| 279 : | public PhysicsVector OldJerk | ||
| 280 : | { | ||
| 281 : | chi11ken | 10 | get { return _oldJerk; } |
| 282 : | set { _oldJerk = value; } | ||
| 283 : | adjohn | 2 | } |
| 284 : | |||
| 285 : | public override bool Kinematic | ||
| 286 : | { | ||
| 287 : | get { return true; } | ||
| 288 : | set { } | ||
| 289 : | } | ||
| 290 : | |||
| 291 : | chi11ken | 10 | public PhysicsVector A0 |
| 292 : | { | ||
| 293 : | get { return _a0; } | ||
| 294 : | set { _a0 = value; } | ||
| 295 : | } | ||
| 296 : | adjohn | 2 | |
| 297 : | chi11ken | 10 | public PhysicsVector A1 |
| 298 : | { | ||
| 299 : | get { return _a1; } | ||
| 300 : | set { _a1 = value; } | ||
| 301 : | } | ||
| 302 : | |||
| 303 : | public PhysicsVector A2 | ||
| 304 : | { | ||
| 305 : | get { return _a2; } | ||
| 306 : | set { _a2 = value; } | ||
| 307 : | } | ||
| 308 : | |||
| 309 : | public PhysicsVector J0 | ||
| 310 : | { | ||
| 311 : | get { return _j0; } | ||
| 312 : | set { _j0 = value; } | ||
| 313 : | } | ||
| 314 : | |||
| 315 : | public PhysicsVector J2 | ||
| 316 : | { | ||
| 317 : | get { return _j2; } | ||
| 318 : | set { _j2 = value; } | ||
| 319 : | } | ||
| 320 : | |||
| 321 : | public bool FirstStep | ||
| 322 : | { | ||
| 323 : | get { return _firstStep; } | ||
| 324 : | set { _firstStep = value; } | ||
| 325 : | } | ||
| 326 : | |||
| 327 : | public float HOld | ||
| 328 : | { | ||
| 329 : | get { return _hOld; } | ||
| 330 : | set { _hOld = value; } | ||
| 331 : | } | ||
| 332 : | |||
| 333 : | adjohn | 2 | // TODO: Replace with a setter once there is one in PhysicsActor to override |
| 334 : | public void SetAcceleration(PhysicsVector accel) | ||
| 335 : | { | ||
| 336 : | _acceleration = accel; | ||
| 337 : | } | ||
| 338 : | |||
| 339 : | public void SetOldAcceleration(PhysicsVector accel) | ||
| 340 : | { | ||
| 341 : | chi11ken | 10 | _oldAcceleration = accel; |
| 342 : | adjohn | 2 | } |
| 343 : | |||
| 344 : | public void SaveState() | ||
| 345 : | { | ||
| 346 : | chi11ken | 10 | _oldPosition = _position; |
| 347 : | _oldVelocity = _velocity; | ||
| 348 : | _oldAcceleration = _acceleration; | ||
| 349 : | _oldJerk = _jerk; | ||
| 350 : | } | ||
| 351 : | adjohn | 2 | |
| 352 : | chi11ken | 10 | public override void AddForce(PhysicsVector force, bool pushforce) |
| 353 : | { | ||
| 354 : | rknop | 15 | // I don't understand what pushforce is, so I'm going to |
| 355 : | // ignore it for now...! (rknop 2009/09/14) | ||
| 356 : | |||
| 357 : | rknop | 17 | // m_log.InfoFormat("[NEWTONPRIM] Adding force {0} to prim at {1} with mass {2}", |
| 358 : | // force, _position, _mass); | ||
| 359 : | rknop | 15 | _velocity += force/_mass; |
| 360 : | rknop | 17 | // m_log.InfoFormat("[NEWTONPRIM] When done : position = {0}, velocity={1}, acceleration={2}, jerk={3}", |
| 361 : | // _position, _velocity, _acceleration, _jerk); | ||
| 362 : | adjohn | 2 | } |
| 363 : | chi11ken | 10 | |
| 364 : | public override void AddAngularForce(PhysicsVector force, bool pushforce) | ||
| 365 : | adjohn | 2 | { |
| 366 : | } | ||
| 367 : | |||
| 368 : | public override void SetMomentum(PhysicsVector momentum) | ||
| 369 : | { | ||
| 370 : | } | ||
| 371 : | |||
| 372 : | public override bool Flying | ||
| 373 : | { | ||
| 374 : | get { return false; } | ||
| 375 : | set { } | ||
| 376 : | } | ||
| 377 : | |||
| 378 : | public override bool SetAlwaysRun | ||
| 379 : | { | ||
| 380 : | get { return false; } | ||
| 381 : | set { return; } | ||
| 382 : | } | ||
| 383 : | |||
| 384 : | public override uint LocalID | ||
| 385 : | { | ||
| 386 : | set { return; } | ||
| 387 : | } | ||
| 388 : | |||
| 389 : | public override bool Grabbed | ||
| 390 : | { | ||
| 391 : | set { return; } | ||
| 392 : | } | ||
| 393 : | |||
| 394 : | public override void link(PhysicsActor obj) | ||
| 395 : | { | ||
| 396 : | } | ||
| 397 : | |||
| 398 : | public override void delink() | ||
| 399 : | { | ||
| 400 : | } | ||
| 401 : | |||
| 402 : | public override void LockAngularMotion(PhysicsVector axis) | ||
| 403 : | { | ||
| 404 : | } | ||
| 405 : | |||
| 406 : | public override bool Selected | ||
| 407 : | { | ||
| 408 : | set { return; } | ||
| 409 : | } | ||
| 410 : | |||
| 411 : | public override void CrossingFailure() | ||
| 412 : | { | ||
| 413 : | } | ||
| 414 : | |||
| 415 : | public override PhysicsVector PIDTarget | ||
| 416 : | { | ||
| 417 : | set { return; } | ||
| 418 : | } | ||
| 419 : | |||
| 420 : | public override bool PIDActive | ||
| 421 : | { | ||
| 422 : | set { return; } | ||
| 423 : | } | ||
| 424 : | |||
| 425 : | public override float PIDTau | ||
| 426 : | { | ||
| 427 : | set { return; } | ||
| 428 : | } | ||
| 429 : | |||
| 430 : | chi11ken | 12 | public override float PIDHoverHeight |
| 431 : | { | ||
| 432 : | set { return; } | ||
| 433 : | } | ||
| 434 : | |||
| 435 : | public override bool PIDHoverActive | ||
| 436 : | { | ||
| 437 : | set { return; } | ||
| 438 : | } | ||
| 439 : | |||
| 440 : | public override PIDHoverType PIDHoverType | ||
| 441 : | { | ||
| 442 : | set { return; } | ||
| 443 : | } | ||
| 444 : | |||
| 445 : | public override float PIDHoverTau | ||
| 446 : | { | ||
| 447 : | set { return; } | ||
| 448 : | } | ||
| 449 : | |||
| 450 : | adjohn | 2 | public override void SubscribeEvents(int ms) |
| 451 : | { | ||
| 452 : | } | ||
| 453 : | |||
| 454 : | public override void UnSubscribeEvents() | ||
| 455 : | { | ||
| 456 : | } | ||
| 457 : | |||
| 458 : | public override bool SubscribedEvents() | ||
| 459 : | { | ||
| 460 : | return false; | ||
| 461 : | } | ||
| 462 : | |||
| 463 : | public float KineticEnergy() | ||
| 464 : | { | ||
| 465 : | chi11ken | 10 | float v = Velocity.length(); |
| 466 : | return 0.5f * Mass * v * v; | ||
| 467 : | adjohn | 2 | } |
| 468 : | } | ||
| 469 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

