graphicalwobject.h
1 /********************************************************************************
2  * FARSA Experiments Library *
3  * Copyright (C) 2007-2012 *
4  * Stefano Nolfi <stefano.nolfi@istc.cnr.it> *
5  * Onofrio Gigliotta <onofrio.gigliotta@istc.cnr.it> *
6  * Gianluca Massera <emmegian@yahoo.it> *
7  * Tomassino Ferrauto <tomassino.ferrauto@istc.cnr.it> *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the Free Software *
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
22  ********************************************************************************/
23 
24 #ifndef GRAPHICALWOBJECT_H
25 #define GRAPHICALWOBJECT_H
26 
27 #include "worldsimconfig.h"
28 #include "world.h"
29 #include "renderworld.h"
30 
31 
32 namespace farsa {
33 
44 class FARSA_WSIM_API GraphicalWObject : public WObject
45 {
46  Q_OBJECT
47 
48 public:
56  GraphicalWObject(World* world, QString name = "unamed", const wMatrix& tm = wMatrix::identity());
57 
61  virtual ~GraphicalWObject();
62 
74  void attachToObject(WObject* object, bool makeOwner = false);
75 
81  WObject* attachedObject() const
82  {
83  return m_attachedObject;
84  }
85 
95  void updateAndRender(RenderWObject* renderer, QGLContext* gw);
96 
107  void updateAndRenderAABB(RenderWObject* renderer, RenderWorld* gw);
108 
121  void updateAndCalculateAABB(wVector& minPoint, wVector& maxPoint, const wMatrix tm);
122 
134  void updateAndCalculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint);
135 
136 protected:
145  virtual void render(RenderWObject* renderer, QGLContext* gw) = 0;
146 
155  virtual void renderAABB(RenderWObject* renderer, RenderWorld* gw);
156 
168  virtual void calculateAABB(wVector& minPoint, wVector& maxPoint, const wMatrix tm);
169 
179  virtual void calculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint);
180 
185  void updateMatrixFromAttachedObject();
186 
193 };
194 
195 }
196 
197 #endif