diff options
| author | Tim Redfern <tim@getdrop.com> | 2023-04-16 21:16:08 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2023-04-16 21:16:08 +0100 |
| commit | f140c2822b7b3798d86798f8b300f9a0d133259f (patch) | |
| tree | 448fb58b3ce0a944395e933d155c4a3c1b5469f1 /nextus | |
| parent | f0db80db36ba375aca859f318c92c4312505044a (diff) | |
add nextus show
Diffstat (limited to 'nextus')
| -rw-r--r-- | nextus/Makefile | 13 | ||||
| -rw-r--r-- | nextus/addons.make | 7 | ||||
| -rw-r--r-- | nextus/config.make | 142 | ||||
| -rw-r--r-- | nextus/src/lineSegmenter.cpp | 109 | ||||
| -rw-r--r-- | nextus/src/lineSegmenter.h | 48 | ||||
| -rw-r--r-- | nextus/src/lineTransformer.cpp | 126 | ||||
| -rw-r--r-- | nextus/src/lineTransformer.h | 21 | ||||
| -rw-r--r-- | nextus/src/main.cpp | 25 | ||||
| -rw-r--r-- | nextus/src/ofApp.cpp | 186 | ||||
| -rw-r--r-- | nextus/src/ofApp.h | 45 |
10 files changed, 722 insertions, 0 deletions
diff --git a/nextus/Makefile b/nextus/Makefile new file mode 100644 index 0000000..177e172 --- /dev/null +++ b/nextus/Makefile @@ -0,0 +1,13 @@ +# Attempt to load a config.make file. +# If none is found, project defaults in config.project.make will be used. +ifneq ($(wildcard config.make),) + include config.make +endif + +# make sure the the OF_ROOT location is defined +ifndef OF_ROOT + OF_ROOT=$(realpath ../../..) +endif + +# call the project makefile! +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk diff --git a/nextus/addons.make b/nextus/addons.make new file mode 100644 index 0000000..f3dbfa3 --- /dev/null +++ b/nextus/addons.make @@ -0,0 +1,7 @@ +ofxGui +ofxSVG +ofxXmlSettings +ofxClipper +ofxMidi +ofxHelios +ofxPONK diff --git a/nextus/config.make b/nextus/config.make new file mode 100644 index 0000000..5f9f022 --- /dev/null +++ b/nextus/config.make @@ -0,0 +1,142 @@ +################################################################################ +# CONFIGURE PROJECT MAKEFILE (optional) +# This file is where we make project specific configurations. +################################################################################ + +################################################################################ +# OF ROOT +# The location of your root openFrameworks installation +# (default) OF_ROOT = ../../.. +################################################################################ + OF_ROOT = ../../openFrameworks + +################################################################################ +# PROJECT ROOT +# The location of the project - a starting place for searching for files +# (default) PROJECT_ROOT = . (this directory) +# +################################################################################ +# PROJECT_ROOT = . + +################################################################################ +# PROJECT SPECIFIC CHECKS +# This is a project defined section to create internal makefile flags to +# conditionally enable or disable the addition of various features within +# this makefile. For instance, if you want to make changes based on whether +# GTK is installed, one might test that here and create a variable to check. +################################################################################ +# None + +################################################################################ +# PROJECT EXTERNAL SOURCE PATHS +# These are fully qualified paths that are not within the PROJECT_ROOT folder. +# Like source folders in the PROJECT_ROOT, these paths are subject to +# exlclusion via the PROJECT_EXLCUSIONS list. +# +# (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXTERNAL_SOURCE_PATHS + +################################################################################ +# PROJECT EXCLUSIONS +# These makefiles assume that all folders in your current project directory +# and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations +# to look for source code. The any folders or files that match any of the +# items in the PROJECT_EXCLUSIONS list below will be ignored. +# +# Each item in the PROJECT_EXCLUSIONS list will be treated as a complete +# string unless teh user adds a wildcard (%) operator to match subdirectories. +# GNU make only allows one wildcard for matching. The second wildcard (%) is +# treated literally. +# +# (default) PROJECT_EXCLUSIONS = (blank) +# +# Will automatically exclude the following: +# +# $(PROJECT_ROOT)/bin% +# $(PROJECT_ROOT)/obj% +# $(PROJECT_ROOT)/%.xcodeproj +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_EXCLUSIONS = + +################################################################################ +# PROJECT LINKER FLAGS +# These flags will be sent to the linker when compiling the executable. +# +# (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ + +# Currently, shared libraries that are needed are copied to the +# $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to +# add a runtime path to search for those shared libraries, since they aren't +# incorporated directly into the final executable application binary. +# TODO: should this be a default setting? +# PROJECT_LDFLAGS=-Wl,-rpath=./libs + +################################################################################ +# PROJECT DEFINES +# Create a space-delimited list of DEFINES. The list will be converted into +# CFLAGS with the "-D" flag later in the makefile. +# +# (default) PROJECT_DEFINES = (blank) +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_DEFINES = + +################################################################################ +# PROJECT CFLAGS +# This is a list of fully qualified CFLAGS required when compiling for this +# project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS +# defined in your platform specific core configuration files. These flags are +# presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below. +# +# (default) PROJECT_CFLAGS = (blank) +# +# Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in +# your platform specific configuration file will be applied by default and +# further flags here may not be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CFLAGS = + +################################################################################ +# PROJECT OPTIMIZATION CFLAGS +# These are lists of CFLAGS that are target-specific. While any flags could +# be conditionally added, they are usually limited to optimization flags. +# These flags are added BEFORE the PROJECT_CFLAGS. +# +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank) +# +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets. +# +# (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank) +# +# Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the +# PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration +# file will be applied by default and further optimization flags here may not +# be needed. +# +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_OPTIMIZATION_CFLAGS_RELEASE = +# PROJECT_OPTIMIZATION_CFLAGS_DEBUG = + +################################################################################ +# PROJECT COMPILERS +# Custom compilers can be set for CC and CXX +# (default) PROJECT_CXX = (blank) +# (default) PROJECT_CC = (blank) +# Note: Leave a leading space when adding list items with the += operator +################################################################################ +# PROJECT_CXX = +# PROJECT_CC = diff --git a/nextus/src/lineSegmenter.cpp b/nextus/src/lineSegmenter.cpp new file mode 100644 index 0000000..3f434b1 --- /dev/null +++ b/nextus/src/lineSegmenter.cpp @@ -0,0 +1,109 @@ + #include "lineSegmenter.h" + +const vector <ofPolyline> & lineSegmenter::getSegments(int num,float coverage, float phase){ + //num - number of segments + //coverage - amount that each segment fills it's slot from 0-1 + //phase - from 0-1 + + //if the path is closed, we can make a segment that crosses the end/beginning + //however we want to be able to deal with open paths + +/* + +segments 0...n - 1 +phase 0...1 + +phase 0 + +segment 0 is (0 -> coverage) / n +segment n - 1 is ((0 -> coverage) + (n-1)) /n + +phase 1: has to be the loop target, it has to look identical + +segment 0 is (1 -> coverage) / n +segment n - 1 is (1 - > coverage) + (n-1) + +*/ + + + segments.clear(); + + for (int i=0;i<num;i++){ + float startIndex=line.getIndexAtPercent((phase+i)/num); //always <1 + float endPoint=(phase+i+coverage)/num; //can be >1 + float endIndex=line.getIndexAtPercent(endPoint>1.0f?endPoint-1.0f:endPoint); + ofPolyline segment; + segment.addVertex(line.getPointAtIndexInterpolated(startIndex)); + for (int j=(int)ceil(startIndex);j<(endPoint>1?line.size():(int)ceil(endIndex));j++){ + segment.addVertex(line[j]); + } + if (endPoint>1){ + segments.push_back(segment); + segment.clear(); + for (int j=0;j<(int)ceil(endIndex);j++){ + segment.addVertex(line[j]); + } + segment.addVertex(line.getPointAtIndexInterpolated(endIndex)); + } + else { + segment.addVertex(line.getPointAtIndexInterpolated(endIndex)); + } + segments.push_back(segment); + } + + return segments; +} + +void lineSegmenter::draw(){ + line.draw(); + return; +} +int lineSegmenter::size(){ + return line.size(); +} + +const vector <colourPolyline> & colourLineSegmenter::getSegments(int num,float coverage, float phase){ + + segments.clear(); + + for (int i=0;i<num;i++){ + float startIndex=line.getIndexAtPercent((phase+i)/num); //always <1 + float endPoint=(phase+i+coverage)/num; //can be >1 + float endIndex=line.getIndexAtPercent(endPoint>1.0f?endPoint-1.0f:endPoint); + colourPolyline segment; + segment.addVertex(line.getPointAtIndexInterpolated(startIndex),line.getColourAtIndexInterpolated(startIndex)); + for (int j=(int)ceil(startIndex);j<(endPoint>1?line.size():(int)ceil(endIndex));j++){ + segment.addVertex(line[j],line.getColourAt(j)); + } + if (endPoint>1){ + segments.push_back(segment); + segment.clear(); + for (int j=0;j<(int)ceil(endIndex);j++){ + segment.addVertex(line[j],line.getColourAt(j)); + } + segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex)); + } + else { + segment.addVertex(line.getPointAtIndexInterpolated(endIndex),line.getColourAtIndexInterpolated(endIndex) ); + } + segments.push_back(segment); + } + + return segments; +} + +void colourLineSegmenter::draw(){ + line.draw(); + return; +} +int colourLineSegmenter::size(){ + return line.size(); +} + + +/* + + + + +*/
\ No newline at end of file diff --git a/nextus/src/lineSegmenter.h b/nextus/src/lineSegmenter.h new file mode 100644 index 0000000..2467c6a --- /dev/null +++ b/nextus/src/lineSegmenter.h @@ -0,0 +1,48 @@ +#pragma once + +#include "ofMain.h" +#include "colourPolyline.h" + +class lineSegmenter{ + public: + lineSegmenter(ofPolyline &_line){ + line=_line; + if (line.isClosed()){ + line.addVertex(line[0]); + } + } + const vector <ofPolyline> &getSegments(int num,float coverage, float phase); + ofPolyline getPoly(){ + return line; + } + void draw(); + int size(); + private: + ofPolyline line; + vector <ofPolyline> segments; +}; + +class colourLineSegmenter{ + public: + colourLineSegmenter(colourPolyline &_line){ + line=_line; + //if (line.isClosed()){ + // line.addVertex(line[0]); + //} + } + colourLineSegmenter(ofPolyline &_line,const ofColor color=ofColor(255,255,255)){ + line=colourPolyline(_line,color); + if (_line.isClosed()){ + line.addVertex(line[0],line.getColourAt(0)); + } + } + const vector <colourPolyline> &getSegments(int num,float coverage, float phase); + colourPolyline getPoly(){ + return line; + } + void draw(); + int size(); + private: + colourPolyline line; + vector <colourPolyline> segments; +};
\ No newline at end of file diff --git a/nextus/src/lineTransformer.cpp b/nextus/src/lineTransformer.cpp new file mode 100644 index 0000000..8e2bd80 --- /dev/null +++ b/nextus/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/nextus/src/lineTransformer.h b/nextus/src/lineTransformer.h new file mode 100644 index 0000000..f5ec22f --- /dev/null +++ b/nextus/src/lineTransformer.h @@ -0,0 +1,21 @@ +#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/nextus/src/main.cpp b/nextus/src/main.cpp new file mode 100644 index 0000000..df57f72 --- /dev/null +++ b/nextus/src/main.cpp @@ -0,0 +1,25 @@ +#include "ofMain.h" +#include "ofApp.h" + + +//======================================================================== +int main(int argc, char *argv[]){ + + + ofGLFWWindowSettings settings; + + settings.decorated = true; + + settings.setSize(1200,900); + settings.setPosition(ofVec2f(0,0)); + settings.resizable = false; + + shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings); + mainWindow->setVerticalSync(false); + + shared_ptr<ofApp> mainApp(new ofApp); + + ofRunApp(mainWindow, mainApp); + ofRunMainLoop(); +} +
\ No newline at end of file diff --git a/nextus/src/ofApp.cpp b/nextus/src/ofApp.cpp new file mode 100644 index 0000000..4f0624c --- /dev/null +++ b/nextus/src/ofApp.cpp @@ -0,0 +1,186 @@ +#include "ofApp.h" +#include "glew.h" + +const ofPoint outputWindowSize=ofPoint(1200,900); + + +//-------------------------------------------------------------- +void ofApp::setup(){ + + + midiIn.listInPorts(); + midiIn.openPort(0); + midiIn.addListener(this); + + if( XML.loadFile("settings.xml") ){ + cout << "settings.xml loaded!" <<std::endl; + + } + else{ + cout << "unable to load settings.xml"<<std::endl; + } + + //outputScale=XML.getValue("SCALE", 1.0f); + + cout << "listening for osc messages on port " << PORT << "\n"; + receiver.setup(PORT); + + ofSetFrameRate(60); +} + + + +//====================== settings + +void ofApp::default_settings(){ + + //outputScale=1.0f; +} + +void ofApp::save_settings(){ + + //XML.setValue("SCALE", outputScale); + + XML.saveFile("settings.xml"); + cout << "settings.xml saved!" <<std::endl; +} + + + +void ofApp::update(){ + +} + + +//-------------------------------------------------------------- GUI +void ofApp::draw(){ + ofBackground(0); + + ofSetColor(255); + ofNoFill(); + +} + + + +//-------------------------------------------------------------- +void ofApp::exit() { + + +} + + + +//-------------------------------------------------------------- + + +void ofApp::keyPressed(ofKeyEventArgs &args){ + if (args.key==OF_KEY_COMMAND){ + //commandPressed=true; + } + + switch(args.key){ + case 'a':{ + load_settings(); + break; + } + case 'd':{ + default_settings(); + break; + } + case 's':{ + save_settings(); + break; + } + } +} + +//-------------------------------------------------------------- + +void ofApp::keyReleased(ofKeyEventArgs &args){ + if (args.key==OF_KEY_COMMAND){ + //commandPressed=false; + } +} + + +//-------------------------------------------------------------- +void ofApp::mouseMoved(int x, int y ){ +} + +//-------------------------------------------------------------- + +void ofApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- + +void ofApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- + +void ofApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseEntered(int x, int y){ + +} + +//-------------------------------------------------------------- +void ofApp::mouseExited(int x, int y){ + +} + +//-------------------------------------------------------------- + +void ofApp::windowResized(int w, int h){ + +} + + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo){ + + + +} + +void ofApp::newMidiMessage(ofxMidiMessage& msg) { + //column 0 for general controls + //printf("Midi: %i %i %i\n",msg.channel,msg.control,msg.value); + + int offset; + + //=============================================== + offset=0; + + if (msg.channel==1&&msg.control==1+offset){ + //pot + //xf_rotate=(((float)msg.value)/64.0f)-1.0f; + } + if (msg.channel==1&&msg.control==33+offset){ + //pot button + //use_rotate=use_rotate?false:true; + } + if (msg.channel==1&&msg.control==65+offset){ + //top button + //rotate_amt=ofRandom(5.0f); + } + if (msg.channel==1&&msg.control==73+offset){ + //bottom button + } + if (msg.channel==1&&msg.control==81+offset){ + //fader + //laser_intensity=msg.value*2; + } + + //=============================================== + offset=1; + +} + diff --git a/nextus/src/ofApp.h b/nextus/src/ofApp.h new file mode 100644 index 0000000..54fab67 --- /dev/null +++ b/nextus/src/ofApp.h @@ -0,0 +1,45 @@ +#pragma once + +#include "ofMain.h" + + +#include "ofxGui.h" +#include "ofxXmlSettings.h" +#include "ofxSVG.h" +#include "ofxClipper.h" +#include "ofxMidi.h" +#include "ofxPONK.h" + +#include "lineTransformer.h" +#include "lineSegmenter.h" + + + +class ofApp: public ofBaseApp, public ofxMidiListener { + + public: + void setup(); + void update(); + void draw(); + void exit(); + + void keyPressed(ofKeyEventArgs &keyargs); + void keyReleased(ofKeyEventArgs & args); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void mouseEntered(int x, int y); + void mouseExited(int x, int y); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + + void newMidiMessage(ofxMidiMessage& eventArgs); + + + //======================================= //saving settings + + ofxXmlSettings XML; + + +}; |
