mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
* Physics worlds * Paul's a good boy * Build working * Ingame and not lagging to hell * Why didn't you commit ahhhhh * Hard collisions working * Solver parity * Decent broadphase work done * BroadPhase outline done * BroadPhase working * waiting for pvs * Fix static PVS AABB * Stop static bodies from awakening * Optimise a bunch of stuff * Even more broadphase stuff * I'm fucking stupid * Optimise fixture updates * Collision solver start * Building * A is for Argumentative * Fix contact caching island flags * Circle shapes actually workeded * Damping * DS2 consumables only * Slightly more stable * Even slightlier more stablier * VV your heart out * Initial joint support * 90% of joints I just wanted to push as I'd scream if I lost progress * JOINT PURGATORY * Joints barely functional lmao * Okay these joints slightly more functional * Remove station FrictionJoint * Also that * Some Box2D ports * Cleanup mass * Edge shape * Active contacts * Fix active contacts * Optimise active contacts even more * Boxes be stacking * I would die for smug oh my fucking god * In which everything is fixed * Distance joints working LETS GO * Remove frequency on distancejoint * Fix some stuff and break joints * Crashing fixed mehbeh * ICollideSpecial and more resilience * auto-clear * showbb vera * Slap that TODO in there * Fix restartround crash * Random fixes * Fix fixture networking * Add intersection method for broadphase * Fix contacts * Licenses done * Optimisations * Fix wall clips * Config caching for island * allocations optimisations * Optimise casts * Optimise events queue for physics * Contact manager optimisations * Optimise controllers * Sloth joint or something idk * Controller graph * Remove content cvar * Random cleanup * Finally remove VirtualController * Manifold structs again * Optimise this absolute retardation * Optimise * fix license * Cleanup physics interface * AHHHHHHHHHHHHH * Fix collisions again * snivybus * Fix potential nasty manifold bug * Tests go snivy * Disable prediction for now * Spans * Fix ShapeTypes * fixes * ch ch changeesss * Kinematic idea * Prevent static bodies from waking * Pass WorldAABB to MoveEvent * Fix collisions * manifold structs fucking WOOORRKKKINNGGG * Better pushing * Fix merge ickies * Optimise MoveEvents * Use event for collisions performance * Fix content tests * Do not research tests * Fix most conflicts * Paul's trying to kill me * Maybe collisions work idk * Make us whole again * Smug is also trying to kill me * nani * shitty collisions * Settling * Do not research collisions * SHIP IT * Fix joints * PVS moment * Fix other assert * Fix locker collisions * serializable sleeptime * Aether2D contacts * Physics is no longer crashing (and burning) * Add to the TODO list Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
127 lines
4.0 KiB
C#
127 lines
4.0 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Robust.Shared.Physics.Dynamics.Joints
|
|
{
|
|
[Serializable, NetSerializable]
|
|
public class SlothJoint : Joint
|
|
{
|
|
// Solver temp
|
|
[NonSerialized] private int _indexA;
|
|
[NonSerialized] private int _indexB;
|
|
[NonSerialized] private Vector2 _rA;
|
|
[NonSerialized] private Vector2 _rB;
|
|
[NonSerialized] private Vector2 _localCenterA;
|
|
[NonSerialized] private Vector2 _localCenterB;
|
|
[NonSerialized] private float _invMassA;
|
|
[NonSerialized] private float _invMassB;
|
|
[NonSerialized] private float _invIA;
|
|
[NonSerialized] private float _invIB;
|
|
[NonSerialized] private float _mass;
|
|
[NonSerialized] private float _currentLength;
|
|
[NonSerialized] private float _softMass;
|
|
|
|
public SlothJoint(PhysicsComponent bodyA, PhysicsComponent bodyB) : base(bodyA, bodyB)
|
|
{
|
|
}
|
|
|
|
public override JointType JointType => JointType.Distance;
|
|
|
|
[field:NonSerialized]
|
|
public override Vector2 WorldAnchorA { get; set; }
|
|
[field:NonSerialized]
|
|
public override Vector2 WorldAnchorB { get; set; }
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public float MaxLength
|
|
{
|
|
get => _maxLength;
|
|
set
|
|
{
|
|
if (MathHelper.CloseTo(value, _maxLength)) return;
|
|
|
|
_maxLength = value;
|
|
Dirty();
|
|
}
|
|
}
|
|
|
|
private float _maxLength;
|
|
|
|
public override Vector2 GetReactionForce(float invDt)
|
|
{
|
|
// TODO: Need break force
|
|
return Vector2.Zero;
|
|
}
|
|
|
|
public override float GetReactionTorque(float invDt)
|
|
{
|
|
return 0f;
|
|
}
|
|
|
|
internal override void InitVelocityConstraints(SolverData data)
|
|
{
|
|
_indexA = BodyA.IslandIndex;
|
|
_indexB = BodyB.IslandIndex;
|
|
_localCenterA = Vector2.Zero; //BodyA->m_sweep.localCenter;
|
|
_localCenterB = Vector2.Zero; //BodyB->m_sweep.localCenter;
|
|
_invMassA = BodyA.InvMass;
|
|
_invMassB = BodyB.InvMass;
|
|
_invIA = BodyA.InvI;
|
|
_invIB = BodyB.InvI;
|
|
|
|
_currentLength = (data.Positions[_indexA] - data.Positions[_indexB]).Length;
|
|
|
|
_softMass = _mass;
|
|
}
|
|
|
|
internal override void SolveVelocityConstraints(SolverData data)
|
|
{
|
|
if (_currentLength < _maxLength) return;
|
|
|
|
var posA = data.Positions[_indexA];
|
|
var posB = data.Positions[_indexB];
|
|
|
|
var vA = data.LinearVelocities[_indexA];
|
|
float wA = data.AngularVelocities[_indexA];
|
|
var vB = data.LinearVelocities[_indexB];
|
|
float wB = data.AngularVelocities[_indexB];
|
|
|
|
var correctionDistance = _maxLength - _currentLength;
|
|
|
|
//var P = _u * impulse;
|
|
//vA -= P * _invMassA;
|
|
//wA -= _invIA * Vector2.Cross(_rA, P);
|
|
//vB += P * _invMassB;
|
|
//wB += _invIB * Vector2.Cross(_rB, P);
|
|
}
|
|
|
|
internal override bool SolvePositionConstraints(SolverData data)
|
|
{
|
|
if (_currentLength < _maxLength) return true;
|
|
|
|
var posA = data.Positions[_indexA];
|
|
var posB = data.Positions[_indexB];
|
|
|
|
var vA = data.LinearVelocities[_indexA];
|
|
float wA = data.AngularVelocities[_indexA];
|
|
var vB = data.LinearVelocities[_indexB];
|
|
float wB = data.AngularVelocities[_indexB];
|
|
|
|
var correctionDistance = _maxLength - _currentLength;
|
|
|
|
data.Positions[_indexB] -= correctionDistance;
|
|
|
|
//var P = _u * impulse;
|
|
//vA -= P * _invMassA;
|
|
//wA -= _invIA * Vector2.Cross(_rA, P);
|
|
//vB += P * _invMassB;
|
|
//wB += _invIB * Vector2.Cross(_rB, P);
|
|
return true;
|
|
}
|
|
}
|
|
}
|