This commit is contained in:
2026-01-26 01:39:22 +02:00
parent 034f737dfb
commit fed672f23e
3 changed files with 50 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ Shape::Shape(
glm::vec3 pos
)
: rotation { 0.0f, 0.0f, 0.0f }
, scale { 1.0f, 1.0f, 1.0f }
, vertices { shapeInfo.vertices }
, indices { shapeInfo.indices }
, pos { pos }
@@ -76,6 +77,7 @@ void Shape::draw() const {
model = glm::rotate(model, glm::radians(rot_amount), rot_axis);
}
}
model = glm::scale(model, this->scale);
this->shader->set_mat4("model", model);
glBindVertexArray(this->vao);
@@ -91,6 +93,7 @@ std::map<std::string, ShapeInfo> shapes {
{
"triangle",
{
// clang-format off
.vertices = {
0.0f, 0.5f, 0.0f, // top
-0.5f, -0.5f, 0.0f, // right
@@ -99,6 +102,44 @@ std::map<std::string, ShapeInfo> shapes {
.indices = {
0, 1, 2
}
// clang-format on
}
},
{
"cube",
{
// clang-format off
.vertices = {
-0.5f, 0.5f, 0.0f, // front top-left, 0
0.5f, 0.5f, 0.0f, // front top-right, 1
0.5f, -0.5f, 0.0f, // front bottom-right, 2
-0.5f, -0.5f, 0.0f, // front bottom-left, 3
-0.5f, 0.5f, -1.0f, // rear top-left, 4
0.5f, 0.5f, -1.0f, // rear top-right, 5
0.5f, -0.5f, -1.0f, // rear bottom-right, 6
-0.5f, -0.5f, -1.0f, // rear bottom-left, 7
},
.indices = {
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
0, 4, 3,
3, 7, 4,
2, 6, 1,
1, 5, 6,
0, 4, 1,
1, 5, 4,
2, 6, 3,
3, 7, 6
}
// clang-format on
}
}
};

View File

@@ -15,6 +15,7 @@ struct ShapeInfo {
class Shape {
public:
glm::vec3 rotation;
glm::vec3 scale;
Shape(
std::shared_ptr<Shader> shader,

View File

@@ -157,17 +157,22 @@ int main() {
{ shader, shapes.at("triangle"), { 0.0f, 0.0f, 0.0f } },
{ shader, shapes.at("triangle"), { 0.5f, 0.0f, -0.5f } },
{ shader, shapes.at("triangle"), { -0.5f, 0.0f, -0.5f } },
{ shader, shapes.at("triangle"), { 0.0f, 0.0f, -1.0f } }
{ shader, shapes.at("triangle"), { 0.0f, 0.0f, -1.0f } },
{ shader, shapes.at("cube"), { 0.0f, 0.0f, -0.25f }}
};
created_shapes.at(1).rotation.y = 90.0f;
created_shapes.at(2).rotation.y = 90.0f;
std::array<glm::vec4, 4> colors {
created_shapes.at(4).scale /= 2;
// created_shapes.at(4).scale.z /= 2;
std::array<glm::vec4, 5> colors {
glm::vec4 { 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 1.0f, 1.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 0.0f }
};
long unsigned int frame { 0 };
@@ -200,7 +205,7 @@ int main() {
};
shader->set_mat4("projection", projection);
for (int i { 0 }; i < created_shapes.size(); i++) {
for (std::size_t i { 0 }; i < created_shapes.size(); i++) {
shader->set_vec4("thecolor", colors[i]);
created_shapes[i].draw();
}