本文整理汇总了C++中ofPolyline::getCentroid2D方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPolyline::getCentroid2D方法的具体用法?C++ ofPolyline::getCentroid2D怎么用?C++ ofPolyline::getCentroid2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPolyline
的用法示例。
在下文中一共展示了ofPolyline::getCentroid2D方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkIfHole
int Shadows::checkIfHole(ofPolyline& _contourLine){
int rta = -1;
// Calculate the centroid
//
ofPoint centroid = _contourLine.getCentroid2D();
// Check if it fits inside another another non-active blob.
//
for( map<int,AnimatedShadow*>::reverse_iterator rit = hands.rbegin(); rit != hands.rend(); rit++ ){
if ( !(rit->second->bActive) ) {
if ( rit->second->isInside( centroid ) ){
rta = rit->second->getId();
}
}
}
return rta;
}
示例2: draw
//.........这里部分代码省略.........
ofNoFill();
ofSetLineWidth(2);
ofSetColor(255, 0, 0);
ofCircle(nearestPoint, 5);
ofSetColor(255, 255, 0);
ofCircle(nearestDataPoint, 7);
// interpolating on indices
{
ofPoint p = poly.getPointAtIndexInterpolated(sinIndex);
ofSetColor(0, 255, 255);
ofCircle(p, 10);
ofSetColor(255, 0, 0);
ofLine(p, p + poly.getTangentAtIndexInterpolated(sinIndex) * 60);
ofSetColor(0, 255, 0);
ofLine(p, p + poly.getNormalAtIndexInterpolated(sinIndex) * 60);
ofSetColor(0, 128, 255);
ofLine(p, p + poly.getRotationAtIndexInterpolated(sinIndex) * 60);
}
// interpolating on length percentages
{
ofPoint p = poly.getPointAtIndexInterpolated(sinIndexLength);
ofSetColor(255, 0, 255);
ofCircle(p, 10);
ofSetColor(255, 0, 0);
ofLine(p, p + poly.getTangentAtIndexInterpolated(sinIndexLength) * 60);
ofSetColor(0, 255, 0);
ofLine(p, p + poly.getNormalAtIndexInterpolated(sinIndexLength) * 60);
ofSetColor(0, 128, 255);
ofLine(p, p + poly.getRotationAtIndexInterpolated(sinIndexLength) * 60);
}
ofSetColor(255, 255, 255);
ofCircle(poly.getCentroid2D(), 20);
ofPopMatrix();
stringstream s;
s << "Number of points: " << poly.size() << endl;
s << "totalLength: " << totalLength << endl;
s << endl;
s << "nearestIndex: " << nearestIndex << endl;
s << "nearestPoint: " << nearestPoint << endl;
s << "nearestDataPoint: " << nearestDataPoint << endl;
s << endl;
s << "lengthAtIndex: " << lengthAtIndex << endl;
s << "pointAtIndex: " << pointAtIndex << endl;
s << endl;
s << "pointAtLength: " << pointAtLength << endl;
s << "pointAtPercent: " << pointAtPercent << endl;
s << endl;
s << "indexAtLength: " << indexAtLength << endl;
s << endl;
s << "sinTime: " << sinTime << endl;
s << "sinIndex: " << sinIndex << endl;
s << "sinIndexLength: " << sinIndexLength << endl;
s << endl;
s << "lengthAtIndexSin: " << lengthAtIndexSin << endl;
s << "pointAtIndexSin: " << pointAtIndexSin << endl;
s << "pointAtPercentSin: " << pointAtPercentSin << endl;
s << endl;
s << "angleAtIndex: " << angleAtIndex << endl;
s << "angleAtIndexSin: " << angleAtIndexSin << endl;
s << endl;
s << "rotAtIndex: " << rotAtIndex << endl;
s << "rotAtIndexSin: " << rotAtIndexSin << endl;
s << endl;
s << "rotMagAtIndex: " << rotMagAtIndex << endl;
s << "rotMagAtIndexSin: " << rotMagAtIndexSin << endl;
s << endl;
s << "normalAtIndex: " << normalAtIndex << endl;
s << "normalAtIndexSin: " << normalAtIndexSin << endl;
ofSetColor(255);
ofDrawBitmapString(s.str(), 10, 30);
}
示例3: kill
void LetterParticle::kill()
{
BaseParticle::kill(); // call the super /parent class!
std::vector<ofTTFCharacter> paths = font.getStringAsPoints(text);
std::vector<ofTTFCharacter>::iterator pathsIter = paths.begin();
while(pathsIter != paths.end())
{
std:
vector<ofPolyline> polylines = (*pathsIter).getOutline();
std::vector<ofPolyline>::const_iterator polyIter = polylines.begin();
while(polyIter != polylines.end())
{
if((*polyIter).size() > 0)
{
ofPolyline resampled = (*polyIter).getResampledBySpacing(2); // this number tells us how many particles
if(resampled.size() > 0)
{
const ofPolyline poly = resampled.getVertices();
auto centroid = poly.getCentroid2D(); // find the middle
// create a particle group
std::shared_ptr<BaseParticleGroup> particleGroup(new BaseParticleGroup());
// add particles to the particle system AND to the particle group
for(int i = 0; i < poly.size(); ++i)
{
std::shared_ptr<ParticleGroupMember> particle(new ParticleGroupMember());
// this is how we get the particle to move away from the center
// of the group (as calculated by the centroid)
auto newVelocity = glm::normalize(poly[i] - centroid) * ofRandom(.5,2);
particle->position = position + poly[i];
particle->velocity = velocity + newVelocity;
particle->acceleration = acceleration;
particle->maxAge = ofRandom(50,100);
particle->particleSystem = particleSystem; // make a link back to the particle system
particleSystem->addParticle(particle);
particleGroup->members.push_back(particle);
}
// add the particle group to the particle system
particleSystem->addParticleGroup(particleGroup);
}
}
++polyIter;
}
++pathsIter;
}
}