/* Burr Solver * Copyright (C) 2003-2006 Andreas Röver * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "VoxelView.h" #include #ifdef __APPLE__ #include #elif WIN32 #include #include #else #include #endif #include #include "../lib/puzzle.h" #include "pieceColor.h" #include VoxelView::VoxelView(int x,int y,int w,int h,const char *l) : Fl_Gl_Window(x,y,w,h,l), arcBall(new ArcBall_c(w, h)), doUpdates(true), size(10), cb(0) { }; static void gluPerspective(double fovy, double aspect, double zNear, double zFar) { double xmin, xmax, ymin, ymax; ymax = zNear * tan(fovy * 3.1415927 / 360.0); ymin = -ymax; xmin = ymin * aspect; xmax = ymax * aspect; glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); } void VoxelView::draw() { if (!doUpdates) return; if (!valid()) { GLfloat LightAmbient[]= { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat LightDiffuse[]= { 0.6f, 0.6f, 0.6f, 0.0f }; GLfloat LightPosition[]= { 700.0f, 200.0f, 700.0f, 1.0f }; GLfloat AmbientParams[] = {0.1, 0.1, 0.1, 1}; GLfloat DiffuseParams[] = {0.7, 0.7, 0.7, 0.1}; GLfloat SpecularParams[] = {0.4, 0.4, 0.4, 0.5}; glLoadIdentity(); glViewport(0,0,w(),h()); glEnable(GL_COLOR_MATERIAL); glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION, LightPosition); glEnable(GL_LIGHT1); glMaterialf(GL_FRONT, GL_SHININESS, 0.5); glMaterialfv(GL_FRONT, GL_AMBIENT, AmbientParams); glMaterialfv(GL_FRONT, GL_DIFFUSE, DiffuseParams); glMaterialfv(GL_FRONT, GL_SPECULAR, SpecularParams); glEnable(GL_RESCALE_NORMAL); arcBall->setBounds(w(), h()); unsigned char r, g, b; Fl::get_color(color(), r, g, b); glClearColor(r/255.0, g/255.0, b/255.0, 0); } if (!cb || !cb->PreDraw()) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(25, 1.0*w()/h(), size, size+100); glMatrixMode(GL_MODELVIEW); } glPushMatrix(); glTranslatef(0, 0, -20-size); drawData(); glPopMatrix(); if (cb) cb->PostDraw(); } void VoxelView::update(bool doIt) { doUpdates = doIt; if (doIt) redraw(); } int VoxelView::handle(int event) { if (Fl_Gl_Window::handle(event)) return 1; switch(event) { case FL_PUSH: arcBall->click(Fl::event_x(), Fl::event_y()); return 1; case FL_DRAG: arcBall->drag(Fl::event_x(), Fl::event_y()); redraw(); return 1; case FL_RELEASE: arcBall->clack(Fl::event_x(), Fl::event_y()); return 1; } return 0; } void VoxelView::addRotationTransformation(void) { arcBall->addTransform(); } void VoxelView::updateRequired(void) { redraw(); } void VoxelView::setSize(double sz) { size = sz; redraw(); }