mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Physics improvement
This commit is contained in:
@@ -50,6 +50,8 @@ namespace Nuake
|
||||
m_TimeStep = m_Time - m_LastFrameTime;
|
||||
m_LastFrameTime = m_Time;
|
||||
|
||||
m_TimeStep = std::min((float)m_TimeStep, 0.5f);
|
||||
|
||||
// Dont update if no scene is loaded.
|
||||
if (CurrentWindow->GetScene())
|
||||
{
|
||||
|
||||
@@ -406,20 +406,36 @@ namespace Nuake
|
||||
|
||||
const std::string& name = entity.GetComponent<NameComponent>().Name;
|
||||
TransformComponent& transformComponent = entity.GetComponent<TransformComponent>();
|
||||
transformComponent.GlobalTransform = transform;
|
||||
//transformComponent.SetLocalPosition(pos);
|
||||
//transformComponent.SetLocalRotation(rotation);
|
||||
//transformComponent.GlobalTransform = transform;
|
||||
transformComponent.SetLocalPosition(pos);
|
||||
transformComponent.Dirty = false;
|
||||
transformComponent.SetLocalRotation(rotation);
|
||||
//transformComponent.SetLocalScale(scale);
|
||||
|
||||
Matrix4 newTransform = Matrix4(1.0f);
|
||||
newTransform = glm::translate(newTransform, pos);
|
||||
newTransform = newTransform * glm::toMat4(rotation);
|
||||
newTransform = glm::scale(newTransform, transformComponent.GetGlobalScale());
|
||||
|
||||
transformComponent.SetLocalTransform(transform);
|
||||
|
||||
const std::string& posStr = "(" + std::to_string(pos.x) + ", " + std::to_string(pos.y) + ", " + std::to_string(pos.z) + ")";
|
||||
const std::string& logMsg = "Physics pos: " + name + " at " + posStr;
|
||||
Logger::Log(logMsg);
|
||||
}
|
||||
// If you take larger steps than 1 / 60th of a second you need to do multiple collision steps in order to keep the simulation stable. Do 1 collision step per 1 / 60th of a second (round up).
|
||||
const int cCollisionSteps = 1;
|
||||
int collisionSteps = 1;
|
||||
const float minStepDuration = 1.0f / 60.0f;
|
||||
if(ts > minStepDuration)
|
||||
{
|
||||
collisionSteps = ts / minStepDuration;
|
||||
}
|
||||
|
||||
// If you want more accurate step results you can do multiple sub steps within a collision step. Usually you would set this to 1.
|
||||
const int cIntegrationSubSteps = 1;
|
||||
|
||||
// Step the world
|
||||
_JoltPhysicsSystem->Update(ts, cCollisionSteps, cIntegrationSubSteps, new JPH::TempAllocatorMalloc(), _JoltJobSystem);
|
||||
_JoltPhysicsSystem->Update(ts, collisionSteps, cIntegrationSubSteps, new JPH::TempAllocatorMalloc(), _JoltJobSystem);
|
||||
}
|
||||
|
||||
void DynamicWorld::Clear()
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Nuake {
|
||||
{
|
||||
json hullPointsJson;
|
||||
|
||||
const size_t hullSize = Hulls[i].size() - 1;
|
||||
const size_t hullSize = Hulls[i].size();
|
||||
for (uint32_t j = 0; j < hullSize; j++)
|
||||
{
|
||||
hullPointsJson[j]["x"] = Hulls[i][j].x;
|
||||
@@ -57,7 +57,7 @@ namespace Nuake {
|
||||
{
|
||||
BEGIN_DESERIALIZE();
|
||||
|
||||
if (j.contains("IsSolider"))
|
||||
if (j.contains("IsSolid"))
|
||||
{
|
||||
IsSolid = j["IsSolid"];
|
||||
}
|
||||
@@ -72,7 +72,7 @@ namespace Nuake {
|
||||
{
|
||||
Vector3 pointPos;
|
||||
DESERIALIZE_VEC3(point, pointPos);
|
||||
hull.push_back(std::move(pointPos));
|
||||
hull.push_back((pointPos));
|
||||
}
|
||||
|
||||
Hulls.push_back(hull);
|
||||
|
||||
@@ -467,7 +467,7 @@ namespace Nuake {
|
||||
{
|
||||
Entity newPEntity = Engine::GetCurrentScene()->CreateEntity("New prefab Entity");
|
||||
newEntity.AddChild(newPEntity);
|
||||
PrefabComponent& prefabComponent = newPEntity.AddComponent<PrefabComponent>();
|
||||
auto& prefabComponent = newPEntity.AddComponent<PrefabComponent>();
|
||||
prefabComponent.SetPrefab(Prefab::New(pointEntity.Prefab));
|
||||
for (auto& e : prefabComponent.PrefabInstance->Entities)
|
||||
{
|
||||
@@ -497,8 +497,8 @@ namespace Nuake {
|
||||
Entity brushEntity = m_Scene->CreateEntity("WorldSpawn");
|
||||
newEntity.AddChild(brushEntity);
|
||||
|
||||
TransformComponent& transformComponent = brushEntity.GetComponent<TransformComponent>();
|
||||
BSPBrushComponent& bsp = brushEntity.AddComponent<BSPBrushComponent>();
|
||||
auto& transformComponent = brushEntity.GetComponent<TransformComponent>();
|
||||
auto& bsp = brushEntity.AddComponent<BSPBrushComponent>();
|
||||
|
||||
bsp.IsSolid = true;
|
||||
bsp.IsTransparent = false;
|
||||
|
||||
Reference in New Issue
Block a user