BIt more cleanup.

This commit is contained in:
2023-11-13 00:48:48 -06:00
parent dba5aa36c5
commit e3c484d20d
33 changed files with 336 additions and 311 deletions

View File

@@ -8,43 +8,40 @@
using namespace Dawn;
void CapsuleMesh::calculateRing(
int32_t segments,
float_t height,
float_t radius,
float_t dr,
float_t y,
float_t dy,
std::vector<glm::vec3> *positions
const int32_t segments,
const float_t height,
const float_t radius,
const float_t dr,
const float_t y,
const float_t dy,
std::vector<glm::vec3> &positions
) {
assertNotNull(positions, "CapsuleMesh::calculateRing: positions cannot be null");
float_t segIncr = 1.0f / (float_t)(segments - 1);
for(int32_t s = 0; s < segments; s++ ) {
float_t x = cosf(MATH_PI * 2 * s * segIncr) * dr;
float_t z = sinf(MATH_PI * 2 * s * segIncr) * dr;
positions->emplace_back(glm::vec3(radius * x, radius * y + height * dy, radius * z ));
positions.emplace_back(glm::vec3(radius * x, radius * y + height * dy, radius * z ));
}
}
void CapsuleMesh::create(
Mesh *mesh,
float_t radius,
float_t height
Mesh &mesh,
const float_t radius,
const float_t height
) {
assertNotNull(mesh, "CapsuleMesh::create: Mesh cannot be null");
std::vector<glm::vec3> positions;
std::vector<meshindice_t> indices;
int32_t slices = 12;
int32_t segments = 12;
int32_t ringsBody = slices + 1;
int32_t ringsTotal = slices + ringsBody;
const int32_t slices = 12;
const int32_t segments = 12;
const int32_t ringsBody = slices + 1;
const int32_t ringsTotal = slices + ringsBody;
positions.reserve(segments * ringsTotal);
indices.reserve((segments - 1) * (ringsTotal - 1) * 6);
float_t bodyIncr = 1.0f / (float_t)(ringsBody - 1);
float_t ringIncr = 1.0f / (float_t)(slices - 1);
const float_t bodyIncr = 1.0f / (float_t)(ringsBody - 1);
const float_t ringIncr = 1.0f / (float_t)(slices - 1);
for(int32_t r = 0; r < slices / 2; r++) {
calculateRing(
segments,
@@ -53,7 +50,7 @@ void CapsuleMesh::create(
sinf(MATH_PI * r * ringIncr),
sinf(MATH_PI * (r * ringIncr - 0.5f)),
-0.5f,
&positions
positions
);
}
@@ -65,7 +62,7 @@ void CapsuleMesh::create(
1.0f,
0.0f,
r * bodyIncr - 0.5f,
&positions
positions
);
}
@@ -77,7 +74,7 @@ void CapsuleMesh::create(
sinf(MATH_PI * r * ringIncr),
sinf(MATH_PI * (r * ringIncr - 0.5f)),
0.5f,
&positions
positions
);
}
@@ -93,7 +90,7 @@ void CapsuleMesh::create(
}
}
mesh->createBuffers(positions.size(), indices.size());
mesh->bufferPositions(0, positions.data(), positions.size());
mesh->bufferIndices(0, indices.data(), indices.size());
mesh.createBuffers(positions.size(), indices.size());
mesh.bufferPositions(0, positions.data(), positions.size());
mesh.bufferIndices(0, indices.data(), indices.size());
}

View File

@@ -11,20 +11,20 @@ namespace Dawn {
class CapsuleMesh {
protected:
static void calculateRing(
int32_t segments,
float_t height,
float_t radius,
float_t dr,
float_t y,
float_t dy,
std::vector<glm::vec3> *positions
const int32_t segments,
const float_t height,
const float_t radius,
const float_t dr,
const float_t y,
const float_t dy,
std::vector<glm::vec3> &positions
);
public:
static void create(
Mesh *mesh,
float_t radius,
float_t height
Mesh &mesh,
const float_t radius,
const float_t height
);
};
}

View File

@@ -8,12 +8,12 @@
using namespace Dawn;
void CubeMesh::buffer(
Mesh *mesh,
glm::vec3 pos, glm::vec3 size,
int32_t verticeStart, int32_t indiceStart
Mesh &mesh,
const glm::vec3 pos,
const glm::vec3 size,
const int32_t verticeStart,
const int32_t indiceStart
) {
assertNotNull(mesh, "CubeMesh::buffer: Mesh cannot be null");
glm::vec3 positions[CUBE_VERTICE_COUNT] = {
pos,
glm::vec3(pos.x+size.x, pos.y, pos.z),
@@ -64,7 +64,7 @@ void CubeMesh::buffer(
verticeStart + 1, verticeStart + 4, verticeStart + 5
};
mesh->bufferPositions(verticeStart, positions, CUBE_VERTICE_COUNT);
mesh->bufferCoordinates(verticeStart, coordinates, CUBE_VERTICE_COUNT);
mesh->bufferIndices(indiceStart, indices, CUBE_INDICE_COUNT);
mesh.bufferPositions(verticeStart, positions, CUBE_VERTICE_COUNT);
mesh.bufferCoordinates(verticeStart, coordinates, CUBE_VERTICE_COUNT);
mesh.bufferIndices(indiceStart, indices, CUBE_INDICE_COUNT);
}

View File

@@ -13,9 +13,11 @@ namespace Dawn {
class CubeMesh {
public:
static void buffer(
Mesh *mesh,
glm::vec3 pos, glm::vec3 size,
int32_t verticeStart, int32_t indiceStart
Mesh &mesh,
const glm::vec3 pos,
const glm::vec3 size,
const int32_t verticeStart,
const int32_t indiceStart
);
};
}

View File

@@ -8,13 +8,15 @@
using namespace Dawn;
void QuadMesh::bufferQuadMeshWithZ(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1,
float_t z, int32_t verticeStart, int32_t indiceStart
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 uv0,
const glm::vec2 xy1,
const glm::vec2 uv1,
const float_t z,
const int32_t verticeStart,
const int32_t indiceStart
) {
assertNotNull(mesh, "QuadMesh::bufferQuadMeshWithZ: Mesh cannot be null");
glm::vec3 positions[QUAD_VERTICE_COUNT] = {
glm::vec3(xy0, z),
glm::vec3(xy1.x, xy0.y, z),
@@ -30,16 +32,19 @@ void QuadMesh::bufferQuadMeshWithZ(
verticeStart + 1, verticeStart + 2, verticeStart + 3
};
mesh->bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
mesh->bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
mesh->bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
mesh.bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
mesh.bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
mesh.bufferIndices(indiceStart, indices, QUAD_INDICE_COUNT);
}
void QuadMesh::bufferQuadMesh(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1,
int32_t verticeStart, int32_t indiceStart
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 uv0,
const glm::vec2 xy1,
const glm::vec2 uv1,
const int32_t verticeStart,
const int32_t indiceStart
) {
QuadMesh::bufferQuadMeshWithZ(
mesh, xy0, uv0, xy1, uv1, 0, verticeStart, indiceStart
@@ -47,40 +52,41 @@ void QuadMesh::bufferQuadMesh(
}
void QuadMesh::bufferCoordinates(
Mesh *mesh,
glm::vec2 uv0, glm::vec2 uv1,
int32_t verticeStart
Mesh &mesh,
const glm::vec2 uv0,
const glm::vec2 uv1,
const int32_t verticeStart
) {
assertNotNull(mesh, "QuadMesh::bufferCoordinates: Mesh cannot be null");
glm::vec2 coordinates[QUAD_VERTICE_COUNT] = {
uv0, glm::vec2(uv1.x, uv0.y),
glm::vec2(uv0.x, uv1.y), uv1
};
mesh->bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
mesh.bufferCoordinates(verticeStart, coordinates, QUAD_VERTICE_COUNT);
}
void QuadMesh::bufferPositions(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 xy1,
int32_t verticeStart
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 xy1,
const int32_t verticeStart
) {
assertNotNull(mesh, "QuadMesh::bufferPositions: Mesh cannot be null");
glm::vec3 positions[QUAD_VERTICE_COUNT] = {
glm::vec3(xy0, 0),
glm::vec3(xy1.x, xy0.y, 0),
glm::vec3(xy0.x, xy1.y, 0),
glm::vec3(xy1, 0)
};
mesh->bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
mesh.bufferPositions(verticeStart, positions, QUAD_VERTICE_COUNT);
}
void QuadMesh::initQuadMesh(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1,
float_t z
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 uv0,
const glm::vec2 xy1,
const glm::vec2 uv1,
const float_t z
) {
assertNotNull(mesh, "QuadMesh::initQuadMesh: Mesh cannot be null");
mesh->createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
mesh.createBuffers(QUAD_VERTICE_COUNT, QUAD_INDICE_COUNT);
QuadMesh::bufferQuadMeshWithZ(mesh, xy0, uv0, xy1, uv1, z, 0, 0);
}

View File

@@ -26,10 +26,14 @@ namespace Dawn {
* @param indiceStart Start indice to buffer to.
*/
static void bufferQuadMeshWithZ(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1,
float_t z, int32_t verticeStart, int32_t indiceStart
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 uv0,
const glm::vec2 xy1,
const glm::vec2 uv1,
const float_t z,
const int32_t verticeStart,
const int32_t indiceStart
);
/**
@@ -44,10 +48,13 @@ namespace Dawn {
* @param indiceStart Start indice to buffer to.
*/
static void bufferQuadMesh(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1,
int32_t verticeStart, int32_t indiceStart
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 uv0,
const glm::vec2 xy1,
const glm::vec2 uv1,
const int32_t verticeStart,
const int32_t indiceStart
);
/**
@@ -59,9 +66,10 @@ namespace Dawn {
* @param verticeStart Start vertice to buffer in to.
*/
static void bufferCoordinates(
Mesh *mesh,
glm::vec2 uv0, glm::vec2 uv1,
int32_t verticeStart
Mesh &mesh,
const glm::vec2 uv0,
const glm::vec2 uv1,
const int32_t verticeStart
);
/**
@@ -73,9 +81,10 @@ namespace Dawn {
* @param verticeStart Start vertice to buffer to.
*/
static void bufferPositions(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 xy1,
int32_t verticeStart
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 xy1,
const int32_t verticeStart
);
/**
@@ -89,10 +98,12 @@ namespace Dawn {
* @param z The Z position of the coordinates.
*/
static void initQuadMesh(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,
glm::vec2 xy1, glm::vec2 uv1,
float_t z
Mesh &mesh,
const glm::vec2 xy0,
const glm::vec2 uv0,
const glm::vec2 xy1,
const glm::vec2 uv1,
const float_t z
);
};
}

View File

@@ -1,11 +0,0 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
class Mesh;
}