96 lines
2.1 KiB
C++
96 lines
2.1 KiB
C++
/*
|
||
* © Copyright 2014 – Urheberrechtshinweis
|
||
* Alle Rechte vorbehalten / All Rights Reserved
|
||
*
|
||
* Programmcode ist urheberrechtlich geschuetzt.
|
||
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
|
||
* Keine Verwendung ohne explizite Genehmigung.
|
||
* (vgl. § 106 ff UrhG / § 97 UrhG)
|
||
*/
|
||
|
||
#include "Cube.h"
|
||
#include "Shader.h"
|
||
|
||
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,
|
||
|
||
};
|
||
|
||
|
||
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);
|
||
rs.funcs->glDrawArrays(GL_TRIANGLES, 0, 12*3);
|
||
//glDrawElements(GL_TRIANGLES, +12, GL_INT, cube_vertex_indices);
|
||
rs.shader->unsetVertices();
|
||
rs.shader->unsetNormals();
|
||
|
||
rs.shader->release();
|
||
|
||
};
|