cube
This commit is contained in:
@@ -20,6 +20,7 @@ Shape::Shape(
|
|||||||
glm::vec3 pos
|
glm::vec3 pos
|
||||||
)
|
)
|
||||||
: rotation { 0.0f, 0.0f, 0.0f }
|
: rotation { 0.0f, 0.0f, 0.0f }
|
||||||
|
, scale { 1.0f, 1.0f, 1.0f }
|
||||||
, vertices { shapeInfo.vertices }
|
, vertices { shapeInfo.vertices }
|
||||||
, indices { shapeInfo.indices }
|
, indices { shapeInfo.indices }
|
||||||
, pos { pos }
|
, pos { pos }
|
||||||
@@ -76,6 +77,7 @@ void Shape::draw() const {
|
|||||||
model = glm::rotate(model, glm::radians(rot_amount), rot_axis);
|
model = glm::rotate(model, glm::radians(rot_amount), rot_axis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
model = glm::scale(model, this->scale);
|
||||||
this->shader->set_mat4("model", model);
|
this->shader->set_mat4("model", model);
|
||||||
|
|
||||||
glBindVertexArray(this->vao);
|
glBindVertexArray(this->vao);
|
||||||
@@ -91,6 +93,7 @@ std::map<std::string, ShapeInfo> shapes {
|
|||||||
{
|
{
|
||||||
"triangle",
|
"triangle",
|
||||||
{
|
{
|
||||||
|
// clang-format off
|
||||||
.vertices = {
|
.vertices = {
|
||||||
0.0f, 0.5f, 0.0f, // top
|
0.0f, 0.5f, 0.0f, // top
|
||||||
-0.5f, -0.5f, 0.0f, // right
|
-0.5f, -0.5f, 0.0f, // right
|
||||||
@@ -99,6 +102,44 @@ std::map<std::string, ShapeInfo> shapes {
|
|||||||
.indices = {
|
.indices = {
|
||||||
0, 1, 2
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ struct ShapeInfo {
|
|||||||
class Shape {
|
class Shape {
|
||||||
public:
|
public:
|
||||||
glm::vec3 rotation;
|
glm::vec3 rotation;
|
||||||
|
glm::vec3 scale;
|
||||||
|
|
||||||
Shape(
|
Shape(
|
||||||
std::shared_ptr<Shader> shader,
|
std::shared_ptr<Shader> shader,
|
||||||
|
|||||||
11
src/main.cpp
11
src/main.cpp
@@ -157,17 +157,22 @@ int main() {
|
|||||||
{ shader, shapes.at("triangle"), { 0.0f, 0.0f, 0.0f } },
|
{ 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.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(1).rotation.y = 90.0f;
|
||||||
created_shapes.at(2).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 },
|
glm::vec4 { 1.0f, 0.0f, 0.0f, 0.0f },
|
||||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||||
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
||||||
{ 1.0f, 1.0f, 0.0f, 0.0f },
|
{ 1.0f, 1.0f, 0.0f, 0.0f },
|
||||||
|
{ 1.0f, 1.0f, 1.0f, 0.0f }
|
||||||
};
|
};
|
||||||
|
|
||||||
long unsigned int frame { 0 };
|
long unsigned int frame { 0 };
|
||||||
@@ -200,7 +205,7 @@ int main() {
|
|||||||
};
|
};
|
||||||
shader->set_mat4("projection", projection);
|
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]);
|
shader->set_vec4("thecolor", colors[i]);
|
||||||
created_shapes[i].draw();
|
created_shapes[i].draw();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user