68 lines
1.8 KiB
C++
68 lines
1.8 KiB
C++
#include "WireCube.h"
|
|
|
|
void WireCube::setup()
|
|
{
|
|
_cube_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}};
|
|
|
|
glGenVertexArrays(1, &_vaoHandle);
|
|
glBindVertexArray(_vaoHandle);
|
|
|
|
glGenBuffers(1, &_vbo_vertices);
|
|
glBindBuffer(GL_ARRAY_BUFFER, _vbo_vertices);
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * _cube_vertices.size() * 3, _cube_vertices.data(), GL_STATIC_DRAW);
|
|
|
|
glVertexAttribPointer(
|
|
0, //attr number = 0
|
|
3,
|
|
GL_FLOAT,
|
|
GL_FALSE,
|
|
0,
|
|
(void*)0);
|
|
glEnableVertexAttribArray(0); //attr number = 0
|
|
}
|
|
|
|
WireCube::WireCube()
|
|
{
|
|
setup();
|
|
}
|
|
|
|
void WireCube::draw(ShaderProgram * shader, glm::mat4x4 proj_matrix, glm::mat4x4 view_matrix)
|
|
{
|
|
_model.glPushMatrix();
|
|
effectTransformations();
|
|
glm::mat4 mvpMatrix = proj_matrix * view_matrix * _model.getMatrix();
|
|
glUniformMatrix4fv(shader->uniform("mvp"), 1, GL_FALSE, glm::value_ptr(mvpMatrix));
|
|
|
|
glLineWidth(2);
|
|
glBindVertexArray(_vaoHandle);
|
|
for (int i = 0; i < _cube_vertices.size() * 3; i += 3)
|
|
glDrawArrays(GL_LINE_LOOP, i, 3);
|
|
_model.glPopMatrix();
|
|
}
|
|
|
|
DrawableType WireCube::getType()
|
|
{
|
|
return DrawableType::WIRE_CUBE;
|
|
}
|
|
|
|
WireCube::~WireCube()
|
|
{
|
|
}
|