Allowed scene items cleanup to happen earlier to prevent access null weak pointers. Also added Sphere Mesh and Sphere Collider(s)

This commit is contained in:
2024-11-26 18:44:52 -06:00
parent e91b1983c8
commit f4120095ed
22 changed files with 380 additions and 79 deletions

View File

@@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
CubeMesh.cpp
QuadMesh.cpp
SphereMesh.cpp
)

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "SphereMesh.hpp"
using namespace Dawn;
void SphereMesh::create(
std::shared_ptr<Mesh> mesh,
const float radius,
const uint32_t segments,
const uint32_t rings
) {
// Create the vertices
std::vector<glm::vec3> vertices;
for(uint32_t r = 0; r < rings; ++r) {
for(uint32_t s = 0; s < segments; ++s) {
float const y = sin(-M_PI_2 + M_PI * r / rings);
float const x = cos(2 * M_PI * s / segments) * sin(M_PI * r / rings);
float const z = sin(2 * M_PI * s / segments) * sin(M_PI * r / rings);
vertices.push_back(glm::vec3(x, y, z) * radius);
}
}
// Create the indices
std::vector<int32_t> indices;
for(uint32_t r = 0; r < rings - 1; ++r) {
for(uint32_t s = 0; s < segments - 1; ++s) {
indices.push_back(r * segments + s);
indices.push_back(r * segments + (s + 1));
indices.push_back((r + 1) * segments + (s + 1));
indices.push_back(r * segments + s);
indices.push_back((r + 1) * segments + (s + 1));
indices.push_back((r + 1) * segments + s);
}
}
mesh->createBuffers(vertices.size(), indices.size());
mesh->bufferPositions(0, vertices.data(), vertices.size());
mesh->bufferIndices(0, indices.data(), indices.size());
}

View File

@@ -0,0 +1,27 @@
// Copyright (c) 2024 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "display/mesh/Mesh.hpp"
namespace Dawn {
class SphereMesh {
public:
/**
* Creates a sphere mesh.
*
* @param mesh The mesh to buffer into.
* @param radius The radius of the sphere.
* @param segments The number of segments.
* @param rings The number of rings.
*/
static void create(
std::shared_ptr<Mesh> mesh,
const float radius = 1.0f,
const uint32_t segments = 16,
const uint32_t rings = 16
);
};
}