Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "ofMain.h"
  4. #include "oscThread.h"
  5.  
  6. class ofApp : public ofBaseApp{
  7.    
  8. public:
  9.     void setup();
  10.     void update();
  11.     void draw();
  12.    
  13.     void keyPressed(int key);
  14.     void keyReleased(int key);
  15.     void dragEvent(ofDragInfo dragInfo);
  16.     void gotMessage(ofMessage msg);
  17.    
  18.     ofEasyCam cam;
  19.     ofMesh mesh;
  20.     vector< vector<oscThread> > braid;
  21. };
  22.  
  23.  
  24.  
  25.  
  26. #include "ofApp.h"
  27.  
  28. //--------------------------------------------------------------
  29. void ofApp::setup(){
  30.     mesh.addVertex(ofVec3f(-150,0));
  31.     mesh.addColor(ofColor(255));
  32.     mesh.addVertex(ofVec3f(150,0));
  33.     mesh.addColor(ofColor(255));
  34.     mesh.addVertex(ofVec3f(200,50));
  35.     mesh.addColor(ofColor(255));
  36.     mesh.addVertex(ofVec3f(50,0));
  37.     mesh.addColor(ofColor(255));
  38.    
  39.     mesh.setMode(OF_PRIMITIVE_POINTS);
  40.    
  41.     glEnable(GL_POINT_SMOOTH);
  42.     glPointSize(3);
  43. }
  44.  
  45. //--------------------------------------------------------------
  46. void ofApp::update(){
  47.     if(braid.size()>0){
  48.         for(int i=0;i<braid.size();i++){
  49.             for(int j=0;j<braid[i].size();j++){
  50.                 braid[i][j].update();
  51.             }
  52.         }
  53.     }
  54. }
  55.  
  56. //--------------------------------------------------------------
  57. void ofApp::draw(){
  58.     ofEnableDepthTest();
  59.     ofBackgroundGradient(ofColor(50), ofColor(0));
  60.    
  61.     cam.begin();
  62.     mesh.draw();
  63.     if(braid.size()>0){
  64.         for(int i=0;i<braid.size();i++){
  65.             for(int j=0;j<braid[i].size();j++){
  66.                 braid[i][j].draw();
  67.             }
  68.         }
  69.     }
  70.     cam.end();
  71.    
  72.     ofDrawBitmapString("Number of Braids: " + ofToString(braid.size()),10,10);
  73. }
  74.  
  75. //--------------------------------------------------------------
  76. void ofApp::keyPressed(int key){
  77.     if(key=='f'){
  78.         vector<oscThread> tempBraid;    //Inner vector
  79.         ofVec2f tempOrigin;             //Origin/dest vector
  80.         tempOrigin.set(ofRandom(4),ofRandom(4));   //Number of vertices in point cloud
  81.        
  82.         for(int i=0;i<1;i++){
  83.             tempBraid.push_back(oscThread(tempOrigin,mesh));
  84.             tempBraid.back().setup();   //Setup new threads
  85.         }
  86.        
  87.         braid.push_back(tempBraid);     //Finally insert tempBraid into outer vector
  88.     }
  89.    
  90.     if(key=='=') {
  91.         if(braid.size()>0){
  92.             for(int i=0;i<braid.size();i++){
  93.                 for(int j=0;j<braid[i].size();j++){
  94.                     braid[i][j].helixTest++;
  95.                 }
  96.             }
  97.         }
  98.     }
  99.    
  100.     if(key=='-') {
  101.         if(braid.size()>0){
  102.             for(int i=0;i<braid.size();i++){
  103.                 for(int j=0;j<braid[i].size();j++){
  104.                     braid[i][j].helixTest--;
  105.                 }
  106.             }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement