use proper pos/rot stuff

This commit is contained in:
JohnCorby 2021-12-13 13:26:54 -08:00
parent b5f12796af
commit adad302ba0
9 changed files with 64 additions and 79 deletions

View File

@ -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);
}
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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
{

View File

@ -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();
}