//**************************************************************************** //! \file engine.hpp //! \date 23-05-2003 //! \class WEngine //! \brief The central Class of the Weird Engine //! \struct Tcoord //! \brief the koordinates phasespace //! \struct TGLObject //! \brief derifed struct designed to contain GL Object lists //! \struct TGLLight //! \brief derived struct designed to contain GL Lights //**************************************************************************** // This file is part of the Dataview. // // The Dataview 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. // // The Dataview 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 DataView; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //**************************************************************************** #ifndef ENGINE_HPP #define ENGINE_HPP #include #include #include #include #include #include #include static const double P2 = 18/M_PI; static const double P3 = 180/M_PI; using namespace std; //*************************************************************************** struct Tcoord //---------------------------------------------------------------------------- //! base class for all object characterisation structs; containing coordinates, //! the speed vector, the eulerian angles und the rotation vector //! used as Camera coordinate container //! \todo get rid of the double coordinate representation and introduce vectors //*************************************************************************** { double x;//!< the position x coordinate double y;//!< the position y coordinate double z;//!< the position z coordinate double vx;//!< the position x speed coordinate double vy;//!< the position y speed coordinate double vz;//!< the position z speed coordinate double ax;//!< the position euler angle around x axis double ay;//!< the position euler angle around y axis double az;//!< the position euler angle around z axis double vax;//!< the position rotation speed around x axis double vay;//!< the position rotation speed around y axis double vaz;//!< the position rotation speed around z axis //! \brief The constructor //! \param ix the position x coordinate //! \param iy the position y coordinate //! \param iz the position z coordinate //! \param ivx the position x speed coordinate //! \param ivy the position y speed coordinate //! \param ivz the position z speed coordinate //! \param iax the position euler angle around x axis //! \param iay the position euler angle around y axis //! \param iaz the position euler angle around z axis //! \param ivax the position rotation speed around x axis //! \param ivay the position rotation speed around y axis //! \param ivaz the position rotation speed around z axis Tcoord( double ix, double iy, double iz, double ivx, double ivy, double ivz, double iax, double iay, double iaz, double ivax, double ivay, double ivaz) : x( ix), y( iy), z( iz), vx( ivx), vy( ivy), vz( ivz), ax( iax), ay( iay), az( iaz), vax( ivax), vay( ivay), vaz( ivaz) { } //! \brief The copy constructor //! \param in the input coordinates Tcoord( const Tcoord &in) : x( in.x), y( in.y), z( in.z), vx( in.vx), vy( in.vy), vz( in.vz), ax( in.ax), ay( in.ay), az( in.az), vax( in.vax), vay( in.vay), vaz( in.vaz) { } //! \brief the copy function //! \param in the input coordinates void copy( const Tcoord &in) { x = in.x; y = in.y; z = in.z; vx = in.vx; vy = in.vy; vz = in.vz; ax = in.ax; ay = in.ay; az = in.az; vax = in.vax; vay = in.vay; vaz = in.vaz; } }; //*************************************************************************** struct TGLObject : public Tcoord //---------------------------------------------------------------------------- //! class for GL display list characterisation //! \todo get rid of the double coordinate representation and introduce vectors //*************************************************************************** { unsigned int *obj;//!< pointer to the GL display List represented by the TGLObject //! \brief The constructor //! \param io pointer to the GL List represented by the TGLObject //! \param ix the position x coordinate //! \param iy the position y coordinate //! \param iz the position z coordinate //! \param ivx the position x speed coordinate //! \param ivy the position y speed coordinate //! \param ivz the position z speed coordinate //! \param iax the position euler angle around x axis //! \param iay the position euler angle around y axis //! \param iaz the position euler angle around z axis //! \param ivax the position rotation speed around x axis //! \param ivay the position rotation speed around y axis //! \param ivaz the position rotation speed around z axis TGLObject( unsigned int *io, double ix, double iy, double iz, double ivx, double ivy, double ivz, double iax, double iay, double iaz, double ivax, double ivay, double ivaz) : Tcoord( ix, iy, iz, ivx, ivy, ivz, iax, iay, iaz, ivax, ivay, ivaz), obj( io) { } }; //*************************************************************************** struct TGLLight : public Tcoord //---------------------------------------------------------------------------- //! class for GL lights characterisation //! \todo get rid of the double coordinate representation and introduce vectors //*************************************************************************** { GLenum id; //!grabFrameBuffer( true);} public slots: //! \brief enable/disable lighting globally //! \param sw true = enable, \n false = disable void enableLights( bool sw); //! \brief enable/disable Mouse Scrolling //! \param sw true = enable, \n false = disable void enableMouseScroll( bool sw) { doscr = sw;} //! \brief enable/disable Mouse zooming //! \param sw true = enable, \n false = disable void enableMouseZoom( bool sw){ dozoo = sw;} //! \brief enable/disable moving of the reference point //! \param sw true = enable, \n false = disable void enableMouseMove( bool sw){ domoo = sw;} //! clears the content of the gl Widget void clear(); //! shows the axes void showAxes( bool sw) { axis = sw;} //! starts playing //! \return the timer ID virtual int play(); //! ends playing virtual void stop(); //! resets the replay speed and if needed the timer too //! \param speed the new speed (Intervall of the timer in ms) //! \return the timer ID or -1 if not playing at the moment int setPlaySpeed( int speed); //! \brief activates/deactivates fog //! \param sw true = enable, \n false = disable //! \param density the fog density //! \param start at which length away from the camera the fog starts //! \param end at which length away from the camera the fog ends //! \param r the red value of the fog color //! \param g the green value of the fog color //! \param b the blue value of the fog color virtual void enableFog( bool sw, double density = 0.35, double start=1., double end=5., double r=0.5, double g=0.5, double b=0.5); inline bool SaveImage( const QString name = "dvscreen.png"); protected: unsigned int axes; //!< the coordinate axes unsigned int grid; //!< a grid unsigned int cont; //!< a plain surface to display shadows on (test) unsigned int glSM, glDF; unsigned int scene; bool fswitch, sswitch, mswitch; bool hidecursor; QPoint cPos, cPos2, GPoint; int curs, curs2; double cx1, cy1, cursx, cursy, cursz, cxh, cyh; Tcoord *Cam; vector ois; vector::iterator itois; vector lights; vector::iterator itlights; vector shades; vector::iterator itshades; map textures; //! \brief overloaded member function inherited from QGLWidget sets up all OpenGL related stuff virtual void initializeGL(); //! \brief overloaded member function inherited from QGLWidget handles everything when resizing comes to term //! \param w new window width //! \param h new window height void resizeGL( const int w, const int h); //! \brief overloaded member function inherited from QGLWidget does the actual drawing void paintGL(); //! \brief mouse key response void mousePressEvent( QMouseEvent *); //! \brief mouse move response (e.g. scrolling or zooming) void mouseMoveEvent( QMouseEvent *); //! \brief to be overwritten in derived classes for Key events virtual void evMouseMove( QMouseEvent *) {}; //! \brief mouse release -> return to normal state void mouseReleaseEvent( QMouseEvent *); //! \brief response to key events needed for moving of reference point void keyPressEvent( QKeyEvent *); //! \brief to be overwritten in derived classes for Key events virtual void evKeyPress( QKeyEvent *) {}; //! \brief timer for the demo void timerEvent( QTimerEvent *); //! This function acts as a kind of film script for the demo //! \brief this is the function that actually directs the demo virtual void director() {}; //! \brief moves the lights according to their velocities (actually no need to overload) virtual void adjustLights(); //! \brief moves the camera according to its velocities (actually no need to overload either) virtual void adjustCamera(); //! \brief moves the objects in the scene according to their velocities (actually no need to overload either) virtual void adjustScene(); //! \brief makes if activated the objects shadows //! \attention overwrite if you want shadows! virtual void makeShades() {}; virtual void makeCont() {}; virtual void drawStatic(); private: void initMoving( bool esc = false); void moveCursor( QMouseEvent *); // object making functions void makeCursor(); void makeAxes(); void makeGrid(); bool axis; bool lightsw; bool doscr; //!< mouse scroll enabled bool dozoo; //!< mouse zoom enabled bool domoo; //!< mouse move enabled unsigned int mcursor; GLUquadricObj *quadratic; //!< used for displaying a sphere (e.g. cursor in move function) int timerID; //!< ID of the timer used to control the replay speed int timeIndex; //!< what time it is (during the replay) int timeIntervall; //!< intervall of the timer id est replay speed GLfloat xm, ym, zm; double zoom; //!< speed factor of mouse zoom bool lbut, rbut, showGrid, reflect; double Rx, Ry, Rz; }; //*************************************************************************** //implementation of public inline functions //*************************************************************************** inline bool WEngine::SaveImage( const QString name) //*************************************************************************** { return getImage().save( name, "PNG"); } #endif