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
passivesphere.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 __PASSIVESPHERE_H
25 #define __PASSIVESPHERE_H
26 
27 #include <stdio.h>
28 #include <cmath>
29 
30 #include "primitive.h"
31 #include "osgprimitive.h"
32 #include "abstractobstacle.h"
33 
34 namespace lpzrobots {
35 
36 /**
37  * (Passive) sphere as obstacle
38  */
40  double radius;
41  double mass;
42  int texture;
43 
44  Sphere* sphere;
45 
46  public:
47 
48  /**
49  * Constructor
50  */
51  PassiveSphere(const OdeHandle& odeHandle, const OsgHandle& osgHandle, double radius = 0.3, double mass = 1.0):
52  AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), mass(mass), texture(0) {
53  sphere = new Sphere(radius);
54  obst.push_back(sphere);
55  obstacle_exists=false;
56  };
57 
58  virtual void setTexture(const std::string& filename){
59  if(sphere) sphere->getOSGPrimitive()->setTexture(filename);
60  }
61 
62  virtual void setPose(const osg::Matrix& pose){
63  this->pose = osg::Matrix::translate(0,0,radius) * pose;
64  if (!obstacle_exists) {
65  create();
66  }
67  sphere->setPose(pose);
68  };
69 
70  virtual Primitive* getMainPrimitive() const { return sphere; }
71 
72 
73  protected:
74  virtual void create(){
75  sphere->setTextures(getTextures(0));
76  if (mass==0.0) {
78  } else {
79  sphere->init(odeHandle, mass, osgHandle);
80  }
81  obstacle_exists=true;
82  };
83 
84 };
85 
86 }
87 
88 #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
Abstract class (interface) for obstacles.
Definition: abstractobstacle.h:46
Matrixd Matrix
Definition: osgforwarddecl.h:47
bool obstacle_exists
Definition: abstractobstacle.h:171
Sphere primitive.
Definition: primitive.h:289
virtual Primitive * getMainPrimitive() const
return the "main" primitive of the obtactle. The meaning of "main" is arbitrary
Definition: passivesphere.h:70
OdeHandle odeHandle
Definition: abstractobstacle.h:173
virtual void create()
overload this function to create the obstactle. All primitives should go into the list "obst" ...
Definition: passivesphere.h:74
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:470
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void setTexture(const std::string &filename)
assigns a texture to the all primitives of this obstactle with repeat -1,-1
Definition: passivesphere.h:58
Definition: primitive.h:89
virtual OSGPrimitive * getOSGPrimitive()
returns the assoziated osg primitive if there or 0
Definition: primitive.cpp:468
Definition: primitive.h:89
PassiveSphere(const OdeHandle &odeHandle, const OsgHandle &osgHandle, double radius=0.3, double mass=1.0)
Constructor.
Definition: passivesphere.h:51
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
std::vector< Primitive * > obst
primitives which belong to this obstacle
Definition: abstractobstacle.h:166
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 setTexture(const std::string &filename)
assigns a texture to the primitive
Definition: osgprimitive.cpp:101
virtual void setPose(const Pose &pose)
set the pose of the primitive
Definition: primitive.cpp:156
(Passive) sphere as obstacle
Definition: passivesphere.h:39
virtual void setPose(const osg::Matrix &pose)
sets position of the obstacle and creates/recreates obstacle if necessary
Definition: passivesphere.h:62