public Particle(int Dim, double[] startPos = null, double startAngl = 0.0) { SpatialDim = Dim; // Particle history // ============================= for (int i = 0; i < m_HistoryLength; i++) { Position.Add(new double[Dim]); Angle.Add(new double()); TranslationalVelocity.Add(new double[Dim]); TranslationalAcceleration.Add(new double[Dim]); RotationalVelocity.Add(new double()); RotationalAcceleration.Add(new double()); HydrodynamicForces.Add(new double[Dim]); HydrodynamicTorque.Add(new double()); } // ============================= if (startPos == null) { startPos = new double[Dim]; } Position[0] = startPos; Position[1] = startPos; //From degree to radiant Angle[0] = StartingAngle = startAngl * 2 * Math.PI / 360; Angle[1] = startAngl * 2 * Math.PI / 360; //UpdateLevelSetFunction(); }
public override string ToString() { StringBuilder __sb = new StringBuilder("MVelocityConstraint("); __sb.Append(", ParentObjectID: "); __sb.Append(ParentObjectID); if (ParentToConstraint != null && __isset.ParentToConstraint) { __sb.Append(", ParentToConstraint: "); __sb.Append(ParentToConstraint == null ? "<null>" : ParentToConstraint.ToString()); } if (TranslationalVelocity != null && __isset.TranslationalVelocity) { __sb.Append(", TranslationalVelocity: "); __sb.Append(TranslationalVelocity == null ? "<null>" : TranslationalVelocity.ToString()); } if (RotationalVelocity != null && __isset.RotationalVelocity) { __sb.Append(", RotationalVelocity: "); __sb.Append(RotationalVelocity == null ? "<null>" : RotationalVelocity.ToString()); } if (__isset.WeightingFactor) { __sb.Append(", WeightingFactor: "); __sb.Append(WeightingFactor); } __sb.Append(")"); return(__sb.ToString()); }
/// <summary> /// The standard description of motion including hydrodynamics. /// </summary> /// <param name="gravity"> /// The gravity (volume forces) acting on the particle. /// </param> /// <param name="density"> /// The density of the particle. /// </param> public Motion(Vector gravity, double density) { if (gravity.IsNullOrEmpty()) { gravity = new Vector(0, 0); } Gravity = new Vector(gravity); Density = density; for (int i = 0; i < NumberOfHistoryEntries; i++) { Position.Add(new Vector(SpatialDim)); TranslationalVelocity.Add(new Vector(SpatialDim)); TranslationalAcceleration.Add(new Vector(SpatialDim)); HydrodynamicForces.Add(new Vector(SpatialDim)); Angle.Add(new double()); RotationalVelocity.Add(new double()); RotationalAcceleration.Add(new double()); HydrodynamicTorque.Add(new double()); } }
/// <summary> /// Updates the reported position and velocity. This essentially sends the data up to ScenePresence. /// </summary> public void UpdatePositionAndVelocity() { if (Body == null) { return; } //int val = Environment.TickCount; CheckIfStandingOnObject(); //m_log.DebugFormat("time:{0}", Environment.TickCount - val); //IsColliding = Body.checkCollideWith(m_parent_scene.TerrainBody); tempTrans1.Dispose(); tempTrans1 = Body.getInterpolationWorldTransform(); tempVector1.Dispose(); tempVector1 = tempTrans1.getOrigin(); tempVector2.Dispose(); tempVector2 = Body.getInterpolationLinearVelocity(); // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! Vector3 vec = new Vector3(tempVector1.getX(), tempVector1.getY(), tempVector1.getZ()); // kluge to keep things in bounds. ODE lets dead avatars drift away (they should be removed!) if (vec.X < -10.0f) { vec.X = 0.0f; } if (vec.Y < -10.0f) { vec.Y = 0.0f; } if (vec.X > m_parent_scene.m_region.RegionSizeX + 10.2f) { vec.X = m_parent_scene.m_region.RegionSizeX + 10.2f; } if (vec.Y > m_parent_scene.m_region.RegionSizeY + 10.2f) { vec.Y = m_parent_scene.m_region.RegionSizeY + 10.2f; } m_position.X = vec.X; m_position.Y = vec.Y; m_position.Z = vec.Z; // Did we move last? = zeroflag // This helps keep us from sliding all over if (m_zeroFlag) { m_velocity.X = 0.0f; m_velocity.Y = 0.0f; m_velocity.Z = 0.0f; // Did we send out the 'stopped' message? if (!m_lastUpdateSent) { m_lastUpdateSent = true; base.RequestPhysicsterseUpdate(); } //Tell any listeners that we've stopped base.TriggerMovementUpdate(); } else { m_lastUpdateSent = false; vec = new Vector3(tempVector2.getX(), tempVector2.getY(), tempVector2.getZ()); m_velocity.X = (vec.X); m_velocity.Y = (vec.Y); m_velocity.Z = (vec.Z); //m_log.Debug(m_target_velocity); if (m_velocity.Z < -6 && !m_hackSentFall) { m_hackSentFall = true; m_pidControllerActive = false; } else if (m_flying && !m_hackSentFly) { //m_hackSentFly = true; //base.SendCollisionUpdate(new CollisionEventUpdate()); } else { m_hackSentFly = false; m_hackSentFall = false; } const float VELOCITY_TOLERANCE = 0.001f; const float POSITION_TOLERANCE = 0.05f; //Check to see whether we need to trigger the significant movement method in the presence if (!RotationalVelocity.ApproxEquals(m_lastRotationalVelocity, VELOCITY_TOLERANCE) || !Velocity.ApproxEquals(m_lastVelocity, VELOCITY_TOLERANCE) || !Position.ApproxEquals(m_lastPosition, POSITION_TOLERANCE)) { // Update the "last" values m_lastPosition = Position; m_lastRotationalVelocity = RotationalVelocity; m_lastVelocity = Velocity; base.RequestPhysicsterseUpdate(); base.TriggerSignificantMovement(); } //Tell any listeners about the new info base.TriggerMovementUpdate(); } if (Body != null) { if (Body.getFriction() < 0.9f) { Body.setFriction(0.9f); } } //if (Body != null) // Body.clearForces(); }
public void Write(TProtocol oprot) { oprot.IncrementRecursionDepth(); try { TStruct struc = new TStruct("MVelocityConstraint"); oprot.WriteStructBegin(struc); TField field = new TField(); if (ParentObjectID == null) { throw new TProtocolException(TProtocolException.INVALID_DATA, "required field ParentObjectID not set"); } field.Name = "ParentObjectID"; field.Type = TType.String; field.ID = 1; oprot.WriteFieldBegin(field); oprot.WriteString(ParentObjectID); oprot.WriteFieldEnd(); if (ParentToConstraint != null && __isset.ParentToConstraint) { field.Name = "ParentToConstraint"; field.Type = TType.Struct; field.ID = 2; oprot.WriteFieldBegin(field); ParentToConstraint.Write(oprot); oprot.WriteFieldEnd(); } if (TranslationalVelocity != null && __isset.TranslationalVelocity) { field.Name = "TranslationalVelocity"; field.Type = TType.Struct; field.ID = 3; oprot.WriteFieldBegin(field); TranslationalVelocity.Write(oprot); oprot.WriteFieldEnd(); } if (RotationalVelocity != null && __isset.RotationalVelocity) { field.Name = "RotationalVelocity"; field.Type = TType.Struct; field.ID = 4; oprot.WriteFieldBegin(field); RotationalVelocity.Write(oprot); oprot.WriteFieldEnd(); } if (__isset.WeightingFactor) { field.Name = "WeightingFactor"; field.Type = TType.Double; field.ID = 5; oprot.WriteFieldBegin(field); oprot.WriteDouble(WeightingFactor); oprot.WriteFieldEnd(); } oprot.WriteFieldStop(); oprot.WriteStructEnd(); } finally { oprot.DecrementRecursionDepth(); } }