seesaw.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 __SEESAW_H
00025 #define __SEESAW_H
00026
00027 #include <stdio.h>
00028 #include <cmath>
00029
00030 #include "primitive.h"
00031 #include "joint.h"
00032 #include "abstractobstacle.h"
00033
00034 namespace lpzrobots {
00035
00036
00037
00038
00039 class Seesaw : public AbstractObstacle{
00040 osg::Vec3 dimension;
00041 double mass;
00042 int texture;
00043
00044 public:
00045
00046
00047
00048
00049
00050
00051 Seesaw(const OdeHandle& odeHandle, const OsgHandle& osgHandle,
00052 const osg::Vec3& dimension = osg::Vec3(4.0, 0.6, 0.3), double mass = 1.0):
00053 AbstractObstacle::AbstractObstacle(odeHandle, osgHandle), dimension(dimension),
00054 mass(mass) {
00055 setTexture("Images/wood_sw.jpg");
00056 obstacle_exists=false;
00057 };
00058
00059
00060 virtual void setPose(const osg::Matrix& pose){
00061 this->pose = osg::Matrix::translate(0,0,dimension.z()/2.0) * pose;
00062 if (!obstacle_exists) {
00063 create();
00064 }
00065 };
00066
00067 virtual Primitive* getMainPrimitive() const {
00068 if(!obst.empty()) return obst[0];
00069 else return 0;
00070 }
00071
00072 protected:
00073 virtual void create(){
00074 Box* support;
00075 support = new Box(dimension.y()*0.9, dimension.y()/2.0, dimension.z());
00076 support->setTextures(getTextures(0));
00077 support->init(odeHandle, 0, osgHandle, Primitive::Geom | Primitive::Draw);
00078 support->setPose(pose);
00079 obst.push_back(support);
00080
00081 Box* bar;
00082 bar = new Box(dimension.y(), dimension.x(), dimension.y()/6.0);
00083 bar->setTextures(getTextures(1));
00084 bar->init(odeHandle, mass, osgHandle);
00085 bar->setPose(osg::Matrix::translate(0,0,dimension.z()/2.0) * pose);
00086 obst.push_back(bar);
00087
00088
00089 HingeJoint* joint = new HingeJoint(support, bar, bar->getPosition(),
00090 bar->toGlobal(Axis(1,0,0)));
00091 joint->init(odeHandle, osgHandle, true, dimension.y()*1.05,false);
00092
00093
00094 obstacle_exists=true;
00095 };
00096
00097 };
00098
00099 }
00100
00101 #endif
00102