#include #include "oct.h" #include "view.h" draw_context::draw_context (view &v) : v(v), l(0), mode(LIGHTED) { } draw_context::~draw_context () { } bool draw_context::may_draw (entity_base *e) { if (drawn.find (e) != drawn.end ()) return false; drawn.insert (e); return true; } void view::draw (draw_context &ctx) { if (ctx.mode == draw_context::DEPTH) { glEnable (GL_POLYGON_OFFSET_FILL); glPolygonOffset (0, 1); glDrawBuffer (GL_NONE); glDepthFunc (GL_LESS); glDisable (GL_LIGHTING); } else { glDisable (GL_POLYGON_OFFSET_FILL); glDrawBuffer (GL_BACK); glDepthFunc (GL_LEQUAL); glEnable (GL_LIGHTING); } glViewport (0, 0, w, h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); GLdouble aspect = (GLdouble)w/h; GLdouble zNear = 0.001; GLdouble zFar = 100.; GLdouble ymax = zNear * tan (fov * (M_PI / 360.0)); glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar); vec3 rz = -d; vec3 rx = cross (u, rz); vec3 ry = cross (rz, rx); gl_matrix &m = ctx.projection; m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0; m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0; m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0; m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1; glMultMatrixf ((GLfloat *)m.data); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef (-p.x, -p.y, -p.z); world.draw (ctx); }