Picob.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #include "stdafx.h"
00024 #include "Picob.h"
00025 
00026 Picob::Picob(const float &bumpLength, const float &pauseLength, vector<Vec3f> &bumps)
00027 :_bumpLength(bumpLength), _pauseLength(pauseLength), _bumps(bumps)
00028 {
00029 }
00030 
00031 Picob::Picob(const Picob &p)
00032 :_bumpLength(p._bumpLength), _pauseLength(p._pauseLength), _bumps(p._bumps)
00033 {
00034 }
00035 
00036 Picob::~Picob()
00037 {
00038 }
00039 
00040 Vec3f Picob::getDeviation(const float &pos) const
00041 {
00042         unsigned int n = pos / (_bumpLength + _pauseLength);
00043         if (n >= _bumps.size() || n < 0 ||pos < 0)
00044                 return Vec3f(0.0, 0.0, 0.0);
00045         float relpos = pos - n * (_bumpLength + _pauseLength);
00046         if (relpos > _bumpLength)
00047                 return Vec3f(0.0, 0.0, 0.0);
00048         //Vec3f temp = sin(relpos/_bumpLength * 2 * M_PI - M_PI) * _bumps[n];
00049         //Vec3f temp = sin(relpos/_bumpLength * M_PI) * _bumps[n];
00050         Vec3f temp = (cos((relpos/_bumpLength) * 2 * M_PI - M_PI) + 1) / 2 * _bumps[n];
00051         //return sin((pos - n * (_bumpLength + _pauseLength)) * M_PI/_bumpLength) * _bumps[n];
00052         return temp;
00053 }
00054 
00055 Vec3f Picob::getDeviation(const float &pos, const float &size) const
00056 {
00057         float sequenceLength = _bumps.size() * (_bumpLength + _pauseLength);
00058         return getDeviation(pos - (size - sequenceLength) / 2);
00059 }
00060 
00061 bool Picob::isFinished(const float &pos) const
00062 {
00063         return pos > _bumps.size() * (_bumpLength + _pauseLength) || pos < 0;
00064 }
00065 
00066 bool Picob::isFinished(const float &pos, const float &size) const
00067 {
00068         float sequenceLength = _bumps.size() * (_bumpLength + _pauseLength);
00069         return pos > (size - sequenceLength) / 2 || pos > (size + sequenceLength) / 2;
00070 }
00071 
00072 void Picob::readPicobList(const char *str, vector<Vec3f> &bumpList)
00073 {
00074         char *part;
00075         float vals[3];
00076         int step=0, lastpos = 0;
00077         for (unsigned int i = 0; i < strlen(str) ; i++)
00078         {
00079                 switch(step)
00080                 {
00081                         //waiting for a special char
00082                         case 0:
00083                                 if (str[i] != '(' && str[i] != ' ' && str[i] != ',')
00084                                         return;
00085                                 lastpos++;
00086                                 step++;
00087                                 break;
00088                         //reading the three number of a triplet
00089                         case 1: case 2: case 3:
00090                                 if (str[i] == ',' || str[i] == ')')
00091                                 {
00092                                         part = new char[i - lastpos + 1];
00093                                         for (unsigned int j = 0 ; j < i - lastpos ; j++)
00094                                                 part[j] = str[lastpos + j];
00095                                         part[i - lastpos] = '\0';
00096                                         vals[step - 1] = atof(part);
00097                                         delete []part;
00098                                         if (step == 3)
00099                                         {
00100                                                 step = 0;
00101                                                 bumpList.push_back(Vec3f(vals[0], vals[1], vals[2]));
00102                                         }
00103                                         else
00104                                                 step++;
00105                                         lastpos = i + 1;
00106                                 }
00107                                 else if (str[i] == '(')
00108                                         lastpos++;
00109                                 break;
00110                 }
00111         }
00112 }

Generated on Tue Oct 16 17:10:43 2007 for Micole by  doxygen 1.4.7