wobject.cpp
1 /********************************************************************************
2  * WorldSim -- library for robot simulations *
3  * Copyright (C) 2008-2013 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #include "wobject.h"
21 #include "world.h"
22 
23 using namespace farsa;
24 
25 WObject::WObject( World* w, QString name, const wMatrix& tm, bool addToWorld ) {
26  this->worldv = w;
27  this->tm = tm;
28  namev = name;
29  texturev = "tile2";
30  colorv = Qt::white;
31  invisible = false;
34  labelv = "";
35  labelpos = wVector(0.0f, 0.0f, 0.0f);
36  labelcol = Qt::white;
37  labeldrawn = false;
38  if ( addToWorld ) {
39  worldv->pushObject( this );
40  }
41 }
42 
44  worldv->popObject( this );
45 }
46 
47 const wMatrix& WObject::matrix() const {
48  return tm;
49 }
50 
51 void WObject::setPosition( const wVector& newpos ) {
52  tm.w_pos = newpos;
53  changedMatrix();
54 }
55 
57  tm.w_pos = wVector(x,y,z);
58  changedMatrix();
59 }
60 
62  return worldv;
63 }
64 
65 const World* WObject::world() const {
66  return worldv;
67 }
68 
69 QString WObject::name() const {
70  return namev;
71 }
72 
73 void WObject::setTexture( QString textureName ) {
74  texturev = textureName;
75 }
76 
77 QString WObject::texture() const {
78  return texturev;
79 }
80 
81 void WObject::setColor( QColor c ) {
82  colorv = c;
83 }
84 
85 void WObject::setAlpha( int alpha ) {
86  colorv.setAlpha( alpha );
87 }
88 
89 QColor WObject::color() const {
90  return colorv;
91 }
92 
95 }
96 
99 }
100 
102  /* nothing to do */
103 }
104 
106  /* nothing to do */
107 }
108 
109 void WObject::setMatrix( const wMatrix& newm ) {
110  tm = newm;
111  changedMatrix();
112 }
113 
114 bool WObject::isInvisible() const {
115  return invisible;
116 }
117 
118 void WObject::setInvisible( bool b ) {
119  invisible = b;
120 }
121 
124 }
125 
127 {
129 }
130 
131 void WObject::setLabel(QString label)
132 {
133  labelv = label;
134 }
135 
136 void WObject::setLabel(QString label, wVector pos, QColor color)
137 {
138  labelv = label;
139  labelpos = pos;
140  labelcol = color;
141 }
142 
143 const QString& WObject::label() const
144 {
145  return labelv;
146 }
147 
149 {
150  labelpos = pos;
151 }
152 
154 {
155  return labelpos;
156 }
157 
158 void WObject::setLabelColor(const QColor& color)
159 {
160  labelcol = color;
161 }
162 
163 const QColor& WObject::labelColor() const
164 {
165  return labelcol;
166 }
167 
168 void WObject::showLabel(bool show)
169 {
170  labeldrawn = show;
171 }
172 
174 {
175  return labeldrawn;
176 }
177 
179  /* nothing to do here */;
180 }
QString namev
Name of the WObject.
Definition: wobject.h:195
wMatrix tm
Trasformation matrix.
Definition: wobject.h:193
virtual void changedMatrix()
virtual function called when the transformation matrix change
Definition: wobject.cpp:178
wVector labelpos
The position of the label in the object frame of reference.
Definition: wobject.h:209
void setUseColorTextureOfOwner(bool b)
set if the object will be rendered with the color and texture of our owner (if we have one) ...
Definition: wobject.cpp:97
World * world()
Return the world.
Definition: wobject.cpp:61
void showLabel(bool show)
Sets whether to show the label or not.
Definition: wobject.cpp:168
bool labelShown() const
Returns whether the label is shown or not.
Definition: wobject.cpp:173
QColor color() const
return the color of this object
Definition: wobject.cpp:89
void setInvisible(bool b)
set invisibility
Definition: wobject.cpp:118
const QString & label() const
Returns the text label to render along with the object.
Definition: wobject.cpp:143
WObject(World *world, QString name="unamed", const wMatrix &tm=wMatrix::identity(), bool addToWorld=true)
create the object and automatically put this into the world
Definition: wobject.cpp:25
QString labelv
The text label of the object.
Definition: wobject.h:207
void drawLocalAxes(bool d)
Sets whether the object local frame of reference should be drawn or not.
Definition: wobject.cpp:122
QString texturev
Texture name.
Definition: wobject.h:197
bool labeldrawn
Whether the label should be rendered or not.
Definition: wobject.h:213
void setTexture(QString textureName)
Set the texture to use for this WObject when rendered.
Definition: wobject.cpp:73
bool invisible
if TRUE it will not renderized
Definition: wobject.h:201
virtual void preUpdate()
preUpdate the WObject this method is called at each step of the world just before the physic update ...
Definition: wobject.cpp:101
World class.
Definition: world.h:223
void setColor(QColor c)
Set the color to use on rendering.
Definition: wobject.cpp:81
const wVector & labelPosition() const
Returns the label position relative to this object.
Definition: wobject.cpp:153
wMatrix class
Definition: wmatrix.h:48
World * worldv
World.
Definition: wobject.h:191
const wMatrix & matrix() const
return a reference to the transformation matrix
Definition: wobject.cpp:47
virtual ~WObject()
destroy the Object and drop it from the world
Definition: wobject.cpp:43
void setLabelColor(const QColor &color)
Sets the color of the label.
Definition: wobject.cpp:158
QColor labelcol
The color of the label.
Definition: wobject.h:211
void setAlpha(int alpha)
set the value of alpha channel (the transparency)
Definition: wobject.cpp:85
void setLabelPosition(const wVector &pos)
Sets the label position relative to this object.
Definition: wobject.cpp:148
void setPosition(const wVector &newpos)
set the position specified in global coordinate frame
Definition: wobject.cpp:51
bool useColorTextureOfOwner() const
if true, we will use color and texture of our owner (if we have one)
Definition: wobject.cpp:93
QColor colorv
Color, it contains also alpha channel.
Definition: wobject.h:199
const QColor & labelColor() const
Returns the color of the label.
Definition: wobject.cpp:163
float real
QString texture() const
Return the texture name.
Definition: wobject.cpp:77
QString name() const
Return the name of this object.
Definition: wobject.cpp:69
void setMatrix(const wMatrix &newm)
set a new matrix
Definition: wobject.cpp:109
bool usecolortextureofowner
if true, we will use color and texture of our owner (if we have one).
Definition: wobject.h:203
bool localAxesDrawn() const
Returns true if the local frame of refecence of the object should be drawn.
Definition: wobject.cpp:126
bool localFrameOfReferenceDrawn
If true, the local frame of reference of the object is drawn.
Definition: wobject.h:205
void setLabel(QString label)
Sets a text label to render along with the object.
Definition: wobject.cpp:131
virtual void postUpdate()
postUpdate the WObject this method is called at each step of the world just after the physic update ...
Definition: wobject.cpp:105
bool isInvisible() const
return if it is invisible
Definition: wobject.cpp:114