//-------------------------------------------------------------- void ofApp::draw(){ float gridsize = 500; cam.begin(); ofDrawGrid(gridsize/2.0, 8.0f, false, false, false, true); ofPushMatrix(); ofMultMatrix(tabmtx); ofDrawAxis(30); ofEnableLighting(); light.enable(); ofPushMatrix(); ofRotateX(90); ofDrawCylinder(0,52,0,3,100); ofPopMatrix(); // you can also get global tablet data at any time TabletData& data = ofxTablet::tabletData; float p= data.pressure*25; if (p<10) p = 10; ofDrawArrow(ofVec3f(0,0,100), ofVec3f(0,0,0), p); ofDisableLighting(); ofPopMatrix(); cam.end(); }
//-------------------------------------------------------------- void LeapVisualizer::drawOrientedCylinder (ofPoint pt0, ofPoint pt1, float radius){ // Draw a cylinder between two points, properly oriented in space. float dx = pt1.x - pt0.x; float dy = pt1.y - pt0.y; float dz = pt1.z - pt0.z; float dh = sqrt(dx*dx + dy*dy + dz*dz); ofPushMatrix(); ofTranslate( (pt0.x+pt1.x)/2, (pt0.y+pt1.y)/2, (pt0.z+pt1.z)/2 ); ofQuaternion q; q.makeRotate (ofPoint(0, -1, 0), ofPoint(dx,dy,dz) ); ofMatrix4x4 m; q.get(m); glMultMatrixf(m.getPtr()); ofDrawCylinder (radius, dh); ofPopMatrix(); }
void ofApp::draw(){ ofBackgroundGradient(ofColor(150),ofColor(25)); cam.begin(); float n = 0; if(noise){ n = ofSignedNoise( ofGetElapsedTimef() ); } furry.begin( cam, translateA, color, hairLeng, alpha, n, tassellation ); ofDrawSphere(1.f); furry.end(); furry.begin( cam, translateB, color, hairLeng, alpha, n, tassellation ); ofDrawCylinder(5.f, 10.f); furry.end(); furry.begin( cam, translateC, color, hairLeng, alpha, n, tassellation ); model.drawFaces(); furry.end(); cam.end(); gui.draw(); }
//-------------------------------------------------------------- void LeapVisualizer::drawArmFromXML(ofxXmlSettings & XML){ float armWidth = XML.getValue("AW", 0.0); float basisLen = 50.0; ofPoint handPt = ofPoint(XML.getValue("PM:X",0.0), XML.getValue("PM:Y",0.0), XML.getValue("PM:Z",0.0)); // palm ofPoint wristPt = ofPoint(XML.getValue("W:X",0.0), XML.getValue("W:Y",0.0), XML.getValue("W:Z",0.0)); // wrist ofPoint elbowPt = ofPoint(XML.getValue("E:X",0.0), XML.getValue("E:Y",0.0), XML.getValue("E:Z",0.0)); // elbow ofPoint handNorm = ofPoint(XML.getValue("PN:X",0.0), XML.getValue("PN:Y",0.0), XML.getValue("PN:Z",0.0)); // palm normal //Hand basis matrix XML.pushTag("HM", 0); ofPoint handBasisX = ofPoint(XML.getValue("XX",0.0), XML.getValue("XY",0.0), XML.getValue("XZ",0.0)); ofPoint handBasisY = ofPoint(XML.getValue("YX",0.0), XML.getValue("YY",0.0), XML.getValue("YZ",0.0)); ofPoint handBasisZ = ofPoint(XML.getValue("ZX",0.0), XML.getValue("ZY",0.0), XML.getValue("ZZ",0.0)); XML.popTag(); // Arm basis matrix XML.pushTag("AM", 0); ofPoint armBasisX = ofPoint(XML.getValue("XX",0.0), XML.getValue("XY",0.0), XML.getValue("XZ",0.0)); ofPoint armBasisY = ofPoint(XML.getValue("YX",0.0), XML.getValue("YY",0.0), XML.getValue("YZ",0.0)); ofPoint armBasisZ = ofPoint(XML.getValue("ZX",0.0), XML.getValue("ZY",0.0), XML.getValue("ZZ",0.0)); XML.popTag(); // Draw the wrist and elbow points. if (bDrawSimple){ ofSetColor(ofColor::orange); ofDrawSphere(handPt, 8.0); ofDrawSphere(wristPt, 8.0); ofDrawSphere(elbowPt, 8.0); ofLine(handPt, wristPt); ofLine(wristPt, elbowPt); ofLine(handPt, handPt+ basisLen*handNorm); ofDrawSphere(handPt+ basisLen*handNorm, 2.0); glLineWidth(2.0); // draw the rotation vectors of the hand. ofSetColor(ofColor::red ); ofLine(handPt, handPt + basisLen*handBasisX); ofSetColor(ofColor::green); ofLine(handPt, handPt + basisLen*handBasisY); ofSetColor(ofColor::blue ); ofLine(handPt, handPt + basisLen*handBasisZ); // draw the rotation vectors of the arm. ofSetColor(ofColor::red ); ofLine(wristPt, wristPt + basisLen*armBasisX); ofSetColor(ofColor::green); ofLine(wristPt, wristPt + basisLen*armBasisY); ofSetColor(ofColor::blue ); ofLine(wristPt, wristPt + basisLen*armBasisZ); glLineWidth(1.0); string handType = XML.getValue("TYPE", "RIGHT"); ofSetColor(ofColor::orange); ofDrawBitmapString(handType, (handPt + (basisLen*1.2)*handBasisY)); } else { // Draw a cylinder between two points, properly oriented in space. float dx = wristPt.x - elbowPt.x; float dy = wristPt.y - elbowPt.y; float dz = wristPt.z - elbowPt.z; float dh = sqrt(dx*dx + dy*dy + dz*dz); ofPushMatrix(); { ofTranslate( (elbowPt.x+wristPt.x)/2, (elbowPt.y+wristPt.y)/2, (elbowPt.z+wristPt.z)/2 ); float theta = 90 - RAD_TO_DEG * asin(dz/dh); float phi = RAD_TO_DEG * atan2(dy,dx); ofRotate(phi, 0,0,1); ofRotate(theta, 0,1,0); ofRotate(90, 1,0,0); // Get the arm Matrix, which provides its orthogonal basis vectors. float ax = armBasisY.x; float ay = armBasisY.y; float az = armBasisY.z; // Compute the longitudinal rotation of the arm ofNode armBasisYNode; armBasisYNode.setPosition(armBasisY); armBasisYNode.rotateAround(0- phi, ofVec3f(0,0,1), ofVec3f(0,0,0)); armBasisYNode.rotateAround(0- theta, ofVec3f(0,1,0), ofVec3f(0,0,0)); armBasisYNode.rotateAround(0- 90, ofVec3f(1,0,0), ofVec3f(0,0,0)); ofPoint newArmBasisY = armBasisYNode.getPosition(); float armRotation = RAD_TO_DEG * atan2f(newArmBasisY.z, newArmBasisY.x); ofPushMatrix(); { ofRotate(armRotation, 0,-1,0); float armThicknessRatio = 0.6; glScalef(armThicknessRatio, 1.0, 1.0); ofSetColor(ofColor::magenta); // Oblate arm cylinder ofDrawCylinder (armWidth/2.0, dh); // Wrist endcap ofPushMatrix(); ofTranslate(ofPoint(0, dh/2,0)); glScalef(1.0, armThicknessRatio, 1.0); ofDrawSphere(armWidth/2.0); ofPopMatrix(); // Elbow endcap ofPushMatrix(); ofTranslate(ofPoint(0, -dh/2,0)); glScalef(1.0, armThicknessRatio, 1.0); ofDrawSphere(armWidth/2.0); ofPopMatrix(); } // Close popMatrix ofPopMatrix(); } // Close popMatrix ofPopMatrix(); } // Close if !drawSimple }
//-------------------------------------------------------------- void LeapVisualizer::drawArm (Hand & hand,ofxLeapMotion & leap){ // Draw the wrist and elbow points. Arm arm = hand.arm(); if (arm.isValid()){ ofPoint handPt = leap.getofPoint ( hand.palmPosition()); ofPoint handNorm = leap.getofPoint ( hand.palmNormal()); ofPoint wristPt = leap.getofPoint ( arm.wristPosition()); ofPoint elbowPt = leap.getofPoint ( arm.elbowPosition()); float basisLen = 50.0; if (bDrawSimple){ ofSetColor(ofColor::white); ofDrawSphere(handPt, 8.0); ofDrawSphere(wristPt, 8.0); ofDrawSphere(elbowPt, 8.0); ofLine(handPt, wristPt); ofLine(wristPt, elbowPt); ofLine(handPt, handPt+ basisLen*handNorm); ofDrawSphere(handPt+ basisLen*handNorm, 2.0); // draw the rotation vectors of the hand. { Leap::Matrix handMatrix = hand.basis(); ofPoint handBasisX = leap.getofPoint( handMatrix.xBasis); ofPoint handBasisY = leap.getofPoint( handMatrix.yBasis); ofPoint handBasisZ = leap.getofPoint( handMatrix.zBasis); glLineWidth(2.0); ofSetColor(ofColor::red ); ofLine(handPt, handPt + basisLen*handBasisX); ofSetColor(ofColor::green); ofLine(handPt, handPt + basisLen*handBasisY); ofSetColor(ofColor::blue ); ofLine(handPt, handPt + basisLen*handBasisZ); glLineWidth(1.0); // draw the identity of the hand (left or right) string whichHandString = "RIGHT"; if (hand.isLeft()){ whichHandString = "LEFT"; } // float handConfidence = hand.confidence(); // whichHandString += " " + ofToString(handConfidence); ofSetColor(ofColor::white); ofDrawBitmapString(whichHandString, (handPt + (basisLen*1.2)*handBasisY)); } // draw the rotation vectors of the arm. { Leap::Matrix armMatrix = arm.basis(); ofPoint armBasisX = leap.getofPoint( armMatrix.xBasis); ofPoint armBasisY = leap.getofPoint( armMatrix.yBasis); ofPoint armBasisZ = leap.getofPoint( armMatrix.zBasis); glLineWidth(2.0); ofSetColor(ofColor::red ); ofLine(wristPt, wristPt + basisLen*armBasisX); ofSetColor(ofColor::green); ofLine(wristPt, wristPt + basisLen*armBasisY); ofSetColor(ofColor::blue ); ofLine(wristPt, wristPt + basisLen*armBasisZ); glLineWidth(1.0); } } else { // Draw a cylinder between two points, properly oriented in space. float armWidth = arm.width(); float dx = wristPt.x - elbowPt.x; float dy = wristPt.y - elbowPt.y; float dz = wristPt.z - elbowPt.z; float dh = sqrt(dx*dx + dy*dy + dz*dz); ofPushMatrix(); { ofTranslate( (elbowPt.x+wristPt.x)/2, (elbowPt.y+wristPt.y)/2, (elbowPt.z+wristPt.z)/2 ); float theta = 90 - RAD_TO_DEG * asin(dz/dh); float phi = RAD_TO_DEG * atan2(dy,dx); ofRotate(phi, 0,0,1); ofRotate(theta, 0,1,0); ofRotate(90, 1,0,0); // Get the arm Matrix, which provides its orthogonal basis vectors. Leap::Matrix armMatrix = arm.basis(); ofPoint armBasisY = leap.getofPoint( armMatrix.yBasis); float ax = armBasisY.x; float ay = armBasisY.y; float az = armBasisY.z; // Compute the longitudinal rotation of the arm. // Sheesh, I really need to learn 3D matrix math. ofNode armBasisYNode; armBasisYNode.setPosition(armBasisY); armBasisYNode.rotateAround(0- phi, ofVec3f(0,0,1), ofVec3f(0,0,0)); armBasisYNode.rotateAround(0- theta, ofVec3f(0,1,0), ofVec3f(0,0,0)); armBasisYNode.rotateAround(0- 90, ofVec3f(1,0,0), ofVec3f(0,0,0)); ofPoint newArmBasisY = armBasisYNode.getPosition(); float armRotation = RAD_TO_DEG * atan2f(newArmBasisY.z, newArmBasisY.x); ofPushMatrix(); { ofRotate(armRotation, 0,-1,0); float armThicknessRatio = 0.6; glScalef(armThicknessRatio, 1.0, 1.0); ofSetColor(ofColor::magenta); // Oblate arm cylinder ofDrawCylinder (armWidth/2.0, dh); // Wrist endcap ofPushMatrix(); ofTranslate(ofPoint(0, dh/2,0)); glScalef(1.0, armThicknessRatio, 1.0); ofDrawSphere(armWidth/2.0); ofPopMatrix(); // Elbow endcap ofPushMatrix(); ofTranslate(ofPoint(0, -dh/2,0)); glScalef(1.0, armThicknessRatio, 1.0); ofDrawSphere(armWidth/2.0); ofPopMatrix(); } // Close popMatrix ofPopMatrix(); } // Close popMatrix ofPopMatrix(); } // Close if !drawSimple } // Close if arm isValid }
//-------------------------------------------------------------- void testApp::nucleotideDraw(int type2, float nucleoPosX, float nucleoPosY, float nucleoPosZ, float rotAngle, float rotX, float rotY, float rotZ){ posX = ofGetWidth()/2; posY = ofGetHeight()/2; posZ = 0; radius = 10; height = 200; dnaImage.getTextureReference().bind(); //gluSphere(quadric, 200, 100, 100); for (int i = 0; i < nucleoNum; ++i){ //type.push_back(type2); if (type2 == 0){ //GUANINE ofPushMatrix(); ofSetColor(100,100,240); ofTranslate(posX, posY, posZ); ofRotate(rotAngle, rotX, rotY, rotZ); ofSetCylinderResolution(50, 100, 2); ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height); if (invert == true){ ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30); }else if(invert == false){ ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30); } ofPopMatrix(); }else if(type2 == 1){ //CYTOSINE ofPushMatrix(); ofSetColor(240,100,100); ofTranslate(posX, posY, posZ); ofRotate(rotAngle, rotX, rotY, rotZ); ofSetCylinderResolution(50, 100, 2); ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height); if (invert == true){ ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30); }else if(invert == false){ ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30); } ofPopMatrix(); }else if(type2 == 2){ //ADENINE ofPushMatrix(); ofSetColor(100,240,100); ofTranslate(posX, posY, posZ); ofRotate(rotAngle, rotX, rotY, rotZ); ofSetCylinderResolution(50, 100, 2); ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height); if (invert == true){ ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30); }else if(invert == false){ ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30); } ofPopMatrix(); }else if(type2 == 3){ //THYMINE ofPushMatrix(); ofSetColor(240,100,240); ofTranslate(posX, posY, posZ); ofRotate(rotAngle, rotX, rotY, rotZ); ofSetCylinderResolution(50, 100, 2); ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height); if (invert == true){ ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30); }else if(invert == false){ ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30); ofSetColor(255, 217, 0); ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30); } ofPopMatrix(); } } }
void createPrimitive::draw(property &p) { prop = p; if(prop.points.size() == 0) return; switch (prop.dType) { case CP_POINT: glDepthMask(GL_FALSE); ofEnableAlphaBlending(); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofEnablePointSprites(); shader.begin(); texture.bind(); prop.vbo.draw(GL_POINTS, 0, (int)prop.points.size()); texture.unbind(); shader.end(); ofDisablePointSprites(); glDepthMask(GL_TRUE); break; case CP_LINE: //ofSetLineWidth(mags[0].x/10); ofSetLineWidth(20); prop.vbo.drawElements(GL_LINE_STRIP, prop.points.size()); break; case CP_CYLINDER: for (int i = 0; i < prop.points.size(); i++) { ofPushMatrix(); //glDepthMask(GL_FALSE); ofEnableDepthTest(); ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255); ofTranslate(prop.points[i].x, prop.points[i].y-prop.mags[i].x/2, prop.points[i].z); ofDrawCylinder(0,0,0, 10, prop.mags[i].x); //glDepthMask(GL_TRUE); ofPopMatrix(); } break; case CP_CYLINDER_SPECTRUM: //if (!prop.drawBins.size()) break; for (int i = 0; i < prop.points.size(); i++) { if(prop.origMags[i] == 0) continue ; ofPushMatrix(); ofTranslate(prop.points[i].x, prop.points[i].y- prop.drawBins[(i % 10)] *200/2, prop.points[i].z); ofDrawCylinder(0,0,0, 10, prop.drawBins[(i % 10)] * 200); ofPopMatrix(); //cout << (i % 10) << " " << prop.drawBins[(i % 10)] << endl; } break; case CP_RECT: //ofNoFill(); for (int i = 0; i < prop.points.size(); i++) { ofPushMatrix(); ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255); ofTranslate(prop.points[i].x-prop.mags[i].x/2, prop.points[i].y-prop.mags[i].x/4, prop.points[i].z); ofRotate(-prop.angle, 0, 0, 1); //ofRect(0, 0, mags[i].x, mags[i].x/2); ofDrawBox(0, 0, 0, prop.mags[i].x, prop.mags[i].x, prop.mags[i].x); ofPopMatrix(); } break; case CP_RECT_ROUNDED: for (int i = 0; i < prop.points.size(); i++) { ofRectRounded(prop.points[i].x-prop.mags[i].x/2, prop.points[i].y-prop.mags[i].x/4, prop.mags[i].x, prop.mags[i].x/2, prop.mags[i].x/4); } break; case CP_ELLIPPSE: for (int i = 0; i < prop.points.size(); i++) { ofEllipse(prop.points[i].x, prop.points[i].y, prop.mags[i].x, prop.mags[i].x/2); //ofRect(points[i].x-mags[i].x/2, points[i].y-mags[i].x/2, mags[i].x, mags[i].x); } break; case CP_LINE_IND: ofSetLineWidth(10); for (int i = 0; i < prop.points.size(); i++) { ofLine(prop.points[i].x, prop.points[i].y, prop.points[i].x, prop.points[i].y+prop.mags[i].x); } break; case CP_SPHERE: for (int i = 0; i < prop.points.size(); i++) { ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255); ofDrawSphere(prop.points[i].x, prop.points[i].y, prop.points[i].z, prop.mags[i].x); } if (particleFlg) { for (int i = 0; i < prop.mags.size(); i++) { prop.mags[i] *= 10.0; } prop.vbo.setNormalData(&prop.mags[0], prop.mags.size(), GL_DYNAMIC_DRAW); glDepthMask(GL_FALSE); ofEnableAlphaBlending(); ofEnableBlendMode(OF_BLENDMODE_ALPHA); ofEnablePointSprites(); shader.begin(); texture.bind(); prop.vbo.draw(GL_POINTS, 0, (int)prop.points.size()); texture.unbind(); shader.end(); ofDisablePointSprites(); glDepthMask(GL_TRUE); } break; case CP_TRIANGLE: prop.vbo.drawElements(GL_TRIANGLE_STRIP, prop.points.size()); break; case CP_TRIANGLE_IND: prop.angle+=5; //ofNoFill(); ofSetLineWidth(10); for (int i = 0; i < prop.points.size(); i++) { ofPushMatrix(); //glDepthMask(GL_FALSE); ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255); ofTranslate(prop.points[i].x, prop.points[i].y); ofRotate(prop.angle, 0, 0, 1); /* ofTriangle(0, -prop.mags[i].x, prop.mags[i].x/-2, prop.mags[i].x/2*sqrt(3), prop.mags[i].x/2, prop.mags[i].x/2*sqrt(3)); */ ofDrawCone(0, prop.mags[i].x/-2,prop.points[i].z, prop.mags[i].x/2, prop.mags[i].x); // glDepthMask(GL_TRUE); ofPopMatrix(); } break; case CP_CIRCLE: for (int i = 0; i < prop.points.size(); i++) { ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255); ofCircle(prop.points[i].x, prop.points[i].y, prop.points[i].z, prop.mags[i].x/2); } default: break; } }