Skip to content

Commit

Permalink
Changed and fixed the cmake list. Changed vulkan model, spriterendere…
Browse files Browse the repository at this point in the history
…r3d(unfinished)
  • Loading branch information
ZHowe1 committed Nov 22, 2024
1 parent 02bbc49 commit b9509c7
Show file tree
Hide file tree
Showing 64 changed files with 196 additions and 179 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ set(dev_definitions
JPH_OBJECT_STREAM
)

target_compile_definitions(${PROJECT_NAME} PRIVATE ${dev_definitions})
target_compile_definitions(${PROJECT_NAME} PRIVATE ${dev_definitions})
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
class CubeMesh
#include <Scenes/Assets/Components/Graphics/Meshes/MeshContainer.hpp>
class CubeMesh : public MeshContainer
{
public:
CubeMesh();
void Draw();

};
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
#pragma once
#include "Core/SceneManagment/Components/GameComponent.hpp"
#include "Scenes/Assets/Components/Physics/PhysicsBody3D.hpp"
#include <Scenes/Assets/Components/Graphics/Meshes/MeshContainer.hpp>

class SphereMesh : public engine3d::GameComponent
class SphereMesh : public MeshContainer
{
public:
SphereMesh(int Radius, int SectorCount, int StackCount)
void CreateSphere();

private:
engine3d::Transform m_Transform;
glm::vec3* m_TransformPosition;
SphereMesh(int Radius, int SectorCount, int StackCount);
};
19 changes: 10 additions & 9 deletions TestApp/Scenes/Assets/Components/Graphics/Meshes/MeshContainer.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#include <Scenes/Assets/Components/Physics/PhysicsBody3D.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/SphereMesh.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/CubeMesh.hpp>

#pragma once
#include <glm/glm.hpp>
#include <vector>
#include <engine3d/Core/internal/Vulkan2Showcase/VulkanModel.hpp>
//! @brief Factory
class MeshContainer
{
public:
MeshContainer();


private:
MeshContainer() = default;
std::vector<engine3d::vk::VulkanModel::Vertex>* GetVertices(){return vertices;}
std::vector<glm::vec3> GetNormals(){return normals;}
std::vector<glm::vec2> GettexCoords(){return texCoords;}

std::vector<glm::vec3> vertices;
protected:
std::vector<engine3d::vk::VulkanModel::Vertex>* vertices;
std::vector<glm::vec3> normals;
std::vector<glm::vec2> texCoords;
};
4 changes: 2 additions & 2 deletions TestApp/Scenes/Assets/Components/Graphics/SpriteRender3D.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include <Core/SceneManagment/Components/GameComponent.hpp>
#include <engine3d/Core/SceneManagment/Components/GameComponent.hpp>
#include <Scenes/Assets/Components/Physics/PhysicsBody3D.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/MeshContainer.hpp>

Expand All @@ -16,7 +16,7 @@ class SpriteRender3D : public engine3d::GameComponent
std::vector<glm::vec2> texCoords;

private:
MeshContainer m_MeshContainer;
MeshContainer* m_MeshContainer;
engine3d::Transform m_Transform;
glm::vec3* m_TransformPosition;
};
Original file line number Diff line number Diff line change
@@ -1,63 +1,80 @@

#include "Core/internal/Vulkan2Showcase/VulkanModel.hpp"
#include <Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/CubeMesh.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/CubeMesh.hpp>
#include <vulkan/vulkan_core.h>
#include <glm/fwd.hpp>
#include <vector>

void CubeMesh::Draw()
CubeMesh::CubeMesh()
{
Ref<vk::VulkanModel> CreateCubeMesh(glm::vec3 offset){
std::vector<vk::VulkanModel::Vertex> vertices{
// left face (white)
{{-.5f, -.5f, -.5f}, {.9f, .9f, .9f}},
{{-.5f, .5f, .5f}, {.9f, .9f, .9f}},
{{-.5f, -.5f, .5f}, {.9f, .9f, .9f}},
{{-.5f, -.5f, -.5f}, {.9f, .9f, .9f}},
{{-.5f, .5f, -.5f}, {.9f, .9f, .9f}},
{{-.5f, .5f, .5f}, {.9f, .9f, .9f}},

// right face (yellow)
{{.5f, -.5f, -.5f}, {.8f, .8f, .1f}},
{{.5f, .5f, .5f}, {.8f, .8f, .1f}},
{{.5f, -.5f, .5f}, {.8f, .8f, .1f}},
{{.5f, -.5f, -.5f}, {.8f, .8f, .1f}},
{{.5f, .5f, -.5f}, {.8f, .8f, .1f}},
{{.5f, .5f, .5f}, {.8f, .8f, .1f}},

// top face (orange, remember y axis points down)
{{-.5f, -.5f, -.5f}, {.9f, .6f, .1f}},
{{.5f, -.5f, .5f}, {.9f, .6f, .1f}},
{{-.5f, -.5f, .5f}, {.9f, .6f, .1f}},
{{-.5f, -.5f, -.5f}, {.9f, .6f, .1f}},
{{.5f, -.5f, -.5f}, {.9f, .6f, .1f}},
{{.5f, -.5f, .5f}, {.9f, .6f, .1f}},

// bottom face (red)
{{-.5f, .5f, -.5f}, {.8f, .1f, .1f}},
{{.5f, .5f, .5f}, {.8f, .1f, .1f}},
{{-.5f, .5f, .5f}, {.8f, .1f, .1f}},
{{-.5f, .5f, -.5f}, {.8f, .1f, .1f}},
{{.5f, .5f, -.5f}, {.8f, .1f, .1f}},
{{.5f, .5f, .5f}, {.8f, .1f, .1f}},

// nose face (blue)
{{-.5f, -.5f, 0.5f}, {.1f, .1f, .8f}},
{{.5f, .5f, 0.5f}, {.1f, .1f, .8f}},
{{-.5f, .5f, 0.5f}, {.1f, .1f, .8f}},
{{-.5f, -.5f, 0.5f}, {.1f, .1f, .8f}},
{{.5f, -.5f, 0.5f}, {.1f, .1f, .8f}},
{{.5f, .5f, 0.5f}, {.1f, .1f, .8f}},

// tail face (green)
{{-.5f, -.5f, -0.5f}, {.1f, .8f, .1f}},
{{.5f, .5f, -0.5f}, {.1f, .8f, .1f}},
{{-.5f, .5f, -0.5f}, {.1f, .8f, .1f}},
{{-.5f, -.5f, -0.5f}, {.1f, .8f, .1f}},
{{.5f, -.5f, -0.5f}, {.1f, .8f, .1f}},
{{.5f, .5f, -0.5f}, {.1f, .8f, .1f}},
};
std::vector<glm::vec3> verts =
{
{.5f, -.5f, -.5f},
{.5f, -.5f, .5f},
{.5f, -.5f, -.5f},
{.5f, .5f, -.5f},
{.5f, .5f, .5f},
{-.5f, -.5f, -.5},
{.5f, -.5f, .5f},
{-.5f, -.5f, .5f},
{-.5f, -.5f, -.5},
{.5f, -.5f, -.5f},
{.5f, -.5f, .5f},
{-.5f, .5f, -.5f},
{.5f, .5f, .5f},
{-.5f, .5f, .5f},
{-.5f, .5f, -.5f},
{.5f, .5f, -.5f},
{.5f, .5f, .5f},
{-.5f, -.5f, 0.5},
{.5f, .5f, 0.5f},
{-.5f, .5f, 0.5f},
{-.5f, -.5f, 0.5},
{.5f, -.5f, 0.5f},
{.5f, .5f, 0.5f},
{-.5f, -.5f, -0.5},
{.5f, .5f, -0.5f},
{-.5f, .5f, -0.5},
{-.5f, -.5f, -0.5},
{.5f, -.5f, -0.5},
{.5f, .5f, -0.5f}

};

std::vector<glm::vec3> colors =
{
{.8f, .8f, .1f},
{.8f, .8f, .1f},
{.8f, .8f, .1f},
{.8f, .8f, .1f},
{.8f, .8f, .1f},
{.9f, .6f, .1f},
{.9f, .6f, .1f},
{.9f, .6f, .1f},
{.9f, .6f, .1f},
{.9f, .6f, .1f},
{.9f, .6f, .1f},
{.8f, .1f, .1f},
{.8f, .1f, .1f},
{.8f, .1f, .1f},
{.8f, .1f, .1f},
{.8f, .1f, .1f},
{.8f, .1f, .1f},

{.1f, .1f, .8f},
{.1f, .1f, .8f},
{.1f, .1f, .8f},
{.1f, .1f, .8f},
{.1f, .1f, .8f},
{.1f, .1f, .8f},

{.1f, .8f, .1},
{.1f, .8f, .1f},
{.1f, .8f, .1f},
{.1f, .8f, .1},
{.1f, .8f, .1f},
{.1f, .8f, .1f}
};

for (auto& v : vertices) {
v.Position += offset;
}
return CreateRef<vk::VulkanModel>(vertices, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
}
}
vertices = engine3d::vk::VulkanModel::CreateVertexVector(verts, colors);

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
// #include "Core/EngineLogger.hpp"
// #include <TestApp/SceneTest/Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/SphereMesh.hpp>
// #include <numbers>
#include "Core/internal/Vulkan2Showcase/VulkanModel.hpp"
#include <Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/SphereMesh.hpp>
using namespace engine3d;
#include <numbers>
SphereMesh::SphereMesh(int Radius, int SectorCount, int StackCount)
{

void SphereMesh::CreateSphere(){
m_Transform = m_GameObjectRef->SceneGetComponent<Transform>();
m_TransformPosition = &m_Transform.m_Position;
std::vector<glm::vec3> verts;
std::vector<glm::vec3>().swap(normals);
std::vector<glm::vec3>().swap(verts);
std::vector<glm::vec2>().swap(texCoords);
float nx, ny, nz, LengthInv = 1.0f / Radius; //vertex normal
float x, y, z, xy; //vertex position
float s, t; //vertex texCoord
float SectorStep = 2 * std::numbers::pi / SectorCount;
float StackStep = std::numbers::pi / StackCount;
float SectorAngle, StackAngle;
for(int i = 0; i <= StackCount; ++i)
{
// starting from pi/2 to -pi/2
StackAngle = std::numbers::pi / 2 - i * StackStep;
xy = Radius * cosf(StackAngle); // r * cos(u)
z = Radius * sinf(StackAngle); // r * sin(u)

// add (SectorCount+1) vertices per stack
// first and last vertices have same position
// and normal, but different tex coords
for(int j = 0; j <= SectorCount; ++j)
{

SectorAngle = j * SectorStep; // starting from 0 to 2pi

// vertex position (x, y, z)
x = xy * cosf(SectorAngle); // r * cos(u) * cos(v)
y = xy * sinf(SectorAngle); // r * cos(u) * sin(v)
verts.push_back(glm::vec3(x,y,z));

// normalized vertex normal (nx, ny, nz)
nx = x * LengthInv;
ny = y * LengthInv;
nz = z * LengthInv;
normals.push_back(glm::vec3(nx,ny,nz));

// vertex tex coord (s, t) range between [0, 1]
s = (float)j / SectorCount;
t = (float)i / StackCount;
texCoords.push_back(glm::vec2(s,t));
}
}

vertices = engine3d::vk::VulkanModel::CreateVertexVector(verts);
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,12 @@
#include <Core/EngineLogger.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/MeshContainer.hpp>
void MeshContainer::SphereBlueprint()
{
std::vector<glm::vec3>().swap(normals);
std::vector<glm::vec3>().swap(vertices);
std::vector<glm::vec2>().swap(texCoords);
float nx, ny, nz, LengthInv = 1.0f / Radius; //vertex normal
float x, y, z, xy; //vertex position
float s, t; //vertex texCoord
float SectorStep = 2 * std::numbers::pi / SectorCount;
float StackStep = std::numbers::pi / StackCount;
float SectorAngle, StackAngle;
for(int i = 0; i <= StackCount; ++i)
{
// starting from pi/2 to -pi/2
StackAngle = std::numbers::pi / 2 - i * StackStep;
xy = Radius * cosf(StackAngle); // r * cos(u)
z = Radius * sinf(StackAngle); // r * sin(u)

// add (SectorCount+1) vertices per stack
// first and last vertices have same position
// and normal, but different tex coords
for(int j = 0; j <= SectorCount; ++j)
{

SectorAngle = j * SectorStep; // starting from 0 to 2pi

// vertex position (x, y, z)
x = xy * cosf(SectorAngle); // r * cos(u) * cos(v)
y = xy * sinf(SectorAngle); // r * cos(u) * sin(v)
vertices.push_back(glm::vec3(x,y,z));

// normalized vertex normal (nx, ny, nz)
nx = x * LengthInv;
ny = y * LengthInv;
nz = z * LengthInv;
normals.push_back(glm::vec3(nx,ny,nz));

// vertex tex coord (s, t) range between [0, 1]
s = (float)j / SectorCount;
t = (float)i / StackCount;
texCoords.push_back(glm::vec2(s,t));
}
}
// For loop is used for printing out the position vectors
for (auto position : vertices)
{
ConsoleLogInfo("vector positions: ({0}, {1}, {2})", position.x,
position.y, position.z);
}
};
// void MeshContainer::SphereBlueprint()
// {
// // For loop is used for printing out the position vectors
// for (auto position : vertices)
// {
// ConsoleLogInfo("vector positions: ({0}, {1}, {2})", position.x,
// position.y, position.z);
// }
//};

26 changes: 4 additions & 22 deletions TestApp/src/Scenes/Assets/Components/Graphics/SpriteRender3D.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
#include <Scenes/Assets/Components/Graphics/SpriteRender3D.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/MeshContainer.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/CubeMesh.hpp>
#include <Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/SphereMesh.hpp>

// #include "Scene"

using namespace engine3d;
const int Radius = 1;
const int SectorCount = 10;
const int StackCount = 10;

SpriteRender3D(MeshContainer* meshBody) : m_MeshContainter(meshBody){}
void SpriteRender3D::CreateMesh()
{
// TODO: change from hardcoded values later
MeshContainer myMeshContainer(int 1, int 10, int 10);
myMeshContainer.SphereBlueprint();
};
SpriteRender3D::SpriteRender3D(MeshContainer* meshBody) : m_MeshContainer(meshBody){}

void SpriteRender3D::OnIntegrate()
{
Expand All @@ -33,18 +23,10 @@ void SpriteRender3D::OnIntegrate()
m_TransformPosition = &m_Transform.m_Position;
};

void SpriteRender3D::Update()
void SpriteRender3D::Update()
{
// std::vector<glm::vec3>().swap(normals);
// std::vector<glm::vec3>().swap(vertices);
// std::vector<glm::vec2>().swap(texCoords);
// float x, y, z, xy; //vertex position
// float nx, ny, nz, LengthInv = 1.0f / Radius; //vertex normal
// float s, t; //vertex texCoord
// float SectorStep = 2 * std::numbers::pi / SectorCount;
// float StackStep = std::numbers::pi / StackCount;
// float SectorAngle, StackAngle;

//! @note needs to be sent to the vulkanmodal
m_MeshContainer->GetVertices();
};

void SpriteRender3D::LateUpdate() {};
Expand Down
Loading

0 comments on commit b9509c7

Please sign in to comment.