random_racer/src/ControlPointGenerator.cpp

Go to the documentation of this file.
00001 #include <sstream>
00002 #include <math.h>
00003 
00004 #include "ControlPointGenerator.h"
00005 #include "Console.h"
00006 
00007 using namespace VRS;
00008 
00009 namespace random_racer
00010 {
00011     
00012 ControlPointGenerator::ControlPointGenerator(unsigned int p_numControlPoints)
00013 {
00014     m_callback = new MethodCallback1<ControlPointGenerator, 
00015                     std::vector<Vector>* >( this, 
00016                         &ControlPointGenerator::generateControlPoints);
00017     
00018     m_numControlPoints = p_numControlPoints - 1;
00019     
00020     // can be changed over the console
00021     m_lowRounds = 500;
00022     m_upRounds = 100;
00023     m_midHeight = 0.6;
00024     
00025     Console::get()->registerCommand("ter_lowrounds",
00026         new MethodCallback1<ControlPointGenerator, const std::string&>(
00027             this, &ControlPointGenerator::terGenrateLowRoundsCommand));
00028     
00029     Console::get()->registerCommand("ter_uprounds",
00030         new MethodCallback1<ControlPointGenerator, const std::string&>(
00031             this, &ControlPointGenerator::terGenrateUpRoundsCommand));
00032             
00033     Console::get()->registerCommand("ter_midheight",
00034         new MethodCallback1<ControlPointGenerator, const std::string&>(
00035             this, &ControlPointGenerator::terGenrateMidHeightCommand));
00036 }
00037 
00038 ControlPointGenerator::~ControlPointGenerator()
00039 {
00040 }
00041 
00042 void 
00043 ControlPointGenerator::generateControlPoints(std::vector<Vector>* p_target)
00044 {
00045     double randIndeX, randIndeY, height;
00046                        
00047     for(unsigned int i = 0; i < m_lowRounds; i++)
00048     {
00049         randIndeX = ((double)rand() / (double)RAND_MAX) * 
00050                 (double)m_numControlPoints;
00051 
00052         randIndeY = ((double)rand() / (double)RAND_MAX) * 
00053                 (double)m_numControlPoints;
00054         
00055         height = ((double)rand() / (double)RAND_MAX) * m_midHeight;
00056         
00057         p_target->push_back(Vector(randIndeX, height, randIndeY));
00058     }
00059     
00060     for(unsigned int i = 0; i < m_upRounds; i++)
00061     {
00062         randIndeX = ((double)rand() / (double)RAND_MAX) * 
00063                 (double)m_numControlPoints;
00064 
00065         randIndeY = ((double)rand() / (double)RAND_MAX) * 
00066                 (double)m_numControlPoints;
00067         
00068         height = (((double)rand() / (double)RAND_MAX) * (1.0 - m_midHeight)) + 
00069                 m_midHeight;
00070         
00071         p_target->push_back(Vector(randIndeX, height, randIndeY));
00072     }
00073 }
00074 
00075 void
00076 ControlPointGenerator::terGenrateLowRoundsCommand(const std::string& 
00077                                                   p_lowRounds)
00078 {
00079     if(!p_lowRounds.empty())
00080     {
00081         int tempRounds;
00082         
00083         std::istringstream s(p_lowRounds);
00084         s >> tempRounds;
00085         if(tempRounds >= 0)
00086             m_lowRounds = (unsigned int)tempRounds;
00087     }
00088     else
00089     {
00090         std::ostringstream s;
00091         s << m_lowRounds;
00092 
00093         Console::get()->addLine(s.str());
00094     }
00095 }
00096 
00097 void
00098 ControlPointGenerator::terGenrateUpRoundsCommand(const std::string& p_upRounds)
00099 {
00100     if(!p_upRounds.empty())
00101     {
00102         int tempUpRounds;
00103         
00104         std::istringstream s(p_upRounds);
00105         s >> tempUpRounds;
00106         if(tempUpRounds >= 0)
00107             m_upRounds = (unsigned int)tempUpRounds;
00108     }
00109     else
00110     {
00111         std::ostringstream s;
00112         s << m_upRounds;
00113 
00114         Console::get()->addLine(s.str());
00115     }
00116 }
00117 
00118 void
00119 ControlPointGenerator::terGenrateMidHeightCommand(const std::string& 
00120                                                   p_midHeight)
00121 {
00122     if(!p_midHeight.empty())
00123     {
00124         double tempMidHeight;
00125         
00126         std::istringstream s(p_midHeight);
00127         s >> tempMidHeight;
00128         if(tempMidHeight > 0 && tempMidHeight < 1)
00129             m_midHeight = tempMidHeight;
00130     }
00131     else
00132     {
00133         std::ostringstream s;
00134         s << m_midHeight;
00135 
00136         Console::get()->addLine(s.str());
00137     }
00138 }
00139 
00140 } // namespace random_racer

Generated on Fri May 11 21:01:57 2007 for Random Racer by  doxygen 1.5.1