add graphics/core/Model
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
#include "Model.hpp"
|
||||
|
||||
using namespace model;
|
||||
|
||||
inline constexpr glm::vec3 X(1, 0, 0);
|
||||
inline constexpr glm::vec3 Y(0, 1, 0);
|
||||
inline constexpr glm::vec3 Z(0, 0, 1);
|
||||
|
||||
void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm) {
|
||||
vertices.push_back({pos-right-up, {0,0}, norm});
|
||||
vertices.push_back({pos+right-up, {1,0}, norm});
|
||||
vertices.push_back({pos+right+up, {1,1}, norm});
|
||||
|
||||
vertices.push_back({pos-right-up, {0,0}, norm});
|
||||
vertices.push_back({pos+right+up, {1,1}, norm});
|
||||
vertices.push_back({pos-right+up, {0,1}, norm});
|
||||
}
|
||||
|
||||
void Mesh::addBox(glm::vec3 pos, glm::vec3 size) {
|
||||
addPlane(pos+Z*size, X*size, Y*size, Z);
|
||||
addPlane(pos-Z*size, -X*size, Y*size, -Z);
|
||||
|
||||
addPlane(pos+Y*size, X*size, -Z*size, Y);
|
||||
addPlane(pos-Y*size, X*size, Z*size, -Y);
|
||||
|
||||
addPlane(pos+X*size, -Z*size, Y*size, X);
|
||||
addPlane(pos-X*size, Z*size, Y*size, -X);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef GRAPHICS_CORE_MODEL_HPP_
|
||||
#define GRAPHICS_CORE_MODEL_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace model {
|
||||
struct Vertex {
|
||||
glm::vec3 coord;
|
||||
glm::vec2 uv;
|
||||
glm::vec3 normal;
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
std::string texture;
|
||||
std::vector<Vertex> vertices;
|
||||
|
||||
void addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm);
|
||||
void addBox(glm::vec3 pos, glm::vec3 size);
|
||||
};
|
||||
|
||||
struct Model {
|
||||
std::vector<Mesh> meshes;
|
||||
|
||||
Mesh& addMesh(const std::string& texture) {
|
||||
meshes.push_back({texture, {}});
|
||||
return meshes[meshes.size()-1];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // GRAPHICS_CORE_MODEL_HPP_
|
||||
Reference in New Issue
Block a user