summaryrefslogtreecommitdiff
path: root/futuregael
diff options
context:
space:
mode:
authorTim Redfern <redfernt@gmail.com>2023-09-20 23:35:53 +0100
committerTim Redfern <redfernt@gmail.com>2023-09-20 23:35:53 +0100
commitcde8fab86a40be5d3c99bfd2d97605638647179f (patch)
tree5f3d25c4eb6757ba399f746dfb96ea175ad8467f /futuregael
parentd47d1294179af82651602c5b548658bcd3b7bdac (diff)
mostly works
Diffstat (limited to 'futuregael')
-rw-r--r--futuregael/addons.make1
-rw-r--r--futuregael/src/lineTransformer.cpp126
-rw-r--r--futuregael/src/lineTransformer.h20
-rw-r--r--futuregael/src/main.cpp2
-rw-r--r--futuregael/src/ofApp.cpp42
-rw-r--r--futuregael/src/ofApp.h21
-rw-r--r--futuregael/src/show.h19
-rw-r--r--futuregael/src/vectortext.h6
8 files changed, 227 insertions, 10 deletions
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<poly.size();i++){
+ tempPoly.addVertex(ofVec3f(poly[i])*xform,poly.getColourAt(i)*colourFade);
+ }
+ return tempPoly;
+}
+
+ofPolyline lineTransformer::makePolygon(int num,float diam){
+ ofPolyline poly;
+ float step=PI*2/num;
+ for (int i=0;i<=num;i++){
+ poly.addVertex(cos(step*i)*diam,sin(step*i)*diam);
+ }
+ return poly;
+}
+
+void lineTransformer::drawPoly(ofPolyline poly,float x,float y){
+ glPushMatrix();
+ ofTranslate(x,y);
+ poly.draw();
+ for (int i=0;i<poly.size();i++){
+ ofDrawBitmapString(poly.getDegreesAtIndex(i),poly[i].x+10,poly[i].y+10,0);
+ }
+ glPopMatrix();
+}
diff --git a/futuregael/src/lineTransformer.h b/futuregael/src/lineTransformer.h
new file mode 100644
index 0000000..9e44d1a
--- /dev/null
+++ b/futuregael/src/lineTransformer.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "ofMain.h"
+#include "colourPolyline.h"
+
+class lineTransformer {
+
+ public:
+ lineTransformer(){
+ }
+ void static drawWarpFrame(glm::vec2 warpframe[4]);
+ void static gaussianElimination(float * input, int n);
+ glm::mat4 static getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]);
+ ofPolyline static polyLineTransform(const ofMatrix4x4 xform,const ofPolyline& poly);
+ ofPolyline static polyLineTransform(ofPoint (*transferFunction)(const ofPoint),const ofPolyline& poly);
+ colourPolyline static polyLineTransform(const ofMatrix4x4 xform,colourPolyline& poly,float colourFade=1.0f);
+ colourPolyline static polyLineTransform(ofPoint (*transferFunction)(const ofPoint),colourPolyline& poly,float colourFade=1.0f);
+ ofPolyline static makePolygon(int num,float diam);
+ void static drawPoly(ofPolyline poly,float x,float y);
+}; \ No newline at end of file
diff --git a/futuregael/src/main.cpp b/futuregael/src/main.cpp
index 02bf31b..54756c1 100644
--- a/futuregael/src/main.cpp
+++ b/futuregael/src/main.cpp
@@ -8,7 +8,7 @@ int main(int argc, char *argv[]){
ofGLFWWindowSettings settings;
- settings.setSize(1024,1024); // 1/8 scale
+ settings.setSize(1024,400); // 1/8 scale
//1200 = 13.2° = 42898 pts theoretical
diff --git a/futuregael/src/ofApp.cpp b/futuregael/src/ofApp.cpp
index 676b480..3fb103b 100644
--- a/futuregael/src/ofApp.cpp
+++ b/futuregael/src/ofApp.cpp
@@ -9,11 +9,32 @@ void ofApp::setup(){
show.load("show.csv");
}
+ textgui.setup("text","",5,10);
+ textgui.add(laser_scale.set("scale", 1.0f, 0.5f, 3.0f));
+ textgui.add(laser_pos_x.set("x", 0.0f, -1000.0f, 1000.0f));
+ textgui.add(laser_pos_y.set("y", 0.0f, -1000.0f, 1000.0f));
+ textgui.add(text_speed.set("speed", 1.0f, 0.0f, 2.0f));
+
+ lasergui.setup("laser","",5,110);
+ lasergui.add(laser_power.set("power", true));
+ lasergui.add(laser_intensity.set("intensity", 30, 0, 255));
+ lasergui.add(laser_points.set("points", 30000, 0, 40000));
+ lasergui.add(laser_subdivide.set("subdivide", 15, 1, 100));
+ lasergui.add(laser_blank_num.set("blank points", 8, 0, 32));
+ lasergui.add(laser_max_angle.set("max angle", 15.0f, 1.0f, 90.0f));
+
}
//--------------------------------------------------------------
void ofApp::update(){
+ laser.set_pts(laser_points);
+ laser.set_subdivide(laser_subdivide);
+ laser.set_blanknum(laser_blank_num);
+ laser.set_maxangle(laser_max_angle);
+
+ laser.set_intensity(laser_intensity);
+
show.update();
}
@@ -22,11 +43,28 @@ void ofApp::update(){
void ofApp::draw(){
ofBackground(0);
+ textgui.draw();
+ lasergui.draw();
if (show.isPlaying()){
vector<colourPolyline>& 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 <colourPolyline> 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<bool> laser_power;
+ ofParameter<int> laser_intensity;
+ ofParameter<int> laser_points;
+ ofParameter<int> laser_subdivide;
+ ofParameter<int> laser_blank_num;
+ ofParameter<float> laser_max_angle;
+
+ ofxPanel textgui;
+ ofParameter<float> laser_scale;
+ ofParameter<float> laser_pos_x;
+ ofParameter<float> laser_pos_y;
+ ofParameter<float> 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<string> 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<colourPolyline>& 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 "<<phase<<" phaseseg "<<phaseseg;
@@ -93,16 +97,20 @@ public:
outlines.clear();
- float s=0.1f;
+ float s=0.05f;
- float p=(-(ofGetWidth()/3))/s;
+ float p=(-ofGetWidth()/3*s)-(width*wordphase);
if (word1>-1&&word1<words.size()){
+ for (int i=0;i<word1;i++){
+ p+=words[i].width;
+ p+=enspace;
+ }
for (auto& g:words[word1].glyphs){
for (auto& o:g.outline){
auto q=o;
q.scale(s,-s);
- q.translate(glm::vec3(p*s,-ofGetHeight()/3,0));
+ q.translate(glm::vec3(p*s,0,0));
outlines.push_back(colourPolyline(q,g.colour*word1amt));
}
p+=g.width;
@@ -115,7 +123,7 @@ public:
for (auto& o:g.outline){
auto q=o;
q.scale(s,-s);
- q.translate(glm::vec3(p*s,-ofGetHeight()/3,0));
+ q.translate(glm::vec3(p*s,0,0));
outlines.push_back(colourPolyline(q,g.colour*word2amt));
}
p+=g.width;
@@ -133,6 +141,7 @@ public:
float avgWordDuration;
vector<colourPolyline> 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<glyph> glyphs;
float amount;
+ float width;
};
class SVGFont{