-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed and fixed the cmake list. Changed vulkan model, spriterendere…
…r3d(unfinished)
- Loading branch information
Showing
64 changed files
with
196 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
TestApp/Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/CubeMesh.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
}; |
12 changes: 3 additions & 9 deletions
12
TestApp/Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/SphereMesh.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
TestApp/Scenes/Assets/Components/Graphics/Meshes/MeshContainer.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 76 additions & 59 deletions
135
TestApp/src/Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/CubeMesh.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
55 changes: 48 additions & 7 deletions
55
TestApp/src/Scenes/Assets/Components/Graphics/Meshes/ChildrenMeshes/SphereMesh.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
59 changes: 9 additions & 50 deletions
59
TestApp/src/Scenes/Assets/Components/Graphics/Meshes/MeshContainer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// } | ||
//}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.