本文整理汇总了C++中Path2d类的典型用法代码示例。如果您正苦于以下问题:C++ Path2d类的具体用法?C++ Path2d怎么用?C++ Path2d使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path2d类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void Island::draw()
{
float pointsPerMeter = SceneController::getPointsPerMeter();
auto centerPos = box2d::toCinder( mBody->GetPosition() ) * pointsPerMeter;
gl::pushModelView();
gl::translate( centerPos );
Path2d path;
path.moveTo( mOuterVerts[0] );
for( int i = 1; i < mOuterVerts.size(); ++i )
path.lineTo( mOuterVerts[i] );
Color color = Color::gray( 0.34f );
color.r *= 1 - mVibrationLevel * 0.5;
color.g *= 1 - mVibrationLevel * 0.2;
gl::color( color );
gl::drawSolid( path );
for( size_t i = 0; i < mBumpers.size(); i++ ) {
Color color = Color::gray( 0.42f );
color.r *= 1 + mBumperVibrationLevels[i];
gl::color( color );
gl::drawSolid( mBumpers[i] );
}
gl::popModelView();
}
示例2: intersect
bool intersect(const Path2d& path)
{
bool closed = false;
for (int i=0; i<path.size()-2 && !closed; i++)
{
for (int j=i+2; j<path.size()-1 && !closed; j++)
{
closed = _intersSegmenti(path[i], path[i+1], path[j], path[j+1]) != P2d::none();
}
}
return closed;
}
示例3: _intersections
std::vector<P2d> _intersections(const Path2d& path1, const Path2d& path2, const bool self_intersect)
{
std::vector<P2d> rv;
if (path1.size() < 2 || path2.size() < 2)
return rv;
int i1, i2, i2_start;
P2d p1a, p1b;
P2d p2a, p2b;
for(i1 = 0, p1a = path1[i1]; i1 < (path1.size() - 1); p1a = p1b)
{
++i1;
p1b = path1[i1];
if (!self_intersect)
{
i2_start = 0;
} else {
// in casi non degeneri due segmenti consecutivi di una linea non si intersecano
i2_start = i1 + 1;
if (i2_start >= (path2.size() - 1))
break;
}
for(i2 = i2_start, p2a = path2[i2]; i2 < (path2.size() - 1); p2a = p2b)
{
++i2;
p2b = path2[i2];
P2d intr = _intersSegmenti(p1a, p1b, p2a, p2b);
if (intr != P2d::none())
{
rv.push_back(intr);
}
}
}
return rv;
}
示例4: switch
void ContinuousPathApp::drawCurves(cairo::Context &ctx, Path2d path, float thickness, Color col)
{
ctx.setLineWidth(thickness);
ctx.setSource(col);
ctx.newSubPath();
int pointIndex = 0;
for (int i=0; i<path.getNumSegments(); i++) {
int segType = path.getSegmentType(i);
// change jumpIndex depending on the type of segment
switch(segType){
case Path2d::CUBICTO:
if(i==0) ctx.moveTo(path.getPoint(pointIndex));
// do a curve to using the next 2 points as the curves and the 3rd as the end point
ctx.curveTo(path.getPoint(pointIndex+1), path.getPoint(pointIndex+2), path.getPoint(pointIndex+3));
pointIndex += 3;
break;
case Path2d::MOVETO:
// don't do anything with this point
ctx.moveTo(path.getPoint(pointIndex));
pointIndex += 0;
break;
default:
pointIndex += 1;
break;
}
}
ctx.stroke();
}
示例5: computeLeftTangent
Path2d PathFitter::FitCurve(vector<Vec2f> const &d, int startIndex, int endIndex, double error)
{
if(error == 0.0) throw "error value must be greater than 0.0";
Vec2f tHat1, tHat2; // Unit tangent vectors at endpoints
vector<BezierCurve> bezCurves; // The vector that will store the BezierCurve values to be returned once the curve fitting is complete
// if startIndex is the beginning of the cur
tHat1 = computeLeftTangent(d, startIndex);
// if endIndex is the end of the curve
tHat2 = computeRightTangent(d, endIndex - 1);
FitCubic(d, &bezCurves, startIndex, endIndex - 1, tHat1, tHat2, error);
// convert the vector of BezierCurves to a Path2d object
Path2d curvePath;
curvePath.moveTo(bezCurves[0].pt1.x, bezCurves[0].pt1.y);
for(int i=0; i<bezCurves.size(); i++){
curvePath.curveTo(bezCurves[i].c1, bezCurves[i].c2, bezCurves[i].pt2);
}
return curvePath;
}
示例6: drawLine
// Draw each path onto the passed cairo context
void PathSimplificationApp::drawPath(cairo::Context &ctx, SmoothPath *smoothPath, int mode)
{
// initialize the line settings
float thickness = 1.0;
ctx.setLineWidth( 1.0f );
ctx.setLineCap(cairo::LINE_CAP_ROUND);
ctx.setLineJoin(cairo::LINE_JOIN_ROUND);
if(smoothPath->inProgress){
// draw lines point to point
vector<Vec2f> pathPoints = smoothPath->getPathPoints();
for (int i=1; i<pathPoints.size(); i++) {
drawLine(ctx, pathPoints[i-1], pathPoints[i], 1.0, Color(1.0, 0.0, 0.0));
drawCircle(ctx, pathPoints[i], 2, Color(1.0, 0.0, 0.0));
}
}else{
// draw smooth lines
Path2d path = smoothPath->getCurrentPath();
drawCurves(ctx, path, thickness, Color(255.0, 0.0, 0.0));
int pointIndex = 0;
// draw circles at the bezier points
for (int i=0; i<path.getNumSegments(); i++) {
Vec2f c1 = path.getPoint(pointIndex+1);
Vec2f c2 = path.getPoint(pointIndex+2);
Vec2f pt1 = path.getPoint(pointIndex);
Vec2f pt2 = path.getPoint(pointIndex+3);
drawCircle(ctx, c1, 1, Color(1.0f, 1.0f, 0.0f), true);
drawCircle(ctx, c2, 1, Color(0.0f, 1.0f, 1.0f));
drawLine(ctx, c1, pt1, 1, Color(1.0, 1.0, 0.0 ));
drawLine(ctx, c2, pt2, 1, Color(0.0, 1.0, 1.0 ));
pointIndex += 3;
}
}
}
示例7: rect
void CanvasContext::rect(float x, float y, float w, float h)
{
Path2d p;
p.moveTo(x, y);
p.lineTo(x, y + h);
p.lineTo(x + w, y + h);
p.lineTo(x + w, y);
p.close();
paths.push_back(p);
}
示例8: wallRect
void Wall::draw()
{
float pointsPerMeter = SceneController::getPointsPerMeter();
auto pos = pointsPerMeter * mBody->GetPosition();
Rectf wallRect( pos.x - mWidth, 0, pos.x + mWidth, app::getWindowHeight() );
Path2d vibrationPath;
vibrationPath.moveTo( wallRect.getUpperRight() );
// right vibrating wall
{
Vec2f controlPoint1( wallRect.x2 + mVibrationLevel, wallRect.y1 + wallRect.getHeight() / 3.0f );
Vec2f controlPoint2( wallRect.x2 + mVibrationLevel, wallRect.y1 + wallRect.getHeight() * 2.0f / 3.0f );
vibrationPath.curveTo( controlPoint1, controlPoint2, wallRect.getLowerRight() );
}
vibrationPath.lineTo( wallRect.getLowerLeft() );
// left vibrating wall
{
Vec2f controlPoint1( wallRect.x1 - mVibrationLevel, wallRect.y1 + wallRect.getHeight() * 2.0f / 3.0f );
Vec2f controlPoint2( wallRect.x1 - mVibrationLevel, wallRect.y1 + wallRect.getHeight() / 3.0f );
vibrationPath.curveTo( controlPoint1, controlPoint2, wallRect.getUpperLeft() );
}
vibrationPath.close();
ColorA vibrationColor = ColorA::gray( 0.2f, 0.6f );
vibrationColor.g += mVibrationLevel * 0.01f;
vibrationColor.b += mVibrationLevel * 0.03f;
gl::color( vibrationColor );
gl::drawSolid( vibrationPath );
ColorA wallColor = ColorA::gray( 0.2f, 1.0f );
wallColor.g += mVibrationLevel * 0.01f;
wallColor.b += mVibrationLevel * 0.015f;
gl::color( wallColor );
gl::drawSolidRect( wallRect );
}
示例9: draw
void SeaSurface:: draw(){
float globalOpacityMod = 1.0f;
globalOpacityMod = -(offset.y + 6000) * 0.002f;
if( globalOpacityMod >= 1.0f ) globalOpacityMod = 1.0f;
for(int n = 0; n < rows.size(); n++){
Path2d path;
path.moveTo( paths.at(n).at(0) );
for(int i = 1; i < paths.at(n).size(); i++ )
path.lineTo( paths.at(n).at(i) );
path.lineTo( vec2( cinder::app::getWindowWidth(), 0.0 ) );
path.lineTo( vec2( 0.0, 0.0 ) );
path.close();
gl::color(ColorA8u(237,160, 135, rows.at(n)->depth * 20.0f * globalOpacityMod ) );
gl::drawSolid(path);
gl::draw(path);
}
}
示例10: draw
void SeaFloor:: draw(){
float globalOpacityMod = 1.0f;
globalOpacityMod = (offset.y + 1000) * 0.002f;
if( globalOpacityMod >= 1.0f ) globalOpacityMod = 1.0f;
for(int n = 0; n < rows.size(); n++){
Path2d path;
path.moveTo( paths.at(n).at(0) );
for(int i = 1; i < paths.at(n).size(); i++ )
path.lineTo( paths.at(n).at(i) );
path.lineTo( vec2( cinder::app::getWindowWidth(), cinder::app::getWindowHeight()) );
path.lineTo( vec2( 0.0, cinder::app::getWindowHeight() ) );
path.close();
gl::color(ColorA8u(192,177,139, rows.at(n)->depth * 30.0f * globalOpacityMod ) );
gl::drawSolid(path);
gl::draw(path);
}
}
示例11: CI_ASSERT
void Island::makeBumpers()
{
CI_ASSERT( mOuterVerts.size() == 6 && mInnerVerts.size() == 5 );
mBumpers.clear();
mBumperBoundingBoxes.clear();
mBumperVibrationLevels.clear();
const float padding = 4;
const float crookedPaddingPercent = 0.036f;
const float boundingBoxExpansion = 1.1f;
// left base
{
Path2d bumper;
bumper.moveTo( mOuterVerts[0] );
bumper.lineTo( mOuterVerts[1].x, mOuterVerts[1].y + padding );
bumper.lineTo( mInnerVerts[1].x, mInnerVerts[1].y + padding );
bumper.lineTo( mInnerVerts[0] );
bumper.close();
mBumpers.push_back( bumper );
}
// left top
{
Vec2f offsetOuter = ( mOuterVerts[2] - mOuterVerts[1] ) * crookedPaddingPercent;
Vec2f offsetInner = ( Vec2f( mOuterVerts[2].x, mInnerVerts[2].y ) - mInnerVerts[1] ) * crookedPaddingPercent;
Path2d bumper;
bumper.moveTo( mOuterVerts[1] + offsetOuter );
bumper.lineTo( mOuterVerts[2] );
bumper.lineTo( mOuterVerts[2].x, mInnerVerts[2].y );
bumper.lineTo( mInnerVerts[1] + offsetInner );
bumper.close();
mBumpers.push_back( bumper );
}
// right top
{
Vec2f offsetOuter = ( mOuterVerts[3] - mOuterVerts[4] ) * crookedPaddingPercent;
Vec2f offsetInner = ( Vec2f( mOuterVerts[3].x, mInnerVerts[2].y ) - mInnerVerts[3] ) * crookedPaddingPercent;
Path2d bumper;
bumper.moveTo( mOuterVerts[3] );
bumper.lineTo( mOuterVerts[4] + offsetOuter );
bumper.lineTo( mInnerVerts[3] + offsetInner );
bumper.lineTo( mOuterVerts[3].x, mInnerVerts[2].y );
bumper.close();
mBumpers.push_back( bumper );
}
// right base
{
Path2d bumper;
bumper.moveTo( mOuterVerts[4].x, mOuterVerts[4].y + padding );
bumper.lineTo( mOuterVerts[5] );
bumper.lineTo( mInnerVerts[4] );
bumper.lineTo( mInnerVerts[3].x, mInnerVerts[3].y + padding );
bumper.close();
mBumpers.push_back( bumper );
}
for( size_t i = 0; i < mBumpers.size(); i++ ) {
mBumperVibrationLevels.push_back( 0 );
// calculate an expanded bounding box for each bumper to do hit detection, ensuring that the entire edge is covered.
Rectf bbox = mBumpers[i].calcBoundingBox();
Vec2f center = bbox.getCenter();
bbox -= center;
bbox *= boundingBoxExpansion;
bbox += center;
mBumperBoundingBoxes.push_back( bbox );
}
}
示例12: prevNormPos1
void Ribbon::draw()
{
Vec2i normPos1, normPos2;
normPos1 = Vec2f::zero();
normPos2 = Vec2f::zero();
for(list<RibbonParticle *>::iterator p = mParticles.begin(); p != mParticles.end(); ++p){
int x1 = (*p)->mPos.x - (*p)->mVel.x;
int x2 = (*p)->mPos.x;
int y1 = (*p)->mPos.y - (*p)->mVel.y;
int y2 = (*p)->mPos.y;
// Capture the previous normal positions
Vec2i prevNormPos1(normPos1);
Vec2i prevNormPos2(normPos2);
// If this is the first segment, make the normals the
// same as the position (we want it to taper in)
if(prevNormPos1 == Vec2i::zero() &&
prevNormPos2 == Vec2i::zero()){
normPos1 = Vec2i(x1, y1);
normPos2 = Vec2i(x2, y2);
prevNormPos1 = normPos1;
prevNormPos2 = normPos2;
}else{
int normX1 = (*p)->mPos.x - ((*p)->mVelNormal.x * 0.5);
int normX2 = (*p)->mPos.x + ((*p)->mVelNormal.x * 0.5);
int normY1 = (*p)->mPos.y - ((*p)->mVelNormal.y * 0.5);
int normY2 = (*p)->mPos.y + ((*p)->mVelNormal.y * 0.5);
normPos1 = Vec2i(normX1,normY1);
normPos2 = Vec2i(normX2,normY2);
}
// Draw the shape between the normals
Path2d path;
path.moveTo(prevNormPos1.x, prevNormPos1.y);
path.lineTo(normPos1.x, normPos1.y);
path.lineTo(normPos2.x, normPos2.y);
path.lineTo(prevNormPos2.x, prevNormPos2.y);
path.close();
// float value = ((*p)->mAge / 200.0);
// Draw the filled ribbon
// Defaults to yellow
float red = 1.0;
float green = 1.0;
float blue = 0.5;
if(mAgeConnectedAt > 0){
int lastConnected = mAge - mAgeConnectedAt;
if(lastConnected < 20){
if(mCapturedGoal){
red = lastConnected * 0.05;
}else{
green = lastConnected * 0.05;
}
blue = lastConnected * 0.025;
}
}
gl::color(Color(red,green,blue));
gl::drawSolid(path);
/*
// Draw the surface normal
gl::color(Color(1.0-value,0,0));
gl::drawLine(normPos1, normPos2);
// Draw a line indicating it's position w/ velocity
gl::color(Color::black());
gl::drawLine(Vec2i(x1,y1), Vec2i(x2, y2));
*/
}
}
示例13: add
void ShapeTesselator::add(const Path2d &path, float approximationScale)
{
add(path.subdivide(approximationScale));
}
示例14: Color
void Path2DSamplesApp::draw()
{
gl::enableAlphaBlending();
gl::clear( Color( 0, 0, 0 ) );
gl::lineWidth( 1.0 );
{
gl::ScopedMatrices mtrx;
gl::translate( vec2( 50.0, 50.0 ) );
drawPath( path1 );
}
{
gl::ScopedMatrices mtrx;
gl::translate( vec2( 50.0, 200.0 ) );
drawPath( path2 );
}
{
gl::ScopedMatrices mtrx;
gl::translate( vec2( 50.0, 300.0 ) );
drawPath( path3 );
}
{
gl::ScopedMatrices mtrx;
gl::translate( vec2( 200.0, 300.0 ) );
drawPath( path4 );
}
{
gl::ScopedMatrices mtrx;
gl::translate( vec2( 350.0, 300.0 ) );
drawPath( path5 );
}
{
gl::ScopedMatrices mtrx;
gl::translate( vec2( 50.0, 400.0 ) );
gl::color( Color( 1, 0 ,0 ) );
gl::draw( path6 );
for( auto &pt : intersectPts ){
Color ptColor = ( path6.contains( pt.first ) ) ? Color( 0, 1, 0 ) : Color( 1, 0, 0 );
gl::color( ptColor );
gl::drawSolidCircle( pt.first, 2.0 );
}
gl::color( 1, 1, 1, 0.2);
gl::drawSolidRect( path6.calcBoundingBox() );
}
gl::lineWidth( 2.0 );
{
gl::ScopedMatrices mtrx;
gl::translate( vec2( 600, 400 ) );
float timePos = ( getElapsedSeconds() * 10.0f );
int amt = 10;
for( int i = 0; i < pathCaches.size()-1; i++ ) {
auto path1 = pathCaches[i];
Path2dCalcCache path2 = pathCaches[i + 1];
float time = timePos;
for( int j = 0; j < amt; j++ ) {
time += 20.0;
float time1 = path1.calcTimeForDistance( time );
vec2 pt1 = path1.getPosition( time1 );
float time2 = path2.calcTimeForDistance( time );
vec2 pt2 = path2.getPosition( time2 );
gl::color( 1, 1, 1, 1);
gl::drawLine( pt1, pt2 );
}
gl::color( 1, 1, 1, 0.2);
gl::draw(path1.getPath2d());
}
}
// draw outlines
// draw solid
// console() << " _ " << endl;
//.........这里部分代码省略.........
示例15: drawCurves
// Draw each path onto the passed cairo context
void ContinuousPathApp::drawPath(cairo::Context &ctx, SmoothPath *smoothPath, int mode)
{
// update the drawing points only if the line hasn't been completed
Path2d path = smoothPath->getCurrentPath();
vector<Vec2f> pathPoints = smoothPath->getPathPoints();
vector<int> endPoints = smoothPath->getEndPoints();
if(path.getNumPoints() == 0) return;
// initialize the line settings
float thickness = 1.0;
ctx.setLineWidth( 1.0f );
ctx.setLineCap(cairo::LINE_CAP_ROUND);
ctx.setLineJoin(cairo::LINE_JOIN_ROUND);
Vec2f pt = path.getPoint(0);
// draw bezier line
if (mode != 5) {
// draw the line based on bezier points
drawCurves(ctx, path, thickness, Color(255.0, 0.0, 0.0));
}
// draw circles at each of the original path points
if(mode != 1 && mode != 5){
for (int i=0; i<pathPoints.size(); i++) {
Vec2f pt = pathPoints[i];
drawCircle(ctx, pt, 1, Color( 1.0f, 1.0f, 1.0f ));
}
}
int i;
int pointIndex = 0;
// draw circles at the bezier points
for (i=0; i<path.getNumSegments(); i++) {
int segType = path.getSegmentType(i);
// change jumpIndex depending on the type of segment
switch(segType){
case Path2d::CUBICTO:
{
Vec2f c1 = path.getPoint(pointIndex+1);
Vec2f c2 = path.getPoint(pointIndex+2);
Vec2f pt1 = path.getPoint(pointIndex);
Vec2f pt2 = path.getPoint(pointIndex+3);
if (mode == 2 || mode == 3) {
if(mode == 2){
for(int j=0; j<endPoints.size(); j++){
if(endPoints[j] == pointIndex){
drawCircle(ctx, pt2, 8, Color(0.0f, 1.0f, 1.0f), true);
}
}
}
if(mode == 3){
// draw the control points and tangent lines
drawCircle(ctx, c1, 2, Color(1.0f, 1.0f, 0.0f), true);
drawCircle(ctx, c2, 2, Color(0.0f, 1.0f, 1.0f));
drawLine(ctx, c1, pt1, 1, Color(1.0, 1.0, 0.0 ));
drawLine(ctx, c2, pt2, 1, Color(0.0, 1.0, 1.0 ));
}
drawCircle(ctx, pt2, 2, Color(1.0f, 0.0f, 1.0f));
drawCircle(ctx, pt1, 2, Color(1.0f, 0.0f, 0.0f), true);
}
if (mode == 4) {
drawLine(ctx, pt1, pt2, 1, Color(1.0, 1.0, 1.0 ));
drawCircle(ctx, pt1, 5, Color(1.0, 0.0, 0.0), true);
drawCircle(ctx, pt2, 3, Color(1.0, 0.0, 1.0));
}
pointIndex += 3;
break;
}
case Path2d::MOVETO:
// don't do anything with this point
pointIndex += 0;
break;
default:
pointIndex += 1;
break;
}
}
if (mode== 5) {
// draw a line between the last bezier point and the current point
for (i=1; i<pathPoints.size(); i++) {
drawLine(ctx, pathPoints[i-1], pathPoints[i], 1.0, Color(1.0, 0.0, 0.0));
//.........这里部分代码省略.........