passivesphere.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __PASSIVESPHERE_H
00025 #define __PASSIVESPHERE_H
00026
00027 #include <stdio.h>
00028 #include <cmath>
00029
00030 #include "primitive.h"
00031 #include "osgprimitive.h"
00032 #include "abstractobstacle.h"
00033
00034 namespace lpzrobots {
00035
00036
00037
00038
00039 class PassiveSphere : public AbstractObstacle{
00040 double radius;
00041 double mass;
00042 int texture;
00043
00044 Sphere* sphere;
00045
00046 public:
00047
00048
00049
00050
00051 PassiveSphere(const OdeHandle& odeHandle, const OsgHandle& osgHandle, double radius = 0.3, double mass = 1.0):
00052 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), radius(radius), mass(mass) {
00053 sphere = new Sphere(radius);
00054 obst.push_back(sphere);
00055 obstacle_exists=false;
00056 };
00057
00058 virtual void setTexture(const std::string& filename){
00059 if(sphere) sphere->getOSGPrimitive()->setTexture(filename);
00060 }
00061
00062 virtual void setPose(const osg::Matrix& pose){
00063 this->pose = osg::Matrix::translate(0,0,radius) * pose;
00064 if (!obstacle_exists) {
00065 create();
00066 }
00067 sphere->setPose(pose);
00068 };
00069
00070 virtual Primitive* getMainPrimitive() const { return sphere; }
00071
00072
00073 protected:
00074 virtual void create(){
00075 sphere->setTextures(getTextures(0));
00076 if (mass==0.0) {
00077 sphere->init(odeHandle, mass, osgHandle, Primitive::Geom | Primitive::Draw);
00078 } else {
00079 sphere->init(odeHandle, mass, osgHandle);
00080 }
00081 obstacle_exists=true;
00082 };
00083
00084 };
00085
00086 }
00087
00088 #endif