summaryrefslogtreecommitdiff
path: root/lasertext/src/ofApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lasertext/src/ofApp.cpp')
-rw-r--r--lasertext/src/ofApp.cpp164
1 files changed, 155 insertions, 9 deletions
diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp
index 5e6865e..a4e076d 100644
--- a/lasertext/src/ofApp.cpp
+++ b/lasertext/src/ofApp.cpp
@@ -5,19 +5,33 @@
what do we want to store/control per letter?
*/
+
+
//--------------------------------------------------------------
void ofApp::setup(){
+ outputWindowSize=ofPoint(ofGetWidth(),ofGetHeight());
+
fonts.open("fonts/");
fonts.allowExt("svg");
fonts.listDir();
ofLogNotice()<<"found "<<fonts.size()<<" fonts";
currentFont=0;
- banner.loadFont("fonts/EMSPepita.svg"); //fonts.getPath(currentFont));
+ banner.loadFont("fonts/EMSDecorousScript.svg"); // EMSPepita.svg"); //fonts.getPath(currentFont));
banner.init("Everything Is Going To Be Alright");
- textgui.setup("text","",5,680);
- textgui.add(text_scale.set("scale", 1.0f, 0.5f, 3.0f));
+ starsgui.setup("stars","",5,350);
+ starsgui.add(stars_x.set("x", 0.0f, -2000.0f, 2000.0f));
+ starsgui.add(stars_y.set("y", 0.0f, -2000.0f, 2000.0f));
+ starsgui.add(stars_radius.set("radius", 100.0f, 10.0f, 500.0f));
+ starsgui.add(stars_speed.set("speed", 5.0f, 0.0f, 10.0f));
+ starsgui.add(stars_life.set("life", 4.0f, 3.0f, 10.0f));
+
+
+ textgui.setup("text","",5,650);
+ 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,750);
@@ -28,6 +42,9 @@ void ofApp::setup(){
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));
+ select_warpframe=-1;
+ bDrawFrame=false;
+
if( XML.loadFile("settings.xml") ){
cout << "settings.xml loaded!" <<std::endl;
@@ -36,7 +53,61 @@ void ofApp::setup(){
cout << "unable to load settings.xml"<<std::endl;
}
+ warpframe[0]=glm::vec2(
+ XML.getValue("WARP:p0:X", 0),
+ XML.getValue("WARP:p0:Y", 0)
+ );
+ warpframe[1]=glm::vec2(
+ XML.getValue("WARP:p1:X", outputWindowSize.x),
+ XML.getValue("WARP:p1:Y", 0)
+ );
+ warpframe[2]=glm::vec2(
+ XML.getValue("WARP:p2:X", outputWindowSize.x),
+ XML.getValue("WARP:p2:Y", outputWindowSize.y)
+ );
+ warpframe[3]=glm::vec2(
+ XML.getValue("WARP:p3:X", 0),
+ XML.getValue("WARP:p3:Y", outputWindowSize.y)
+ );
+
+ laser_pos_x=XML.getValue("POSITION:X", 0);
+ laser_pos_y=XML.getValue("POSITION:Y", 0);
+ laser_scale=XML.getValue("SCALE", 1.0f);
+
+ stars.init(ofVec2f(2000.0f,2000.0f),100.0f,1.0,5.0,4.0,1.0);
+
+}
+
+//====================== settings
+
+void ofApp::default_settings(){
+ warpframe[0]=glm::vec2(0,0);
+ warpframe[1]=glm::vec2(outputWindowSize.x,0);
+ warpframe[2]=glm::vec2(outputWindowSize.x,outputWindowSize.y);
+ warpframe[3]=glm::vec2(0,outputWindowSize.y);
+ outputPosition=ofPoint(0,0);
+ outputScale=1.0f;
}
+
+void ofApp::save_settings(){
+ XML.setValue("WARP:p0:X", warpframe[0].x);
+ XML.setValue("WARP:p0:Y", warpframe[0].y);
+ XML.setValue("WARP:p1:X", warpframe[1].x);
+ XML.setValue("WARP:p1:Y", warpframe[1].y);
+ XML.setValue("WARP:p2:X", warpframe[2].x);
+ XML.setValue("WARP:p2:Y", warpframe[2].y);
+ XML.setValue("WARP:p3:X", warpframe[3].x);
+ XML.setValue("WARP:p3:Y", warpframe[3].y);
+
+ XML.setValue("POSITION:X", laser_pos_x);
+ XML.setValue("POSITION:Y", laser_pos_y);
+
+ XML.setValue("SCALE", laser_scale);
+
+ XML.saveFile("settings.xml");
+ cout << "settings.xml saved!" <<std::endl;
+}
+
//--------------------------------------------------------------
void ofApp::update(){
banner.update(text_speed);
@@ -47,6 +118,14 @@ void ofApp::update(){
laser.set_maxangle(laser_max_angle);
laser.set_intensity(laser_intensity);
+
+
+ stars.centre=ofVec2f(stars_x,stars_y);
+ stars.radius=stars_radius;
+ stars.speed=stars_speed;
+ stars.lifespan=stars_life;;
+
+ stars.update();
}
//--------------------------------------------------------------
@@ -56,28 +135,79 @@ void ofApp::draw(){
textgui.draw();
lasergui.draw();
+ starsgui.draw();
+
+ lineTransformer::drawWarpFrame(warpframe);
+
+ glm::vec2 src[]={
+ glm::vec2(0,0),
+ glm::vec2(ofGetWidth(),0),
+ glm::vec2(ofGetWidth(),ofGetHeight()),
+ glm::vec2(0,ofGetHeight())
+ };
+
+ glm::vec2 mp=glm::vec2(outputWindowSize.x/2,outputWindowSize.y/2);
+
+ glm::vec2 scaled_dest[]={
+ ((warpframe[0]-mp)*outputScale)+mp,
+ ((warpframe[1]-mp)*outputScale)+mp,
+ ((warpframe[2]-mp)*outputScale)+mp,
+ ((warpframe[3]-mp)*outputScale)+mp
+ };
- vector<colourPolyline> shapes = banner.getOutlines(0.08f*text_scale); //+(0.02f*sin(ofGetElapsedTimef()*.1f)));
+ ofMatrix4x4 warp =lineTransformer::getPerspectiveTransformMatrix(src,warpframe);
+
+ vector<colourPolyline> shapes = banner.getOutlines(0.08f); //*text_scale); //+(0.02f*sin(ofGetElapsedTimef()*.1f)));
+
+ ofMatrix4x4 rm = ofMatrix4x4::newIdentityMatrix();
+ rm.translate(laser_pos_x,laser_pos_y,0);
+ rm.scale(laser_scale,laser_scale,laser_scale);
+ rm.translate(outputWindowSize.x/2,outputWindowSize.y/2,0);
+
+ vector <colourPolyline> warpedOutput;
+ vector <colourPolyline> warpedScaledOutput;
+
+ for (auto s:shapes){
+ warpedOutput.push_back(lineTransformer::polyLineTransform(warp,s));
+ }
+
+ for (auto s:warpedOutput){
+ warpedScaledOutput.push_back(lineTransformer::polyLineTransform(rm,s));
+ }
int num = 0;
- if (laser_power) num=laser.draw(shapes);
+ if (laser_power&&shapes.size()) num=laser.draw(warpedScaledOutput);
//banner.draw();
ofPushMatrix();
ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
//ofScale(0.05,-0.05,0.05);
- for (auto& s: shapes) s.draw();
+ for (auto& s: warpedOutput) s.draw();
ofPopMatrix();
+ ofSetColor(255,255,255);
+
+ vector<colourPolyline> starshapes=stars.getPoints();
+ int numstars=0;
+ for (auto& s: starshapes) {
+ numstars+=s.size();
+ s.draw();
+ }
+
+ num+=laser.draw(starshapes);
+
if (num>0){
- ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num));
+ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)+", stars: "+ofToString(numstars));
}
else {
- ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser power off ");
+ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser power off, stars: "+ofToString(numstars));
}
+
+
+
}
@@ -99,6 +229,7 @@ void ofApp::keyPressed(ofKeyEventArgs &args){
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
+ /*
if (key>=' '&&key<='~'){
banner.addGlyph(key);
}
@@ -120,7 +251,13 @@ void ofApp::keyReleased(int key){
break;
}
}
-
+ */
+ switch(key){
+ case 's':{
+ save_settings();
+ break;
+ }
+ }
}
//--------------------------------------------------------------
@@ -130,14 +267,23 @@ void ofApp::mouseMoved(int x, int y ){
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
+ if (select_warpframe>-1){
+ warpframe[select_warpframe]=glm::vec2(x,y);
+ }
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
+ for (int i=0;i<4;i++){
+ if (ofPoint(x,y).distance(warpframe[i])<25){
+ select_warpframe=i;
+ }
+ }
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
+ select_warpframe=-1;
}
//--------------------------------------------------------------