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
kazu 3b62f23c0e worked on 3D display
some ui changes
refactoring
new icons
2018-02-03 23:30:55 +01:00

89 lines
1.8 KiB
C++

#include "Cube.h"
#include "Shader.h"
#include <QtOpenGL>
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();
};