#include "DisplayClass.h" #include "gl.h" #include "BSPTree.h" DisplayClass::Renderer DisplayClass::renderer; DisplayClass::DisplayClass() { cubehole0 = Cubehole(3.0, 6.0, 3.0, 0.0, 0.0, 0.0, 2.0, 2.0, vmml::vec4f(1.0, 0.85, 0.06, 0.5), vmml::vec4f(1.0, 0.85, 0.06, 0.5), vmml::vec4f(1.0, 0.85, 0.06, 0.5), vmml::vec4f(1.0, 0.85, 0.06, 0.5)); cubehole1 = Cubehole(2.0, 6.0, 2.0, 0.0, 0.0, 0.0, 1.0, 1.0, vmml::vec4f(0.0, 0.85, 0.06, 0.5), vmml::vec4f(0.0, 0.85, 0.06, 0.5), vmml::vec4f(0.0, 0.85, 0.06, 0.5), vmml::vec4f(0.0, 0.85, 0.06, 0.5)); cubehole2 = Cubehole(1.0, 6.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, vmml::vec4f(1.0, 0.0, 0.06, 0.5), vmml::vec4f(1.0, 0.0, 0.06, 0.5), vmml::vec4f(1.0, 0.0, 0.06, 0.5), vmml::vec4f(1.0, 0.0, 0.06, 0.5)); } 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, -15.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 = cubehole0.getTriangles(); std::list t1 = cubehole1.getTriangles(); triangles.splice(triangles.end(), t1); std::list t2 = cubehole2.getTriangles(); triangles.splice(triangles.end(), t2); BSPTree tree(triangles); vmml::mat4f transform, inverseTransform; glGetFloatv(GL_MODELVIEW_MATRIX, transform.array); transform.inverse(inverseTransform); vmml::vec3f viewPoint = inverseTransform*vmml::vec3f::ZERO; glBegin(GL_TRIANGLES); tree.visit(renderer, viewPoint); glEnd(); glFlush(); }