exampleDraWin.cpp

This is an example for the usage of the DraWin class. More details about this example.

// ----------------------------------------------------------------------------
//
// $Id$
//
// Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
//
// This file is part of MIP.
//
// MIP is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// MIP is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with MIP. If not, see <http://www.gnu.org/licenses/>.
//
// Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
//
// ----------------------------------------------------------------------------


// #include <Parameter.h>
#include <CommonOptions.h>
#include <DraWinGL.h>

#define DEBUG 0

using namespace MipResources;

int main(int argc,const char* argv[]){

 CommonOptions::init(argc,(char* const *)argv);
 commonOptions->updateValues();
  
 // ask for two lists
 unsigned int draList; 
 DraWin *draWin = new DraWinGL( argc, argv ); 
 while(!draWin->addList(Time(0,1000),draList)){
  usleep(1000);
 }
 unsigned int draList2;
 while(!draWin->addList(Time(0,1000),draList2)){
  usleep(1000);
 }
 
  cout << "Enter to start" << endl;
 getchar();
 
 Timer timer;
 Timer timer2;
 Decimal  speed = 0.05;
 Decimal  pulsation = 1.0;
 Position position(1.0,0.0);
 Decimal  radius(1.0);
 Position target(0.0,0.0);
 bool forward = true;
 while(1){
  if(fabs(radius)> 1.0){
   forward = !forward;
  }
  if (forward){
   radius -= speed*timer2.get().dCast();
  }else{
   radius += speed*timer2.get().dCast();
  }
  position = Position(cos(pulsation*timer.get().dCast()),sin(pulsation*timer.get().dCast()))*radius;
  
  // push a point
  Pose pose(position, 0.0);
  DraWinObj *robot = new MobileRob2D(pose,0.1);
  robot->setColor(Colors::blue());
  while(!draWin->pushObj(robot, Time(0,5000),draList)){
   usleep(1000);
  }

  
  
  DraWinObj *point2 = new Point2D(position,4.0);
  point2->setColor(Colors::blue());
  while(!draWin->pushObj(point2, Time(0,5000),draList)){
   usleep(1000);
  }
  
  // overlap a the point in the second list to create the wake
  DraWinObj *point = new Point2D(position,2.0);
  point->setColor(Colors::lightBlue());
  while(!draWin->overlapObj(point, Time(0,5000),draList2)){
   usleep(1000);
  }
  
  // push a segment
  DraWinObj *segment = new Segment2D(position,target);
  while(!draWin->pushObj(segment, Time(0,5000),draList)){
   usleep(1000);
  }

  // push a point
  DraWinObj *point3 = new Point2D(target,4.0);
  point3->setColor(Colors::red());
  while(!draWin->pushObj(point3, Time(0,5000),draList)){
   usleep(1000);
  }

  // set the bounding box to follow a point
  DraWinObj *bb = new CmdBB2D(target,1.2,1.2);
  while(!draWin->pushObj(bb, Time(0,5000),draList)){
   usleep(1000);
  }
   
  // swap the first list to effectively draw
  while(!draWin->swapList(Time(0,500),draList)){
   usleep(1000);
  }
  
   timer2.reset();
  usleep(20000);
 }
 return 0;
}

Generated on Mon Feb 20 07:01:06 2017 for MIP by  doxygen 1.5.6