This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/3D/misc/Cube.cpp
2018-10-25 12:15:13 +02:00

96 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © 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();
};