示例#1
0
void myMouse(int button, int state, int x, int y) {
  // If left button was clicked
  if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
      // Store where the user clicked, note Y is backwards.
    abc[NUMPOINTS].setxy((float)x,(float)(SCREEN_HEIGHT - y));
    NUMPOINTS++;

    // Draw the red  dot.
    drawDot(x, SCREEN_HEIGHT - y);

    // If 3 points are drawn do the curve.
    if(NUMPOINTS == 4) {
        glColor3f(0,1.0,0);
        drawLine(abc[0], abc[1]);
        drawLine(abc[1], abc[2]);
        drawLine(abc[2], abc[3]);
        glColor3f(1.0,1.0,1.0);

		//This line is where we specify everything
		//the first parameter is which style:
		// 1 = Sampling
		// 2 = Forward Differentiation
		// 3 = Subdivision
		// and the last parameter is how many subdivisions
		drawBezierLine(3,abc[0], abc[1], abc[2], abc[3], 10000);
        
		
		NUMPOINTS = 0;
    }
  }
}
示例#2
0
文件: ofApp.cpp 项目: Nslaver/Bezier
//--------------------------------------------------------------
void ofApp::draw(){
	
	ofEnableDepthTest();
    
    ofEnableLighting();
    pointLight.enable();
    pointLight2.enable();
    pointLight3.enable();

	cam.lookAt(camObjective);

	//Cam setup
	cam.begin();
	//cam.draw();
	//ofSetColor(0, 255, 0);
	//camObjective.draw();
	//ofDrawAxis(floorLimits);

	//Bezier line with evaluator
	ofFill();
    ofSetColor(pointLight.getDiffuseColor());
    //pointLight.draw();
    ofSetColor(pointLight2.getDiffuseColor());
    //pointLight2.draw();
    ofSetColor(pointLight3.getDiffuseColor());
    //pointLight3.draw();


	ofSetColor(ofColor::red);
	drawBezierLine();		
  
	//ofSetColor(ofColor::mediumPurple);
	//actorNode.draw();
	
	ofSetColor(ofColor::blueSteel);
	myHuman.draw();
		
	
	//daWorld

	ofSetColor(0, 15, 250);
	daWorld.draw();

	//Floor

	
	ofSetColor(0, 100, 25);
	floor.draw();

    /* Quad Floor
	glBegin(GL_QUADS);	
        glVertex3f( floorLimits, 0.0,  floorLimits);
		glVertex3f( floorLimits, 0.0, -floorLimits);
		glVertex3f(-floorLimits, 0.0, -floorLimits);
        glVertex3f(-floorLimits, 0.0,  floorLimits);
    glEnd();
	*/
	

	// draw bzNodes
	for(int i=0; i<kBezierPoints; i++) {
		ofSetColor(255, 128, 255);
		bzPoints[i].draw();
		if(i == 0 || i == 2){
			ofSetColor(255, 255, 0);
			ofVec3f v1 = bzNodes[i].getGlobalPosition();
			ofVec3f v2 = bzNodes[i+1].getGlobalPosition();
			ofLine(v1,v2);
		}
	}

	//glPushMatrix();

		
    //glPopMatrix();
	cam.end();

	
	ofSetColor(ofColor::gray);
	ofVec2f mouse(mouseX, mouseY);
	ofLine(nearestVertex, mouse);
	
	ofNoFill();
	ofSetColor(ofColor::yellow);
	ofSetLineWidth(2);
	ofCircle(nearestVertex, 4);
	ofSetLineWidth(1);

	// Test Mouse Picker
	/*ofVec3f cur2 = cam.worldToScreen(bzNodes[nearestIndex].getGlobalPosition());
	ofVec3f cur1 = cam.screenToWorld(ofVec3f(mouse.x,mouse.y, cur2.z));
	ofVec3f cur3 = cam.screenToWorld(ofVec3f(mouse.x,mouse.y, 1));	
		bool t = false;

		string s2 = string("Cursor") + 
		""+ ofToString(mouse)+
		"\n"+ ofToString(cur1)+
		"\n"+ ofToString(cur2)+
		"\n"+ ofToString(cur3);
	
	

	glDisable(GL_CULL_FACE);
	ofSetColor(255,0,0);
	ofDisableLighting();
	ofDrawBitmapString(s2, ofPoint(20, 40));
	glEnable(GL_CULL_FACE);*/

	

	//MSG

	string s = string("BZ Point: P") + 
		""+ ofToString(nearestIndex+1) + 
		"("+ ofToString(bzNodes[nearestIndex].getGlobalPosition()) + ")";

	ofDrawBitmapString(s, ofPoint(20, 20));	
}