SDK/Physics2D: Fix entity rotation not being taken into account for static physics
This commit is contained in:
@@ -51,9 +51,15 @@ namespace Ndk
|
||||
|
||||
m_object = std::make_unique<Nz::RigidBody2D>(&world, 1.f, geom);
|
||||
m_object->SetPositionOffset(positionOffset);
|
||||
m_object->SetPosition(Nz::Vector2f(matrix.GetTranslation()));
|
||||
m_object->SetUserdata(reinterpret_cast<void*>(static_cast<std::ptrdiff_t>(m_entity->GetId())));
|
||||
|
||||
if (m_entity->HasComponent<NodeComponent>())
|
||||
{
|
||||
auto& entityNode = m_entity->GetComponent<NodeComponent>();
|
||||
m_object->SetPosition(Nz::Vector2f(entityNode.GetPosition()));
|
||||
m_object->SetRotation(entityNode.GetRotation().To2DAngle());
|
||||
}
|
||||
|
||||
if (m_pendingStates.valid)
|
||||
ApplyPhysicsState(*m_object);
|
||||
}
|
||||
|
||||
@@ -249,19 +249,16 @@ namespace Ndk
|
||||
else
|
||||
body->SetVelocity(Nz::Vector2f::Zero());
|
||||
|
||||
/*if (newRotation != oldRotation)
|
||||
{
|
||||
Nz::Quaternionf transition = newRotation * oldRotation.GetConjugate();
|
||||
Nz::EulerAnglesf angles = transition.ToEulerAngles();
|
||||
Nz::Vector3f angularVelocity(Nz::ToRadians(angles.pitch * invElapsedTime),
|
||||
Nz::ToRadians(angles.yaw * invElapsedTime),
|
||||
Nz::ToRadians(angles.roll * invElapsedTime));
|
||||
Nz::RadianAnglef oldRotation = body->GetRotation();
|
||||
Nz::RadianAnglef newRotation = node.GetRotation(Nz::CoordSys_Global).To2DAngle();
|
||||
|
||||
physObj->SetRotation(oldRotation);
|
||||
physObj->SetAngularVelocity(angularVelocity);
|
||||
if (newRotation != oldRotation)
|
||||
{
|
||||
body->SetRotation(oldRotation);
|
||||
body->SetAngularVelocity((newRotation - oldRotation) * invElapsedTime);
|
||||
}
|
||||
else
|
||||
physObj->SetAngularVelocity(Nz::Vector3f::Zero());*/
|
||||
body->SetAngularVelocity(Nz::RadianAnglef::Zero());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user