本文整理汇总了C++中Path2d::calcBoundingBox方法的典型用法代码示例。如果您正苦于以下问题:C++ Path2d::calcBoundingBox方法的具体用法?C++ Path2d::calcBoundingBox怎么用?C++ Path2d::calcBoundingBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path2d
的用法示例。
在下文中一共展示了Path2d::calcBoundingBox方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void Path2DSamplesApp::update()
{
auto bounds = path6.calcBoundingBox();
for( auto &pt : intersectPts ){
vec2 &pos = pt.first;
vec2 &vel = pt.second;
pos += vel;
if( pos.x > bounds.x2 || pos.x < bounds.x1 ) {
pos.x -= vel.x;
pt.second.x *= -1.0;
}
if( pos.y > bounds.y2 || pos.y < bounds.y1 ) {
pos.y -= vel.y;
pt.second.y *= -1.0;
}
}
// pt.second *= vec2( -1, 1 );
// }
/*
if( pos.y > bounds.y2 || pos.y < bounds.y1 )
pt.second *= vec2( 1, -1 );
*/
// Color ptColor = ( path6.contains( pt ) ) ? Color( 0, 1, 0 ) : Color( 1, 0, 0 );
// gl::color( ptColor );
// gl::drawSolidCircle( pt, 2.0 );
}
示例2: randFloat
void Path2DSamplesApp::setup()
{
// lineTo
path1.moveTo( vec2( 0.0, 0.0 ) );
path1.lineTo( vec2( 100.0, 100.0 ) );
path1.lineTo( vec2( 200.0, 0.0 ) );
path1.lineTo( vec2( 300.0, 100.0 ) );
path1.lineTo( vec2( 400.0, 0.0 ) );
// quadTo - waves
float waveWidth = 100.0;
path2.moveTo( vec2( 0.0, 50.0 ) );
for( int i = 0; i < 5; i++ ) {
float startX = i * waveWidth;
path2.quadTo( vec2( startX, 0.0 ), vec2( startX + waveWidth / 2.0, 0.0 ) );
path2.quadTo( vec2( startX + waveWidth / 2.0, 50.0 ), vec2( startX + waveWidth, 50.0 ) );
}
// curveTo
path3.moveTo( vec2( 0 ) );
path3.curveTo( vec2( 25.0, 0.0 ), vec2( 50.0, 25.0 ), vec2( 50.0, 50.0 ) );
// arc & arcTo
// path4.moveTo( zero<vec2>() );
// path4.arc( vec2( 25.0, 25.0 ), 25.0, 0.0, glm::pi<float> );
path4.arc( vec2( 25.0, 25.0 ), 25.0, 0.0, M_PI );
path5.moveTo( vec2( 0.0, 0.0 ) );
// end point, tangent position, radius
path5.arcTo( vec2( 50.0, 50.0 ), vec2( 50.0, 0.0 ), 25.0 );
// path for contains
path6.moveTo( vec2( 0.0, 0.0 ) );
path6.quadTo( vec2( 80.0, 30.0), vec2( 100, 50) );
path6.quadTo( vec2( 180.0, 50.0), vec2( 210.0, 20.0) );
path6.quadTo( vec2( 270.0, 10.0), vec2( 280.0, 100.0) );
path6.quadTo( vec2( 200.0, 150.0), vec2( 140.0, 100.0) );
path6.quadTo( vec2( 100.0, 150.0), vec2( 50.0, 80.0) );
path6.close();
// points to look for intersection
for( int i = 0; i < 50; i++ ) {
auto bounds = path6.calcBoundingBox();
std::pair<vec2, vec2> pair;
pair.first = vec2( randFloat( bounds.x1 , bounds.x2), randFloat( bounds.y1, bounds.y2 ) );
pair.second = vec2( randFloat( -1, 1), randFloat( -1, 1) );
intersectPts.push_back( pair );
}
// move over a bit and dot affine matrix copies and rotate
{
int amount = 10;
for( int i = 0; i < amount; i++ ){
MatrixAffine2<float> affineMtrx;
affineMtrx.scale( 0.3 );
affineMtrx.rotate( ( ( M_PI * 2) / 8 ) * i );
auto pathCopy = path2.transformCopy( affineMtrx );
pathCaches.emplace_back( pathCopy );
}
}
// snowflake using
}
示例3: 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;
//.........这里部分代码省略.........