示例#1
0
//--------------------------------------------------------------
void ofApp::draw(){

	phase += 0.35f;

	ofSetHexColor(0xDDDDFF);
	ofDrawRectangle(200,200,300,180);


	ofSetColor(255,255,255,128);
	ofPushMatrix();
		float width = cooper.stringWidth("catch me\nif you can!");
		ofTranslate(350,290,0);
		ofRotateDeg(phase*3, 0,0,1);
		ofScale(1 + 0.5f * sin(phase/10.0f), 1 + 0.5f * sin(phase/10.0f), 1);
		cooper.drawString("catch me\nif you can!", -width/2,20);
	ofPopMatrix();

	ofSetColor(255,150,140,128);
	ofPushMatrix();
	    ofTranslate(330,280,0);
		ofRotateDeg(phase*5, 0,0,1);
		ofDrawRectangle(-25,-25,50,50);
	ofPopMatrix();

	if (bSnapshot == true){
		// grab a rectangle at 200,200, width and height of 300,180
		img.grabScreen(200,200,300,180);
        
		string fileName = "snapshot_"+ofToString(snapCounter, 5, '0')+".png";
		img.save(fileName);
		snapString = "saved " + fileName;
		snapCounter++;
		bSnapshot = false;
	}

	ofSetHexColor(0x000000);
	ofDrawBitmapString("press 'x' to capture screen \n", 200,460);
	ofDrawBitmapString(snapString, 600,460);


	ofSetHexColor(0xFFFFFF);
	if(snapCounter > 0) {
		img.draw(600,200,300,180);
	}


}
示例#2
0
//------------------------------------------------
void ofxBox2dRect::draw() {

	if(body == NULL) {
		return;
	}

    ofPushMatrix();
    ofTranslate(ofxBox2dBaseShape::getPosition());
    ofRotateDeg(getRotation());
    // Temporary fix until we switch to OF 0.8.0.
    mesh.draw();
    ofPopMatrix();

    /*
    const b2Transform& xf = body->GetTransform();
    ofPolyline shape;
    for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext()) {
        b2PolygonShape* poly = (b2PolygonShape*)f->GetShape();
        if(poly) {
            for(int i=0; i<poly->m_count; i++) {
                b2Vec2 pt = b2Mul(xf, poly->m_vertices[i]);
                shape.addVertex(worldPtToscreenPt(pt));
            }
        }
    }
    shape.close();
    shape.draw();*/


    // update the polyline
    // getRectangleShape();
    /*
    ofPath path;
    for (int i=0; i<shape.size(); i++) {
        if(i==0)path.moveTo(shape[i]);
        else path.lineTo(shape[i]);
    }

    // draw the path
    path.setColor(ofGetStyle().color);
    path.setFilled(ofGetStyle().bFill);
    path.draw();

    // are we sleeping
    if(isSleeping()) {
        ofPushStyle();
        ofEnableAlphaBlending();
        path.setColor(ofColor(255, 100));
        path.setFilled(true);
        path.draw();
        ofPopStyle();
    }
	*/
}
示例#3
0
//--------------------------------------------------------------
void rotateToNormal(ofVec3f normal) {
	normal.normalize();

	float rotationAmount;
	ofVec3f rotationAngle;
	ofQuaternion rotation;

	ofVec3f axis(0, 0, 1);
	rotation.makeRotate(axis, normal);
	rotation.getRotate(rotationAmount, rotationAngle);
	ofRotateDeg(rotationAmount, rotationAngle.x, rotationAngle.y, rotationAngle.z);
}
//--------------------------------------------------------------
void ofxBox2dCompoundShape::draw() {
    if(!isBody()) return;
    
    ofPushMatrix(); {
        ofTranslate(getPosition().x, getPosition().y, 0);
        ofRotateDeg(getRotation(), 0, 0, 1);
        
        ofPushStyle(); {
            ofNoFill();
            for( auto& shape : mShapes ) {
                if( shape->getType() == ofxBox2dCompoundShape::Shape::SHAPE_TYPE_CIRCLE ) {
                    auto circle = dynamic_pointer_cast<ofxBox2dCompoundShape::Circle>(shape);
                    ofDrawCircle(circle->x, circle->y, circle->radius);
                } else {
                    auto rect = dynamic_pointer_cast<ofxBox2dCompoundShape::Rectangle>(shape);
                    ofDrawRectangle( -rect->width/2.f+rect->x, -rect->height/2.f+rect->y, rect->width, rect->height );
                }
            }
            
        } ofPopStyle();
    
    } ofPopMatrix();
}
示例#5
0
//--------------------------------------------------------------
void ofApp::draw(){
	// Calculate aspect ratio of grabber image
	float grabberAspectRatio = grabber.getWidth() / grabber.getHeight();

	// Draw camera image centered in the window
	ofPushMatrix();
	ofSetColor(255);
	ofSetRectMode(OF_RECTMODE_CENTER);

	// Draw from the center of the window
	ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);

	if(cameraFacingFront) {
		// If the camera is front, then rotate clockwise
		ofRotateDeg(appOrientation);
	} else {
		// If the camera is backfacing, then rotate counter clockwise
		ofRotateDeg(-appOrientation);
	}

	// Rotate the cameras orientation offset
	ofRotateDeg(cameraOrientation);

	int width = ofGetWidth();
	int height = ofGetHeight();

	// If its landscape mode, then swap width and height
	if(appOrientation == 90 || appOrientation == 270){
		std::swap(width, height);
	}

	// Draw the image
	if(width < height) {
		grabber.draw(0,0, width * grabberAspectRatio,
					 width);
	} else {
		grabber.draw(0,0, height,
					 height * 1.0/grabberAspectRatio);
	}

	ofPopMatrix();
	ofSetRectMode(OF_RECTMODE_CORNER);

	// Draw text gui
	ofDrawRectangle(0, 0, 300, 120);
	ofSetColor(0);
	ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate()),20,20);
	ofDrawBitmapString("camera fps: " + ofToString(camera_fps),20,40);

	if(cameraFacingFront) {
		ofDrawBitmapString("facing: front (click to swap)", 20, 60);
	}  else {
		ofDrawBitmapString("facing: back (click to swap)", 20, 60);
	}
	ofDrawBitmapString("camera orientation: " + ofToString(cameraOrientation) ,20,80);
	ofDrawBitmapString("app orientation: " + ofToString(appOrientation) ,20,100);

	// Draw the image through raw pixels
	ofSetColor(255);
	ofDrawRectangle(0, 130, 300, 20);
	ofSetColor(0);
	ofDrawBitmapString("raw pixel data" ,20,143);

	ofSetColor(255);
	grabberImage.draw(0,150, 300, 300*1.0/grabberAspectRatio);
}
示例#6
0
	//----------
	void Device::drawWorld() {
		auto colorSource = this->getColorSource();
		auto depthSource = this->getDepthSource();
		auto bodySource = this->getBodySource();

		if (!depthSource) {
			ofLogError("ofxKinectForWindows2::Device::drawPrettyMesh") << "No depth source initialised";
			return;
		}
		
		//point cloud
		{
			//setup some point cloud properties for kicks
			bool usePointSize = true;

#if OF_VERSION_MAJOR > 0 || OF_VERSION_MINOR >= 10
			auto mainWindow = std::static_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
			usePointSize = mainWindow ? mainWindow->getSettings().glVersionMajor <= 2 : false;
#endif

			usePointSize = false;

			if (usePointSize) {
				glPushAttrib(GL_POINT_BIT);
				glPointSize(5.0f);
				glEnable(GL_POINT_SMOOTH);
			}

			ofPushStyle();

			bool useColor = colorSource.get();
			if (useColor) {
				useColor &= colorSource->getTexture().isAllocated();
			}

			if (useColor) {
				//bind kinect color camera texture and draw mesh from depth (which has texture coordinates)
				colorSource->getTexture().bind();
			}

			auto opts = Source::Depth::PointCloudOptions(true, Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera);
			auto mesh = depthSource->getMesh(opts);

			//draw point cloud
			mesh.drawVertices();

			//draw triangles
			ofSetColor(255, 150);
			mesh.drawWireframe();

			//draw fills faded
			ofSetColor(255, 50);
			mesh.drawFaces();

			if (useColor) {
				//unbind colour camera
				colorSource->getTexture().unbind();
			}

			ofPopStyle();

			//clear the point cloud drawing attributes
			if (usePointSize) {
				glPopAttrib();
			}
		}
		
		//bodies and floor
		if (bodySource) {
			bodySource->drawWorld();

			ofPushMatrix();
			ofRotateDeg(90, 0, 0, 1);
			ofMultMatrix(bodySource->getFloorTransform());
			ofDrawGridPlane(5.0f);
			ofPopMatrix();
		}

		//draw the view cones of depth and colour cameras
		ofPushStyle();
		ofNoFill();
		ofSetLineWidth(2.0f);
		ofSetColor(100, 200, 100);
		depthSource->drawFrustum();
		if (colorSource) {
			ofSetColor(200, 100, 100);
			colorSource->drawFrustum();
		}
		ofPopStyle();
	}