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
seesaw.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 __SEESAW_H
25 #define __SEESAW_H
26 
27 #include <stdio.h>
28 #include <cmath>
29 
30 #include "primitive.h"
31 #include "joint.h"
32 #include "abstractobstacle.h"
33 
34 namespace lpzrobots {
35 
36 /**
37  * Seesaw
38  */
39 class Seesaw : public AbstractObstacle{
40  osg::Vec3 dimension;
41  double mass;
42  int texture;
43 
44  public:
45  /**
46  * Constructor
47  * the support of the seesaw is fixed to the world
48  * @param mass mass of the bar
49  * @param dimension (length of bar, width of bar, height of support)
50  */
52  const osg::Vec3& dimension = osg::Vec3(4.0, 0.6, 0.3), double mass = 1.0):
53  AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension),
54  mass(mass), texture(0) {
55  setTexture("Images/wood_sw.jpg");
56  obstacle_exists=false;
57  };
58 
59 
60  virtual void setPose(const osg::Matrix& pose){
61  this->pose = osg::Matrix::translate(0,0,dimension.z()/2.0) * pose;
62  if (!obstacle_exists) {
63  create();
64  }
65  };
66 
67  virtual Primitive* getMainPrimitive() const {
68  if(!obst.empty()) return obst[0];
69  else return 0;
70  }
71 
72  protected:
73  virtual void create(){
74  Box* support;
75  support = new Box(dimension.y()*0.9, dimension.y()/2.0, dimension.z());
76  support->setTextures(getTextures(0));
77  support->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
78  support->setPose(pose);
79  obst.push_back(support);
80 
81  Box* bar;
82  bar = new Box(dimension.y(), dimension.x(), dimension.y()/6.0);
83  bar->setTextures(getTextures(1));
84  bar->init(odeHandle, mass, osgHandle);
85  bar->setPose(osg::Matrix::translate(0,0,dimension.z()/2.0) * pose);
86  obst.push_back(bar);
87 
88  // connect them together
89  HingeJoint* joint = new HingeJoint(bar, support, bar->getPosition(),
90  bar->toGlobal(Axis(1,0,0)));
91  joint->init(odeHandle, osgHandle, true, dimension.y()*1.05,false);
92 
93  // maybe set stop values
94  obstacle_exists=true;
95  };
96 
97 };
98 
99 }
100 
101 #endif
102 
Data structure for accessing the ODE.
Definition: odehandle.h:44
Seesaw(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const osg::Vec3 &dimension=osg::Vec3(4.0, 0.6, 0.3), double mass=1.0)
Constructor the support of the seesaw is fixed to the world.
Definition: seesaw.h:51
OsgHandle osgHandle
Definition: abstractobstacle.h:174
Definition: axis.h:36
virtual std::vector< TextureDescr > getTextures(int primitive) const
returns the textures of the given primitive
Definition: abstractobstacle.cpp:147
virtual void setTexture(const std::string &texturefilename)
assigns a texture to the all primitives of this obstactle with repeat -1,-1
Definition: abstractobstacle.cpp:107
Abstract class (interface) for obstacles.
Definition: abstractobstacle.h:46
Seesaw.
Definition: seesaw.h:39
osg::Vec3 toGlobal(const osg::Vec3 &pos) const
transforms the given point in local corrds of the primitive to global coordinates ...
Definition: primitive.cpp:307
Matrixd Matrix
Definition: osgforwarddecl.h:47
bool obstacle_exists
Definition: abstractobstacle.h:171
OdeHandle odeHandle
Definition: abstractobstacle.h:173
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
Definition: primitive.h:89
virtual void setPose(const osg::Matrix &pose)
sets position of the obstacle and creates/recreates obstacle if necessary
Definition: seesaw.h:60
Vec3f Vec3
Definition: osgforwarddecl.h:42
Definition: primitive.h:89
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
virtual Primitive * getMainPrimitive() const
return the "main" primitive of the obtactle. The meaning of "main" is arbitrary
Definition: seesaw.h:67
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
osg::Matrix pose
Definition: abstractobstacle.h:170
virtual void create()
overload this function to create the obstactle. All primitives should go into the list "obst" ...
Definition: seesaw.h:73
virtual void init(const OdeHandle &odeHandle, const OsgHandle &osgHandle, bool withVisual=true, double visualSize=0.2, bool ignoreColl=true)
initialises (and creates) the joint.
Definition: joint.cpp:195
virtual void setPose(const Pose &pose)
set the pose of the primitive
Definition: primitive.cpp:156
virtual Pos getPosition() const
returns the position
Definition: primitive.cpp:181
Definition: joint.h:183
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