Robot Simulator of the Robotics Group for Self-Organization of Control: passivebox.h Source File

# passivebox.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __PASSIVEBOX_H
    00025 #define __PASSIVEBOX_H
    00026
    00027 #include <stdio.h>
    00028 #include <cmath>
    00029
    00030 #include "primitive.h"
    00031 #include "abstractobstacle.h"
    00032
    00033 namespace lpzrobots {
    00034
    00035 /**
    00036  *  (Passive) box as obstacle
    00037  */
    00038 class PassiveBox : public AbstractObstacle{
    00039   osg::Vec3 dimension;
    00040   double mass;
    00041   int texture;
    00042
    00043
    00044   Box* box;
    00045
    00046
    00047  public:
    00048
    00049   /**
    00050    * Constructor, if you set mass=0.0, you get a box which cannot be moved
    00051    */
    00052   PassiveBox(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
    00053              const osg::Vec3& dimension = osg::Vec3(1.0, 1.0, 1.0), double mass = 1.0):
    00054     AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension), mass(mass) {
    00055     box = new Box(dimension.x(), dimension.y(), dimension.z());
    00056     obst.push_back(box);
    00057     obstacle_exists=false;
    00058   };
    00059
    00060
    00061   virtual void setPose(const osg::Matrix& pose){
    00062     this->pose = osg::Matrix::translate(0,0,dimension.z()/2) * pose;
    00063     if (!obstacle_exists) {
    00064       create();
    00065     }
    00066     box->setPose(pose);
    00067   };
    00068
    00069
    00070   virtual Primitive* getMainPrimitive() const { return box; }
    00071
    00072  protected:
    00073   virtual void create(){
    00074     box->setTextures(getTextures(0));
    00075     if (mass==0.0) {
    00076       box->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw);
    00077     } else {
    00078       box->init(odeHandle, mass, osgHandle);
    00079     }
    00080 //     osg::Vec3 pos=pose.getTrans();
    00081 //     box->setPosition(pos);
    00082     obstacle_exists=true;
    00083   };
    00084
    00085 };
    00086
    00087 }
    00088
    00089 #endif
    00090