From adad302ba09344979c6ccde262a984288daadbcb Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Mon, 13 Dec 2021 13:26:54 -0800 Subject: [PATCH] use proper pos/rot stuff --- .../TransformSync/AnglerTransformSync.cs | 16 +++++------ .../TransformSync/JellyfishTransformSync.cs | 27 +++++-------------- .../TransformSync/ShipTransformSync.cs | 8 +++--- .../Rigidbodies/SectoredRigidbodySync.cs | 20 +++++++------- .../Transforms/SectoredTransformSync.cs | 12 ++++----- .../Rigidbodies/UnsectoredRigidbodySync.cs | 20 +++++++------- .../Transforms/UnsectoredTransformSync.cs | 12 ++++----- .../TransformSync/PlayerProbeSync.cs | 4 +-- .../TransformSync/OccasionalTransformSync.cs | 24 ++++++++--------- 9 files changed, 64 insertions(+), 79 deletions(-) diff --git a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs index 38b2a731..c3328045 100644 --- a/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs +++ b/QSB/Anglerfish/TransformSync/AnglerTransformSync.cs @@ -79,28 +79,28 @@ namespace QSB.Anglerfish.TransformSync || !QSBCore.ShowLinesInDebug || !IsReady || ReferenceTransform == null - || ((OWRigidbody)AttachedObject).IsSuspended()) + || AttachedObject.IsSuspended()) { return; } base.OnRenderObject(); - Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._arrivalDistance, Color.blue); - Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._pursueDistance, Color.red); - Popcron.Gizmos.Sphere(AttachedObject.transform.position, _qsbAngler.AttachedObject._escapeDistance, Color.yellow); - Popcron.Gizmos.Sphere(AttachedObject.transform.position + Popcron.Gizmos.Sphere(AttachedObject.GetPosition(), _qsbAngler.AttachedObject._arrivalDistance, Color.blue); + Popcron.Gizmos.Sphere(AttachedObject.GetPosition(), _qsbAngler.AttachedObject._pursueDistance, Color.red); + Popcron.Gizmos.Sphere(AttachedObject.GetPosition(), _qsbAngler.AttachedObject._escapeDistance, Color.yellow); + Popcron.Gizmos.Sphere(AttachedObject.GetPosition() + AttachedObject.transform.TransformDirection(_qsbAngler.AttachedObject._mouthOffset), 3, Color.grey); if (_qsbAngler.TargetTransform != null) { - Popcron.Gizmos.Line(_qsbAngler.TargetTransform.position, ((OWRigidbody)AttachedObject).GetPosition(), Color.gray); + Popcron.Gizmos.Line(_qsbAngler.TargetTransform.position, AttachedObject.GetPosition(), Color.gray); Popcron.Gizmos.Line(_qsbAngler.TargetTransform.position, _qsbAngler.TargetTransform.position + _qsbAngler.TargetVelocity, Color.green); - Popcron.Gizmos.Line(((OWRigidbody)AttachedObject).GetPosition(), _qsbAngler.AttachedObject._targetPos, Color.red); + Popcron.Gizmos.Line(AttachedObject.GetPosition(), _qsbAngler.AttachedObject._targetPos, Color.red); Popcron.Gizmos.Sphere(_qsbAngler.AttachedObject._targetPos, 5, Color.red); } - // Popcron.Gizmos.Line(AttachedObject.transform.position, _qsbAngler.AttachedObject.GetTargetPosition(), Color.white); + // Popcron.Gizmos.Line(AttachedObject.GetPosition(), _qsbAngler.AttachedObject.GetTargetPosition(), Color.white); } } } diff --git a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs index 25648ef2..967ad70d 100644 --- a/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs +++ b/QSB/JellyfishSync/TransformSync/JellyfishTransformSync.cs @@ -92,18 +92,6 @@ namespace QSB.JellyfishSync.TransformSync _shouldUpdate = false; - var targetPos = ReferenceTransform.DecodePos(transform.position); - var targetRot = ReferenceTransform.DecodeRot(transform.rotation); - - var positionToSet = targetPos; - var rotationToSet = targetRot; - - if (UseInterpolation) - { - positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos); - rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); - } - var hasMoved = CustomHasMoved( transform.position, _localPrevPosition, @@ -124,14 +112,11 @@ namespace QSB.JellyfishSync.TransformSync return true; } - ((OWRigidbody)AttachedObject).SetPosition(positionToSet); - ((OWRigidbody)AttachedObject).SetRotation(rotationToSet); - - var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); - var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); - - ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); - ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); + var pos = ReferenceTransform.DecodePos(transform.position); + AttachedObject.SetPosition(pos); + AttachedObject.SetRotation(ReferenceTransform.DecodeRot(transform.rotation)); + AttachedObject.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, pos)); + AttachedObject.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity)); return true; } @@ -143,7 +128,7 @@ namespace QSB.JellyfishSync.TransformSync || !QSBCore.ShowLinesInDebug || !IsReady || ReferenceTransform == null - || ((OWRigidbody)AttachedObject).IsSuspended()) + || AttachedObject.IsSuspended()) { return; } diff --git a/QSB/ShipSync/TransformSync/ShipTransformSync.cs b/QSB/ShipSync/TransformSync/ShipTransformSync.cs index 9921365d..aadc0e3b 100644 --- a/QSB/ShipSync/TransformSync/ShipTransformSync.cs +++ b/QSB/ShipSync/TransformSync/ShipTransformSync.cs @@ -40,8 +40,8 @@ namespace QSB.ShipSync.TransformSync var targetPos = ReferenceTransform.DecodePos(transform.position); var targetRot = ReferenceTransform.DecodeRot(transform.rotation); - ((ShipBody)AttachedObject).SetPosition(targetPos); - ((ShipBody)AttachedObject).SetRotation(targetRot); + AttachedObject.SetPosition(targetPos); + AttachedObject.SetRotation(targetRot); } protected override bool UpdateTransform() @@ -77,8 +77,8 @@ namespace QSB.ShipSync.TransformSync var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); - SetVelocity((ShipBody)AttachedObject, targetVelocity); - ((ShipBody)AttachedObject).SetAngularVelocity(targetAngularVelocity); + SetVelocity(AttachedObject, targetVelocity); + AttachedObject.SetAngularVelocity(targetAngularVelocity); return true; } diff --git a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs index bc484fcd..da74a8bf 100644 --- a/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs +++ b/QSB/Syncs/Sectored/Rigidbodies/SectoredRigidbodySync.cs @@ -96,10 +96,10 @@ namespace QSB.Syncs.Sectored.Rigidbodies { if (ReferenceTransform != null) { - transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); - transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); - _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(((OWRigidbody)AttachedObject).GetVelocity(), AttachedObject.transform.position); - _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(((OWRigidbody)AttachedObject).GetAngularVelocity()); + transform.position = ReferenceTransform.EncodePos(AttachedObject.GetPosition()); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.GetRotation()); + _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(AttachedObject.GetVelocity(), AttachedObject.GetPosition()); + _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(AttachedObject.GetAngularVelocity()); } else { @@ -136,8 +136,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies if (UseInterpolation) { - positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos); - rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); + positionToSet = SmartSmoothDamp(AttachedObject.GetPosition(), targetPos); + rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.GetRotation(), targetRot, ref _rotationSmoothVelocity, SmoothTime); } var hasMoved = CustomHasMoved( @@ -160,14 +160,14 @@ namespace QSB.Syncs.Sectored.Rigidbodies return true; } - ((OWRigidbody)AttachedObject).MoveToPosition(positionToSet); - ((OWRigidbody)AttachedObject).MoveToRotation(rotationToSet); + AttachedObject.MoveToPosition(positionToSet); + AttachedObject.MoveToRotation(rotationToSet); var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); - ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); - ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); + AttachedObject.SetVelocity(targetVelocity); + AttachedObject.SetAngularVelocity(targetAngularVelocity); return true; } diff --git a/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs b/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs index ffc0b883..a935288e 100644 --- a/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs +++ b/QSB/Syncs/Sectored/Transforms/SectoredTransformSync.cs @@ -67,8 +67,8 @@ namespace QSB.Syncs.Sectored.Transforms { if (ReferenceTransform != null) { - transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); - transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); + transform.position = ReferenceTransform.EncodePos(AttachedObject.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.rotation); } else { @@ -85,13 +85,13 @@ namespace QSB.Syncs.Sectored.Transforms { if (UseInterpolation) { - AttachedObject.transform.localPosition = SmartSmoothDamp(AttachedObject.transform.localPosition, targetPos); - AttachedObject.transform.localRotation = QuaternionHelper.SmoothDamp(AttachedObject.transform.localRotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); + AttachedObject.localPosition = SmartSmoothDamp(AttachedObject.localPosition, targetPos); + AttachedObject.localRotation = QuaternionHelper.SmoothDamp(AttachedObject.localRotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); } else { - AttachedObject.transform.localPosition = targetPos; - AttachedObject.transform.localRotation = targetRot; + AttachedObject.localPosition = targetPos; + AttachedObject.localRotation = targetRot; } } diff --git a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs index bc4236d9..191b519b 100644 --- a/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs +++ b/QSB/Syncs/Unsectored/Rigidbodies/UnsectoredRigidbodySync.cs @@ -83,10 +83,10 @@ namespace QSB.Syncs.Unsectored.Rigidbodies protected void SetValuesToSync() { - transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); - transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); - _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(((OWRigidbody)AttachedObject).GetVelocity(), AttachedObject.transform.position); - _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(((OWRigidbody)AttachedObject).GetAngularVelocity()); + transform.position = ReferenceTransform.EncodePos(AttachedObject.GetPosition()); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.GetRotation()); + _relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeVel(AttachedObject.GetVelocity(), AttachedObject.GetPosition()); + _relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().EncodeAngVel(AttachedObject.GetAngularVelocity()); } protected override bool UpdateTransform() @@ -105,8 +105,8 @@ namespace QSB.Syncs.Unsectored.Rigidbodies if (UseInterpolation) { - positionToSet = SmartSmoothDamp(AttachedObject.transform.position, targetPos); - rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); + positionToSet = SmartSmoothDamp(AttachedObject.GetPosition(), targetPos); + rotationToSet = QuaternionHelper.SmoothDamp(AttachedObject.GetRotation(), targetRot, ref _rotationSmoothVelocity, SmoothTime); } var hasMoved = CustomHasMoved( @@ -129,14 +129,14 @@ namespace QSB.Syncs.Unsectored.Rigidbodies return true; } - ((OWRigidbody)AttachedObject).MoveToPosition(positionToSet); - ((OWRigidbody)AttachedObject).MoveToRotation(rotationToSet); + AttachedObject.MoveToPosition(positionToSet); + AttachedObject.MoveToRotation(rotationToSet); var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos); var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity); - ((OWRigidbody)AttachedObject).SetVelocity(targetVelocity); - ((OWRigidbody)AttachedObject).SetAngularVelocity(targetAngularVelocity); + AttachedObject.SetVelocity(targetVelocity); + AttachedObject.SetAngularVelocity(targetAngularVelocity); return true; } diff --git a/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs b/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs index 0ce0a5ab..13dad20f 100644 --- a/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs +++ b/QSB/Syncs/Unsectored/Transforms/UnsectoredTransformSync.cs @@ -50,8 +50,8 @@ namespace QSB.Syncs.Unsectored.Transforms { if (HasAuthority) { - transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); - transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); + transform.position = ReferenceTransform.EncodePos(AttachedObject.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.rotation); return true; } @@ -59,13 +59,13 @@ namespace QSB.Syncs.Unsectored.Transforms var targetRot = ReferenceTransform.DecodeRot(transform.rotation); if (UseInterpolation) { - AttachedObject.transform.position = SmartSmoothDamp(AttachedObject.transform.position, targetPos); - AttachedObject.transform.rotation = QuaternionHelper.SmoothDamp(AttachedObject.transform.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); + AttachedObject.position = SmartSmoothDamp(AttachedObject.position, targetPos); + AttachedObject.rotation = QuaternionHelper.SmoothDamp(AttachedObject.rotation, targetRot, ref _rotationSmoothVelocity, SmoothTime); } else { - AttachedObject.transform.position = targetPos; - AttachedObject.transform.rotation = targetRot; + AttachedObject.position = targetPos; + AttachedObject.rotation = targetRot; } return true; diff --git a/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs index e3986216..ecc07513 100644 --- a/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs +++ b/QSB/Tools/ProbeTool/TransformSync/PlayerProbeSync.cs @@ -91,8 +91,8 @@ namespace QSB.Tools.ProbeTool.TransformSync if (ReferenceTransform != null) { - transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position); - transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation); + transform.position = ReferenceTransform.EncodePos(AttachedObject.position); + transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.rotation); } else { diff --git a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs index 64b03c02..fa9b3f47 100644 --- a/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs +++ b/QSB/TornadoSync/TransformSync/OccasionalTransformSync.cs @@ -130,10 +130,10 @@ namespace QSB.TornadoSync.TransformSync } var pos = ReferenceTransform.DecodePos(transform.position); - ((OWRigidbody)AttachedObject).SetPosition(pos); - ((OWRigidbody)AttachedObject).SetRotation(ReferenceTransform.DecodeRot(transform.rotation)); - ((OWRigidbody)AttachedObject).SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, pos)); - ((OWRigidbody)AttachedObject).SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity)); + AttachedObject.SetPosition(pos); + AttachedObject.SetRotation(ReferenceTransform.DecodeRot(transform.rotation)); + AttachedObject.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, pos)); + AttachedObject.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity)); Move(); @@ -169,10 +169,10 @@ namespace QSB.TornadoSync.TransformSync _toMove.Add(new MoveData { Child = child, - RelPos = ((OWRigidbody)AttachedObject).transform.EncodePos(pos), - RelRot = ((OWRigidbody)AttachedObject).transform.EncodeRot(child.GetRotation()), - RelVel = ((OWRigidbody)AttachedObject).EncodeVel(child.GetVelocity(), pos), - RelAngVel = ((OWRigidbody)AttachedObject).EncodeAngVel(child.GetAngularVelocity()) + RelPos = AttachedObject.transform.EncodePos(pos), + RelRot = AttachedObject.transform.EncodeRot(child.GetRotation()), + RelVel = AttachedObject.EncodeVel(child.GetVelocity(), pos), + RelAngVel = AttachedObject.EncodeAngVel(child.GetAngularVelocity()) }); } @@ -180,11 +180,11 @@ namespace QSB.TornadoSync.TransformSync { foreach (var data in _toMove) { - var pos = ((OWRigidbody)AttachedObject).transform.DecodePos(data.RelPos); + var pos = AttachedObject.transform.DecodePos(data.RelPos); data.Child.SetPosition(pos); - data.Child.SetRotation(((OWRigidbody)AttachedObject).transform.DecodeRot(data.RelRot)); - data.Child.SetVelocity(((OWRigidbody)AttachedObject).DecodeVel(data.RelVel, pos)); - data.Child.SetAngularVelocity(((OWRigidbody)AttachedObject).DecodeAngVel(data.RelAngVel)); + data.Child.SetRotation(AttachedObject.transform.DecodeRot(data.RelRot)); + data.Child.SetVelocity(AttachedObject.DecodeVel(data.RelVel, pos)); + data.Child.SetAngularVelocity(AttachedObject.DecodeAngVel(data.RelAngVel)); } _toMove.Clear(); }