mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-20 15:41:01 +00:00
rename relative transform stuff
This commit is contained in:
parent
e284c5ce66
commit
4c535fd544
@ -112,11 +112,11 @@ namespace QSB.JellyfishSync.TransformSync
|
||||
return true;
|
||||
}
|
||||
|
||||
var pos = ReferenceTransform.DecodePos(transform.position);
|
||||
var pos = ReferenceTransform.FromRelPos(transform.position);
|
||||
AttachedObject.SetPosition(pos);
|
||||
AttachedObject.SetRotation(ReferenceTransform.DecodeRot(transform.rotation));
|
||||
AttachedObject.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, pos));
|
||||
AttachedObject.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity));
|
||||
AttachedObject.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
||||
AttachedObject.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, pos));
|
||||
AttachedObject.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -39,10 +39,10 @@ namespace QSB.MeteorSync.Events
|
||||
var body = qsbFragment.Body;
|
||||
var refBody = qsbFragment.RefBody;
|
||||
var pos = body.GetPosition();
|
||||
msg.Pos = refBody.transform.EncodePos(pos);
|
||||
msg.Rot = refBody.transform.EncodeRot(body.GetRotation());
|
||||
msg.Vel = refBody.EncodeVel(body.GetVelocity(), pos);
|
||||
msg.AngVel = refBody.EncodeAngVel(body.GetAngularVelocity());
|
||||
msg.Pos = refBody.transform.ToRelPos(pos);
|
||||
msg.Rot = refBody.transform.ToRelRot(body.GetRotation());
|
||||
msg.Vel = refBody.ToRelVel(body.GetVelocity(), pos);
|
||||
msg.AngVel = refBody.ToRelAngVel(body.GetAngularVelocity());
|
||||
}
|
||||
|
||||
return msg;
|
||||
@ -100,11 +100,11 @@ namespace QSB.MeteorSync.Events
|
||||
}
|
||||
|
||||
var refBody = qsbFragment.RefBody;
|
||||
var pos = refBody.transform.DecodePos(msg.Pos);
|
||||
var pos = refBody.transform.FromRelPos(msg.Pos);
|
||||
body.SetPosition(pos);
|
||||
body.SetRotation(refBody.transform.DecodeRot(msg.Rot));
|
||||
body.SetVelocity(refBody.DecodeVel(msg.Vel, pos));
|
||||
body.SetAngularVelocity(refBody.DecodeAngVel(msg.AngVel));
|
||||
body.SetRotation(refBody.transform.FromRelRot(msg.Rot));
|
||||
body.SetVelocity(refBody.FromRelVel(msg.Vel, pos));
|
||||
body.SetAngularVelocity(refBody.FromRelAngVel(msg.AngVel));
|
||||
});
|
||||
}
|
||||
else if (!msg.IsDetached && qsbFragment.IsDetached)
|
||||
|
@ -1,6 +1,7 @@
|
||||
using QSB.SectorSync;
|
||||
using QSB.Syncs;
|
||||
using QSB.Syncs.Sectored.Rigidbodies;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
@ -37,8 +38,8 @@ namespace QSB.ShipSync.TransformSync
|
||||
return;
|
||||
}
|
||||
|
||||
var targetPos = ReferenceTransform.DecodePos(transform.position);
|
||||
var targetRot = ReferenceTransform.DecodeRot(transform.rotation);
|
||||
var targetPos = ReferenceTransform.FromRelPos(transform.position);
|
||||
var targetRot = ReferenceTransform.FromRelRot(transform.rotation);
|
||||
|
||||
AttachedObject.SetPosition(targetPos);
|
||||
AttachedObject.SetRotation(targetRot);
|
||||
@ -72,10 +73,10 @@ namespace QSB.ShipSync.TransformSync
|
||||
return false;
|
||||
}
|
||||
|
||||
var targetPos = ReferenceTransform.DecodePos(transform.position);
|
||||
var targetPos = ReferenceTransform.FromRelPos(transform.position);
|
||||
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity);
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
|
||||
|
||||
SetVelocity(AttachedObject, targetVelocity);
|
||||
AttachedObject.SetAngularVelocity(targetAngularVelocity);
|
||||
|
@ -96,10 +96,10 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
{
|
||||
if (ReferenceTransform != null)
|
||||
{
|
||||
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());
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedObject.GetPosition());
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedObject.GetRotation());
|
||||
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedObject.GetVelocity(), AttachedObject.GetPosition());
|
||||
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedObject.GetAngularVelocity());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -128,18 +128,18 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
return false;
|
||||
}
|
||||
|
||||
var targetPos = ReferenceTransform.DecodePos(transform.position);
|
||||
var targetRot = ReferenceTransform.DecodeRot(transform.rotation);
|
||||
var targetPos = ReferenceTransform.FromRelPos(transform.position);
|
||||
var targetRot = ReferenceTransform.FromRelRot(transform.rotation);
|
||||
|
||||
var positionToSet = targetPos;
|
||||
var rotationToSet = targetRot;
|
||||
|
||||
if (UseInterpolation)
|
||||
{
|
||||
var relPos = ReferenceTransform.EncodePos(AttachedObject.GetPosition());
|
||||
var relRot = ReferenceTransform.EncodeRot(AttachedObject.GetRotation());
|
||||
positionToSet = ReferenceTransform.DecodePos(SmartSmoothDamp(relPos, transform.position));
|
||||
rotationToSet = ReferenceTransform.DecodeRot(SmartSmoothDamp(relRot, transform.rotation));
|
||||
var relPos = ReferenceTransform.ToRelPos(AttachedObject.GetPosition());
|
||||
var relRot = ReferenceTransform.ToRelRot(AttachedObject.GetRotation());
|
||||
positionToSet = ReferenceTransform.FromRelPos(SmartSmoothDamp(relPos, transform.position));
|
||||
rotationToSet = ReferenceTransform.FromRelRot(SmartSmoothDamp(relRot, transform.rotation));
|
||||
}
|
||||
|
||||
var hasMoved = CustomHasMoved(
|
||||
@ -165,8 +165,8 @@ namespace QSB.Syncs.Sectored.Rigidbodies
|
||||
AttachedObject.MoveToPosition(positionToSet);
|
||||
AttachedObject.MoveToRotation(rotationToSet);
|
||||
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity);
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
|
||||
|
||||
AttachedObject.SetVelocity(targetVelocity);
|
||||
AttachedObject.SetAngularVelocity(targetAngularVelocity);
|
||||
|
@ -67,8 +67,8 @@ namespace QSB.Syncs.Sectored.Transforms
|
||||
{
|
||||
if (ReferenceTransform != null)
|
||||
{
|
||||
transform.position = ReferenceTransform.EncodePos(AttachedObject.position);
|
||||
transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.rotation);
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedObject.position);
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedObject.rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -279,8 +279,8 @@ namespace QSB.Syncs
|
||||
|
||||
if (HasAuthority)
|
||||
{
|
||||
transform.position = ReferenceTransform.EncodePos(AttachedObject.transform.position);
|
||||
transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.transform.rotation);
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedObject.transform.position);
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedObject.transform.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,8 +312,8 @@ namespace QSB.Syncs
|
||||
* Cyan Line = Connection between Green/Yellow cube and reference transform
|
||||
*/
|
||||
|
||||
Popcron.Gizmos.Cube(ReferenceTransform.DecodePos(transform.position), ReferenceTransform.DecodeRot(transform.rotation), Vector3.one / 4, Color.red);
|
||||
Popcron.Gizmos.Line(ReferenceTransform.DecodePos(transform.position), AttachedObject.transform.position, Color.red);
|
||||
Popcron.Gizmos.Cube(ReferenceTransform.FromRelPos(transform.position), ReferenceTransform.FromRelRot(transform.rotation), Vector3.one / 4, Color.red);
|
||||
Popcron.Gizmos.Line(ReferenceTransform.FromRelPos(transform.position), AttachedObject.transform.position, Color.red);
|
||||
var color = HasMoved() ? Color.green : Color.yellow;
|
||||
Popcron.Gizmos.Cube(AttachedObject.transform.position, AttachedObject.transform.rotation, Vector3.one / 4, color);
|
||||
Popcron.Gizmos.Cube(ReferenceTransform.position, ReferenceTransform.rotation, Vector3.one / 4, Color.magenta);
|
||||
|
@ -1,19 +0,0 @@
|
||||
using QSB.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Syncs
|
||||
{
|
||||
/// encode = absolute to relative
|
||||
/// decode = relative to absolute
|
||||
public static class TransformSyncUtil
|
||||
{
|
||||
public static Vector3 EncodePos(this Transform reference, Vector3 pos) => reference.InverseTransformPoint(pos);
|
||||
public static Vector3 DecodePos(this Transform reference, Vector3 relPos) => reference.TransformPoint(relPos);
|
||||
public static Quaternion EncodeRot(this Transform reference, Quaternion rot) => reference.InverseTransformRotation(rot);
|
||||
public static Quaternion DecodeRot(this Transform reference, Quaternion relRot) => reference.TransformRotation(relRot);
|
||||
public static Vector3 EncodeVel(this OWRigidbody reference, Vector3 vel, Vector3 pos) => vel - reference.GetPointVelocity(pos);
|
||||
public static Vector3 DecodeVel(this OWRigidbody reference, Vector3 relVel, Vector3 pos) => relVel + reference.GetPointVelocity(pos);
|
||||
public static Vector3 EncodeAngVel(this OWRigidbody reference, Vector3 angVel) => angVel - reference.GetAngularVelocity();
|
||||
public static Vector3 DecodeAngVel(this OWRigidbody reference, Vector3 relAngVel) => relAngVel + reference.GetAngularVelocity();
|
||||
}
|
||||
}
|
@ -83,10 +83,10 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
||||
|
||||
protected void SetValuesToSync()
|
||||
{
|
||||
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());
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedObject.GetPosition());
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedObject.GetRotation());
|
||||
_relativeVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelVel(AttachedObject.GetVelocity(), AttachedObject.GetPosition());
|
||||
_relativeAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().ToRelAngVel(AttachedObject.GetAngularVelocity());
|
||||
}
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
@ -97,18 +97,18 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
||||
return true;
|
||||
}
|
||||
|
||||
var targetPos = ReferenceTransform.DecodePos(transform.position);
|
||||
var targetRot = ReferenceTransform.DecodeRot(transform.rotation);
|
||||
var targetPos = ReferenceTransform.FromRelPos(transform.position);
|
||||
var targetRot = ReferenceTransform.FromRelRot(transform.rotation);
|
||||
|
||||
var positionToSet = targetPos;
|
||||
var rotationToSet = targetRot;
|
||||
|
||||
if (UseInterpolation)
|
||||
{
|
||||
var relPos = ReferenceTransform.EncodePos(AttachedObject.GetPosition());
|
||||
var relRot = ReferenceTransform.EncodeRot(AttachedObject.GetRotation());
|
||||
positionToSet = ReferenceTransform.DecodePos(SmartSmoothDamp(relPos, transform.position));
|
||||
rotationToSet = ReferenceTransform.DecodeRot(SmartSmoothDamp(relRot, transform.rotation));
|
||||
var relPos = ReferenceTransform.ToRelPos(AttachedObject.GetPosition());
|
||||
var relRot = ReferenceTransform.ToRelRot(AttachedObject.GetRotation());
|
||||
positionToSet = ReferenceTransform.FromRelPos(SmartSmoothDamp(relPos, transform.position));
|
||||
rotationToSet = ReferenceTransform.FromRelRot(SmartSmoothDamp(relRot, transform.rotation));
|
||||
}
|
||||
|
||||
var hasMoved = CustomHasMoved(
|
||||
@ -134,8 +134,8 @@ namespace QSB.Syncs.Unsectored.Rigidbodies
|
||||
AttachedObject.MoveToPosition(positionToSet);
|
||||
AttachedObject.MoveToRotation(rotationToSet);
|
||||
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity);
|
||||
var targetVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, targetPos);
|
||||
var targetAngularVelocity = ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity);
|
||||
|
||||
AttachedObject.SetVelocity(targetVelocity);
|
||||
AttachedObject.SetAngularVelocity(targetAngularVelocity);
|
||||
|
@ -48,8 +48,8 @@ namespace QSB.Syncs.Unsectored.Transforms
|
||||
|
||||
protected override bool UpdateTransform()
|
||||
{
|
||||
var relPos = ReferenceTransform.EncodePos(AttachedObject.position);
|
||||
var relRot = ReferenceTransform.EncodeRot(AttachedObject.rotation);
|
||||
var relPos = ReferenceTransform.ToRelPos(AttachedObject.position);
|
||||
var relRot = ReferenceTransform.ToRelRot(AttachedObject.rotation);
|
||||
if (HasAuthority)
|
||||
{
|
||||
transform.position = relPos;
|
||||
@ -59,13 +59,13 @@ namespace QSB.Syncs.Unsectored.Transforms
|
||||
|
||||
if (UseInterpolation)
|
||||
{
|
||||
AttachedObject.position = ReferenceTransform.DecodePos(SmartSmoothDamp(relPos, transform.position));
|
||||
AttachedObject.rotation = ReferenceTransform.DecodeRot(SmartSmoothDamp(relRot, transform.rotation));
|
||||
AttachedObject.position = ReferenceTransform.FromRelPos(SmartSmoothDamp(relPos, transform.position));
|
||||
AttachedObject.rotation = ReferenceTransform.FromRelRot(SmartSmoothDamp(relRot, transform.rotation));
|
||||
}
|
||||
else
|
||||
{
|
||||
AttachedObject.position = ReferenceTransform.DecodePos(transform.position);
|
||||
AttachedObject.rotation = ReferenceTransform.DecodeRot(transform.rotation);
|
||||
AttachedObject.position = ReferenceTransform.FromRelPos(transform.position);
|
||||
AttachedObject.rotation = ReferenceTransform.FromRelRot(transform.rotation);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -91,8 +91,8 @@ namespace QSB.Tools.ProbeTool.TransformSync
|
||||
|
||||
if (ReferenceTransform != null)
|
||||
{
|
||||
transform.position = ReferenceTransform.EncodePos(AttachedObject.position);
|
||||
transform.rotation = ReferenceTransform.EncodeRot(AttachedObject.rotation);
|
||||
transform.position = ReferenceTransform.ToRelPos(AttachedObject.position);
|
||||
transform.rotation = ReferenceTransform.ToRelRot(AttachedObject.rotation);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using QSB.ShipSync.TransformSync;
|
||||
using QSB.Syncs;
|
||||
using QSB.Syncs.Unsectored.Rigidbodies;
|
||||
using QSB.Tools.ProbeTool.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
@ -129,11 +130,11 @@ namespace QSB.TornadoSync.TransformSync
|
||||
QueueMove(child);
|
||||
}
|
||||
|
||||
var pos = ReferenceTransform.DecodePos(transform.position);
|
||||
var pos = ReferenceTransform.FromRelPos(transform.position);
|
||||
AttachedObject.SetPosition(pos);
|
||||
AttachedObject.SetRotation(ReferenceTransform.DecodeRot(transform.rotation));
|
||||
AttachedObject.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeVel(_relativeVelocity, pos));
|
||||
AttachedObject.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().DecodeAngVel(_relativeAngularVelocity));
|
||||
AttachedObject.SetRotation(ReferenceTransform.FromRelRot(transform.rotation));
|
||||
AttachedObject.SetVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelVel(_relativeVelocity, pos));
|
||||
AttachedObject.SetAngularVelocity(ReferenceTransform.GetAttachedOWRigidbody().FromRelAngVel(_relativeAngularVelocity));
|
||||
|
||||
Move();
|
||||
|
||||
@ -169,10 +170,10 @@ namespace QSB.TornadoSync.TransformSync
|
||||
_toMove.Add(new MoveData
|
||||
{
|
||||
Child = child,
|
||||
RelPos = AttachedObject.transform.EncodePos(pos),
|
||||
RelRot = AttachedObject.transform.EncodeRot(child.GetRotation()),
|
||||
RelVel = AttachedObject.EncodeVel(child.GetVelocity(), pos),
|
||||
RelAngVel = AttachedObject.EncodeAngVel(child.GetAngularVelocity())
|
||||
RelPos = AttachedObject.transform.ToRelPos(pos),
|
||||
RelRot = AttachedObject.transform.ToRelRot(child.GetRotation()),
|
||||
RelVel = AttachedObject.ToRelVel(child.GetVelocity(), pos),
|
||||
RelAngVel = AttachedObject.ToRelAngVel(child.GetAngularVelocity())
|
||||
});
|
||||
}
|
||||
|
||||
@ -180,11 +181,11 @@ namespace QSB.TornadoSync.TransformSync
|
||||
{
|
||||
foreach (var data in _toMove)
|
||||
{
|
||||
var pos = AttachedObject.transform.DecodePos(data.RelPos);
|
||||
var pos = AttachedObject.transform.FromRelPos(data.RelPos);
|
||||
data.Child.SetPosition(pos);
|
||||
data.Child.SetRotation(AttachedObject.transform.DecodeRot(data.RelRot));
|
||||
data.Child.SetVelocity(AttachedObject.DecodeVel(data.RelVel, pos));
|
||||
data.Child.SetAngularVelocity(AttachedObject.DecodeAngVel(data.RelAngVel));
|
||||
data.Child.SetRotation(AttachedObject.transform.FromRelRot(data.RelRot));
|
||||
data.Child.SetVelocity(AttachedObject.FromRelVel(data.RelVel, pos));
|
||||
data.Child.SetAngularVelocity(AttachedObject.FromRelAngVel(data.RelAngVel));
|
||||
}
|
||||
_toMove.Clear();
|
||||
}
|
||||
|
16
QSB/Utility/RelativeTransformUtil.cs
Normal file
16
QSB/Utility/RelativeTransformUtil.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Utility
|
||||
{
|
||||
public static class RelativeTransformUtil
|
||||
{
|
||||
public static Vector3 ToRelPos(this Transform reference, Vector3 pos) => reference.InverseTransformPoint(pos);
|
||||
public static Vector3 FromRelPos(this Transform reference, Vector3 relPos) => reference.TransformPoint(relPos);
|
||||
public static Quaternion ToRelRot(this Transform reference, Quaternion rot) => reference.InverseTransformRotation(rot);
|
||||
public static Quaternion FromRelRot(this Transform reference, Quaternion relRot) => reference.TransformRotation(relRot);
|
||||
public static Vector3 ToRelVel(this OWRigidbody reference, Vector3 vel, Vector3 pos) => vel - reference.GetPointVelocity(pos);
|
||||
public static Vector3 FromRelVel(this OWRigidbody reference, Vector3 relVel, Vector3 pos) => relVel + reference.GetPointVelocity(pos);
|
||||
public static Vector3 ToRelAngVel(this OWRigidbody reference, Vector3 angVel) => angVel - reference.GetAngularVelocity();
|
||||
public static Vector3 FromRelAngVel(this OWRigidbody reference, Vector3 relAngVel) => relAngVel + reference.GetAngularVelocity();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user