update network code to use uniform scale on Transform

This commit is contained in:
greerdv
2021-05-26 14:20:22 +01:00
parent 29163fba1a
commit 4018bb587c
4 changed files with 14 additions and 15 deletions
@@ -488,18 +488,17 @@ void TransformCompressor::Marshal(WriteBuffer& wb, const AZ::Transform& value) c
{
AZ::u8 flags = 0;
auto flagsMarker = wb.InsertMarker(flags);
AZ::Matrix3x3 m33 = AZ::Matrix3x3::CreateFromTransform(value);
AZ::Vector3 scale = m33.ExtractScale();
AZ::Quaternion rot = AZ::Quaternion::CreateFromMatrix3x3(m33.GetOrthogonalized());
float scale = value.GetUniformScale();
AZ::Quaternion rot = value.GetRotation();
if (!rot.IsIdentity())
{
flags |= HAS_ROT;
wb.Write(rot, QuatCompMarshaler());
}
if (!scale.IsClose(AZ::Vector3::CreateOne()))
if (!AZ::IsClose(scale, 1.0f, AZ::Constants::Tolerance))
{
flags |= HAS_SCALE;
wb.Write(scale, Vec3CompMarshaler());
wb.Write(scale, HalfMarshaler());
}
AZ::Vector3 pos = value.GetTranslation();
if (!pos.IsZero())
@@ -527,9 +526,9 @@ void TransformCompressor::Unmarshal(AZ::Transform& value, ReadBuffer& rb) const
}
if (flags & HAS_SCALE)
{
AZ::Vector3 scale;
rb.Read(scale, Vec3CompMarshaler());
xform.MultiplyByScale(scale);
float scale;
rb.Read(scale, HalfMarshaler());
xform.MultiplyByUniformScale(scale);
}
if (flags & HAS_POS)
{
@@ -34,11 +34,11 @@ namespace Multiplayer
private:
void OnRotationChangedEvent(const AZ::Quaternion& rotation);
void OnTranslationChangedEvent(const AZ::Vector3& translation);
void OnScaleChangedEvent(const AZ::Vector3& scale);
void OnScaleChangedEvent(float scale);
AZ::Event<AZ::Quaternion>::Handler m_rotationEventHandler;
AZ::Event<AZ::Vector3>::Handler m_translationEventHandler;
AZ::Event<AZ::Vector3>::Handler m_scaleEventHandler;
AZ::Event<float>::Handler m_scaleEventHandler;
};
class NetworkTransformComponentController
@@ -14,7 +14,7 @@
<NetworkProperty Type="AZ::Quaternion" Name="rotation" Init="AZ::Quaternion::CreateIdentity()" ReplicateFrom="Authority" ReplicateTo="Client" IsRewindable="true" IsPredictable="true" IsPublic="true" Container="Object" ExposeToEditor="false" GenerateEventBindings="true" />
<NetworkProperty Type="AZ::Vector3" Name="translation" Init="AZ::Vector3::CreateZero()" ReplicateFrom="Authority" ReplicateTo="Client" IsRewindable="true" IsPredictable="true" IsPublic="true" Container="Object" ExposeToEditor="false" GenerateEventBindings="true" />
<NetworkProperty Type="AZ::Vector3" Name="scale" Init="AZ::Vector3::CreateZero()" ReplicateFrom="Authority" ReplicateTo="Client" IsRewindable="true" IsPredictable="true" IsPublic="true" Container="Object" ExposeToEditor="false" GenerateEventBindings="true" />
<NetworkProperty Type="float" Name="scale" Init="0.0f" ReplicateFrom="Authority" ReplicateTo="Client" IsRewindable="true" IsPredictable="true" IsPublic="true" Container="Object" ExposeToEditor="false" GenerateEventBindings="true" />
<NetworkProperty Type="uint8_t" Name="resetCount" Init="0" ReplicateFrom="Authority" ReplicateTo="Client" IsRewindable="false" IsPredictable="true" IsPublic="true" Container="Object" ExposeToEditor="false" GenerateEventBindings="true" />
<NetworkProperty Type="NetEntityId" Name="parentEntityId" Init="InvalidNetEntityId" ReplicateFrom="Authority" ReplicateTo="Client" IsRewindable="true" IsPredictable="true" IsPublic="true" Container="Object" ExposeToEditor="false" GenerateEventBindings="true" />
<NetworkProperty Type="int32_t" Name="parentAttachmentBoneId" Init="-1" ReplicateFrom="Authority" ReplicateTo="Client" IsRewindable="true" IsPredictable="true" IsPublic="true" Container="Object" ExposeToEditor="false" GenerateEventBindings="true" />
@@ -32,7 +32,7 @@ namespace Multiplayer
NetworkTransformComponent::NetworkTransformComponent()
: m_rotationEventHandler([this](const AZ::Quaternion& rotation) { OnRotationChangedEvent(rotation); })
, m_translationEventHandler([this](const AZ::Vector3& translation) { OnTranslationChangedEvent(translation); })
, m_scaleEventHandler([this](const AZ::Vector3& scale) { OnScaleChangedEvent(scale); })
, m_scaleEventHandler([this](float scale) { OnScaleChangedEvent(scale); })
{
;
}
@@ -68,10 +68,10 @@ namespace Multiplayer
GetTransformComponent()->SetWorldTM(worldTm);
}
void NetworkTransformComponent::OnScaleChangedEvent(const AZ::Vector3& scale)
void NetworkTransformComponent::OnScaleChangedEvent(float scale)
{
AZ::Transform worldTm = GetTransformComponent()->GetWorldTM();
worldTm.SetScale(scale);
worldTm.SetUniformScale(scale);
GetTransformComponent()->SetWorldTM(worldTm);
}
@@ -100,7 +100,7 @@ namespace Multiplayer
{
SetRotation(worldTm.GetRotation());
SetTranslation(worldTm.GetTranslation());
SetScale(worldTm.GetScale());
SetScale(worldTm.GetUniformScale());
}
}
}