Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
playground.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __PLAYGROUND_H
25 #define __PLAYGROUND_H
26 
27 #include "mathutils.h"
28 #include "abstractground.h"
29 #include "primitive.h"
30 
31 namespace lpzrobots {
32 
33  class Playground : public AbstractGround {
34 
35  protected:
36 
37  double length, width, height;
38  double factorlength2;
39 
40  public:
41 
43  const osg::Vec3& dimension = osg::Vec3(7.0, 0.2, 0.5) ,
44  double factorxy = 1, bool createGround=true)
45  : AbstractGround(odeHandle, osgHandle, createGround, dimension.x(), dimension.x()*factorxy, dimension.y()) {
46 
47  length=dimension.x();
48  width=dimension.y();
49  height=dimension.z();
50  factorlength2=factorxy;
51  };
52 
53  virtual void changeGeometry(double length, double width, double height, double factorxy){
54  AbstractGround::changeGeometry(length, width, height, factorxy);
55  this->length = length;
56  this->width = width;
57  this->height = height;
58  this->factorlength2 = factorxy;
59  if (obstacle_exists) {
60  destroy();
61  create();
62  }
63  }
64 
65  protected:
66  virtual void create(){
67  createGround();
68 
69  Box* box;
70  osg::Vec3 offset(0,
71  (length/2 * factorlength2 + width/2),
72  height/2+0.01f/*reduces graphic errors and ode collisions*/);
73  box = new Box( length + 2 * width , width, height);
74  box->setTextures(getTextures(0));
75  box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
76  box->setPose(osg::Matrix::translate(offset) * pose);
77  obst.push_back(box);
78 
79  box = new Box( length + 2 * width , width, height);
80  box->setTextures(getTextures(1));
81  box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
82  box->setPose(osg::Matrix::translate(offset) * osg::Matrix::rotate(M_PI, 0,0,1) * pose);
83  obst.push_back(box);
84 
85  osg::Vec3 offset2(0, (length/2 + width/2),
86  height/2+0.01f/*reduces graphic errors and ode collisions*/);
87  box = new Box( length * factorlength2 , width, height);
88  box->setTextures(getTextures(2));
89  box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
90  box->setPose(osg::Matrix::translate(offset2) * osg::Matrix::rotate(M_PI/2.0, 0,0,1) * pose);
91  obst.push_back(box);
92 
93  box = new Box( length * factorlength2 , width, height);
94  box->setTextures(getTextures(3));
95  box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
96  box->setPose(osg::Matrix::translate(offset2) * osg::Matrix::rotate(3.0*M_PI/2.0, 0,0,1)
97  * pose);
98  obst.push_back(box);
99 
100 
101  obstacle_exists=true;
102  };
103 
104  };
105 
106 }
107 
108 #endif
Data structure for accessing the ODE.
Definition: odehandle.h:44
OsgHandle osgHandle
Definition: abstractobstacle.h:174
virtual std::vector< TextureDescr > getTextures(int primitive) const
returns the textures of the given primitive
Definition: abstractobstacle.cpp:147
bool obstacle_exists
Definition: abstractobstacle.h:171
double height
Definition: playground.h:37
OdeHandle odeHandle
Definition: abstractobstacle.h:173
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void createGround()
Definition: abstractground.cpp:123
virtual void changeGeometry(double length, double width, double height, double factorxy)
Definition: abstractground.cpp:73
Definition: primitive.h:89
virtual void create()
overload this function to create the obstactle. All primitives should go into the list "obst" ...
Definition: playground.h:66
Vec3f Vec3
Definition: osgforwarddecl.h:42
Definition: primitive.h:89
double length
Definition: playground.h:37
double width
Definition: playground.h:37
Definition: playground.h:33
std::vector< Primitive * > obst
primitives which belong to this obstacle
Definition: abstractobstacle.h:166
Box primitive.
Definition: primitive.h:267
double factorlength2
Definition: playground.h:38
virtual void setTextures(const std::vector< TextureDescr > &textures)
assign a set of texture to the surfaces of the primitive
Definition: primitive.cpp:142
osg::Matrix pose
Definition: abstractobstacle.h:170
Playground(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const osg::Vec3 &dimension=osg::Vec3(7.0, 0.2, 0.5), double factorxy=1, bool createGround=true)
Definition: playground.h:42
virtual void setPose(const Pose &pose)
set the pose of the primitive
Definition: primitive.cpp:156
Definition: abstractground.h:36
virtual void destroy()
is called to destroy the object. The default implementation is to delete all primitives in "obst"...
Definition: abstractobstacle.cpp:171
virtual void changeGeometry(double length, double width, double height, double factorxy)
Definition: playground.h:53
virtual void init(const OdeHandle &odeHandle, double mass, const OsgHandle &osgHandle, char mode=Body|Geom|Draw)
registers primitive in ODE and OSG.
Definition: primitive.cpp:417