graphicalwobject.cpp
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 #include "graphicalwobject.h"
25 
26 namespace farsa {
27 
28 GraphicalWObject::GraphicalWObject(World* world, QString name, const wMatrix& tm) :
29  WObject(world, name, tm, false),
30  m_attachedObject(NULL),
31  m_displacement(wMatrix::identity())
32 {
33  // Adding here to the world, even if not at the end of the hierarchy (all classes inheriting
34  // from this have the same renderer anyway)
35  world->pushObject(this);
36 }
37 
39 {
40  // Nothing do to here
41 }
42 
43 void GraphicalWObject::attachToObject(WObject* object, bool makeOwner, const wMatrix& displacement)
44 {
45  m_attachedObject = object;
46  m_displacement = displacement;
47 
48  if (makeOwner) {
49  setOwner(m_attachedObject, true);
50  } else {
51  setOwner(NULL);
52  }
53 }
54 
55 void GraphicalWObject::setDisplacement(const wMatrix& displacement)
56 {
57  m_displacement = displacement;
58 }
59 
60 void GraphicalWObject::updateAndRender(RenderWObject* renderer, QGLContext* gw)
61 {
63 
64  render(renderer, gw);
65 }
66 
68 {
70 
71  renderAABB(renderer, gw);
72 }
73 
75 {
77 
78  calculateAABB(minPoint, maxPoint, tm);
79 }
80 
81 void GraphicalWObject::updateAndCalculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint)
82 {
84 
85  calculateOBB(dimension, minPoint, maxPoint);
86 }
87 
89 {
90  // The default implementation does nothing
91 }
92 
93 void GraphicalWObject::calculateAABB(wVector& minPoint, wVector& maxPoint, const wMatrix)
94 {
95  // The default implementation does nothing
96  minPoint = wVector(0, 0, 0);
97  maxPoint = wVector(0, 0, 0);
98 }
99 
100 void GraphicalWObject::calculateOBB(wVector& dimension, wVector& minPoint, wVector& maxPoint)
101 {
102  // The default implementation does nothing
103  dimension = wVector(0, 0, 0);
104  minPoint = wVector(0, 0, 0);
105  maxPoint = wVector(0, 0, 0);
106 }
107 
109 {
110  if (m_attachedObject == NULL) {
111  return;
112  }
113 
114  setMatrix(m_displacement * m_attachedObject->matrix());
115 }
116 
117 }