First render

This commit is contained in:
Dynamitos
2020-10-23 01:47:56 +02:00
parent 8d4c43361b
commit b4fc5df74e
21 changed files with 128 additions and 43 deletions
+1 -1
View File
@@ -73,5 +73,5 @@ float4 fragmentMain(
} }
return float4(result, 1); return float4(0, 1, 0, 1);
} }
+1
View File
@@ -1,3 +1,4 @@
#pragma pack_matrix(column_major)
const static float PI = 3.1415926535897932f; const static float PI = 3.1415926535897932f;
const static uint MAX_PARTICLES = 65536; const static uint MAX_PARTICLES = 65536;
const static uint BLOCK_SIZE = 8; const static uint BLOCK_SIZE = 8;
+1
View File
@@ -2,6 +2,7 @@ struct PrimitiveSceneData
{ {
float4x4 localToWorld; float4x4 localToWorld;
float4x4 worldToLocal; float4x4 worldToLocal;
float4 actorLocation;
}; };
layout(set = 3, binding = 0, std430) layout(set = 3, binding = 0, std430)
+6 -20
View File
@@ -106,14 +106,6 @@ void findMeshRoots(aiNode *node, List<aiNode *> &meshNodes)
findMeshRoots(node->mChildren[i], meshNodes); findMeshRoots(node->mChildren[i], meshNodes);
} }
} }
void loadToBuffer(Array<Vector>& 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) VertexStreamComponent createVertexStream(uint32 size, aiVector3D* sourceData, Gfx::PGraphics graphics)
{ {
Array<Vector> buffer(size); Array<Vector> buffer(size);
@@ -126,9 +118,8 @@ VertexStreamComponent createVertexStream(uint32 size, aiVector3D* sourceData, Gf
vbInfo.vertexSize = sizeof(Vector); vbInfo.vertexSize = sizeof(Vector);
vbInfo.resourceData.data = (uint8 *)buffer.data(); vbInfo.resourceData.data = (uint8 *)buffer.data();
vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER; vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
vbInfo.resourceData.size = buffer.size(); vbInfo.resourceData.size = sizeof(Vector) * buffer.size();
const Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo); return VertexStreamComponent(graphics->createVertexBuffer(vbInfo), 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32B32_SFLOAT);
return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32B32_SFLOAT);
} }
VertexStreamComponent createVertexStream(uint32 size, aiVector2D* sourceData, Gfx::PGraphics graphics) 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.vertexSize = sizeof(Vector2);
vbInfo.resourceData.data = (uint8 *)buffer.data(); vbInfo.resourceData.data = (uint8 *)buffer.data();
vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER; vbInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER;
vbInfo.resourceData.size = buffer.size(); vbInfo.resourceData.size = sizeof(Vector2) * buffer.size();
Gfx::PVertexBuffer vertexBuffer = graphics->createVertexBuffer(vbInfo); return VertexStreamComponent(graphics->createVertexBuffer(vbInfo), 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT);
return VertexStreamComponent(vertexBuffer, 0, vbInfo.vertexSize, Gfx::SE_FORMAT_R32G32_SFLOAT);
} }
void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics) void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMeshes, const Array<PMaterialAsset>& materials, Gfx::PGraphics graphics)
{ {
@@ -190,7 +180,7 @@ void MeshLoader::loadGlobalMeshes(const aiScene* scene, Array<PMesh>& globalMesh
idxInfo.indexType = Gfx::SE_INDEX_TYPE_UINT32; idxInfo.indexType = Gfx::SE_INDEX_TYPE_UINT32;
idxInfo.resourceData.data = (uint8 *)indices.data(); idxInfo.resourceData.data = (uint8 *)indices.data();
idxInfo.resourceData.owner = Gfx::QueueType::DEDICATED_TRANSFER; 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); Gfx::PIndexBuffer indexBuffer = graphics->createIndexBuffer(idxInfo);
indexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS); indexBuffer->transferOwnership(Gfx::QueueType::GRAPHICS);
@@ -239,15 +229,11 @@ void MeshLoader::import(const std::filesystem::path &path)
Assimp::Importer importer; Assimp::Importer importer;
importer.ReadFile(path.string().c_str(), importer.ReadFile(path.string().c_str(),
aiProcess_FlipUVs | aiProcess_FlipUVs |
aiProcess_ImproveCacheLocality |
aiProcess_OptimizeMeshes |
aiProcess_GenBoundingBoxes |
aiProcess_Triangulate | aiProcess_Triangulate |
aiProcess_SortByPType | aiProcess_SortByPType |
aiProcess_GenSmoothNormals | aiProcess_GenSmoothNormals |
aiProcess_GenUVCoords | aiProcess_GenUVCoords |
aiProcess_FindDegenerates | aiProcess_FindDegenerates);
aiProcess_EmbedTextures);
const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace); const aiScene *scene = importer.ApplyPostProcessing(aiProcess_CalcTangentSpace);
Array<PMaterialAsset> globalMaterials(scene->mNumMaterials); Array<PMaterialAsset> globalMaterials(scene->mNumMaterials);
+17
View File
@@ -1868,6 +1868,23 @@ typedef enum SeStencilFaceFlagBits
SE_STENCIL_FACE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF SE_STENCIL_FACE_FLAG_BITS_MAX_ENUM = 0x7FFFFFFF
} SeStencilFaceFlagBits; } SeStencilFaceFlagBits;
typedef SeFlags SeStencilFaceFlags; 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 enum class QueueType
{ {
GRAPHICS = 1, GRAPHICS = 1,
+2 -2
View File
@@ -210,10 +210,10 @@ IndexBuffer::IndexBuffer(QueueFamilyMapping mapping, uint32 size, Gfx::SeIndexTy
switch (indexType) switch (indexType)
{ {
case SE_INDEX_TYPE_UINT16: case SE_INDEX_TYPE_UINT16:
numIndices = size / 16; numIndices = size / sizeof(uint16);
break; break;
case SE_INDEX_TYPE_UINT32: case SE_INDEX_TYPE_UINT32:
numIndices = size / 32; numIndices = size / sizeof(uint32);
default: default:
break; break;
} }
+7 -1
View File
@@ -569,7 +569,8 @@ public:
inline SeAttachmentStoreOp getStoreOp() const { return storeOp; } inline SeAttachmentStoreOp getStoreOp() const { return storeOp; }
inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; } inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; }
inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; } inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; }
SeClearValue clear;
SeColorComponentFlags componentFlags;
protected: protected:
PTexture2D texture; PTexture2D texture;
SeAttachmentLoadOp loadOp; SeAttachmentLoadOp loadOp;
@@ -589,6 +590,11 @@ public:
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE) SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE)
: RenderTargetAttachment(nullptr, loadOp, storeOp, stencilLoadOp, stencilStoreOp), owner(owner) : 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 virtual PTexture2D getTexture() override
{ {
+2 -1
View File
@@ -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; depthBufferInfo.usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
depthBuffer = graphics->createTexture2D(depthBufferInfo); depthBuffer = graphics->createTexture2D(depthBufferInfo);
Gfx::PRenderTargetAttachment depthAttachment = 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); Gfx::PRenderTargetLayout layout = new Gfx::RenderTargetLayout(colorAttachment, depthAttachment);
renderPass = graphics->createRenderPass(layout); renderPass = graphics->createRenderPass(layout);
+4 -1
View File
@@ -36,6 +36,10 @@ ShaderBuffer::ShaderBuffer(PGraphics graphics, uint32 size, VkBufferUsageFlags u
init::BufferCreateInfo( init::BufferCreateInfo(
usage, usage,
size); size);
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
uint32 queueFamilyIndex = graphics->getFamilyMapping().getQueueTypeFamilyIndex(queueType);
info.pQueueFamilyIndices = &queueFamilyIndex;
info.queueFamilyIndexCount = 0;
VkBufferMemoryRequirementsInfo2 bufferReqInfo; VkBufferMemoryRequirementsInfo2 bufferReqInfo;
bufferReqInfo.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2; bufferReqInfo.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2;
bufferReqInfo.pNext = nullptr; 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); 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()); vkBindBufferMemory(graphics->getDevice(), buffers[i].buffer, buffers[i].allocation->getHandle(), buffers[i].allocation->getOffset());
} }
info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
} }
ShaderBuffer::~ShaderBuffer() ShaderBuffer::~ShaderBuffer()
@@ -203,7 +203,7 @@ void SecondaryCmdBuffer::bindVertexBuffer(const Array<VertexInputStream>& stream
void SecondaryCmdBuffer::bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) void SecondaryCmdBuffer::bindIndexBuffer(Gfx::PIndexBuffer indexBuffer)
{ {
PIndexBuffer buf = indexBuffer.cast<IndexBuffer>(); PIndexBuffer buf = indexBuffer.cast<IndexBuffer>();
vkCmdBindIndexBuffer(handle, buf->getHandle(), 0, VK_INDEX_TYPE_UINT16); vkCmdBindIndexBuffer(handle, buf->getHandle(), 0, cast(buf->getIndexType()));
} }
void SecondaryCmdBuffer::draw(const MeshBatchElement& data) void SecondaryCmdBuffer::draw(const MeshBatchElement& data)
{ {
@@ -282,7 +282,6 @@ Array<const char *> Graphics::getRequiredExtensions()
{ {
extensions.add(glfwExtensions[i]); extensions.add(glfwExtensions[i]);
} }
std::cout << ENABLE_VALIDATION << std::endl;
#if ENABLE_VALIDATION #if ENABLE_VALIDATION
extensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); extensions.add(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
#endif // ENABLE_VALIDATION #endif // ENABLE_VALIDATION
@@ -1307,4 +1307,40 @@ Gfx::SeCompareOp Seele::Vulkan::cast(const VkCompareOp &op)
default: default:
return SE_COMPARE_OP_MAX_ENUM; return SE_COMPARE_OP_MAX_ENUM;
} }
} }
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;
}
@@ -46,5 +46,7 @@ VkPolygonMode cast(const Gfx::SePolygonMode &mode);
Gfx::SePolygonMode cast(const VkPolygonMode &mode); Gfx::SePolygonMode cast(const VkPolygonMode &mode);
VkCompareOp cast(const Gfx::SeCompareOp &op); VkCompareOp cast(const Gfx::SeCompareOp &op);
Gfx::SeCompareOp cast(const VkCompareOp &op); Gfx::SeCompareOp cast(const VkCompareOp &op);
VkClearValue cast(const Gfx::SeClearValue &clear);
Gfx::SeClearValue cast(const VkClearValue &clear);
} // namespace Vulkan } // namespace Vulkan
} // namespace Seele } // namespace Seele
@@ -131,7 +131,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
{ {
bindings.resize(element.streamIndex + 1); // This should not cause any actual allocations 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) if((bindingsMask & (1 << element.streamIndex)) != 0)
{ {
assert(currBinding.binding == element.streamIndex); assert(currBinding.binding == element.streamIndex);
@@ -228,7 +228,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
cast(gfxInfo.depthStencilState.depthCompareOp) cast(gfxInfo.depthStencilState.depthCompareOp)
); );
const auto colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments; const auto& colorAttachments = gfxInfo.renderPass->getLayout()->colorAttachments;
Array<VkPipelineColorBlendAttachmentState> blendAttachments(colorAttachments.size()); Array<VkPipelineColorBlendAttachmentState> blendAttachments(colorAttachments.size());
for(uint32 i = 0; i < colorAttachments.size(); ++i) for(uint32 i = 0; i < colorAttachments.size(); ++i)
{ {
@@ -237,7 +237,7 @@ PGraphicsPipeline PipelineCache::createPipeline(const GraphicsPipelineCreateInfo
blendAttachment.alphaBlendOp = (VkBlendOp)attachment.alphaBlendOp; blendAttachment.alphaBlendOp = (VkBlendOp)attachment.alphaBlendOp;
blendAttachment.blendEnable = attachment.blendEnable; blendAttachment.blendEnable = attachment.blendEnable;
blendAttachment.colorBlendOp = (VkBlendOp)attachment.colorBlendOp; blendAttachment.colorBlendOp = (VkBlendOp)attachment.colorBlendOp;
blendAttachment.colorWriteMask = attachment.colorWriteMask; blendAttachment.colorWriteMask = colorAttachments[i]->componentFlags;
blendAttachment.dstAlphaBlendFactor = (VkBlendFactor)attachment.dstAlphaBlendFactor; blendAttachment.dstAlphaBlendFactor = (VkBlendFactor)attachment.dstAlphaBlendFactor;
blendAttachment.srcAlphaBlendFactor = (VkBlendFactor)attachment.srcAlphaBlendFactor; blendAttachment.srcAlphaBlendFactor = (VkBlendFactor)attachment.srcAlphaBlendFactor;
blendAttachment.dstColorBlendFactor = (VkBlendFactor)attachment.dstColorBlendFactor; blendAttachment.dstColorBlendFactor = (VkBlendFactor)attachment.dstColorBlendFactor;
@@ -52,6 +52,12 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout)
desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
desc.finalLayout = 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(); VkAttachmentReference &ref = colorRefs.add();
ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
ref.attachment = attachmentCounter; ref.attachment = attachmentCounter;
@@ -71,6 +77,12 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::PRenderTargetLayout layout)
desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
desc.finalLayout = 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; VkAttachmentReference &ref = depthRef;
ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
ref.attachment = attachmentCounter; ref.attachment = attachmentCounter;
+3 -3
View File
@@ -8,7 +8,7 @@ Transform::Transform()
} }
Transform::Transform(Transform &&other) 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.position = Vector4(0, 0, 0, 0);
other.rotation = Quaternion(0, 0, 0, 0); other.rotation = Quaternion(0, 0, 0, 0);
@@ -16,7 +16,7 @@ Transform::Transform(Transform &&other)
} }
Transform::Transform(const 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 Transform::toMatrix()
{ {
Matrix4 mat; Matrix4 mat(1.0f);
mat[3][0] = position.x; mat[3][0] = position.x;
mat[3][1] = position.y; mat[3][1] = position.y;
+16 -3
View File
@@ -51,7 +51,12 @@ void Actor::setWorldLocation(Vector location)
{ {
rootComponent->setWorldLocation(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); rootComponent->setWorldRotation(rotation);
} }
@@ -63,7 +68,11 @@ void Actor::setRelativeLocation(Vector location)
{ {
rootComponent->setRelativeLocation(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); rootComponent->setRelativeRotation(rotation);
} }
@@ -75,7 +84,11 @@ void Actor::addWorldTranslation(Vector translation)
{ {
rootComponent->addWorldTranslation(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); rootComponent->addWorldRotation(rotation);
} }
+6 -3
View File
@@ -22,15 +22,18 @@ public:
void detachChild(PActor child); void detachChild(PActor child);
Array<PActor> getChildren(); Array<PActor> getChildren();
void setWorldLocation(Vector location); void setWorldLocation(Vector location);
void setWorldRotation(Vector4 rotation); void setWorldRotation(Quaternion rotation);
void setWorldRotation(Vector rotation);
void setWorldScale(Vector scale); void setWorldScale(Vector scale);
void setRelativeLocation(Vector location); void setRelativeLocation(Vector location);
void setRelativeRotation(Vector4 rotation); void setRelativeRotation(Quaternion rotation);
void setRelativeRotation(Vector rotation);
void setRelativeScale(Vector scale); void setRelativeScale(Vector scale);
void addWorldTranslation(Vector translation); void addWorldTranslation(Vector translation);
void addWorldRotation(Vector4 rotation); void addWorldRotation(Quaternion rotation);
void addWorldRotation(Vector rotation);
PComponent getRootComponent(); PComponent getRootComponent();
void setRootComponent(PComponent newRoot); void setRootComponent(PComponent newRoot);
+2
View File
@@ -14,6 +14,8 @@ CameraActor::CameraActor()
cameraComponent->aspectRatio = 1.777778f; cameraComponent->aspectRatio = 1.777778f;
cameraComponent->setParent(sceneComponent); cameraComponent->setParent(sceneComponent);
cameraComponent->setOwner(this); cameraComponent->setOwner(this);
addWorldTranslation(Vector(0, 0, 50));
addWorldRotation(Vector(0, -1, 0));
} }
CameraActor::~CameraActor() CameraActor::~CameraActor()
@@ -24,6 +24,7 @@ void CameraComponent::mouseMove(float deltaX, float deltaY)
rotationX += deltaX/100.f; rotationX += deltaX/100.f;
rotationY += deltaY/100.f; rotationY += deltaY/100.f;
rotationY = std::clamp(rotationY, -1.5f, 1.5f); rotationY = std::clamp(rotationY, -1.5f, 1.5f);
addWorldRotation(Vector(rotationX, rotationY, 0));
bNeedsViewBuild = true; bNeedsViewBuild = true;
} }
@@ -31,18 +32,20 @@ void CameraComponent::mouseScroll(double x)
{ {
distance += static_cast<float>(x); distance += static_cast<float>(x);
distance = std::max(distance, 1.f); distance = std::max(distance, 1.f);
addWorldTranslation(Vector(0, 0, x));
bNeedsViewBuild = true; bNeedsViewBuild = true;
} }
void CameraComponent::moveOrigin(float up) void CameraComponent::moveOrigin(float up)
{ {
originPoint.y += up; originPoint.y += up;
addWorldTranslation(Vector(0, up, 0));
bNeedsViewBuild = true; bNeedsViewBuild = true;
} }
void CameraComponent::buildViewMatrix() 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)); rotation = glm::rotate(rotation, rotationY, Vector(1, 0, 0));
Vector4 translation(0, 0, distance, 1); Vector4 translation(0, 0, distance, 1);
translation = rotation * translation; translation = rotation * translation;
+1 -1
View File
@@ -203,7 +203,7 @@ void Component::setRelativeLocationAndRotation(Vector newLocation, Quaternion ne
} }
const Transform desiredRelTransform(newLocation, newRotation); const Transform desiredRelTransform(newLocation, newRotation);
const Transform desiredWorldTransform = parent->getTransform() * desiredRelTransform; const Transform desiredWorldTransform = desiredRelTransform; // Check for absolutes etc
internalSetTransform(desiredWorldTransform.getPosition(), desiredWorldTransform.getRotation()); internalSetTransform(desiredWorldTransform.getPosition(), desiredWorldTransform.getRotation());
} }