/* ging methods */ void CinderOpenNISkeleton::debugDrawLabels( Font font, ci::Rectf depthArea ) { // Apply scale based on window size, vs dimensions of depth image ( will be 320 or 640 ) ci::Vec2i inputSize = CinderOpenNISkeleton::getDimensions(); ci::Vec3f depthMapScale = ci::Vec3f( depthArea.getWidth() / inputSize.x, depthArea.getHeight() / inputSize.y, 0.5f ); for (int i = 0; i < maxUsers; ++i) { // Do the labels first XnPoint3D userCenterOfMass; mUserGenerator.GetCoM(currentUsers[i], userCenterOfMass); mDepthGenerator.ConvertRealWorldToProjective(1, &userCenterOfMass, &userCenterOfMass); // Scale and place based on center of 'depthArea' rectangle ci::Vec2i labelPosition = ci::Vec2i(depthArea.getX1() + depthMapScale.x*userCenterOfMass.X, depthArea.getY1() + depthMapScale.y*userCenterOfMass.Y); glColor4f(1.0f-Colors[i%nColors][0], 1.0f-Colors[i%nColors][1], 1.0f-Colors[i%nColors][2], 1); if ( mUserGenerator.GetSkeletonCap().IsTracking(currentUsers[i]) ) { // Is being tracked gl::drawString("Tracking", labelPosition, Color::white(), font ); } else if ( mUserGenerator.GetSkeletonCap().IsCalibrating(currentUsers[i]) ) { // Is calibrating gl::drawString("Calibrating", labelPosition, Color::white(), font ); } else { // Still waiting for intial pose gl::drawString("Waiting for Pose", labelPosition, Color::white(), font ); } } }
void View::addCenterLines( std::vector<RenderData> &data, const ci::ColorA &color, const ci::Rectf rect, float lineWidth ) { vec2 offset = rect.getUpperLeft(); float w = rect.getWidth(); float h = rect.getHeight(); float hw = w*0.5; float hh = h*0.5; addLine( data, color, offset + vec2(0, hh), offset + vec2(w, hh), lineWidth ); addLine( data, color, offset + vec2(hw, 0), offset + vec2(hw, h), lineWidth ); }
void GestureApp::drawUi() { // Dial gl::color( ColorAf( Colorf::white(), 0.2f + mDialBrightness ) ); gl::drawSolidCircle( mDialPosition, mDialRadius, mCircleResolution * 2 ); gl::color( mBackgroundColor ); float angle = mDialValue * (float)M_PI * 2.0f; vec2 pos( math<float>::cos( angle ), math<float>::sin( angle ) ); pos *= mDialRadius - mDotSpacing; gl::drawSolidCircle( mDialPosition + pos, mDotRadius, mCircleResolution ); // Swipe float x = mSwipeRect.x1 + mSwipePos * mSwipeRect.getWidth(); Rectf a( mSwipeRect.x1, mSwipeRect.y1, x, mSwipeRect.y2 ); Rectf b( x, mSwipeRect.y1, mSwipeRect.x2, mSwipeRect.y2 ); gl::color( ColorAf( Colorf::gray( 0.5f ), 0.2f + mSwipeBrightness ) ); gl::drawSolidRect( a ); gl::color( ColorAf( Colorf::white(), 0.2f + mSwipeBrightness ) ); gl::drawSolidRect( b ); // Keys for ( vector<Key>::iterator iter = mKeys.begin(); iter != mKeys.end(); ++iter ) { gl::color( ColorAf( Colorf::white(), 0.2f + iter->mBrightness ) ); gl::drawSolidRect( iter->mBounds ); } }
void QLiveGUI::init( ci::Rectf rect ) // rect doesn't make any f*****g sense! TODO: remove this shit! { std::vector<QLiveTrackRef> tracks = mLive->getTracks(); if ( tracks.empty() ) return; int margin = 15; int n = 0; for( auto k=0; k < tracks.size(); k++ ) if ( !boost::starts_with( tracks[k]->getName(), "_") ) // IGNORE all the params in the tracks that starts with "_" n++; Vec2f size; size.x = ( rect.getWidth() - ( n + 1 ) * margin ) / n; size.y = 150; for( auto k=0; k < tracks.size(); k++ ) { if ( boost::starts_with( tracks[k]->getName(), "_") ) // IGNORE all the params in the tracks that starts with "_" continue; mControls.push_back( QLiveGuiTrackControl::create( mLive, tracks[k], size, mCanvas ) ); } }
// ------------------------------------------------------- void BasePretzel::updateBounds(const ci::Vec2f &offset, const ci::Rectf &parentBounds){ mOffset.set(offset); mParentBounds = parentBounds; mBounds.x2 = parentBounds.getWidth(); mGlobalOffset.set( mGlobal->getGlobalPos() ); }
void WaveformPlot::load( const std::vector<float> &samples, const ci::Rectf &bounds, size_t pixelsPerVertex ) { mBounds = bounds; mWaveforms.clear(); ivec2 waveSize = bounds.getSize(); mWaveforms.push_back( Waveform( samples, waveSize, pixelsPerVertex, Waveform::CalcMode::MIN_MAX ) ); mWaveforms.push_back( Waveform( samples, waveSize, pixelsPerVertex, Waveform::CalcMode::AVERAGE ) ); }
void View::addPointGrid( std::vector<RenderData> &data, const ci::ColorA &color, const ci::Rectf rect, float gridInterval, float pointSize ) { vec2 offset = rect.getUpperLeft(); float w = rect.getWidth(); float h = rect.getHeight(); float hw = w*0.5; float hh = h*0.5; for( int x = 0; x <= hw; x+=gridInterval ) { for( int y = 0; y <= hh; y+=gridInterval ) { addPoint( data, color, offset + vec2(hw+x, hh+y), pointSize ); addPoint( data, color, offset + vec2(hw-x, hh+y), pointSize ); addPoint( data, color, offset + vec2(hw-x, hh-y), pointSize ); addPoint( data, color, offset + vec2(hw+x, hh-y), pointSize ); } } }
void World::setBounds(const ci::Rectf& f, const float restitution) { if (f.x2 <= f.x1 || f.y2 <= f.y1) { DS_LOG_WARNING_M("World constructed on invalid bounds (" << f << ")", PHYSICS_LOG); return; } b2BodyDef def; def.type = b2_staticBody; def.fixedRotation = true; mBounds = mWorld->CreateBody(&def); if (!mBounds) throw std::runtime_error("ds::physics::World() can't create mBounds"); b2PolygonShape shape; b2FixtureDef fixtureDef; fixtureDef.shape = &shape; fixtureDef.density = 0.0f; fixtureDef.friction = mFriction; fixtureDef.restitution = restitution; // Make the world walls large enough to prevent anything from flying outside. const float world_w = f.getWidth(), world_h = f.getHeight(); // left set_polygon_shape(*this, f.x1-world_w, f.y1-world_h, f.x1, f.y2+world_h, shape); fixtureDef.userData = BOUNDS_LEFT_PTR; mBounds->CreateFixture(&fixtureDef); // top set_polygon_shape(*this, f.x1-world_w, f.y1-world_h, f.x2+world_w, f.y1, shape); fixtureDef.userData = BOUNDS_TOP_PTR; mBounds->CreateFixture(&fixtureDef); // right set_polygon_shape(*this, f.x2, f.y1-world_h, f.x2+world_w, f.y2+world_h, shape); fixtureDef.userData = BOUNDS_RIGHT_PTR; mBounds->CreateFixture(&fixtureDef); // bottom set_polygon_shape(*this, f.x1-world_w, f.y2, f.x2+world_w, f.y2+world_h, shape); fixtureDef.userData = BOUNDS_BOTTOM_PTR; mBounds->CreateFixture(&fixtureDef); }
void WaveformPlot::load( const audio::BufferRef &buffer, const ci::Rectf &bounds, size_t pixelsPerVertex ) { mBounds = bounds; mWaveforms.clear(); size_t numChannels = buffer->getNumChannels(); ivec2 waveSize = bounds.getSize(); waveSize.y /= numChannels; for( size_t ch = 0; ch < numChannels; ch++ ) { mWaveforms.push_back( Waveform( buffer->getChannel( ch ), buffer->getNumFrames(), waveSize, pixelsPerVertex, Waveform::CalcMode::MIN_MAX ) ); mWaveforms.push_back( Waveform( buffer->getChannel( ch ), buffer->getNumFrames(), waveSize, pixelsPerVertex, Waveform::CalcMode::AVERAGE ) ); } }
void ViewerController::createGridLayout(const ci::Rectf area, const int numItems, std::vector<ci::Vec2f>& positions){ if(numItems < 1) return; float xStart = area.getX1(); float yStart = area.getY1(); float numContents = (float)(numItems); int contentsPerRow = (int)ceilf(sqrt(numContents)); if(numContents > 5) contentsPerRow += 1; /// make the aspect more wide if(numContents > 15) contentsPerRow += 1; /// make the aspect more wide if(numContents > 25) contentsPerRow += 1; /// make the aspect more wide if(numContents > 35) contentsPerRow += 2; /// make the aspect more more wide int numRows = (int)ceilf(numContents / (float)(contentsPerRow)); float xSpacing = area.getWidth() / (float)(contentsPerRow); float ySpacing = area.getHeight() / (float)(numRows); int rowCounter = 0; xStart += xSpacing / 2.0f; float xp = xStart; float yp = yStart; for(int i = 0; i < numItems; i++){ ci::Vec2f origin = ci::Vec2f(xp, yp); if(contentsPerRow == 1){ origin.x = area.getX1() + area.getWidth() / 2.0f; } if(numRows == 1){ origin.y = yStart + area.getHeight() / 4.0f; } positions.push_back(origin); xp += xSpacing; rowCounter++; if(rowCounter == contentsPerRow){ rowCounter = 0; xp = xStart; if(numRows == 2){ // 2 rows, the second row was too low yp += ySpacing / 2.0f; } else { yp += ySpacing; } } } }
void Control::setRect(const ci::Rectf &rect) { setSize(rect.getSize()); setLocation(rect.getUpperLeft()); }
ci::Rectf Control::screen(const ci::Rectf &rect) const { return rect + screen(rect.getUpperLeft()); }
ci::gl::TextureRef PretzelGlobal::getTextureFromSkin( ci::Rectf rect ){ Surface srf( rect.getWidth(), rect.getHeight(), true); srf.copyFrom( mSkinSurf, Area(rect.x1, rect.y1, rect.x2, rect.y2), vec2(-rect.x1, -rect.y1) ); return ci::gl::Texture::create( srf ); }
void Draw(const Movable& DrawData, const Texture& Tex) // @Remove second param { using namespace ci; gl::pushModelView(); gl::translate(DrawData.GetCenterPos()); // gl::drawStrokedRect( ToRect(DrawData.GetAABB()) ); gl::rotate(DrawData.GetAngle()); gl::scale(DrawData.GetScale().x, DrawData.GetScale().y); gl::translate(-Tex.getSize() / 2.f); glEnableClientState(GL_VERTEX_ARRAY); GLfloat verts[8]; glVertexPointer(2, GL_FLOAT, 0, verts); glEnableClientState(GL_TEXTURE_COORD_ARRAY); GLfloat texCoords[8]; glTexCoordPointer(2, GL_FLOAT, 0, texCoords); const ci::Rectf destRect = Tex.getCleanBounds(); verts[0 * 2 + 0] = destRect.getX2(); verts[0 * 2 + 1] = destRect.getY1(); verts[1 * 2 + 0] = destRect.getX1(); verts[1 * 2 + 1] = destRect.getY1(); verts[2 * 2 + 0] = destRect.getX2(); verts[2 * 2 + 1] = destRect.getY2(); verts[3 * 2 + 0] = destRect.getX1(); verts[3 * 2 + 1] = destRect.getY2(); const ci::Rectf srcCoords = Tex.getAreaTexCoords(Tex.getCleanBounds()); texCoords[0 * 2 + 0] = srcCoords.getX2(); texCoords[0 * 2 + 1] = srcCoords.getY1(); texCoords[1 * 2 + 0] = srcCoords.getX1(); texCoords[1 * 2 + 1] = srcCoords.getY1(); texCoords[2 * 2 + 0] = srcCoords.getX2(); texCoords[2 * 2 + 1] = srcCoords.getY2(); texCoords[3 * 2 + 0] = srcCoords.getX1(); texCoords[3 * 2 + 1] = srcCoords.getY2(); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); gl::popModelView(); }
void ParticleSystem::add( ci::Vec2f pos, ci::Vec2f velocity, ci::ColorA color, ci::Rectf srcCoords, ci::Rectf destRect ) { Particle p = { verts.size(), velocity, pos, pos }; particles.push_back( p ); // Vertices verts.push_back( destRect.getX1() ); verts.push_back( destRect.getY2() ); verts.push_back(0); verts.push_back( destRect.getX2() ); verts.push_back( destRect.getY2() ); verts.push_back(0); verts.push_back( destRect.getX2() ); verts.push_back( destRect.getY1() ); verts.push_back(0); verts.push_back( destRect.getX1() ); verts.push_back( destRect.getY2() ); verts.push_back(0); verts.push_back( destRect.getX2() ); verts.push_back( destRect.getY1() ); verts.push_back(0); verts.push_back( destRect.getX1() ); verts.push_back( destRect.getY1() ); verts.push_back(0); // Texture coords color.a = Constants::Particles::ALPHA; texCoords.push_back( srcCoords.getX1() ); texCoords.push_back( srcCoords.getY2() ); texCoords.push_back( srcCoords.getX2() ); texCoords.push_back( srcCoords.getY2() ); texCoords.push_back( srcCoords.getX2() ); texCoords.push_back( srcCoords.getY1() ); texCoords.push_back( srcCoords.getX1() ); texCoords.push_back( srcCoords.getY2() ); texCoords.push_back( srcCoords.getX2() ); texCoords.push_back( srcCoords.getY1() ); texCoords.push_back( srcCoords.getX1() ); texCoords.push_back( srcCoords.getY1() ); // Colors // ci::ColorA color = ci::ColorA(ci::CM_HSV, _debugColor, 1.0, 1.0, 1.0); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); colors.push_back( color ); }
AABB::AABB(ci::Rectf const& Rect) #endif : m_Center(Rect.getCenter()) , m_HalfSize(Rect.getSize() / 2.f) { }