00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00049
00050 Vec3f temp = (cos((relpos/_bumpLength) * 2 * M_PI - M_PI) + 1) / 2 * _bumps[n];
00051
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
00082 case 0:
00083 if (str[i] != '(' && str[i] != ' ' && str[i] != ',')
00084 return;
00085 lastpos++;
00086 step++;
00087 break;
00088
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 }