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 
48 class FARSA_WSIM_API GraphicalWObject : public WObject
49 {
50  Q_OBJECT
51 
52 public:
60  GraphicalWObject(World* world, QString name = "unamed", const wMatrix& tm = wMatrix::identity());
61 
65  virtual ~GraphicalWObject();
66 
81  void attachToObject(WObject* object, bool makeOwner = false, const wMatrix& displacement = wMatrix::identity());
82 
88  WObject* attachedObject() const
89  {
90  return m_attachedObject;
91  }
92 
101  void setDisplacement(const wMatrix& displacement);
102 
111  const wMatrix& getDisplacement() const
112  {
113  return m_displacement;
114  }
115 
125  void updateAndRender(RenderWObject* renderer, QGLContext* gw);
126 
137  void updateAndRenderAABB(RenderWObject* renderer, RenderWorld* gw);
138 
151  void updateAndCalculateAABB(wVector& minPoint, wVector& maxPoint, const wMatrix tm);
152 
164  void updateAndCalculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint);
165 
166 protected:
175  virtual void render(RenderWObject* renderer, QGLContext* gw) = 0;
176 
185  virtual void renderAABB(RenderWObject* renderer, RenderWorld* gw);
186 
198  virtual void calculateAABB(wVector& minPoint, wVector& maxPoint, const wMatrix tm);
199 
209  virtual void calculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint);
210 
215  void updateMatrixFromAttachedObject();
216 
217 private:
223  WObject *m_attachedObject;
224 
234  wMatrix m_displacement;
235 };
236 
237 }
238 
239 #endif