#include "Cube.h" #include "Shader.h" #include static float cube_vertices[] = { -1, -1, -1, -1, +1, -1, +1, +1, -1, +1, +1, -1, +1, -1, -1, -1, -1, -1, -1, -1, +1, +1, -1, +1, +1, +1, +1, +1, +1, +1, -1, +1, +1, -1, -1, +1, -1, -1, -1, +1, -1, -1, +1, -1, +1, +1, -1, +1, -1, -1, +1, -1, -1, -1, +1, -1, -1, +1, +1, -1, +1, +1, +1, +1, +1, +1, +1, -1, +1, +1, -1, -1, +1, +1, -1, -1, +1, -1, -1, +1, +1, -1, +1, +1, +1, +1, +1, +1, +1, -1, -1, +1, -1, -1, -1, -1, -1, -1, +1, -1, -1, +1, -1, +1, +1, -1, +1, -1, }; static float cube_normals[] = { 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, 0, +1, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, }; //static Shader* shader = nullptr; Cube::Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) { } Cube::Cube(Point3 pos, Point3 size, Point3 rot) : pos(pos), size(size), rot(rot) { } void Cube::setColor(float r, float g, float b) { this->color = Point3(r,g,b); } void Cube::render(const RenderSettings& rs) { rs.shader->bind(); QMatrix4x4 mat; mat.translate(pos.x, pos.y, pos.z); mat.rotate(rot.x, +1, 0, 0); mat.rotate(rot.y, 0, +1, 0); mat.rotate(rot.z, 0, 0, +1); mat.scale(size.x, size.y, size.z); rs.shader->setModelMatrix(mat); rs.shader->setColor(color.x, color.y, color.z); rs.shader->setVertices(cube_vertices); rs.shader->setNormals(cube_normals); glDrawArrays(GL_TRIANGLES, 0, 12*3); //glDrawElements(GL_TRIANGLES, +12, GL_INT, cube_vertex_indices); rs.shader->unsetVertices(); rs.shader->unsetNormals(); rs.shader->release(); };