Example #1
0
//--------------------------------------------------------------
void testApp::drawScene() {
	glEnable(GL_DEPTH_TEST);
	
	for (int i = 0; i < numObj; i++) {
		ofxVec3f pos = objPos[i];
		ofxVec4f col = objCol[i];
		int size = objSize[i];
		ofSetColor(col.x, col.y, col.z);
		ofxQuaternion qua = objRot[i];
		float rad = 0.0; ofxVec3f rvec;
		qua.getRotate(rad, rvec);
		ofPushMatrix();
		ofTranslate(pos.x, pos.y, pos.z);
		ofRotate(ofRadToDeg(rad), rvec.x, rvec.y, rvec.z);
		int typ = objType[i];
		if (typ == 1) { 
			ofxSphere(0,0,0, size);
		}else {
			ofxBox(0,0,0, size);
		}
		ofPopMatrix();
	}
	
	ofSetColor(255, 255, 255);
}
void ofxIndustrialRobotVisualizer::drawArm(int i, int w, int h){
	float l = helper->getLength(i); //The length of the arm
	ofxVec3f axis = helper->getAxis(i); //The axis the arm rotates around
	ofxVec3f offset = helper->getOffset(i);
	float r = helper->getRotationAngle(i);
	glRotated(r, axis.x, axis.y, axis.z); // Rotate it around the axis
	glTranslated(0, l, 0);
	ofxBox(ofxVec3f(0,-l/2.0,0), ofxVec3f(w, l, h), ofxVec3f(0.0, 0.0, 0.0));
	glTranslated(-offset.y, offset.x, offset.z);	
}
//--------------------------------------------------------------
void testApp::draw(){
	
	camera.place();//this MUST be inside the draw function, and actually places the camera in position
	
	ofxLightsOn(); //turn lights on
	ofSetColor(255, 255, 255);
	
	ofxSphere(centerX - 150, centerY - 150, 0, 50, 100, 100, rotX, rotY, 0);
	
	ofxBox(centerX + 150, centerY - 150, 0, 100, 200, 20, rotX, rotY, 0);
	
	ofxCone(centerX - 150, centerY + 150, 0, 50, 100, 50, rotX, rotY, 0);
	
	ofxCapsule(centerX + 150, centerY + 150, 0, 100, 100, 50, rotX, rotY, 0);
	
	ofxLightsOff(); //turn lights off to draw text
	string info = "PRESSING MOUSE WILL TURN SMOOTH LIGHTS OFF";
	ofSetColor(0, 0, 0);
	ofDrawBitmapString(info, 20, 20);


}
void ofxIndustrialRobotVisualizer::drawGeneric(){
	
	//Base
	ofSetColor(0, 255, 255);	
	glTranslated(0, -25, 0);
	//ofxBox(ofxVec3f(0,25,0), ofxVec3f(200, 50, 200));	
	
	//model.draw();
	ofSetColor(255, 0, 0);
	glPushMatrix();
	glScaled(1.0, -1.0, 1.0);
	ofSetColor(255, 255, 255);

//	model.draw();
	glPopMatrix();
	//	ofxSphere(ofxVec3f(0,0,0), ofxVec3f(200, 200, 200));
	
	glRotated(180, 0.0, 0.0, -1.0); 
	glPushMatrix();
		glScaled(1.0, 1.0, -1.0);
	//	glScaled(0.1, 0.1, 0.1);
	drawArm0();
	drawArm1();
	drawArm2();
	drawArm3();
	drawArm4();
	//Draw tool
	ofSetColor(255, 0, 0);
	float l = helper->getTool()->l; //The length of the tool
	ofxVec3f rotation = helper->getTool()->getRotation();
	glRotated(rotation.z, 0.0, 0.0, 1.0);
	ofxBox(ofxVec3f(helper->getTool()->h/2.0,l/2,0), ofxVec3f(helper->getTool()->h, l, helper->getTool()->w), ofxVec3f(0.0, 0.0, 0.0));
	//	ofxVec3f axis = helper->getAxis(i); //The axis the arm rotates around
	//	ofxVec3f offset = helper->getOffset(i);
	//	glRotated(helper->getRotationAngle(i), axis.x, axis.y, axis.z); // Rotate it around the axis
	//	glTranslated(0, l, 0);
	//	ofxBox(ofxVec3f(0,-l/2.0,0), ofxVec3f(60, l, 60), ofxVec3f(0.0, 0.0, 0.0));
	//	glTranslated(-offset.y, offset.x, offset.z);	
	
	glPopMatrix();
	glScaled(1.0, 1.0, -1.0);

	//Target
	glRotated(180, 0.0, 1.0, 0.0); 
	ofSetColor(255, 0, 0);
	ofxSphere(controller->targetPosition, ofxVec3f(20, 20, 20));
	glBegin(GL_LINE_STRIP);
	glVertex3d(controller->targetPosition.x, controller->targetPosition.y, controller->targetPosition.z);
	ofxVec3f temp = controller->targetPosition+ controller->targetDir*500.0;
	glVertex3d(temp.x,temp.y, temp.z);
	glEnd();
	
	glPushMatrix();
	ofSetColor(0, 255, 0);
	for(int i=0;i<timeline->numberPositionCues(); i++){
		ofxVec3f vec = timeline->getPositionCue(i)->position;
		ofxSphere(vec, ofxVec3f(10, 10, 10));	
	}
	timeline->spline.drawRaw(10, 5);
	ofSetColor(255, 255, 0, 100);
	timeline->spline.drawSmooth(50, 0, 10);
	glLineWidth(1);
	ofSetColor(255, 255, 255, 255);
	ofFill();
	//	glDisable(GL_DEPTH_TEST);
	
/*	glBegin(GL_POLYGON);
	for(int i=0;i<3;i++){
		glVertex3f(plotter->spaceDefinition[i].x,plotter->spaceDefinition[i].y,plotter->spaceDefinition[i].z);
	}
	glVertex3f(plotter->fourthCorner().x,plotter->fourthCorner().y,plotter->fourthCorner().z);
	glEnd();
*/
	for(int i=0;i<plotter->lines.size();i++){
		glBegin(GL_LINE_STRIP);
		ofxVec3f x = (plotter->spaceDefinition[1]-plotter->spaceDefinition[0]).normalized();
		ofxVec3f y = (plotter->spaceDefinition[2]-plotter->spaceDefinition[1]).normalized();
		for(int u=0;u<plotter->lines[i].size();u++){
			ofxVec3f point = x * plotter->lines[i][u].x + y * plotter->lines[i][u].y + plotter->spaceDefinition[0];
			glVertex3f(point.x,point.y,point.z);
		}

		glEnd();
	}
	
	glPopMatrix();
	
	
}