public void AddParticles(Vector2 position, int count) { var particles = new List <Vector2>(); var velocities = new List <Vector2>(); for (var i = 0; i < count; i++) { particles.Add(new Vector2(position.X + (float)Math.Cos(2 * Math.PI * i / count) * 0.5f, position.Y + (float)Math.Sin(2 * Math.PI * i / count) * 0.5f)); velocities.Add(new Vector2((float)Math.Cos(2 * Math.PI * i / count) * 3.0f, (float)Math.Sin(2 * Math.PI * i / count) * 3.0f)); } Particles = Particles.ToList().Concat(particles).ToArray(); Velocities = Velocities.ToList().Concat(velocities).ToArray(); _velocityBuffer = _velocityBuffer.ToList().Concat(velocities).ToArray(); var tmp = ParticleCount + count; var tmp_arr = new float[tmp, tmp]; for (int i = 0; i < ParticleCount; i++) { for (int j = 0; j < ParticleCount; j++) { tmp_arr [i, j] = _w [i, j]; } } ParticleCount += count; _w = tmp_arr; }
/// <summary> /// Converts the form settings to the actual pitches and velocities /// </summary> /// <param name="bcfs"></param> public BasicChordMidiSettings(BasicChordFormSettings bcfs) { Durations = new List <int>(bcfs.Durations); ChordOffs = new List <bool>(bcfs.ChordOffs); for (int chordIndex = 0; chordIndex < bcfs.Durations.Count; ++chordIndex) { List <byte> midiPitches = new List <byte>(); List <byte> midiVelocities = new List <byte>(); float verticalVelocityFactor = 1.0F; if (bcfs.VerticalVelocityFactors.Count > chordIndex) { verticalVelocityFactor = bcfs.VerticalVelocityFactors[chordIndex]; } if (bcfs.ChordDensities[chordIndex] > 0) { if (bcfs.ChordDensities[chordIndex] == 1) { midiPitches.Add(bcfs.MidiPitches[chordIndex]); midiVelocities.Add(bcfs.Velocities[chordIndex]); } else { midiPitches = GetMidiPitches(chordIndex, bcfs.MidiPitches, bcfs.ChordDensities, bcfs.Inversions, bcfs.InversionIndices); midiVelocities = GetVerticalVelocities(bcfs.Velocities[chordIndex], bcfs.ChordDensities[chordIndex], verticalVelocityFactor); } } MidiPitches.Add(midiPitches); Velocities.Add(midiVelocities); } }
public void BufferNewValue(Pose newPose, float delta) { Vector3 newPosition = newPose.position; Vector3 newVelocity = Vector3.zero; if (delta > Mathf.Epsilon && _previousPosition.HasValue) { newVelocity = (newPosition - _previousPosition.Value) / delta; } int nextWritePos = (_lastWritePos < 0) ? 0 : (_lastWritePos + 1) % _bufferLength; if (Velocities.Count <= nextWritePos) { Velocities.Add(newVelocity); } else { Velocities[nextWritePos] = newVelocity; } _previousPosition = newPosition; _lastWritePos = nextWritePos; }
public void Update(Vector2 position, Vector2 velocity) { Positions.Add(position); ActualPosition = position; Velocities.Add(velocity); ActualVelocity = velocity; }
public static void generateSphereContact(Vector3 spherePosition, float sphereRadius, Vector3 sphereVelocity, int layerMask, ref List <SoftContact> softContacts, ref Dictionary <Rigidbody, Velocities> originalVelocities, Collider temporaryCollider, bool interpretAsEllipsoid = true) { if (temporaryCollider.attachedRigidbody != null && !temporaryCollider.attachedRigidbody.isKinematic) { SoftContact contact = new SoftContact(); contact.body = temporaryCollider.attachedRigidbody; //Store this rigidbody's pre-contact velocities and inverse world inertia tensor Velocities originalBodyVelocities; if (!originalVelocities.TryGetValue(contact.body, out originalBodyVelocities)) { originalBodyVelocities = new Velocities(); originalBodyVelocities.velocity = contact.body.velocity; originalBodyVelocities.angularVelocity = contact.body.angularVelocity; Matrix4x4 tensorRotation = Matrix4x4.TRS(Vector3.zero, contact.body.rotation * contact.body.inertiaTensorRotation, Vector3.one); Matrix4x4 worldInertiaTensor = (tensorRotation * Matrix4x4.Scale(contact.body.inertiaTensor) * tensorRotation.inverse); originalBodyVelocities.invWorldInertiaTensor = worldInertiaTensor.inverse; originalVelocities.Add(contact.body, originalBodyVelocities); //Premptively apply the force due to gravity BEFORE soft contact //so soft contact can factor it in during the collision solve if (contact.body.useGravity) { contact.body.AddForce(-Physics.gravity, ForceMode.Acceleration); contact.body.velocity += Physics.gravity * Time.fixedDeltaTime; } } if (interpretAsEllipsoid || temporaryCollider is MeshCollider) { //First get the world spherical normal contact.normal = (temporaryCollider.bounds.center - spherePosition).normalized; //Then divide by the world extends squared to get the world ellipsoidal normal Vector3 colliderExtentsSquared = Vector3.Scale(temporaryCollider.bounds.extents, (temporaryCollider.bounds.extents)); contact.normal = new Vector3(contact.normal.x / colliderExtentsSquared.x, contact.normal.y / colliderExtentsSquared.y, contact.normal.z / colliderExtentsSquared.z).normalized; } else { //Else, use the analytic support functions that we have for boxes and capsules to generate the normal Vector3 objectLocalBoneCenter = temporaryCollider.transform.InverseTransformPoint(spherePosition); Vector3 objectPoint = temporaryCollider.transform.TransformPoint(temporaryCollider.ClosestPointOnSurface(objectLocalBoneCenter)); contact.normal = (objectPoint - spherePosition).normalized * (temporaryCollider.IsPointInside(objectLocalBoneCenter) ? -1f : 1f); } contact.position = spherePosition + (contact.normal * sphereRadius); contact.velocity = sphereVelocity; contact.invWorldInertiaTensor = originalBodyVelocities.invWorldInertiaTensor; softContacts.Add(contact); } }
public void AddParticle(Vector2[] positions, float life) { var l = new float[positions.Length]; for (var i = 0; i < positions.Length; i++) { l[i] = life; } Velocities.Upload(header, new Vector2[positions.Length]); Positions.Upload(header, positions); Lifes.Upload(header, l); header = (header + positions.Length) % capacity; }
void FixedUpdate() { Constants.SetConstants(compute, Time.fixedDeltaTime); VelSimulation.Simulate(); Broadphase.FindBand(2f * constants.radius); for (var i = 0; i < 4; i++) { ParticleSolver.Solve(); WallSolver.Solve(); Velocities.ClampMagnitude(); } PosSimulation.Simulate(); BoundsChecker.Check(); Lifes.Simulate(); }
void OnDestroy() { if (Positions != null) { Positions.Dispose(); } if (Velocities != null) { Velocities.Dispose(); } if (Lifes != null) { Lifes.Dispose(); } if (Constants != null) { Constants.Dispose(); } if (Polygons != null) { Polygons.Dispose(); } if (VelSimulation != null) { VelSimulation.Dispose(); } if (PosSimulation != null) { PosSimulation.Dispose(); } if (Collisions != null) { Collisions.Dispose(); } if (PolygonSolver != null) { PolygonSolver.Dispose(); } if (ParticleSolver != null) { ParticleSolver.Dispose(); } if (Combiner != null) { Combiner.Dispose(); } }
void OnDestroy() { if (Positions != null) { Positions.Dispose(); } if (Velocities != null) { Velocities.Dispose(); } if (Lifes != null) { Lifes.Dispose(); } if (Constants != null) { Constants.Dispose(); } if (Walls != null) { Walls.Dispose(); } if (VelSimulation != null) { VelSimulation.Dispose(); } if (PosSimulation != null) { PosSimulation.Dispose(); } if (Broadphase != null) { Broadphase.Dispose(); } if (WallSolver != null) { WallSolver.Dispose(); } if (ParticleSolver != null) { ParticleSolver.Dispose(); } if (Combiner != null) { Combiner.Dispose(); } }
public void Clear() { Bodies.Clear(); Velocities.Clear(); Contacts.Clear(); foreach (var state in ContactStates) { for (int i = 0; i < state.contactCount; i++) { ContactState.Free(state.contacts[i]); } ContactConstraintState.Free(state); // Array.Clear(state.contacts, 0, state.contactCount); } ContactStates.Clear(); }
public override void Draw(DebugViewXNA draw) { if (NextWaypointIndex >= Path.Count && FrontPath != null) { float noop; } float topSpeed = Velocities == null ? MaxSpeed : Velocities.Max(); for (int i = 0; i < Path.Count - 1; i++) { Color color = Color.Lerp(Color.Red, Color.Green, Velocities[i + 1] / topSpeed); draw.DrawSegment(Path[i].Position, Path[i + 1].Position, color, 0.04f); } foreach (int index in stoppingPoints) { draw.DrawCircle(Path[index].Position, 0.2f, Color.Red); } }
void FixedUpdate() { Constants.SetConstants(compute, constants.FixedDeltaTime); VelSimulation.Simulate(); if (particleCollisionEnabled) { Collisions.Detect(2f * constants.radius); } for (var i = 0; i < 10; i++) { PolygonSolver.Solve(); if (particleCollisionEnabled) { ParticleSolver.Solve(); } Velocities.ClampMagnitude(); } PosSimulation.Simulate(); BoundsChecker.Check(); Lifes.Simulate(); }
public void ResetSpeedsBuffer() { Velocities.Clear(); _lastWritePos = -1; _previousPosition = null; }
public override string ToString() { return($"Wizard(id:{Id};Position:{ActualPosition};Velocity:{Velocities.Last()};CanShootSnaffle:{CanShootSnaffle})"); }
public override string ToString() { return($"Snaffle(id:{Id};Position:{ActualPosition};Velocity:{Velocities.Last()};CanBeShooted:{CanBeShooted})"); }
public override string ToString() { return($"Bludger(id:{Id};Position:{ActualPosition};Velocity:{Velocities.Last()};IdLastVictim:{IdLastVictim})"); }
/// <summary> /// Returns a human readable representation of the <c>JointStates</c> values. /// </summary> public override string ToString() => $"Positions: {Positions?.ToString() ?? "null"}; Velocities: {Velocities?.ToString() ?? "null"}; Efforts: {Efforts?.ToString() ?? "null"};";
public void PollingRate(int rate, long fightDuration, bool forceInterpolate) { if (forceInterpolate && Positions.Count == 0) { Positions.Add(new Point3D(short.MinValue, short.MinValue, 0, 0)); Deads.Add(new Tuple <long, long>(0, fightDuration)); } if (Positions.Count == 0) { _start = -1; _end = -1; return; } else if (Positions.Count == 1 && !forceInterpolate) { Velocities = null; return; } List <Point3D> interpolatedPositions = new List <Point3D>(); int tablePos = 0; Point3D currentVelocity = null; for (int i = -50 * rate; i < fightDuration; i += rate) { Point3D pt = Positions[tablePos]; if (i <= pt.Time) { currentVelocity = null; interpolatedPositions.Add(new Point3D(pt.X, pt.Y, pt.Z, i)); } else { if (tablePos == Positions.Count - 1) { interpolatedPositions.Add(new Point3D(pt.X, pt.Y, pt.Z, i)); } else { Point3D ptn = Positions[tablePos + 1]; if (ptn.Time < i) { tablePos++; currentVelocity = null; i -= rate; } else { Point3D last = interpolatedPositions.Last().Time > pt.Time ? interpolatedPositions.Last() : pt; Point3D velocity = Velocities.Find(x => x.Time <= i && x.Time > last.Time); currentVelocity = velocity ?? currentVelocity; if (ptn.Time - pt.Time < 400) { float ratio = (float)(i - pt.Time) / (ptn.Time - pt.Time); interpolatedPositions.Add(new Point3D(pt, ptn, ratio, i)); } else { if (currentVelocity == null || (Math.Abs(currentVelocity.X) <= 1e-1 && Math.Abs(currentVelocity.Y) <= 1e-1)) { interpolatedPositions.Add(new Point3D(last.X, last.Y, last.Z, i)); } else { float ratio = (float)(i - last.Time) / (ptn.Time - last.Time); interpolatedPositions.Add(new Point3D(last, ptn, ratio, i)); } } } } } } Positions = interpolatedPositions.Where(x => x.Time >= 0).ToList(); Velocities = null; }
public void Add(Body body) { body.IslandIndex = Bodies.Count; Bodies.Add(body); Velocities.Add(new VelocityState()); }
public override string ToString() { return($"Entity(id:{Id};Position:{ActualPosition};Velocity:{Velocities.Last()})"); }