Пример #1
0
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 );
		}
	}
}
Пример #3
0
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 );
}
Пример #4
0
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 );
        }
    }
}
Пример #5
0
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);
}
Пример #6
0
 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 );
 }