3#include <glm/ext/scalar_constants.hpp>
4#include <glm/geometric.hpp>
10const float PI = glm::pi<float>();
26inline std::vector<glm::vec3> skyboxGeometry{
28 {-1.0f, -1.0f, -1.0f},
32 {-1.0f, -1.0f, -1.0f},
44 {-1.0f, -1.0f, -1.0f},
45 {-1.0f, -1.0f, -1.0f},
56 {-1.0f, -1.0f, -1.0f},
61 {-1.0f, -1.0f, -1.0f},
71inline std::vector<glm::vec3> cubeGeometry{
103inline std::vector<unsigned int> cubeIndices{
107 14, 15, 12, 12, 15, 13,
108 16, 19, 18, 17, 19, 16,
109 22, 23, 20, 20, 23, 21};
110inline std::vector<glm::vec2> cubeTexCoord{
143inline std::vector<glm::vec3> cubeNormals{
170inline std::vector<glm::vec3> pyramidGeometry{
198inline std::vector<unsigned int> pyramidIndices{
199 0, 1, 2, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
201inline std::vector<glm::vec3> pyramidNormals{
221inline std::vector<glm::vec2> pyramidTexCoords{
241inline MeshInfo getSphereVertices(
const glm::vec3 ¢er = {0, 0, 0},
const glm::vec3 &radius = {1, 1, 1},
const unsigned int &stacks = 30,
const unsigned int &slices = 30) {
245 for (
auto i = 0; i <= stacks; ++i) {
247 float V = i / (float)stacks;
250 for (
int j = 0; j <= slices; ++j) {
252 float U = j / (float)slices;
253 float theta = U * (PI * 2);
255 float x = center.x + radius.x * (cosf(theta) * sinf(phi));
256 float y = center.y + radius.y * cosf(phi);
257 float z = center.z + radius.z * sinf(theta) * sinf(phi);
259 coords.
vertex.push_back(glm::vec3(x, y, z));
260 coords.
normals.push_back(glm::vec3(x, y, z));
264 coords.
texCoords.push_back(glm::vec2(s, t));
268 for (
auto i = 0; i < slices * stacks + slices; ++i) {
271 coords.
indices.push_back(i + slices + 1);
272 coords.
indices.push_back(i + slices);
274 coords.
indices.push_back(i + slices + 1);
276 coords.
indices.push_back(i + 1);
281inline MeshInfo getUnitCirclePoints(
const unsigned int &slices = 20) {
283 auto step = 2 * PI / slices;
286 for (
auto i = 0; i <= slices; i++) {
287 sectorAngle = i * step;
288 coords.
vertex.emplace_back(glm::cos(sectorAngle), glm::sin(sectorAngle), 0);
294inline MeshInfo getCylinderVertices(
const float &height = 5.f,
const unsigned int &slices = 20,
const Pair<float> radius = {1, 1},
const unsigned int &stacks = 20) {
296 auto unitCircle = getUnitCirclePoints(slices);
298 for (
auto i = 0; i < 2; i++) {
299 auto h = -height / 2.f + i * height;
302 for (
auto j = 0; j <= slices; j++) {
303 auto uv = unitCircle.vertex[j];
306 coords.
vertex.emplace_back(uv.x * radius.x, uv.y * radius.y, h);
308 coords.
normals.emplace_back(uv);
310 coords.
texCoords.emplace_back((
float)j / slices, t);
314 auto baseCenterIndex = unitCircle.vertex.size();
315 auto topCenterIndex = baseCenterIndex + slices + 1;
318 for (
int i = 0; i < 2; i++) {
319 auto h = (height / 2.f) * factor;
322 coords.
vertex.push_back({0, 0, h});
323 coords.
normals.push_back({0, 0, nz});
324 coords.
texCoords.push_back({0.5f, 0.5f});
326 for (
int j = 0; j <= slices; j++) {
327 auto uv = unitCircle.vertex[j];
330 coords.
vertex.push_back({uv.x * radius.x, uv.y * radius.y, h});
332 coords.
normals.push_back({0, 0, nz});
334 coords.
texCoords.push_back({-uv.x * 0.5f + 0.5f, -uv.y * 0.5f + 0.5f});
341 auto k2 = slices + 1;
343 for (
auto i = 0; i < slices; i++, k1++, k2++) {
344 coords.
indices.emplace_back(k1);
345 coords.
indices.emplace_back(k1 + 1);
346 coords.
indices.emplace_back(k2);
348 coords.
indices.emplace_back(k2);
349 coords.
indices.emplace_back(k1 + 1);
350 coords.
indices.emplace_back(k2 + 1);
353 for (
int i = 0, k = baseCenterIndex + 1; i < slices; i++, k++) {
354 coords.
indices.push_back(baseCenterIndex);
355 coords.
indices.push_back((i < slices - 1) ? k + 1 : baseCenterIndex + 1);
359 for (
int i = 0, k = topCenterIndex + 1; i < slices; i++, k++) {
360 coords.
indices.push_back(topCenterIndex);
362 coords.
indices.push_back((i < slices - 1) ? k + 1 : topCenterIndex + 1);
368inline MeshInfo getThorusVertices(
const unsigned int &side = 20,
const unsigned int §or = 20) {
370 float R = 1, r = 0.5;
372 float lenghtInv = 1.f / r;
373 float sectorStep = 2 * PI / sector;
374 float sideStep = 2 * PI / side;
376 float sideAngle, sectorAngle, xy, x, y, z;
380 for (
auto i = 0; i <= side; ++i) {
381 sideAngle = PI - i * sideStep;
382 xy = r * cosf(sideAngle);
383 z = r * sinf(sideAngle);
386 for (
auto j = 0; j <= sector; ++j) {
387 sectorAngle = j * sectorStep;
389 x = xy * cosf(sectorAngle);
390 y = xy * sinf(sectorAngle);
392 coords.
normals.push_back(glm::vec3{x, y, z} * lenghtInv);
394 x += R * cosf(sectorAngle);
395 y += R * sinf(sectorAngle);
396 coords.
vertex.push_back(glm::vec3(x, y, z));
399 s = (float)j / sector;
401 coords.
texCoords.push_back(glm::vec2(s, t));
406 for (
int i = 0; i < side; ++i) {
407 k1 = i * (sector + 1);
408 k2 = k1 + sector + 1;
409 for (
int j = 0; j < sector; ++j, ++k1, ++k2) {
412 coords.
indices.push_back(k1 + 1);
413 coords.
indices.push_back(k1 + 1);
415 coords.
indices.push_back(k2 + 1);
421inline std::vector<glm::vec4> getColorVector(
const glm::vec4 &color,
const size_t &size) {
422 auto res = std::vector<glm::vec4>{};
423 for (
size_t i = 0; i < size; i++) {
424 res.push_back(color);
Utility struct to temporally store mesh vectors.
Definition MeshVertices.hpp:15
std::vector< glm::vec3 > vertex
mesh normalized position coords vertices
Definition MeshVertices.hpp:17
std::vector< glm::vec2 > texCoords
mesh texture coords vertices
Definition MeshVertices.hpp:21
std::vector< glm::vec3 > normals
mesh normal coords vertices
Definition MeshVertices.hpp:19
std::vector< unsigned int > indices
mesh vertex coords indices
Definition MeshVertices.hpp:23