// Render
void KinectApp::draw()
{

	// Clear window
	gl::setViewport( getWindowBounds() );
	gl::clear( Colorf( 0.1f, 0.1f, 0.1f ) );

	// We're capturing
	if ( mKinect->isCapturing() ) {

		// Set up camera for 3D
		gl::setMatrices( mCamera );

		// Move skeletons down below the rest of the interface
		gl::pushMatrices();
		gl::translate( 0.0f, -0.62f, 0.0f );

		// Iterate through skeletons
		uint32_t i = 0;
		for ( vector<Skeleton>::const_iterator skeletonIt = mSkeletons.cbegin(); skeletonIt != mSkeletons.cend(); ++skeletonIt, i++ ) {

			// Skeleton is valid when all joints are present
			if ( skeletonIt->size() == JointName::NUI_SKELETON_POSITION_COUNT ) {

				// Set color
				gl::color( mKinect->getUserColor( i ) );

				// Draw joints
				for ( Skeleton::const_iterator jointIt = skeletonIt->cbegin(); jointIt != skeletonIt->cend(); ++jointIt ) {
					gl::drawSphere( jointIt->second * Vec3f( -1.0f, 1.0f, 1.0f ), 0.025f, 16 );
				}

				// Draw body
				for ( vector<vector<JointName> >::const_iterator segmentIt = mSegments.cbegin(); segmentIt != mSegments.cend(); ++segmentIt ) {
					drawSegment( * skeletonIt, * segmentIt );
				}

			}

		}

		// Switch to 2D
		gl::popMatrices();
		gl::setMatricesWindow( getWindowSize(), true );

		// Draw depth and video textures
		gl::color( Colorf::white() );
		if ( mDepthSurface ) {
			Area srcArea( 0, 0, mDepthSurface.getWidth(), mDepthSurface.getHeight() );
			Rectf destRect( 265.0f, 15.0f, 505.0f, 195.0f );
			gl::draw( gl::Texture( mDepthSurface ), srcArea, destRect );
		}
		if ( mVideoSurface ) {
			Area srcArea( 0, 0, mVideoSurface.getWidth(), mVideoSurface.getHeight() );
			Rectf destRect( 508.0f, 15.0f, 748.0f, 195.0f );
			gl::draw( gl::Texture( mVideoSurface ), srcArea, destRect);
		}

	}

	// Check audio data
	if ( mData != 0 ) {

		// Get dimensions
		int32_t dataSize = mInput->getDataSize();
		float scale = 240.0f / (float)dataSize;
		float height = 180.0f;
		Vec2f position( 751.0f, 15.0f );

		// Draw background
		gl::color( ColorAf::black() );
		Rectf background( position.x, position.y, position.x + 240.0f, position.y + 180.0f );
		gl::drawSolidRect( background );

		// Draw audio input
		gl::color( ColorAf::white() );
		PolyLine<Vec2f> mLine;
		for ( int32_t i = 0; i < dataSize; i++ ) {
			mLine.push_back( position + Vec2f( i * scale, math<float>::clamp( mData[ i ], -1.0f, 1.0f ) * height * 0.5f + height * 0.5f ) );
		}
		if ( mLine.size() > 0 ) {
			gl::draw( mLine );
		}

	}

	// Draw the interface
	params::InterfaceGl::draw();

}
Пример #2
0
int main(int argc, char *argv[])
{
	Figure f;

	// get some coordinates ready to use in a lot of objects
	
	Coordinate *a = new Coordinate (500,500);
	Coordinate *b = new Coordinate (1500,1500);

	// draw a polyline

	PolyLine *polyline = new PolyLine(a, b);
	polyline->push_back(new Coordinate(2000,1500));
	polyline->setLineStyle(Attributes::Dotted);
	
	// give the polyline arrows
	
	Arrow arr;
	arr.setType(Arrow::ClosedPointed);
	arr.setStyle(Arrow::Filled);

	polyline->setBackwardArrowBool(1);
	polyline->setBackwardArrow(arr);
	
	polyline->setForwardArrowBool(1);
	polyline->setForwardArrow(arr);
	
	// polyline is ready, keep it in the fig
	
	f.push_back(polyline);
	
	// an example box using the same coordinates

	Box *box = new Box(a, b);
	box->setThickness(2);
	f.push_back(box);
	
	// an ellipse in that box

	RadiiEllipse *re = new RadiiEllipse(new Coordinate(1000, 1000), new Coordinate(500, 200));
	f.push_back(re);
	
	// another ellipse in that box

	DiameterEllipse *de = new DiameterEllipse(new Coordinate(500, 800), new Coordinate(1500, 1200));
	f.push_back(de);
	
	// a circle defined by a radius, in the box

	RadiusCircle *rc = new RadiusCircle(new Coordinate(1000, 1000), 500);
	f.push_back(rc);
	
	// a circle defined by two points defining its radius

	DiameterCircle *dc = new DiameterCircle(a, b);
	f.push_back(dc);
	
	// some text

	Text* text = new Text(new Coordinate(1900, 900), "fig++");
	text->setFontSize(50);
	f.push_back(text);

	// an arc defined by its three defining points
	// first point comes first

	Arc* arc = new Arc(new Coordinate(1000, 1000), new Coordinate(2000, 1000), new Coordinate(2000, 2000));
	f.push_back(arc);
	
	// this is what's useful: putting something on an arbitrary place

	for (float x = 0; x <= 314; x=x+19.625) {
		PolyLine *l = 
			new PolyLine( 
				new Coordinate(
					(int)(1500.0+500.0*cos(x/100)),
					(int)(1500.0+500.0*sin(x/100))
				),
				new Coordinate(
					(int)(1500.0+1000.0*cos(x/100)),
					(int)(1500.0+1000.0*sin(x/100))
				)
			);
		l->setForwardArrowBool(1);
		arr.setType(Arrow::ClosedIntended);
		l->setForwardArrow(arr);
		f.push_back(l);
	}
	
	// a vector of coordinates

	std::vector<Coordinate *> vc;

	vc.push_back( new Coordinate (2500, 500) );
	vc.push_back( new Coordinate (3000, 500) );
	vc.push_back( new Coordinate (3000, 1000) );
	vc.push_back( new Coordinate (3500, 1000) );
	vc.push_back( new Coordinate (3500, 1500) );
	vc.push_back( new Coordinate (3000, 1500) );
	vc.push_back( new Coordinate (3000, 2000) );
	vc.push_back( new Coordinate (2500, 2000) );
	vc.push_back( new Coordinate (2500, 1500) );
	vc.push_back( new Coordinate (2000, 1500) );
	vc.push_back( new Coordinate (2000, 1000) );
	vc.push_back( new Coordinate (2500, 1000) );
	
	// the vector as a polyline

	Polygon *pl = new Polygon ();
	for (std::vector<Coordinate *>::iterator i = vc.begin(); i != vc.end(); i++)
		pl->push_back(*i);
	f.push_back(pl);
	
	// two possible splines defined by the vector

	Spline *spline1 = new Spline();
	Spline *spline2 = new Spline();
	for (std::vector<Coordinate *>::iterator i = vc.begin(); i != vc.end(); i++) {
		spline1->push_back( new SplineCoordinate(*i, -1) ); // interpolated
		spline2->push_back( new SplineCoordinate(*i, 1) ); //approximated
	}
	spline1->setSubType(Spline::Closed);
	f.push_back(spline1);
	spline2->setSubType(Spline::Closed);
	f.push_back(spline2);
	
	// print the file to the standard out

	std::cout << f;

	return EXIT_SUCCESS;
}
Пример #3
0
void Puppeteer::draw()
{
    // ----------------------------debug

    if (Constants::Debug::DRAW_PUPPETEER_BOUNDS) {
        Vec3f origin = Vec3f::zero();
        PolyLine<Vec3f> boundsL;
        boundsL.push_back(origin - axisVert * armLenL);
        boundsL.push_back(origin - axisVert * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL);
        boundsL.push_back(origin - axisVert * armLenL);
        boundsL.push_back(origin - axisVert * armLenL + normal * armLenL); //
        boundsL.push_back(origin - axisVert * armLenL + normal * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL + normal * armLenL + axisHoriz * armLenL);
        boundsL.push_back(origin + axisVert * armLenL + normal * armLenL);
        boundsL.push_back(origin - axisVert * armLenL + normal * armLenL);

        PolyLine<Vec3f> boundsR;
        boundsR.push_back(origin - axisVert * armLenR);
        boundsR.push_back(origin - axisVert * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR);
        boundsR.push_back(origin - axisVert * armLenR);
        boundsR.push_back(origin - axisVert * armLenR + normal * armLenR); //
        boundsR.push_back(origin - axisVert * armLenR + normal * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR + normal * armLenR - axisHoriz * armLenR);
        boundsR.push_back(origin + axisVert * armLenR + normal * armLenR);
        boundsR.push_back(origin - axisVert * armLenR + normal * armLenR);

        gl::pushMatrices();

        MayaCamUI* mayaCam = Constants::mayaCam();
        gl::setMatrices(mayaCam->getCamera());

        float scale = 1.0f;
        // original bounding boxes
        gl::color(Color(0.5f, 0.5f, 0.5f));
        gl::pushModelView();
        gl::translate(shoulderL);
        gl::draw(boundsL);
        gl::popModelView();

        gl::pushModelView();
        gl::translate(shoulderR);
        gl::draw(boundsR);
        gl::popModelView();

        // normalized bound boxes
        gl::color(Color(0, 0, 1));
        gl::pushModelView();
        gl::translate(-.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::rotate( Quatf(normalizationMatrix) );
        gl::draw(boundsL);
        gl::popModelView();

        gl::pushModelView();
        gl::translate(-.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::drawCube(handL, Vec3f(0.1f, 0.1f, 0.1f));
        gl::popModelView();

        gl::color(Color(0, 1, 0));
        gl::pushModelView();
        gl::translate(.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::rotate( Quatf(normalizationMatrix) );
        gl::draw(boundsR);
        gl::popModelView();

        gl::pushModelView();
        gl::translate(.5f, 0, 0);
        gl::scale(scale, scale, scale);
        gl::drawCube(handR, Vec3f(0.1f, 0.1f, 0.1f));
        gl::popModelView();

        gl::popMatrices();

        gl::color( Color(1, 1, 1));
    }

    arduino->draw();
}