View of /trunk/NewtonPlugin/NewtonPrim.cs
Parent Directory
|
Revision Log
Revision 18 -
(download)
(annotate)
Thu Dec 3 22:48:17 2009 UTC (3 years, 5 months ago) by rknop
File size: 12256 byte(s)
Thu Dec 3 22:48:17 2009 UTC (3 years, 5 months ago) by rknop
File size: 12256 byte(s)
Patch to work with opensim trunk ca. 2009/12/03. * prebuild patch updated * Biggest change: Physics engines now use Vector3 instead of PhysicsVector. This was more than a search and replace, because Vector3 has a Multiply(Vector3, float) method, but *not* a Multiply(float, Vector3)... PhysicsVector had both. So I had to rearrange some products. Additionally, Vector3 is a struct whereas PhysicsVector was a class; it turns out that when you pass a struct in C#, it is passed by *value*, but a class is passed by *reference*. (I'm sure somebody thought that was a good idea.) So, a couple of functions (periodicBCs and one that moves characters around) had to be updated to deal with this. I've connected this to a grid for the first time, and am not sure that the boundary conditions are functioning quite as desired. I will continue to futz with it.
/* * Copyright (c) Contributors, http://opensimulator.org/ * See CONTRIBUTORS.TXT for a full list of copyright holders. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the OpenSim Project nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; using System.Collections.Generic; using OpenMetaverse; using Nini.Config; using OpenSim.Framework; using OpenSim.Region.Physics.Manager; using System.Reflection; using log4net; namespace OpenSim.Region.Physics.NewtonPlugin { public class NewtonPrim : PhysicsActor { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private float _mass; private Vector3 _position; private Vector3 _velocity; private Vector3 _oldPosition; private Vector3 _oldVelocity; private Vector3 _acceleration; private Vector3 _oldAcceleration; private Vector3 _jerk; private Vector3 _oldJerk; private Vector3 _size; private Vector3 _a0; private Vector3 _j0; private Vector3 _a1; private Vector3 _a2; private Vector3 _j2; private bool _firstStep; private float _hOld; private Vector3 m_rotationalVelocity = Vector3.Zero; private Quaternion _orientation; private bool iscolliding; private bool isPhysical; public NewtonPrim() { _mass = 1.0f; _velocity = new Vector3(); _position = new Vector3(); _acceleration = new Vector3(); _jerk = new Vector3(); _oldPosition = new Vector3(); _oldVelocity = new Vector3(); _oldAcceleration = new Vector3(); _oldJerk = new Vector3(); _a0 = new Vector3(); _j0 = new Vector3(); _a1 = new Vector3(); _a2 = new Vector3(); _j2 = new Vector3(); _firstStep = true; } public override int PhysicsActorType { get { return (int) ActorTypes.Prim; } set { return; } } public override Vector3 RotationalVelocity { get { return m_rotationalVelocity; } set { m_rotationalVelocity = value; } } public override bool IsPhysical { get { return isPhysical; } set { isPhysical = value; } } public override bool ThrottleUpdates { get { return false; } set { return; } } public override bool IsColliding { get { return iscolliding; } set { iscolliding = value; } } public override bool CollidingGround { get { return false; } set { return; } } public override bool CollidingObj { get { return false; } set { return; } } public override bool Stopped { get { return false; } } public Vector3 OldPosition { get { return _oldPosition; } set { _oldPosition = value; } } public override Vector3 Position { get { return _position; } set { // m_log.InfoFormat("[NEWTONPRIM] Somebody set our position to {0}", value); _position = value; } } public override Vector3 Size { get { return _size; } set { _size = value; } } public override float Mass { get { return _mass; } // set { // m_log.InfoFormat("[NEWTONPRIM] Somebody tried to set mass to {0}, ignored.", // value); // } } // We're the Physics Engine, we control mass!!! // (More to the point : I don't know how to ask // for the out-of-engine mass, and it was getting // set after the object had been enabled physical, // which led to inconsistencies and scariness // with AddForce) public void SetMass(float mass) { // m_log.InfoFormat("[NEWTONPRIM] Somebody tried to set mass to {0}, ignored.",mass); } public override Vector3 Force { get { return Vector3.Zero; } set { return; } } public override int VehicleType { get { return 0; } set { return; } } public override void VehicleFloatParam(int param, float value) { } public override void VehicleVectorParam(int param, Vector3 value) { } public override void VehicleRotationParam(int param, Quaternion rotation) { } public override void SetVolumeDetect(int param) { } public override Vector3 CenterOfMass { get { return Vector3.Zero; } } public override Vector3 GeometricCenter { get { return Vector3.Zero; } } public override PrimitiveBaseShape Shape { set { return; } } public override float Buoyancy { get { return 0f; } set { return; } } public override bool FloatOnWater { set { return; } } public Vector3 OldVelocity { get { return _oldVelocity; } set { _oldVelocity = value; } } public override Vector3 Velocity { get { return _velocity; } set { _velocity = value; } } public override Vector3 Torque { get { return Vector3.Zero; } set { return; } } public override float CollisionScore { get { return 0f; } set { } } public override Quaternion Orientation { get { return _orientation; } set { _orientation = value; } } public Vector3 OldAcceleration { get { return _oldAcceleration; } set { _oldAcceleration = value; } } // set commented out because PhysicsActor.Acceleration doesn't have // a set! public override Vector3 Acceleration { get { return _acceleration; } // set { _acceleration = value; } } public Vector3 Jerk { get { return _jerk; } set { _jerk = value; } } public Vector3 OldJerk { get { return _oldJerk; } set { _oldJerk = value; } } public override bool Kinematic { get { return true; } set { } } public Vector3 A0 { get { return _a0; } set { _a0 = value; } } public Vector3 A1 { get { return _a1; } set { _a1 = value; } } public Vector3 A2 { get { return _a2; } set { _a2 = value; } } public Vector3 J0 { get { return _j0; } set { _j0 = value; } } public Vector3 J2 { get { return _j2; } set { _j2 = value; } } public bool FirstStep { get { return _firstStep; } set { _firstStep = value; } } public float HOld { get { return _hOld; } set { _hOld = value; } } // TODO: Replace with a setter once there is one in PhysicsActor to override public void SetAcceleration(Vector3 accel) { _acceleration = accel; } public void SetOldAcceleration(Vector3 accel) { _oldAcceleration = accel; } public void SaveState() { _oldPosition = _position; _oldVelocity = _velocity; _oldAcceleration = _acceleration; _oldJerk = _jerk; } public override void AddForce(Vector3 force, bool pushforce) { // I don't understand what pushforce is, so I'm going to // ignore it for now...! (rknop 2009/09/14) // (rknop 2009/12/03 -- I seem to remember being told it's // an impulse.) // m_log.InfoFormat("[NEWTONPRIM] Adding force {0} to prim at {1} with mass {2}", // force, _position, _mass); _velocity += force/_mass; // m_log.InfoFormat("[NEWTONPRIM] When done : position = {0}, velocity={1}, acceleration={2}, jerk={3}", // _position, _velocity, _acceleration, _jerk); } public override void AddAngularForce(Vector3 force, bool pushforce) { } public override void SetMomentum(Vector3 momentum) { } public override bool Flying { get { return false; } set { } } public override bool SetAlwaysRun { get { return false; } set { return; } } public override uint LocalID { set { return; } } public override bool Grabbed { set { return; } } public override void link(PhysicsActor obj) { } public override void delink() { } public override void LockAngularMotion(Vector3 axis) { } public override bool Selected { set { return; } } public override void CrossingFailure() { } public override Vector3 PIDTarget { set { return; } } public override bool PIDActive { set { return; } } public override float PIDTau { set { return; } } public override float PIDHoverHeight { set { return; } } public override bool PIDHoverActive { set { return; } } public override PIDHoverType PIDHoverType { set { return; } } public override float PIDHoverTau { set { return; } } public override void SubscribeEvents(int ms) { } public override void UnSubscribeEvents() { } public override bool SubscribedEvents() { return false; } public float KineticEnergy() { float v = Velocity.Length(); return 0.5f * Mass * v * v; } } }
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

