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
octaplayground.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 __OCTAPLAYGROUND_H
25 #define __OCTAPLAYGROUND_H
26 
27 #include "abstractground.h"
28 
29 namespace lpzrobots {
30 
31  class OctaPlayground : public AbstractGround {
32 
33 
34  protected:
35  double radius, width, height;
36 
38  double angle;
39  double box_length;
40 
41  public:
42 
43 
45  const Pos& geometry = Pos(7,0.2,0.5), int numberCorners=8, bool createGround=true):
46  AbstractGround::AbstractGround(odeHandle, osgHandle,createGround,2*geometry.x(),2*geometry.x(), geometry.y()) {
47  radius = geometry.x();
48  width = geometry.y();
49  height = geometry.z();
50 
51  number_elements=numberCorners;
52  angle= 2*M_PI/number_elements;
53  // obst.resize(number_elements);
54 
55  calcBoxLength();
56  };
57 
58 protected:
59 
60  virtual void create(){
61  createGround();
62 
63  // radius for positioning is smaller than radius since we use secants.
64  // r is the smallest distance of the secant to the center of the circle.
65  double r = sqrt(pow((1+cos(angle))/2, 2) + pow( sin(angle)/2 ,2)) * radius;
66  for (int i=0; i<number_elements; i++){
67  Box* box = new Box(width , box_length , height);
68  box->setTextures(getTextures(i));
69  box->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
70  osg::Matrix R = osg::Matrix::rotate(- i*angle, 0,0,1) *
71  osg::Matrix::translate( cos(M_PI - i*angle) * r,
72  sin(M_PI - i*angle) * r,
73  height/2+0.01f /*reduces graphic errors and ode collisions*/
74  )* pose;
75  box->setPose(R);
76  obst.push_back(box);
77  }
78  obstacle_exists=true;
79  };
80 
81  virtual void calcBoxLength(){
82  double r = radius+width/2;
83  // box_length =1.4 * sqrt( 2 * pow(radius,2) * (1 - cos(angle)) );
84  box_length = sqrt(pow( 1 - cos(angle), 2) + pow(sin(angle),2)) * r;
85  }
86 
87 };
88 
89 }
90 
91 #endif
double height
Definition: octaplayground.h:35
Data structure for accessing the ODE.
Definition: odehandle.h:44
double width
Definition: octaplayground.h:35
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
Matrixd Matrix
Definition: osgforwarddecl.h:47
double radius
Definition: octaplayground.h:35
bool obstacle_exists
Definition: abstractobstacle.h:171
OdeHandle odeHandle
Definition: abstractobstacle.h:173
OctaPlayground(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const Pos &geometry=Pos(7, 0.2, 0.5), int numberCorners=8, bool createGround=true)
Definition: octaplayground.h:44
Definition: pos.h:36
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void createGround()
Definition: abstractground.cpp:123
Definition: primitive.h:89
Definition: primitive.h:89
double box_length
Definition: octaplayground.h:39
std::vector< Primitive * > obst
primitives which belong to this obstacle
Definition: abstractobstacle.h:166
Box primitive.
Definition: primitive.h:267
virtual void setTextures(const std::vector< TextureDescr > &textures)
assign a set of texture to the surfaces of the primitive
Definition: primitive.cpp:142
virtual void calcBoxLength()
Definition: octaplayground.h:81
osg::Matrix pose
Definition: abstractobstacle.h:170
int number_elements
Definition: octaplayground.h:37
double angle
Definition: octaplayground.h:38
virtual void setPose(const Pose &pose)
set the pose of the primitive
Definition: primitive.cpp:156
Definition: octaplayground.h:31
Definition: abstractground.h:36
virtual void create()
overload this function to create the obstactle. All primitives should go into the list "obst" ...
Definition: octaplayground.h:60
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