mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Reworked editor camera
This commit is contained in:
30
Editor/src/ComponentsPanel/RigidbodyPanel.h
Normal file
30
Editor/src/ComponentsPanel/RigidbodyPanel.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "ComponentPanel.h"
|
||||
#include <src/Scene/Components/RigidbodyComponent.h>
|
||||
#include <src/Core/FileSystem.h>
|
||||
|
||||
class RigidbodyPanel : ComponentPanel {
|
||||
|
||||
public:
|
||||
RigidbodyPanel() {}
|
||||
|
||||
void Draw(Nuake::Entity entity) override
|
||||
{
|
||||
if (!entity.HasComponent<Nuake::RigidBodyComponent>())
|
||||
return;
|
||||
|
||||
auto& component = entity.GetComponent<Nuake::RigidBodyComponent>();
|
||||
BeginComponentTable(RIGIDBODY, Nuake::RigidBodyComponent);
|
||||
{
|
||||
{
|
||||
ImGui::Text("Mass");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Mass", &component.Mass, 0.1f, 0.1f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.Mass, 0.0f);
|
||||
}
|
||||
}
|
||||
EndComponentTable();
|
||||
}
|
||||
};
|
||||
@@ -1406,7 +1406,12 @@ namespace Nuake {
|
||||
if (entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F))
|
||||
{
|
||||
editorCam->IsMoving = true;
|
||||
editorCam->TargetPos = Vector3(0, 0, 0);
|
||||
editorCam->TargetPos = Selection.Entity.GetComponent<TransformComponent>().GetGlobalPosition();
|
||||
}
|
||||
|
||||
if (entityIsSelected && Input::IsKeyPressed(GLFW_KEY_ESCAPE))
|
||||
{
|
||||
Selection = EditorSelection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ EditorSelectionPanel::EditorSelectionPanel()
|
||||
mScriptPanel = ScriptPanel();
|
||||
mQuakeMapPanel = QuakeMapPanel();
|
||||
mCameraPanel = CameraPanel();
|
||||
mRigidbodyPanel = RigidbodyPanel();
|
||||
}
|
||||
|
||||
void EditorSelectionPanel::ResolveFile(Ref<Nuake::File> file)
|
||||
@@ -96,6 +97,8 @@ void EditorSelectionPanel::DrawEntity(Nuake::Entity entity)
|
||||
mMeshPanel.Draw(entity);
|
||||
mQuakeMapPanel.Draw(entity);
|
||||
mCameraPanel.Draw(entity);
|
||||
mRigidbodyPanel.Draw(entity);
|
||||
|
||||
/*
|
||||
if (Selection.Entity.HasComponent<MeshComponent>())
|
||||
{
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../ComponentsPanel/MeshPanel.h"
|
||||
#include "../ComponentsPanel/QuakeMapPanel.h"
|
||||
#include "../ComponentsPanel/CameraPanel.h"
|
||||
#include "../ComponentsPanel/RigidbodyPanel.h"
|
||||
|
||||
#include "../Actions/EditorSelection.h"
|
||||
#include <src/Resource/Project.h>
|
||||
@@ -21,6 +22,7 @@ private:
|
||||
MeshPanel mMeshPanel;
|
||||
QuakeMapPanel mQuakeMapPanel;
|
||||
CameraPanel mCameraPanel;
|
||||
RigidbodyPanel mRigidbodyPanel;
|
||||
|
||||
Ref<Nuake::File> currentFile;
|
||||
Ref<Nuake::Resource> selectedResource;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <src/Vendors/glm/ext/quaternion_common.hpp>
|
||||
#include <src/Core/Logger.h>
|
||||
|
||||
#include <src/Core/Physics/PhysicsShapes.h>
|
||||
|
||||
#include <Jolt/Jolt.h>
|
||||
#include <Jolt/RegisterTypes.h>
|
||||
#include <Jolt/Core/Factory.h>
|
||||
@@ -257,6 +259,40 @@ namespace Nuake
|
||||
|
||||
void DynamicWorld::AddRigidbody(Ref<RigidBody> rb)
|
||||
{
|
||||
JPH::BodyInterface& bodyInterface = _JoltPhysicsSystem->GetBodyInterface();
|
||||
|
||||
auto rbShape = rb->GetShape();
|
||||
switch (rbShape->GetType())
|
||||
{
|
||||
case RigidbodyShapes::BOX:
|
||||
{
|
||||
Box* box = (Box*)rbShape.get();
|
||||
const Vector3& boxSize = box->GetSize();
|
||||
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()
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
break;
|
||||
case RigidbodyShapes::SPHERE:
|
||||
|
||||
break;
|
||||
case RigidbodyShapes::CAPSULE:
|
||||
|
||||
break;
|
||||
case RigidbodyShapes::MESH:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicWorld::AddGhostbody(Ref<GhostObject> gb)
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Nuake
|
||||
Size = glm::vec3(1);
|
||||
m_Type = BOX;
|
||||
}
|
||||
|
||||
// Sphere
|
||||
Box::Box(glm::vec3 size) {
|
||||
Size = size;
|
||||
@@ -21,8 +22,6 @@ namespace Nuake
|
||||
m_Type = BOX;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Sphere
|
||||
Sphere::Sphere(float radius) {
|
||||
Radius = radius;
|
||||
|
||||
@@ -3,17 +3,12 @@
|
||||
#include "../Core/Core.h"
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class Entity;
|
||||
namespace Physics {
|
||||
class RigidBody {
|
||||
private:
|
||||
bool m_IsDynamic = false;
|
||||
bool m_IsKinematic = false;
|
||||
Vector3 m_InitialVel;
|
||||
|
||||
Ref<PhysicShape> m_CollisionShape;
|
||||
public:
|
||||
float m_Mass;
|
||||
@@ -23,23 +18,12 @@ namespace Nuake
|
||||
RigidBody(float mass, glm::vec3 position, Ref<PhysicShape> shape, glm::vec3 initialVel = glm::vec3(0, 0, 0));
|
||||
|
||||
void UpdateTransform();
|
||||
Vector3 GetPosition() const;
|
||||
Vector3 GetRotation() const;
|
||||
|
||||
void SetEntityID(Entity ent);
|
||||
|
||||
void SetKinematic(bool value);
|
||||
bool IsKinematic() const { return m_IsKinematic; }
|
||||
|
||||
bool HasShape() { return m_CollisionShape != nullptr; }
|
||||
void SetShape(Ref<PhysicShape> shape);
|
||||
Ref<PhysicShape> GetShape() const { return m_CollisionShape; }
|
||||
|
||||
float GetMass() const { return m_Mass; }
|
||||
void SetMass(float m);
|
||||
|
||||
void MoveAndSlide(glm::vec3 velocity);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,65 +15,26 @@ namespace Nuake
|
||||
|
||||
RigidBody::RigidBody(glm::vec3 position, Entity handle)
|
||||
{
|
||||
Ref<Box> shape = CreateRef<Box>();
|
||||
m_CollisionShape = shape;
|
||||
|
||||
|
||||
|
||||
m_Mass = 0.0f;
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
m_IsDynamic = (m_Mass != 0.0f);
|
||||
|
||||
|
||||
|
||||
m_InitialVel = glm::vec3(0, 0, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
RigidBody::RigidBody(float mass, glm::vec3 position, Ref<PhysicShape> shape, glm::vec3 initialVel)
|
||||
{
|
||||
m_CollisionShape = shape;
|
||||
|
||||
m_Mass = mass;
|
||||
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
m_IsDynamic = (m_Mass != 0.0f);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RigidBody::SetShape(Ref<PhysicShape> shape)
|
||||
{
|
||||
m_CollisionShape = shape;
|
||||
|
||||
}
|
||||
|
||||
void RigidBody::UpdateTransform()
|
||||
{
|
||||
}
|
||||
|
||||
glm::vec3 RigidBody::GetRotation() const {
|
||||
return { 0, 0, 0 };
|
||||
}
|
||||
|
||||
void RigidBody::SetEntityID(Entity ent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RigidBody::SetKinematic(bool value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
glm::vec3 RigidBody::GetPosition() const {
|
||||
return { 0, 0, 0 };
|
||||
}
|
||||
|
||||
void RigidBody::SetMass(float m) { }
|
||||
void RigidBody::MoveAndSlide(glm::vec3 velocity)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Nuake
|
||||
this->IsEmbedded = true;
|
||||
|
||||
ModelLoader loader;
|
||||
auto otherModel = loader.LoadModel(FileSystem::Root + j["Path"].dump());
|
||||
auto otherModel = loader.LoadModel(j["Path"], false);
|
||||
m_Meshes = otherModel->GetMeshes();
|
||||
|
||||
this->Path = j["Path"];
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Nuake
|
||||
ModelLoader::ModelLoader() {}
|
||||
ModelLoader::~ModelLoader() {}
|
||||
|
||||
Ref<Model> ModelLoader::LoadModel(const std::string& path)
|
||||
Ref<Model> ModelLoader::LoadModel(const std::string& path, bool absolute)
|
||||
{
|
||||
m_Meshes.clear();
|
||||
Ref<Model> model = CreateRef<Model>(path);
|
||||
@@ -27,8 +27,9 @@ namespace Nuake
|
||||
aiProcess_FixInfacingNormals |
|
||||
aiProcess_CalcTangentSpace;
|
||||
|
||||
modelDir = path + "/../";
|
||||
const aiScene* scene = import.ReadFile(path, importFlags);
|
||||
modelDir = absolute ? path + "/../" : FileSystem::Root + path + "/../";
|
||||
const std::string filePath = absolute ? path : FileSystem::Root + path;
|
||||
const aiScene* scene = import.ReadFile(filePath, importFlags);
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
|
||||
{
|
||||
std::string assimpErrorMsg = std::string(import.GetErrorString());
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Nuake
|
||||
ModelLoader();
|
||||
~ModelLoader();
|
||||
|
||||
Ref<Model> LoadModel(const std::string& path);
|
||||
Ref<Model> LoadModel(const std::string& path, bool absolute = false);
|
||||
private:
|
||||
std::string modelDir;
|
||||
std::vector<Ref<Mesh>> m_Meshes;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Nuake {
|
||||
void ModelComponent::LoadModel()
|
||||
{
|
||||
auto loader = ModelLoader();
|
||||
this->ModelResource = loader.LoadModel(FileSystem::Root + ModelPath);
|
||||
this->ModelResource = loader.LoadModel(ModelPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Nuake
|
||||
bool Deserialize(const std::string str)
|
||||
{
|
||||
BEGIN_DESERIALIZE();
|
||||
ModelPath = j["ModelPath"].dump();
|
||||
ModelPath = j["ModelPath"];
|
||||
ModelResource = CreateRef<Model>();
|
||||
|
||||
if (j.contains("ModelResource"))
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "src/Rendering/Renderer.h"
|
||||
|
||||
namespace Nuake {
|
||||
RigidBodyComponent::RigidBodyComponent()
|
||||
RigidBodyComponent::RigidBodyComponent() : Mass(0.0f)
|
||||
{
|
||||
//m_Rigidbody = CreateRef<Physics::RigidBody>();
|
||||
}
|
||||
@@ -16,40 +16,11 @@ namespace Nuake {
|
||||
return m_Rigidbody;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetRigidBody(Ref<Physics::RigidBody> rb)
|
||||
{
|
||||
m_Rigidbody = rb;
|
||||
PhysicsManager::Get()->RegisterBody(rb);
|
||||
}
|
||||
|
||||
bool RigidBodyComponent::HasRigidBody() const
|
||||
{
|
||||
return m_Rigidbody != nullptr;
|
||||
}
|
||||
|
||||
float RigidBodyComponent::GetMass() {
|
||||
if (m_Rigidbody)
|
||||
return m_Rigidbody->GetMass();
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SetMass(float m)
|
||||
{
|
||||
if (!m_Rigidbody)
|
||||
return;
|
||||
m_Rigidbody->SetMass(m);
|
||||
}
|
||||
|
||||
|
||||
void RigidBodyComponent::SyncTransformComponent(TransformComponent* tc)
|
||||
{
|
||||
if (!m_Rigidbody)
|
||||
return;
|
||||
|
||||
glm::vec3 newPosition = m_Rigidbody->GetPosition();
|
||||
glm::vec3 newRotation = m_Rigidbody->GetRotation();
|
||||
//tc->Translation = newPosition;
|
||||
//tc->Rotation = newRotation;
|
||||
}
|
||||
|
||||
void RigidBodyComponent::SyncWithTransform(TransformComponent* tc)
|
||||
|
||||
@@ -12,23 +12,30 @@ namespace Nuake {
|
||||
class RigidBodyComponent
|
||||
{
|
||||
public:
|
||||
float mass = 0.0f;
|
||||
float Mass;
|
||||
Ref<Physics::RigidBody> m_Rigidbody;
|
||||
bool IsKinematic = false;
|
||||
|
||||
RigidBodyComponent();
|
||||
Ref<Physics::RigidBody> GetRigidBody() const;
|
||||
void SetRigidBody(Ref<Physics::RigidBody> rb);
|
||||
bool HasRigidBody() const;
|
||||
|
||||
void SetMass(float m);
|
||||
float GetMass();
|
||||
|
||||
|
||||
void SyncTransformComponent(TransformComponent* tc);
|
||||
void SyncWithTransform(TransformComponent* tc);
|
||||
|
||||
|
||||
void DrawShape(TransformComponent* tc);
|
||||
void DrawEditor();
|
||||
|
||||
json Serialize()
|
||||
{
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL_LBL("Mass", Mass);
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
bool Deserialize(std::string str)
|
||||
{
|
||||
BEGIN_DESERIALIZE();
|
||||
Mass = j["Mass"];
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -65,15 +65,14 @@ namespace Nuake
|
||||
float x = j["Rotation"]["x"];
|
||||
float y = j["Rotation"]["y"];
|
||||
float z = j["Rotation"]["z"];
|
||||
|
||||
this->Rotation = Quat(w, x, y, z);
|
||||
}
|
||||
|
||||
|
||||
this->Scale = Vector3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]);
|
||||
|
||||
LocalTransform = Matrix4(1);
|
||||
GlobalTransform = Matrix4(1);
|
||||
Dirty = true;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace Nuake
|
||||
if (glm::length(Translation - TargetPos) < 3.0f)
|
||||
{
|
||||
IsMoving = false;
|
||||
Translation = Translation - TargetPos;
|
||||
Translation = TargetPos - glm::normalize((TargetPos - Translation)) * 3.0f;
|
||||
Direction = TargetPos - Translation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +28,14 @@ namespace Nuake
|
||||
|
||||
if (hover)
|
||||
{
|
||||
bool previous = controlled;
|
||||
controlled = isPressingMouse;
|
||||
|
||||
if (!previous && controlled)
|
||||
{
|
||||
mouseLastX = x;
|
||||
mouseLastY = y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -164,6 +172,9 @@ namespace Nuake
|
||||
Translation += Vector3(Direction) * Input::YScroll;
|
||||
Input::YScroll = 0.0f;
|
||||
}
|
||||
|
||||
mouseLastX = x;
|
||||
mouseLastY = y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
#include "../Components/QuakeMap.h"
|
||||
#include "../Components/WrenScriptComponent.h"
|
||||
#include "../Components/CharacterControllerComponent.h"
|
||||
#include "../Components/RigidbodyComponent.h"
|
||||
#include "src/Scene/Components/BSPBrushComponent.h"
|
||||
|
||||
#include "src/Scene/Components/Components.h"
|
||||
#include <src/Scene/Components/BoxCollider.h>
|
||||
|
||||
//#include <src/Scene/Components/BoxCollider.h>
|
||||
#include "src/Scene/Components/BSPBrushComponent.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
void Entity::AddChild(Entity ent)
|
||||
@@ -53,6 +52,9 @@ namespace Nuake
|
||||
SERIALIZE_OBJECT_REF_LBL("BSPBrushComponent", GetComponent<BSPBrushComponent>());
|
||||
if (HasComponent<QuakeMapComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("QuakeMapComponent", GetComponent<QuakeMapComponent>());
|
||||
if (HasComponent<RigidBodyComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("RigidBodyComponent", GetComponent<RigidBodyComponent>());
|
||||
|
||||
END_SERIALIZE();
|
||||
}
|
||||
|
||||
@@ -74,6 +76,7 @@ namespace Nuake
|
||||
DESERIALIZE_COMPONENT(WrenScriptComponent);
|
||||
DESERIALIZE_COMPONENT(CharacterControllerComponent);
|
||||
DESERIALIZE_COMPONENT(BoxColliderComponent);
|
||||
DESERIALIZE_COMPONENT(RigidBodyComponent);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ namespace Nuake {
|
||||
BEGIN_SERIALIZE();
|
||||
SERIALIZE_VAL(Name);
|
||||
SERIALIZE_OBJECT(m_Environement)
|
||||
std::vector<json> entities = std::vector<json>();
|
||||
std::vector<json> entities = std::vector<json>();
|
||||
for (Entity e : GetAllEntities())
|
||||
entities.push_back(e.Serialize());
|
||||
SERIALIZE_VAL_LBL("Entities", entities);
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Nuake
|
||||
|
||||
if (ent.HasComponent<BoxColliderComponent>())
|
||||
{
|
||||
float mass = rigidbody.mass;
|
||||
float mass = rigidbody.Mass;
|
||||
|
||||
BoxColliderComponent& boxComponent = ent.GetComponent<BoxColliderComponent>();
|
||||
Ref<Physics::Box> boxShape = CreateRef<Physics::Box>(boxComponent.Size);
|
||||
|
||||
Reference in New Issue
Block a user