Skip to content

Commit

Permalink
Check if euler has changed before returning value (#7540)
Browse files Browse the repository at this point in the history
Check if the euler angle has changed before returning a rotation or euler value in GetProperty.

When getting an euler angle:
If the euler angle hasn't changed we should update the euler angle with the value from the quaternion

When getting a quaternion:
If the euler angle has changed it is likely that we are getting the quaternion in a go.animate callback, in which case we should update the quaternion with the value of the euler angle
  • Loading branch information
britzl authored and Jhonnyg committed Apr 14, 2023
1 parent f37ca62 commit 4f6f1e6
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions engine/gameobject/src/gameobject/gameobject.cpp
Expand Up @@ -2434,11 +2434,16 @@ namespace dmGameObject
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2];
}

static void CheckEuler(Instance* instance)
static bool HasEulerChanged(Instance* instance)
{
Vector3& euler = instance->m_EulerRotation;
Vector3& prev_euler = instance->m_PrevEulerRotation;
if (!Vec3Equals((uint32_t*)(&euler), (uint32_t*)(&prev_euler)))
return !Vec3Equals((uint32_t*)(&euler), (uint32_t*)(&prev_euler));
}

static void CheckEuler(Instance* instance)
{
if (HasEulerChanged(instance))
{
UpdateEulerToRotation(instance);
}
Expand Down Expand Up @@ -3276,6 +3281,10 @@ namespace dmGameObject
}
else if (property_id == PROP_ROTATION)
{
if (HasEulerChanged(instance))
{
UpdateEulerToRotation(instance);
}
float* rotation = instance->m_Transform.GetRotationPtr();
out_value.m_ValuePtr = rotation;
out_value.m_ElementIds[0] = PROP_ROTATION_X;
Expand All @@ -3286,31 +3295,50 @@ namespace dmGameObject
}
else if (property_id == PROP_ROTATION_X)
{
if (HasEulerChanged(instance))
{
UpdateEulerToRotation(instance);
}
float* rotation = instance->m_Transform.GetRotationPtr();
out_value.m_ValuePtr = rotation;
out_value.m_Variant = PropertyVar(*out_value.m_ValuePtr);
}
else if (property_id == PROP_ROTATION_Y)
{
if (HasEulerChanged(instance))
{
UpdateEulerToRotation(instance);
}
float* rotation = instance->m_Transform.GetRotationPtr();
out_value.m_ValuePtr = rotation + 1;
out_value.m_Variant = PropertyVar(*out_value.m_ValuePtr);
}
else if (property_id == PROP_ROTATION_Z)
{
if (HasEulerChanged(instance))
{
UpdateEulerToRotation(instance);
}
float* rotation = instance->m_Transform.GetRotationPtr();
out_value.m_ValuePtr = rotation + 2;
out_value.m_Variant = PropertyVar(*out_value.m_ValuePtr);
}
else if (property_id == PROP_ROTATION_W)
{
if (HasEulerChanged(instance))
{
UpdateEulerToRotation(instance);
}
float* rotation = instance->m_Transform.GetRotationPtr();
out_value.m_ValuePtr = rotation + 3;
out_value.m_Variant = PropertyVar(*out_value.m_ValuePtr);
}
else if (property_id == PROP_EULER)
{
UpdateRotationToEuler(instance);
if (!HasEulerChanged(instance))
{
UpdateRotationToEuler(instance);
}
out_value.m_ValuePtr = (float*)&instance->m_EulerRotation;
out_value.m_ElementIds[0] = PROP_EULER_X;
out_value.m_ElementIds[1] = PROP_EULER_Y;
Expand All @@ -3319,19 +3347,28 @@ namespace dmGameObject
}
else if (property_id == PROP_EULER_X)
{
UpdateRotationToEuler(instance);
out_value.m_ValuePtr = ((float*)&instance->m_EulerRotation);
if (!HasEulerChanged(instance))
{
UpdateRotationToEuler(instance);
}
out_value.m_ValuePtr = ((float*)&instance->m_EulerRotation);
out_value.m_Variant = PropertyVar(*out_value.m_ValuePtr);
}
else if (property_id == PROP_EULER_Y)
{
UpdateRotationToEuler(instance);
if (!HasEulerChanged(instance))
{
UpdateRotationToEuler(instance);
}
out_value.m_ValuePtr = ((float*)&instance->m_EulerRotation) + 1;
out_value.m_Variant = PropertyVar(*out_value.m_ValuePtr);
}
else if (property_id == PROP_EULER_Z)
{
UpdateRotationToEuler(instance);
if (!HasEulerChanged(instance))
{
UpdateRotationToEuler(instance);
}
out_value.m_ValuePtr = ((float*)&instance->m_EulerRotation) + 2;
out_value.m_Variant = PropertyVar(*out_value.m_ValuePtr);
}
Expand Down

0 comments on commit 4f6f1e6

Please sign in to comment.