From b4fc5df74e9b787ac28d250e7cb7fab63ca93016 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Fri, 23 Oct 2020 01:47:56 +0200 Subject: [PATCH] First render --- res/shaders/ForwardPlus.slang | 2 +- res/shaders/lib/Common.slang | 1 + res/shaders/lib/PrimitiveSceneData.slang | 1 + src/Engine/Asset/MeshLoader.cpp | 26 +++---------- src/Engine/Graphics/GraphicsEnums.h | 17 +++++++++ src/Engine/Graphics/GraphicsResources.cpp | 4 +- src/Engine/Graphics/GraphicsResources.h | 8 +++- src/Engine/Graphics/RenderPass/BasePass.cpp | 3 +- src/Engine/Graphics/Vulkan/VulkanBuffer.cpp | 5 ++- .../Graphics/Vulkan/VulkanCommandBuffer.cpp | 2 +- src/Engine/Graphics/Vulkan/VulkanGraphics.cpp | 1 - .../Graphics/Vulkan/VulkanGraphicsEnums.cpp | 38 ++++++++++++++++++- .../Graphics/Vulkan/VulkanGraphicsEnums.h | 2 + .../Graphics/Vulkan/VulkanPipelineCache.cpp | 6 +-- .../Graphics/Vulkan/VulkanRenderPass.cpp | 12 ++++++ src/Engine/Math/Transform.cpp | 6 +-- src/Engine/Scene/Actor/Actor.cpp | 19 ++++++++-- src/Engine/Scene/Actor/Actor.h | 9 +++-- src/Engine/Scene/Actor/CameraActor.cpp | 2 + .../Scene/Components/CameraComponent.cpp | 5 ++- src/Engine/Scene/Components/Component.cpp | 2 +- 21 files changed, 128 insertions(+), 43 deletions(-) diff --git a/res/shaders/ForwardPlus.slang b/res/shaders/ForwardPlus.slang index 14fc7c2..c5c4dc5 100644 --- a/res/shaders/ForwardPlus.slang +++ b/res/shaders/ForwardPlus.slang @@ -73,5 +73,5 @@ float4 fragmentMain( } - return float4(result, 1); + return float4(0, 1, 0, 1); } diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index fd8fc74..ca14766 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -1,3 +1,4 @@ +#pragma pack_matrix(column_major) const static float PI = 3.1415926535897932f; const static uint MAX_PARTICLES = 65536; const static uint BLOCK_SIZE = 8; diff --git a/res/shaders/lib/PrimitiveSceneData.slang b/res/shaders/lib/PrimitiveSceneData.slang index cd6e162..d0c72aa 100644 --- a/res/shaders/lib/PrimitiveSceneData.slang +++ b/res/shaders/lib/PrimitiveSceneData.slang @@ -2,6 +2,7 @@ struct PrimitiveSceneData { float4x4 localToWorld; float4x4 worldToLocal; + float4 actorLocation; }; layout(set = 3, binding = 0, std430) diff --git a/src/Engine/Asset/MeshLoader.cpp b/src/Engine/Asset/MeshLoader.cpp index e46b4ab..311689e 100644 --- a/src/Engine/Asset/MeshLoader.cpp +++ b/src/Engine/Asset/MeshLoader.cpp @@ -106,14 +106,6 @@ void findMeshRoots(aiNode *node, List &meshNodes) findMeshRoots(node->mChildren[i], meshNodes); } } -void loadToBuffer(Array& buffer, const aiVector3D* sourceData, uint32 size) -{ - buffer.resize(size); - for(uint32 i = 0; i < size; ++i) - { - buffer[i] = Vector(sourceData[i].x, sourceData[i].y, sourceData[i].z); - } -} VertexStreamComponent createVertexStream(uint32 size, aiVector3D* sourceData, Gfx::PGraphics graphics) { Array buffer(size); @@ -126,9 +118,8 @@ VertexStreamComponent createVertexStream(uint32 size, aiVector3D* sourceData, Gf vbInfo.vertexSize = sizeof(Vector); vbInfo.resourceData.data = (uint8 *)buffer.data(); vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER; - vbInfo.resourceData.size = buffer.size(); - const Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo); - return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32B32_SFLOAT); + vbInfo.resourceData.size = sizeof(Vector) * buffer.size(); + return VertexStreamComponent(graphics->createVertexBuffer(vbInfo), 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32B32_SFLOAT); } VertexStreamComponent createVertexStream(uint32 size, aiVector2D* sourceData, Gfx::PGraphics graphics) { @@ -142,9 +133,8 @@ VertexStreamComponent createVertexStream(uint32 size, aiVector2D* sourceData, Gf vbInfo.vertexSize = sizeof(Vector2); vbInfo.resourceData.data = (uint8 *)buffer.data(); vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER; - vbInfo.resourceData.size = buffer.size(); - Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo); - return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT); + vbInfo.resourceData.size = sizeof(Vector2) * buffer.size(); + return VertexStreamComponent(graphics->createVertexBuffer(vbInfo), 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT); } void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array& globalMeshes, const Array& materials, Gfx::PGraphics graphics) { @@ -190,7 +180,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array& globalMesh idxInfo.indexType = Gfx::SE_INDEX_TYPE_UINT32; idxInfo.resourceData.data = (uint8 *)indices.data(); idxInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER; - idxInfo.resourceData.size = indices.size(); + idxInfo.resourceData.size = sizeof(uint32) * indices.size(); Gfx::PIndexBuffer indexBuffer = graphics->createIndexBuffer(idxInfo); indexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS); @@ -239,15 +229,11 @@ void MeshLoader::import(const std::filesystem::path &path) Assimp::Importer importer; importer.ReadFile(path.string().c_str(), aiProcess_FlipUVs | - aiProcess_ImproveCacheLocality | - aiProcess_OptimizeMeshes | - aiProcess_GenBoundingBoxes | aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_GenSmoothNormals | aiProcess_GenUVCoords | - aiProcess_FindDegenerates | - aiProcess_EmbedTextures); + aiProcess_FindDegenerates); const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace); Array globalMaterials(scene->mNumMaterials); diff --git a/src/Engine/Graphics/GraphicsEnums.h b/src/Engine/Graphics/GraphicsEnums.h index dbbe085..970ff32 100644 --- a/src/Engine/Graphics/GraphicsEnums.h +++ b/src/Engine/Graphics/GraphicsEnums.h @@ -1868,6 +1868,23 @@ typedef enum SeStencilFaceFlagBits SE_STENCIL_FACE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF } SeStencilFaceFlagBits; typedef SeFlags SeStencilFaceFlags; + +typedef union SeClearColorValue { + float float32[4]; + int32_t int32[4]; + uint32_t uint32[4]; +} SeClearColorValue; + +typedef struct SeClearDepthStencilValue { + float depth; + uint32_t stencil; +} SeClearDepthStencilValue; + +typedef union SeClearValue { + SeClearColorValue color; + SeClearDepthStencilValue depthStencil; +} SeClearValue; + enum class QueueType { GRAPHICS = 1, diff --git a/src/Engine/Graphics/GraphicsResources.cpp b/src/Engine/Graphics/GraphicsResources.cpp index d95f79e..de7393f 100644 --- a/src/Engine/Graphics/GraphicsResources.cpp +++ b/src/Engine/Graphics/GraphicsResources.cpp @@ -210,10 +210,10 @@ IndexBuffer::IndexBuffer(QueueFamilyMapping mapping, uint32 size, Gfx::SeIndexTy switch (indexType) { case SE_INDEX_TYPE_UINT16: - numIndices = size / 16; + numIndices = size / sizeof(uint16); break; case SE_INDEX_TYPE_UINT32: - numIndices = size / 32; + numIndices = size / sizeof(uint32); default: break; } diff --git a/src/Engine/Graphics/GraphicsResources.h b/src/Engine/Graphics/GraphicsResources.h index 28d856f..a2669fc 100644 --- a/src/Engine/Graphics/GraphicsResources.h +++ b/src/Engine/Graphics/GraphicsResources.h @@ -569,7 +569,8 @@ public: inline SeAttachmentStoreOp getStoreOp() const { return storeOp; } inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; } inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; } - + SeClearValue clear; + SeColorComponentFlags componentFlags; protected: PTexture2D texture; SeAttachmentLoadOp loadOp; @@ -589,6 +590,11 @@ public: SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE) : RenderTargetAttachment(nullptr, loadOp, storeOp, stencilLoadOp, stencilStoreOp), owner(owner) { + clear.color.float32[0] = 0.0f; + clear.color.float32[1] = 0.0f; + clear.color.float32[2] = 0.0f; + clear.color.float32[3] = 0.0f; + componentFlags = SE_COLOR_COMPONENT_R_BIT | SE_COLOR_COMPONENT_G_BIT | SE_COLOR_COMPONENT_B_BIT | SE_COLOR_COMPONENT_A_BIT; } virtual PTexture2D getTexture() override { diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index d9ae906..a7d51be 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -93,7 +93,8 @@ BasePass::BasePass(const PScene scene, Gfx::PGraphics graphics, Gfx::PViewport v depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; depthBuffer = graphics->createTexture2D(depthBufferInfo); Gfx::PRenderTargetAttachment depthAttachment = - new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE); + new Gfx::RenderTargetAttachment(depthBuffer, Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); + depthAttachment->clear.depthStencil.depth = 1.0f; Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment); renderPass = graphics->createRenderPass(layout); diff --git a/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp b/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp index 0401014..659ce23 100644 --- a/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanBuffer.cpp @@ -36,6 +36,10 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, uint32 size, VkBufferUsageFlags u init::BufferCreateInfo( usage, size); + info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + uint32 queueFamilyIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(queueType); + info.pQueueFamilyIndices = &queueFamilyIndex; + info.queueFamilyIndexCount = 0; VkBufferMemoryRequirementsInfo2 bufferReqInfo; bufferReqInfo.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2; bufferReqInfo.pNext = nullptr; @@ -53,7 +57,6 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, uint32 size, VkBufferUsageFlags u buffers[i].allocation = graphics->getAllocator()->allocate(memRequirements, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, buffers[i].buffer); vkBindBufferMemory(graphics->getDevice(), buffers[i].buffer, buffers[i].allocation->getHandle(), buffers[i].allocation->getOffset()); } - info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; } ShaderBuffer::~ShaderBuffer() diff --git a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp index 92157c4..2ecb137 100644 --- a/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanCommandBuffer.cpp @@ -203,7 +203,7 @@ void SecondaryCmdBuffer::bindVertexBuffer(const Array& stream void SecondaryCmdBuffer::bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) { PIndexBuffer buf = indexBuffer.cast(); - vkCmdBindIndexBuffer(handle, buf->getHandle(), 0, VK_INDEX_TYPE_UINT16); + vkCmdBindIndexBuffer(handle, buf->getHandle(), 0, cast(buf->getIndexType())); } void SecondaryCmdBuffer::draw(const MeshBatchElement& data) { diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp index da11af9..e9002e8 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp @@ -282,7 +282,6 @@ Array Graphics::getRequiredExtensions() { extensions.add(glfwExtensions[i]); } - std::cout << ENABLE_VALIDATION << std::endl; #if ENABLE_VALIDATION extensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); #endif // ENABLE_VALIDATION diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp index 2871fe7..b18e2a8 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.cpp @@ -1307,4 +1307,40 @@ Gfx::SeCompareOp Seele::Vulkan::cast(const VkCompareOp &op) default: return SE_COMPARE_OP_MAX_ENUM; } -} \ No newline at end of file +} + +VkClearValue Seele::Vulkan::cast(const Gfx::SeClearValue& clear) +{ + VkClearValue result; + if(sizeof(clear) == sizeof(Gfx::SeClearColorValue)) + { + result.color.float32[0] = clear.color.float32[0]; + result.color.float32[1] = clear.color.float32[1]; + result.color.float32[2] = clear.color.float32[2]; + result.color.float32[3] = clear.color.float32[3]; + } + else + { + result.depthStencil.depth = clear.depthStencil.depth; + result.depthStencil.stencil = clear.depthStencil.stencil; + } + return result; +} + +Gfx::SeClearValue Seele::Vulkan::cast(const VkClearValue& clear) +{ + Gfx::SeClearValue result; + if(sizeof(clear) == sizeof(VkClearColorValue)) + { + result.color.float32[0] = clear.color.float32[0]; + result.color.float32[1] = clear.color.float32[1]; + result.color.float32[2] = clear.color.float32[2]; + result.color.float32[3] = clear.color.float32[3]; + } + else + { + result.depthStencil.depth = clear.depthStencil.depth; + result.depthStencil.stencil = clear.depthStencil.stencil; + } + return result; +} diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.h b/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.h index 7a7cbb1..51f73ab 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.h +++ b/src/Engine/Graphics/Vulkan/VulkanGraphicsEnums.h @@ -46,5 +46,7 @@ VkPolygonMode cast(const Gfx::SePolygonMode &mode); Gfx::SePolygonMode cast(const VkPolygonMode &mode); VkCompareOp cast(const Gfx::SeCompareOp &op); Gfx::SeCompareOp cast(const VkCompareOp &op); +VkClearValue cast(const Gfx::SeClearValue &clear); +Gfx::SeClearValue cast(const VkClearValue &clear); } // namespace Vulkan } // namespace Seele \ No newline at end of file diff --git a/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp b/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp index dd1d21c..2a5bb2c 100644 --- a/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanPipelineCache.cpp @@ -131,7 +131,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo { bindings.resize(element.streamIndex + 1); // This should not cause any actual allocations } - VkVertexInputBindingDescription currBinding = bindings[element.streamIndex]; + VkVertexInputBindingDescription& currBinding = bindings[element.streamIndex]; if((bindingsMask & (1 << element.streamIndex)) != 0) { assert(currBinding.binding == element.streamIndex); @@ -228,7 +228,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo cast(gfxInfo.depthStencilState.depthCompareOp) ); - const auto colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments; + const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments; Array blendAttachments(colorAttachments.size()); for(uint32 i = 0; i < colorAttachments.size(); ++i) { @@ -237,7 +237,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo blendAttachment.alphaBlendOp = (VkBlendOp)attachment.alphaBlendOp; blendAttachment.blendEnable = attachment.blendEnable; blendAttachment.colorBlendOp = (VkBlendOp)attachment.colorBlendOp; - blendAttachment.colorWriteMask = attachment.colorWriteMask; + blendAttachment.colorWriteMask = colorAttachments[i]->componentFlags; blendAttachment.dstAlphaBlendFactor = (VkBlendFactor)attachment.dstAlphaBlendFactor; blendAttachment.srcAlphaBlendFactor = (VkBlendFactor)attachment.srcAlphaBlendFactor; blendAttachment.dstColorBlendFactor = (VkBlendFactor)attachment.dstColorBlendFactor; diff --git a/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp b/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp index c90ec51..649cf0c 100644 --- a/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanRenderPass.cpp @@ -52,6 +52,12 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout) desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + VkClearValue& clearValue = clearValues.add(); + if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) + { + clearValue = cast(colorAttachment->clear); + } + VkAttachmentReference &ref = colorRefs.add(); ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; ref.attachment = attachmentCounter; @@ -71,6 +77,12 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout) desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + VkClearValue& clearValue = clearValues.add(); + if(desc.loadOp == VK_ATTACHMENT_LOAD_OP_CLEAR) + { + clearValue = cast(layout->depthAttachment->clear); + } + VkAttachmentReference &ref = depthRef; ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; ref.attachment = attachmentCounter; diff --git a/src/Engine/Math/Transform.cpp b/src/Engine/Math/Transform.cpp index 3691c9e..812393e 100644 --- a/src/Engine/Math/Transform.cpp +++ b/src/Engine/Math/Transform.cpp @@ -8,7 +8,7 @@ Transform::Transform() } Transform::Transform(Transform &&other) - : position(other.position), rotation(other.rotation), scale(scale) + : position(other.position), rotation(other.rotation), scale(other.scale) { other.position = Vector4(0, 0, 0, 0); other.rotation = Quaternion(0, 0, 0, 0); @@ -16,7 +16,7 @@ Transform::Transform(Transform &&other) } Transform::Transform(const Transform &other) - : position(other.position), rotation(other.rotation), scale(scale) + : position(other.position), rotation(other.rotation), scale(other.scale) { } @@ -45,7 +45,7 @@ Vector Transform::inverseTransformPosition(const Vector &v) const } Matrix4 Transform::toMatrix() { - Matrix4 mat; + Matrix4 mat(1.0f); mat[3][0] = position.x; mat[3][1] = position.y; diff --git a/src/Engine/Scene/Actor/Actor.cpp b/src/Engine/Scene/Actor/Actor.cpp index 806632e..5f0b5a4 100644 --- a/src/Engine/Scene/Actor/Actor.cpp +++ b/src/Engine/Scene/Actor/Actor.cpp @@ -51,7 +51,12 @@ void Actor::setWorldLocation(Vector location) { rootComponent->setWorldLocation(location); } -void Actor::setWorldRotation(Vector4 rotation) + +void Actor::setWorldRotation(Quaternion rotation) +{ + rootComponent->setWorldRotation(rotation); +} +void Actor::setWorldRotation(Vector rotation) { rootComponent->setWorldRotation(rotation); } @@ -63,7 +68,11 @@ void Actor::setRelativeLocation(Vector location) { rootComponent->setRelativeLocation(location); } -void Actor::setRelativeRotation(Vector4 rotation) +void Actor::setRelativeRotation(Quaternion rotation) +{ + rootComponent->setRelativeRotation(rotation); +} +void Actor::setRelativeRotation(Vector rotation) { rootComponent->setRelativeRotation(rotation); } @@ -75,7 +84,11 @@ void Actor::addWorldTranslation(Vector translation) { rootComponent->addWorldTranslation(translation); } -void Actor::addWorldRotation(Vector4 rotation) +void Actor::addWorldRotation(Quaternion rotation) +{ + rootComponent->addWorldRotation(rotation); +} +void Actor::addWorldRotation(Vector rotation) { rootComponent->addWorldRotation(rotation); } diff --git a/src/Engine/Scene/Actor/Actor.h b/src/Engine/Scene/Actor/Actor.h index 5ae57f7..2a733ec 100644 --- a/src/Engine/Scene/Actor/Actor.h +++ b/src/Engine/Scene/Actor/Actor.h @@ -22,15 +22,18 @@ public: void detachChild(PActor child); Array getChildren(); void setWorldLocation(Vector location); - void setWorldRotation(Vector4 rotation); + void setWorldRotation(Quaternion rotation); + void setWorldRotation(Vector rotation); void setWorldScale(Vector scale); void setRelativeLocation(Vector location); - void setRelativeRotation(Vector4 rotation); + void setRelativeRotation(Quaternion rotation); + void setRelativeRotation(Vector rotation); void setRelativeScale(Vector scale); void addWorldTranslation(Vector translation); - void addWorldRotation(Vector4 rotation); + void addWorldRotation(Quaternion rotation); + void addWorldRotation(Vector rotation); PComponent getRootComponent(); void setRootComponent(PComponent newRoot); diff --git a/src/Engine/Scene/Actor/CameraActor.cpp b/src/Engine/Scene/Actor/CameraActor.cpp index d374a2e..c3cb95e 100644 --- a/src/Engine/Scene/Actor/CameraActor.cpp +++ b/src/Engine/Scene/Actor/CameraActor.cpp @@ -14,6 +14,8 @@ CameraActor::CameraActor() cameraComponent->aspectRatio = 1.777778f; cameraComponent->setParent(sceneComponent); cameraComponent->setOwner(this); + addWorldTranslation(Vector(0, 0, 50)); + addWorldRotation(Vector(0, -1, 0)); } CameraActor::~CameraActor() diff --git a/src/Engine/Scene/Components/CameraComponent.cpp b/src/Engine/Scene/Components/CameraComponent.cpp index 48a84bd..67e52f6 100644 --- a/src/Engine/Scene/Components/CameraComponent.cpp +++ b/src/Engine/Scene/Components/CameraComponent.cpp @@ -24,6 +24,7 @@ void CameraComponent::mouseMove(float deltaX, float deltaY) rotationX += deltaX/100.f; rotationY += deltaY/100.f; rotationY = std::clamp(rotationY, -1.5f, 1.5f); + addWorldRotation(Vector(rotationX, rotationY, 0)); bNeedsViewBuild = true; } @@ -31,18 +32,20 @@ void CameraComponent::mouseScroll(double x) { distance += static_cast(x); distance = std::max(distance, 1.f); + addWorldTranslation(Vector(0, 0, x)); bNeedsViewBuild = true; } void CameraComponent::moveOrigin(float up) { originPoint.y += up; + addWorldTranslation(Vector(0, up, 0)); bNeedsViewBuild = true; } void CameraComponent::buildViewMatrix() { - Matrix4 rotation = glm::rotate(Matrix4(), rotationX, Vector(0, 1, 0)); + Matrix4 rotation = glm::rotate(Matrix4(1.0f), rotationX, Vector(0, 1, 0)); rotation = glm::rotate(rotation, rotationY, Vector(1, 0, 0)); Vector4 translation(0, 0, distance, 1); translation = rotation * translation; diff --git a/src/Engine/Scene/Components/Component.cpp b/src/Engine/Scene/Components/Component.cpp index df38619..9b2abfb 100644 --- a/src/Engine/Scene/Components/Component.cpp +++ b/src/Engine/Scene/Components/Component.cpp @@ -203,7 +203,7 @@ void Component::setRelativeLocationAndRotation(Vector newLocation, Quaternion ne } const Transform desiredRelTransform(newLocation, newRotation); - const Transform desiredWorldTransform = parent->getTransform() * desiredRelTransform; + const Transform desiredWorldTransform = desiredRelTransform; // Check for absolutes etc internalSetTransform(desiredWorldTransform.getPosition(), desiredWorldTransform.getRotation()); }