From cde8fab86a40be5d3c99bfd2d97605638647179f Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 20 Sep 2023 23:35:53 +0100 Subject: mostly works --- futuregael/addons.make | 1 + futuregael/src/lineTransformer.cpp | 126 +++++++++++++++++++++++++++++++++++++ futuregael/src/lineTransformer.h | 20 ++++++ futuregael/src/main.cpp | 2 +- futuregael/src/ofApp.cpp | 42 ++++++++++++- futuregael/src/ofApp.h | 21 +++++++ futuregael/src/show.h | 19 ++++-- futuregael/src/vectortext.h | 6 +- 8 files changed, 227 insertions(+), 10 deletions(-) create mode 100644 futuregael/src/lineTransformer.cpp create mode 100644 futuregael/src/lineTransformer.h diff --git a/futuregael/addons.make b/futuregael/addons.make index e79327f..58fda94 100644 --- a/futuregael/addons.make +++ b/futuregael/addons.make @@ -1,3 +1,4 @@ +ofxGui ofxCsv ofxSvg ofxHelios \ No newline at end of file diff --git a/futuregael/src/lineTransformer.cpp b/futuregael/src/lineTransformer.cpp new file mode 100644 index 0000000..8e2bd80 --- /dev/null +++ b/futuregael/src/lineTransformer.cpp @@ -0,0 +1,126 @@ +#include "lineTransformer.h" + + +void lineTransformer::drawWarpFrame(glm::vec2 warpframe[4]){ + ofSetColor(255,255,255); + ofNoFill(); + for (int i=0;i<4;i++){ + ofDrawCircle(warpframe[i],25); + ofDrawLine(warpframe[i],warpframe[(i+1)%4]); + } +} + +void lineTransformer::gaussianElimination(float * input, int n) +{ + auto i = 0; + auto j = 0; + auto m = n - 1; + + while (i < m && j < n) + { + auto iMax = i; + for (auto k = i + 1; k < m; ++k) + { + if (fabs(input[k * n + j]) > fabs(input[iMax * n + j])) + { + iMax = k; + } + } + + if (input[iMax * n + j] != 0) + { + if (i != iMax) + { + for (auto k = 0; k < n; ++k) + { + auto ikIn = input[i * n + k]; + input[i * n + k] = input[iMax * n + k]; + input[iMax * n + k] = ikIn; + } + } + + float ijIn = input[i * n + j]; + for (auto k = 0; k < n; ++k) + { + input[i * n + k] /= ijIn; + } + + for (auto u = i + 1; u < m; ++u) + { + auto ujIn = input[u * n + j]; + for (auto k = 0; k < n; ++k) + { + input[u * n + k] -= ujIn * input[i * n + k]; + } + } + + ++i; + } + ++j; + } + + for (auto i = m - 2; i >= 0; --i) + { + for (auto j = i + 1; j < n - 1; ++j) + { + input[i * n + m] -= input[i * n + j] * input[j * n + m]; + } + } +} + +glm::mat4 lineTransformer::getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]) +{ + float p[8][9] = + { + { -src[0][0], -src[0][1], -1, 0, 0, 0, src[0][0] * dst[0][0], src[0][1] * dst[0][0], -dst[0][0] }, // h11 + { 0, 0, 0, -src[0][0], -src[0][1], -1, src[0][0] * dst[0][1], src[0][1] * dst[0][1], -dst[0][1] }, // h12 + { -src[1][0], -src[1][1], -1, 0, 0, 0, src[1][0] * dst[1][0], src[1][1] * dst[1][0], -dst[1][0] }, // h13 + { 0, 0, 0, -src[1][0], -src[1][1], -1, src[1][0] * dst[1][1], src[1][1] * dst[1][1], -dst[1][1] }, // h21 + { -src[2][0], -src[2][1], -1, 0, 0, 0, src[2][0] * dst[2][0], src[2][1] * dst[2][0], -dst[2][0] }, // h22 + { 0, 0, 0, -src[2][0], -src[2][1], -1, src[2][0] * dst[2][1], src[2][1] * dst[2][1], -dst[2][1] }, // h23 + { -src[3][0], -src[3][1], -1, 0, 0, 0, src[3][0] * dst[3][0], src[3][1] * dst[3][0], -dst[3][0] }, // h31 + { 0, 0, 0, -src[3][0], -src[3][1], -1, src[3][0] * dst[3][1], src[3][1] * dst[3][1], -dst[3][1] }, // h32 + }; + + gaussianElimination(&p[0][0], 9); + + return glm::mat4(p[0][8], p[3][8], 0, p[6][8], + p[1][8], p[4][8], 0, p[7][8], + 0, 0, 1, 0, + p[2][8], p[5][8], 0, 1); +} + +ofPolyline lineTransformer::polyLineTransform(const ofMatrix4x4 xform, const ofPolyline& poly){ + ofPolyline tempPoly; + for (auto& p:poly){ + tempPoly.addVertex(ofVec3f(p)*xform); + } + return tempPoly; +} + +colourPolyline lineTransformer::polyLineTransform(const ofMatrix4x4 xform,colourPolyline& poly,float colourFade){ + colourPolyline tempPoly; + for (int i=0;i& outlines=show.getOutlines(); + ofMatrix4x4 rm = ofMatrix4x4::newIdentityMatrix(); + rm.translate(laser_pos_x,laser_pos_y,0); + rm.scale(laser_scale,laser_scale,laser_scale); + rm.translate(ofGetWidth()/2,ofGetHeight()/2,0); + + vector scaledOutput; + + for (auto s:outlines){ + scaledOutput.push_back(lineTransformer::polyLineTransform(rm,s)); + } + + int num = 0; + + if (laser_power) num=laser.draw(scaledOutput); + ofPushMatrix(); ofTranslate(ofGetWidth()/2,ofGetHeight()/2); for (auto o:outlines){ @@ -34,14 +72,12 @@ void ofApp::draw(){ } ofPopMatrix(); - ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+"fps, shapes: "+ofToString(outlines.size())); + ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+"fps, laser points: "+ofToString(num)); } else { ofSetWindowTitle("idle"); } - - } diff --git a/futuregael/src/ofApp.h b/futuregael/src/ofApp.h index 20bf7d6..8e4b4aa 100644 --- a/futuregael/src/ofApp.h +++ b/futuregael/src/ofApp.h @@ -1,6 +1,9 @@ #pragma once #include "ofMain.h" +#include "ofxGui.h" +#include "ofxHelios.h" +#include "lineTransformer.h" #include "show.h" @@ -23,4 +26,22 @@ class ofApp : public ofBaseApp{ void dragEvent(ofDragInfo dragInfo); Show show; + + ofxHelios laser; + + //======= laser gui + + ofxPanel lasergui; + ofParameter laser_power; + ofParameter laser_intensity; + ofParameter laser_points; + ofParameter laser_subdivide; + ofParameter laser_blank_num; + ofParameter laser_max_angle; + + ofxPanel textgui; + ofParameter laser_scale; + ofParameter laser_pos_x; + ofParameter laser_pos_y; + ofParameter text_speed; }; diff --git a/futuregael/src/show.h b/futuregael/src/show.h index c5a7605..45d0023 100644 --- a/futuregael/src/show.h +++ b/futuregael/src/show.h @@ -13,6 +13,7 @@ public: clear(); vector m=ofSplitString(message," "); + width=0; for (auto& word: m){ glyphWord w; int pos=0; @@ -28,8 +29,10 @@ public: ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255) )); pos++; + w.width+=w.glyphs[w.glyphs.size()-1].width; } words.push_back(w); + width+=(w.width+enspace); } if (audio.load(audiofile)){ @@ -49,8 +52,9 @@ public: words.clear(); } vector& getOutlines(float time){ + float wordphase=time/duration; float phase=time/avgWordDuration; - float phaseseg=fmod(phase,(int)phase); + float phaseseg=fmod(phase,1.0f); //ofLog()<<"phase "<-1&&word1 outlines; float enspace; + float width; }; diff --git a/futuregael/src/vectortext.h b/futuregael/src/vectortext.h index e5adbdb..1f0d11c 100644 --- a/futuregael/src/vectortext.h +++ b/futuregael/src/vectortext.h @@ -40,9 +40,13 @@ public: class glyphWord{ public: - glyphWord(){amount=1.0f;} + glyphWord(){ + amount=1.0f; + width=0.0f; + } vector glyphs; float amount; + float width; }; class SVGFont{ -- cgit v1.2.3