WorldSim - 1.2.0
Utilities
Configuration
GA
NNFW
WorldSim
Total 99%
Experiments
Main Page
Modules
Classes
Files
File List
worldsim
src
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
{
32
// Adding here to the world, even if not at the end of the hierarchy (all classes inheriting
33
// from this have the same renderer anyway)
34
world->pushObject(
this
);
35
}
36
37
GraphicalWObject::~GraphicalWObject
()
38
{
39
// Nothing do to here
40
}
41
42
void
GraphicalWObject::attachToObject
(
WObject
*
object
,
bool
makeOwner)
43
{
44
m_attachedObject
= object;
45
46
if
(makeOwner) {
47
setOwner
(
m_attachedObject
,
true
);
48
}
else
{
49
setOwner
(NULL);
50
}
51
}
52
53
void
GraphicalWObject::updateAndRender
(
RenderWObject
* renderer, QGLContext* gw)
54
{
55
updateMatrixFromAttachedObject
();
56
57
render
(renderer, gw);
58
}
59
60
void
GraphicalWObject::updateAndRenderAABB
(
RenderWObject
* renderer,
RenderWorld
* gw)
61
{
62
updateMatrixFromAttachedObject
();
63
64
renderAABB
(renderer, gw);
65
}
66
67
void
GraphicalWObject::updateAndCalculateAABB
(
wVector
& minPoint,
wVector
& maxPoint,
const
wMatrix
tm)
68
{
69
updateMatrixFromAttachedObject
();
70
71
calculateAABB
(minPoint, maxPoint, tm);
72
}
73
74
void
GraphicalWObject::updateAndCalculateOBB
(
wVector
& dimension,
wVector
& minPoint,
wVector
& maxPoint)
75
{
76
updateMatrixFromAttachedObject
();
77
78
calculateOBB
(dimension, minPoint, maxPoint);
79
}
80
81
void
GraphicalWObject::renderAABB
(
RenderWObject
*,
RenderWorld
*)
82
{
83
// The default implementation does nothing
84
}
85
86
void
GraphicalWObject::calculateAABB
(
wVector
& minPoint,
wVector
& maxPoint,
const
wMatrix
)
87
{
88
// The default implementation does nothing
89
minPoint =
wVector
(0, 0, 0);
90
maxPoint =
wVector
(0, 0, 0);
91
}
92
93
void
GraphicalWObject::calculateOBB
(
wVector
& dimension,
wVector
& minPoint,
wVector
& maxPoint)
94
{
95
// The default implementation does nothing
96
dimension =
wVector
(0, 0, 0);
97
minPoint =
wVector
(0, 0, 0);
98
maxPoint =
wVector
(0, 0, 0);
99
}
100
101
void
GraphicalWObject::updateMatrixFromAttachedObject
()
102
{
103
if
(
m_attachedObject
== NULL) {
104
return
;
105
}
106
107
setMatrix
(
m_attachedObject
->
matrix
());
108
}
109
110
}