#include "DisplayClass.h" #include "gl.h" #include "BSPTree.h" DisplayClass::Renderer DisplayClass::renderer; DisplayClass::DisplayClass() { cubeing[0] = Trapezocube(11.0, 10.0, 10.0, 0.5, 0.0, 0.0, 1.75, 0); cubeing[1] = Trapezocube(10.0, 9.0, 9.0, 0.5, 0.0, 0.0, 2.25, 90); cubeing[2] = Trapezocube(9.0, 8.0, 8.0, 0.5, 0.0, 0.0, 2.75, 180); cubeing[3] = Trapezocube(8.0, 7.0, 7.0, 0.5, 0.0, 0.0, 3.25, 270); cubeing[4] = Trapezocube(7.0, 6.0, 6.0, 0.5, 0.0, 0.0, 3.75, 0); cubeing[5] = Trapezocube(6.0, 5.0, 5.0, 0.5, 0.0, 0.0, 4.25, 90); cubeing[6] = Trapezocube(5.0, 4.0, 4.0, 0.5, 0.0, 0.0, 4.75, 180); cubeing[7] = Trapezocube(4.0, 3.0, 3.0, 0.5, 0.0, 0.0, 5.25, 270); } void DisplayClass::renderScene(unsigned long delta) { static float angle = 0.0; angle += delta*0.025; if(angle >= 360) angle -= 360; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // Clean up matrix glTranslatef(0.0, 0.0, -30.0); // Then set up transformation glRotatef(angle, 0.0, 1.0, 0.0); glRotatef(angle*2, 1.0, 0.0, 0.0); glRotatef(angle*3, 0.0, 0.0, 1.0); glRotatef(-angle*5, 1.0, 1.0, 1.0); std::list triangles; for(int i = 0; i < 8; ++i) { std::list t = cubeing[i].getTriangles(); triangles.splice(triangles.end(), t); } BSPTree tree(triangles); vmml::mat4f transform, inverseTransform; glGetFloatv(GL_MODELVIEW_MATRIX, transform.array); transform.inverse(inverseTransform); vmml::vec3f viewPoint = inverseTransform*vmml::vec3f(0, 0, 0); glBegin(GL_TRIANGLES); tree.visit(renderer, viewPoint); glEnd(); glFlush(); }