worldsim/include/graphicalwobject.h

00001 /********************************************************************************
00002  *  FARSA Experiments Library                                                   *
00003  *  Copyright (C) 2007-2012                                                     *
00004  *  Stefano Nolfi <stefano.nolfi@istc.cnr.it>                                   *
00005  *  Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it>                           *
00006  *  Gianluca Massera <emmegian@yahoo.it>                                        *
00007  *  Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it>                         *
00008  *                                                                              *
00009  *  This program is free software; you can redistribute it and/or modify        *
00010  *  it under the terms of the GNU General Public License as published by        *
00011  *  the Free Software Foundation; either version 2 of the License, or           *
00012  *  (at your option) any later version.                                         *
00013  *                                                                              *
00014  *  This program is distributed in the hope that it will be useful,             *
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00017  *  GNU General Public License for more details.                                *
00018  *                                                                              *
00019  *  You should have received a copy of the GNU General Public License           *
00020  *  along with this program; if not, write to the Free Software                 *
00021  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00022  ********************************************************************************/
00023 
00024 #ifndef GRAPHICALWOBJECT_H
00025 #define GRAPHICALWOBJECT_H
00026 
00027 #include "worldsimconfig.h"
00028 #include "world.h"
00029 #include "renderworld.h"
00030 
00031 
00032 namespace farsa {
00033 
00044 class FARSA_WSIM_API GraphicalWObject : public WObject
00045 {
00046     Q_OBJECT
00047 
00048 public:
00056     GraphicalWObject(World* world, QString name = "unamed", const wMatrix& tm = wMatrix::identity());
00057 
00061     virtual ~GraphicalWObject();
00062 
00074     void attachToObject(WObject* object, bool makeOwner = false);
00075 
00081     WObject* attachedObject() const
00082     {
00083         return m_attachedObject;
00084     }
00085 
00095     void updateAndRender(RenderWObject* renderer, QGLContext* gw);
00096 
00107     void updateAndRenderAABB(RenderWObject* renderer, RenderWorld* gw);
00108 
00121     void updateAndCalculateAABB(wVector& minPoint, wVector& maxPoint, const wMatrix tm);
00122 
00134     void updateAndCalculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint);
00135 
00136 protected:
00145     virtual void render(RenderWObject* renderer, QGLContext* gw) = 0;
00146 
00155     virtual void renderAABB(RenderWObject* renderer, RenderWorld* gw);
00156 
00168     virtual void calculateAABB(wVector& minPoint, wVector& maxPoint, const wMatrix tm);
00169 
00179     virtual void calculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint);
00180 
00185     void updateMatrixFromAttachedObject();
00186 
00192     WObject *m_attachedObject;
00193 };
00194 
00195 }
00196 
00197 #endif