diff options
author | Chris Xiong <chirs241097@gmail.com> | 2015-11-01 23:32:22 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2015-11-01 23:32:22 +0800 |
commit | f68cc9034a576b6f91cf0db0344ece971944c973 (patch) | |
tree | 123744e85445f51d058b74d9c9fb2174f6abefd7 /extensions | |
parent | 1981e9bc81e92f479c725e6ac60ff3bd419cefd0 (diff) | |
download | bullet-lab-remix-f68cc9034a576b6f91cf0db0344ece971944c973.tar.xz |
Move hge to an archive.
Finish the main part of smPath.
This is a C++ project, add C++ tags to all source code that
could be identified as C source files.
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/smpath.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/extensions/smpath.cpp b/extensions/smpath.cpp index d86e18b..9d73b4a 100644 --- a/extensions/smpath.cpp +++ b/extensions/smpath.cpp @@ -1,13 +1,27 @@ #include <cmath> #include "smpath.hpp" smPathSegment::smPathSegment(smvec2d _a,smvec2d _b){a=_a,b=_b;} -smvec2d smPathSegment::getPointOnPath(double percentage) -{return a+percentage*(b-a);} +smvec2d smPathSegment::getPointOnPath(double rt) +{return a+rt*(b-a);} double smPathSegment::getPathLength() {return (a-b).l();} smPathCircular::smPathCircular(smvec2d _ctr,double _a,double _b,double _r) {ctr=_ctr,a=_a,b=_b,r=_r;} -smvec2d smPathCircular::getPointOnPath(double percentage) -{return smvec2d(ctr.x+r*cos(a+percentage*(b-a)),ctr.y+r*sin(a+percentage*(b-a)));} +smvec2d smPathCircular::getPointOnPath(double rt) +{return smvec2d(ctr.x+r*cos(a+rt*(b-a)),ctr.y+r*sin(a+rt*(b-a)));} double smPathCircular::getPathLength() {return fabs(a-b)*r;} +int smPathCollection::pushPath(smPathBase *p){paths[cpaths++]=p;return cpaths-1;} +smPathBase* smPathCollection::getPath(int pid){return paths[pid];} +smvec2d smPathCollection::getPointOnCollection(double rt) +{ + double l=0.,tl=0.; + int i; + for(i=0;i<cpaths;++i)l+=paths[i]->getPathLength(); + for(i=0;i<cpaths;++i) + { + if(tl+paths[i]->getPathLength()>=l*rt)break; + tl+=paths[i]->getPathLength(); + } + return paths[i]->getPointOnPath(rt-tl/l); +} |