Advertisement
Guest User

braidTest

a guest
Mar 12th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. #include "ofApp.h"
  2.  
  3. //TODO
  4. // Get rotation to work on the mesh.
  5.  
  6. // Get meshOsc to be... seperate. It appears that each individual mesh is somehow
  7. // tied to each other
  8.  
  9. // Get variation in the frequency and amplitude of the waves
  10.  
  11. // Put the primitives inside of a two dimensional vector, to tie it to it's corresponding point in the point cloud
  12.  
  13. //--------------------------------------------------------------
  14. void ofApp::setup(){
  15. mesh.addVertex(ofVec3f(-150,0));
  16. mesh.addColor(ofColor(255));
  17. mesh.addVertex(ofVec3f(150,0));
  18. mesh.addColor(ofColor(255));
  19.  
  20. mesh.addIndex(0);
  21. mesh.addIndex(1);
  22.  
  23. mesh.setMode(OF_PRIMITIVE_POINTS);
  24.  
  25. glEnable(GL_POINT_SMOOTH);
  26. glPointSize(3);
  27. }
  28.  
  29. //--------------------------------------------------------------
  30. void ofApp::update(){
  31. if(oscNum>0){
  32. for(int i=0;i<oscNum;i++){
  33. updateWave(i);
  34. }
  35. }
  36. }
  37.  
  38. //--------------------------------------------------------------
  39. void ofApp::draw(){
  40. ofEnableDepthTest();
  41. ofBackgroundGradient(ofColor(50),ofColor(0));
  42.  
  43. cam.begin();
  44. ofPushMatrix();
  45. mesh.draw();
  46. for(int i=0;i<oscNum;i++){
  47. oscMesh[i].draw();
  48. }
  49. ofPopMatrix();
  50. cam.end();
  51.  
  52. ofDrawBitmapString("OSCNUM: " + ofToString(oscNum),10,10);
  53. ofDrawBitmapString("F: " + ofToString(f),10,20);
  54. ofDrawBitmapString("AMP: " + ofToString(amp),10,30);
  55. }
  56.  
  57. //--------------------------------------------------------------
  58. void ofApp::keyPressed(int key){
  59.  
  60. if(key=='p'){ //POINTS
  61. for(int i=0;i<oscNum;i++){
  62. oscMesh[i].getMesh().setMode(OF_PRIMITIVE_POINTS);
  63. }
  64. }
  65. if(key=='l'){ //LINES
  66. for(int i=0;i<oscNum;i++){
  67. oscMesh[i].getMesh().setMode(OF_PRIMITIVE_LINE_STRIP);
  68. }
  69. }
  70. if(key=='f'){ //FIRE
  71. sendWave(0,1);
  72. }
  73. }
  74.  
  75. //--------------------------------------------------------------
  76. void ofApp::sendWave(int index, int burst){
  77.  
  78. ofVec3f firingPoint = mesh.getVertex(index);
  79. ofVec3f destPoint = mesh.getVertex(index+1);
  80.  
  81. int res = 150;
  82.  
  83. for(int i=0;i<burst;i++){
  84. oscNum++;
  85. oscMesh.resize(oscNum);
  86.  
  87. for (float x=0;x<res;x++){
  88. float delta = x/res;
  89.  
  90. ofVec3f signal = firingPoint.getInterpolated(destPoint, delta);
  91.  
  92. oscMesh[i].getMesh().addVertex(signal);
  93. oscMesh[i].getMesh().addColor(ofColor(ofRandom(255),ofRandom(255),ofRandom(255)));
  94. }
  95.  
  96. oscMesh[i].getMesh().addVertex(destPoint);
  97. oscMesh[i].getMesh().addColor(ofColor(ofRandom(255),ofRandom(255),ofRandom(255)));
  98.  
  99. oscMesh[i].getMesh().setupIndicesAuto();
  100. oscMesh[i].getMesh().setMode(OF_PRIMITIVE_LINE_STRIP);
  101.  
  102. //oscMesh[i].setPosition(firingPoint.x,firingPoint.y,firingPoint.z);
  103. float degree = 90;
  104. oscMesh[i].tilt(degree);
  105.  
  106. }
  107.  
  108. }
  109.  
  110. //--------------------------------------------------------------
  111. void ofApp::updateWave(int i){
  112.  
  113. speed = 5;
  114.  
  115. float time = ofGetElapsedTimef()/speed;
  116.  
  117. int res = oscMesh[i].getMesh().getNumVertices(); //Resolution
  118.  
  119. for (int x=1;x<res;x++){
  120. float delta = x/res;
  121.  
  122. float amp = 10; //Amplitude
  123. float f = 10; //Frequency
  124. float p = x; //Phase
  125.  
  126. float oscillation = amp * sin(2 * pi * f * time + p);
  127. ofVec3f oscTemp = oscMesh[i].getMesh().getVertex(x);
  128. oscTemp.z = oscillation;
  129.  
  130. oscMesh[i].getMesh().setVertex(x,oscTemp);
  131. }
  132.  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement