Added panel for box collider and created first rigidbody
This commit is contained in:
39
Editor/src/ComponentsPanel/BoxColliderPanel.h
Normal file
39
Editor/src/ComponentsPanel/BoxColliderPanel.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "ComponentPanel.h"
|
||||
#include <src/Scene/Components/BoxCollider.h>
|
||||
#include <src/Core/FileSystem.h>
|
||||
#include <src/Scene/Entities/ImGuiHelper.h>
|
||||
|
||||
class BoxColliderPanel : ComponentPanel {
|
||||
public:
|
||||
BoxColliderPanel() {}
|
||||
|
||||
void Draw(Nuake::Entity entity) override
|
||||
{
|
||||
if (!entity.HasComponent<Nuake::BoxColliderComponent>())
|
||||
return;
|
||||
|
||||
auto& component = entity.GetComponent<Nuake::BoxColliderComponent>();
|
||||
BeginComponentTable(BOX COLLIDER, Nuake::BoxColliderComponent);
|
||||
{
|
||||
{
|
||||
ImGui::Text("Size");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGuiHelper::DrawVec3("BoxSize", &component.Size);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.Size, glm::vec3(1, 1, 1));
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Is Trigger");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("##isTrigger", &component.IsTrigger);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.IsTrigger, false);
|
||||
}
|
||||
}
|
||||
EndComponentTable();
|
||||
}
|
||||
};
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
ImGui::Text("Collision");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Checkbox("#Collison", &component.HasCollisions);
|
||||
ImGui::Checkbox("##Collison", &component.HasCollisions);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.HasCollisions, true);
|
||||
}
|
||||
|
||||
@@ -1399,6 +1399,11 @@ namespace Nuake {
|
||||
|
||||
void EditorInterface::Update(float ts)
|
||||
{
|
||||
if (!Engine::GetCurrentScene())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto& editorCam = Engine::GetCurrentScene()->m_EditorCamera;
|
||||
editorCam->Update(ts, m_IsHoveringViewport);
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ EditorSelectionPanel::EditorSelectionPanel()
|
||||
mQuakeMapPanel = QuakeMapPanel();
|
||||
mCameraPanel = CameraPanel();
|
||||
mRigidbodyPanel = RigidbodyPanel();
|
||||
mBoxColliderPanel = BoxColliderPanel();
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::ResolveFile(Ref<Nuake::File> file)
|
||||
@@ -98,6 +99,7 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
|
||||
mQuakeMapPanel.Draw(entity);
|
||||
mCameraPanel.Draw(entity);
|
||||
mRigidbodyPanel.Draw(entity);
|
||||
mBoxColliderPanel.Draw(entity);
|
||||
|
||||
/*
|
||||
if (Selection.Entity.HasComponent<MeshComponent>())
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#include "../Actions/EditorSelection.h"
|
||||
#include "src/Scene/Entities/Entity.h"
|
||||
|
||||
#include "src/Core/FileSystem.h"
|
||||
#include <src/Resource/Project.h>
|
||||
|
||||
#include "../ComponentsPanel/TransformPanel.h"
|
||||
#include "../ComponentsPanel/LightPanel.h"
|
||||
@@ -10,9 +12,7 @@
|
||||
#include "../ComponentsPanel/QuakeMapPanel.h"
|
||||
#include "../ComponentsPanel/CameraPanel.h"
|
||||
#include "../ComponentsPanel/RigidbodyPanel.h"
|
||||
|
||||
#include "../Actions/EditorSelection.h"
|
||||
#include <src/Resource/Project.h>
|
||||
#include "../ComponentsPanel/BoxColliderPanel.h"
|
||||
|
||||
class EditorSelectionPanel {
|
||||
private:
|
||||
@@ -23,9 +23,11 @@ private:
|
||||
QuakeMapPanel mQuakeMapPanel;
|
||||
CameraPanel mCameraPanel;
|
||||
RigidbodyPanel mRigidbodyPanel;
|
||||
BoxColliderPanel mBoxColliderPanel;
|
||||
|
||||
Ref<Nuake::File> currentFile;
|
||||
Ref<Nuake::Resource> selectedResource;
|
||||
|
||||
public:
|
||||
EditorSelectionPanel();
|
||||
|
||||
|
||||
10
Nuake/JoltImplementation.h
Normal file
10
Nuake/JoltImplementation.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class JoltImplementation
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
@@ -185,6 +185,7 @@ namespace Nuake
|
||||
}
|
||||
};
|
||||
JPH::BodyID sphere_id;
|
||||
BPLayerInterfaceImpl JoltBroadphaseLayerInterface = BPLayerInterfaceImpl();
|
||||
namespace Physics
|
||||
{
|
||||
DynamicWorld::DynamicWorld() : _stepCount(0)
|
||||
@@ -194,10 +195,10 @@ namespace Nuake
|
||||
const uint32_t MaxBodyPairs = 1024;
|
||||
const uint32_t MaxContactConstraints = 1024;
|
||||
|
||||
BPLayerInterfaceImpl broad_phase_layer_interface;
|
||||
|
||||
|
||||
_JoltPhysicsSystem = CreateRef<JPH::PhysicsSystem>();
|
||||
_JoltPhysicsSystem->Init(MaxBodies, NumBodyMutexes, MaxBodyPairs, MaxContactConstraints, broad_phase_layer_interface, MyBroadPhaseCanCollide, MyObjectCanCollide);
|
||||
_JoltPhysicsSystem->Init(MaxBodies, NumBodyMutexes, MaxBodyPairs, MaxContactConstraints, JoltBroadphaseLayerInterface, MyBroadPhaseCanCollide, MyObjectCanCollide);
|
||||
|
||||
// A body activation listener gets notified when bodies activate and go to sleep
|
||||
// Note that this is called from a job so whatever you do here needs to be thread safe.
|
||||
@@ -213,7 +214,7 @@ namespace Nuake
|
||||
|
||||
// The main way to interact with the bodies in the physics system is through the body interface. There is a locking and a non-locking
|
||||
// variant of this. We're going to use the locking version (even though we're not planning to access bodies from multiple threads)
|
||||
JPH::BodyInterface& bodyInterface = _JoltPhysicsSystem->GetBodyInterface();
|
||||
_JoltBodyInterface = &_JoltPhysicsSystem->GetBodyInterface();
|
||||
|
||||
// Next we can create a rigid body to serve as the floor, we make a large box
|
||||
// Create the settings for the collision volume (the shape).
|
||||
@@ -228,16 +229,16 @@ namespace Nuake
|
||||
JPH::BodyCreationSettings floor_settings(floor_shape, JPH::Vec3(0.0f, -1.0f, 0.0f), JPH::Quat::sIdentity(), JPH::EMotionType::Static, Layers::NON_MOVING);
|
||||
|
||||
// Create the actual rigid body
|
||||
JPH::Body* floor = bodyInterface.CreateBody(floor_settings); // Note that if we run out of bodies this can return nullptr
|
||||
JPH::Body* floor = _JoltBodyInterface->CreateBody(floor_settings); // Note that if we run out of bodies this can return nullptr
|
||||
|
||||
bodyInterface.AddBody(floor->GetID(), JPH::EActivation::DontActivate);
|
||||
_JoltBodyInterface->AddBody(floor->GetID(), JPH::EActivation::DontActivate);
|
||||
|
||||
JPH::BodyCreationSettings sphere_settings(new JPH::SphereShape(0.5f), JPH::Vec3(0.0, 2.0, 0.0), JPH::Quat::sIdentity(), JPH::EMotionType::Dynamic, Layers::MOVING);
|
||||
sphere_id = bodyInterface.CreateAndAddBody(sphere_settings, JPH::EActivation::Activate);
|
||||
sphere_id = _JoltBodyInterface->CreateAndAddBody(sphere_settings, JPH::EActivation::Activate);
|
||||
|
||||
// Now you can interact with the dynamic body, in this case we're going to give it a velocity.
|
||||
// (note that if we had used CreateBody then we could have set the velocity straight on the body before adding it to the physics system)
|
||||
bodyInterface.SetLinearVelocity(sphere_id, JPH::Vec3(0.0f, -5.0f, 0.0f));
|
||||
_JoltBodyInterface->SetLinearVelocity(sphere_id, JPH::Vec3(0.0f, -5.0f, 0.0f));
|
||||
|
||||
// We simulate the physics world in discrete time steps. 60 Hz is a good rate to update the physics system.
|
||||
const float cDeltaTime = 1.0f / 60.0f;
|
||||
@@ -245,7 +246,7 @@ namespace Nuake
|
||||
// Optional step: Before starting the physics simulation you can optimize the broad phase. This improves collision detection performance (it's pointless here because we only have 2 bodies).
|
||||
// You should definitely not call this every frame or when e.g. streaming in a new level section as it is an expensive operation.
|
||||
// Instead insert all new objects in batches instead of 1 at a time to keep the broad phase efficient.
|
||||
_JoltPhysicsSystem->OptimizeBroadPhase();
|
||||
//_JoltPhysicsSystem->OptimizeBroadPhase();
|
||||
_JoltJobSystem = new JPH::JobSystemThreadPool(JPH::cMaxPhysicsJobs, JPH::cMaxPhysicsBarriers, std::thread::hardware_concurrency() - 1);
|
||||
}
|
||||
|
||||
@@ -271,16 +272,15 @@ namespace Nuake
|
||||
JPH::BoxShapeSettings boxShapeSettings(JPH::Vec3(boxSize.x, boxSize.y, boxSize.z));
|
||||
|
||||
// Create the shape
|
||||
JPH::ShapeSettings::ShapeResult floor_shape_result = boxShapeSettings.Create();
|
||||
JPH::ShapeRefC floor_shape = floor_shape_result.Get(); // We don't expect an error here, but you can check floor_shape_result for HasError() / GetError()
|
||||
JPH::ShapeSettings::ShapeResult boxShapeResult = boxShapeSettings.Create();
|
||||
JPH::ShapeRefC boxShape = boxShapeResult.Get(); // We don't expect an error here, but you can check floor_shape_result for HasError() / GetError()
|
||||
|
||||
// Create the settings for the body itself. Note that here you can also set other properties like the restitution / friction.
|
||||
JPH::BodyCreationSettings boxSettings(floor_shape, JPH::Vec3(0.0f, -1.0f, 0.0f), JPH::Quat::sIdentity(), JPH::EMotionType::Static, Layers::NON_MOVING);
|
||||
const auto& startPos = rb->GetPosition();
|
||||
JPH::BodyCreationSettings bodySettings(boxShape, JPH::Vec3(startPos.x, startPos.y, startPos.z), JPH::Quat::sIdentity(), JPH::EMotionType::Static, Layers::NON_MOVING);
|
||||
|
||||
// Create the actual rigid body
|
||||
JPH::Body* floor = bodyInterface.CreateBody(floor_settings); // Note that if we run out of bodies this can return nullptr
|
||||
|
||||
bodyInterface.AddBody(floor->GetID(), JPH::EActivation::DontActivate);
|
||||
JPH::BodyID floor = _JoltBodyInterface->CreateAndAddBody(bodySettings, JPH::EActivation::DontActivate); // Note that if we run out of bodies this can return nullptr
|
||||
}
|
||||
break;
|
||||
case RigidbodyShapes::SPHERE:
|
||||
|
||||
@@ -15,10 +15,12 @@ namespace JPH
|
||||
class JobSystemThreadPool;
|
||||
class ContactListener;
|
||||
class BodyActivationListener;
|
||||
class BodyInterface;
|
||||
}
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class BPLayerInterfaceImpl;
|
||||
class MyContactListener;
|
||||
class MyBodyActivationListener;
|
||||
|
||||
@@ -30,7 +32,8 @@ namespace Nuake
|
||||
JPH::JobSystemThreadPool* _JoltJobSystem;
|
||||
Scope<MyContactListener> _contactListener;
|
||||
Scope<MyBodyActivationListener> _bodyActivationListener;
|
||||
|
||||
JPH::BodyInterface* _JoltBodyInterface;
|
||||
BPLayerInterfaceImpl* _JoltBroadphaseLayerInterface;
|
||||
public:
|
||||
DynamicWorld();
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ public:
|
||||
KinematicBody();
|
||||
~KinematicBody();
|
||||
|
||||
|
||||
|
||||
void MoveAndCollide();
|
||||
void MoveAndSlide();
|
||||
};
|
||||
@@ -9,9 +9,10 @@ namespace Nuake
|
||||
namespace Physics {
|
||||
class RigidBody {
|
||||
private:
|
||||
Ref<PhysicShape> m_CollisionShape;
|
||||
Ref<PhysicShape> _collisionShape;
|
||||
Vector3 _position;
|
||||
public:
|
||||
float m_Mass;
|
||||
float _mass;
|
||||
|
||||
RigidBody();
|
||||
RigidBody(glm::vec3 position, Entity handle);
|
||||
@@ -20,10 +21,10 @@ namespace Nuake
|
||||
void UpdateTransform();
|
||||
|
||||
void SetEntityID(Entity ent);
|
||||
|
||||
bool HasShape() { return m_CollisionShape != nullptr; }
|
||||
Vector3 GetPosition() const { return _position; }
|
||||
bool HasShape() { return _collisionShape != nullptr; }
|
||||
void SetShape(Ref<PhysicShape> shape);
|
||||
Ref<PhysicShape> GetShape() const { return m_CollisionShape; }
|
||||
Ref<PhysicShape> GetShape() const { return _collisionShape; }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,15 @@ namespace Nuake
|
||||
|
||||
}
|
||||
|
||||
RigidBody::RigidBody(glm::vec3 position, Entity handle)
|
||||
RigidBody::RigidBody(glm::vec3 position, Entity handle) : _position(position)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RigidBody::RigidBody(float mass, glm::vec3 position, Ref<PhysicShape> shape, glm::vec3 initialVel)
|
||||
RigidBody::RigidBody(float mass, glm::vec3 position, Ref<PhysicShape> shape, glm::vec3 initialVel) :
|
||||
_position(position),
|
||||
_collisionShape(shape),
|
||||
_mass(mass)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace Nuake
|
||||
|
||||
if (!previous && controlled)
|
||||
{
|
||||
firstMouse = true;
|
||||
mouseLastX = x;
|
||||
mouseLastY = y;
|
||||
}
|
||||
@@ -42,6 +43,7 @@ namespace Nuake
|
||||
if (controlled && !isPressingMouse)
|
||||
{
|
||||
controlled = false;
|
||||
firstMouse = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +147,7 @@ namespace Nuake
|
||||
|
||||
if (Pitch > 89.0f)
|
||||
Pitch = 89.0f;
|
||||
|
||||
if (Pitch < -89.0f)
|
||||
Pitch = -89.0f;
|
||||
|
||||
@@ -172,7 +175,9 @@ namespace Nuake
|
||||
Translation += Vector3(Direction) * Input::YScroll;
|
||||
Input::YScroll = 0.0f;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
}
|
||||
mouseLastX = x;
|
||||
mouseLastY = y;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,6 @@ namespace Nuake
|
||||
|
||||
Ref<Physics::RigidBody> btRigidbody = CreateRef<Physics::RigidBody>(mass, transform.GetGlobalPosition(), boxShape);
|
||||
|
||||
rigidbody.m_Rigidbody = btRigidbody;
|
||||
|
||||
//btRigidbody->SetKinematic(rigidbody.IsKinematic);
|
||||
|
||||
PhysicsManager::Get()->RegisterBody(btRigidbody);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user