123 lines
4.1 KiB
C++
Raw Blame History

#pragma once
class Dataset
{
public:
Dataset() {}
~Dataset() {}
std::vector<glm::vec3> vertices;
std::vector<glm::vec3> normals;
std::vector<glm::vec3> colors;
std::vector<glm::vec2> tex_mapping;
void clear()
{
vertices.clear();
normals.clear();
colors.clear();
tex_mapping.clear();
}
void simpleCube()
{
clear();
vertices = { { -1.0, -1.0, 1.0}, { 1.0, -1.0, 1.0}, { 1.0, 1.0, 1.0},
{ 1.0, 1.0, 1.0}, { -1.0, 1.0, 1.0}, { -1.0, -1.0, 1.0},
{ 1.0, -1.0, 1.0}, { 1.0, -1.0, -1.0}, { 1.0, 1.0, -1.0},
{ 1.0, 1.0, -1.0}, { 1.0, 1.0, 1.0}, { 1.0, -1.0, 1.0},
{ -1.0, 1.0, -1.0}, { 1.0, 1.0, -1.0}, { 1.0, -1.0, -1.0},
{ 1.0, -1.0, -1.0}, { -1.0, -1.0, -1.0}, { -1.0, 1.0, -1.0},
{ -1.0, -1.0, -1.0}, { -1.0, -1.0, 1.0}, { -1.0, 1.0, 1.0},
{ -1.0, 1.0, 1.0}, { -1.0, 1.0, -1.0}, { -1.0, -1.0, -1.0},
{ -1.0, -1.0, -1.0}, { 1.0, -1.0, -1.0}, { 1.0, -1.0, 1.0},
{ 1.0, -1.0, 1.0}, { -1.0, -1.0, 1.0}, { -1.0, -1.0, -1.0},
{ -1.0, 1.0, 1.0}, { 1.0, 1.0, 1.0}, { 1.0, 1.0, -1.0},
{ 1.0, 1.0, -1.0}, { -1.0, 1.0, -1.0}, { -1.0, 1.0, 1.0} };
tex_mapping = {
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, // one triangle
{0.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}, //the other triangle
};
colors = {
{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
{0.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 0.0, 0.0},
{0.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
{0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0},
{1.0, 1.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 0.0},
{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 1.0},
{1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 1.0},
{1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 0.0, 0.0},
{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 1.0, 0.0},
{0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
{1.0, 1.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0},
{0.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}
},
genNormals();
}
void simpleFloor()
{
clear();
vertices = {{-10.0, 0.0, -10.0}, {-10.0, 0.0, 10.0}, {10.0, 0.0, -10.0},
{10.0, 0.0, 10.0}, {10.0, 0.0, -10.0}, {-10.0, 0.0, 10.0}};
colors = { {0.7, 0.7, 0.7}, {0.7, 0.7, 0.7}, {0.7, 0.7, 0.7},
{0.7, 0.7, 0.7}, {0.7, 0.7, 0.7}, {0.7, 0.7, 0.7} };
genNormals();
}
void checkeredFloor(float size, int squares,
glm::vec3 light_color, glm::vec3 dark_color)
{
clear();
float maxX = size / 2.f, maxY = size / 2.f;
float minX = -size / 2.f, minY = -size / 2.f;
float side_size = size / (float)squares;
int color = 1;
for (float x = minX; x < maxX; x += side_size)
{
for (float y = minY; y < maxY; y += side_size)
{
color *= -1;
glm::vec3 tile_color = (color > 0) ? light_color : dark_color;
//gen 1 carr<72>
vertices.emplace_back(x, 0, y); //upleft
vertices.emplace_back(x, 0, y + side_size); //downleft
vertices.emplace_back(x + side_size, 0, y + side_size); //downright
vertices.emplace_back(x + side_size, 0, y + side_size); //downright
vertices.emplace_back(x + side_size, 0, y); //upright
vertices.emplace_back(x, 0, y); //upleft
for (int z = 0; z < 6; z++)
colors.push_back(tile_color);
}
color *= -1;
}
genNormals();
}
private:
void genNormals()
{
for (unsigned int i = 0; i < vertices.size() - 2; i += 3)
{
glm::vec3 norm = glm::cross(vertices[i + 1] - vertices[i], vertices[i + 2] - vertices[i]);
normals.push_back(norm); normals.push_back(norm); normals.push_back(norm);
}
}
};