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; } } } }
/* 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 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 ); }