Browse Source

Merge branch 'feature-singleInstance' into develop

master
Krisjanis Rijnieks 11 years ago
parent
commit
7197e2bca8
  1. 82
      README.md
  2. 5
      example/.gitignore
  3. 17
      example/Project.xcconfig
  4. 1145
      example/example.xcodeproj/project.pbxproj
  5. 86
      example/example.xcodeproj/xcshareddata/xcschemes/example Debug.xcscheme
  6. 86
      example/example.xcodeproj/xcshareddata/xcschemes/example Release.xcscheme
  7. 22
      example/openFrameworks-Info.plist
  8. 161
      example/src/ofApp.cpp
  9. 16
      example/src/ofApp.h
  10. 0
      src/Surfaces/SurfaceManager.cpp
  11. 0
      src/Surfaces/SurfaceManager.h
  12. 0
      src/Surfaces/SurfaceManagerGui.cpp
  13. 0
      src/Surfaces/SurfaceManagerGui.h
  14. 0
      src/Surfaces/SurfaceType.h
  15. 158
      src/ofxPiMapper.cpp
  16. 34
      src/ofxPiMapper.h

82
README.md

@ -20,7 +20,7 @@ Currently I have decided to use [A successful Git branching model](http://nvie.c
I'm trying to organize the project by adding future release version milestones and assigning specific issues as TODO items to them. If you notice something strange or see that there is something that can be done in a better way, don't hesitate and add an issue.
As of Release 0.1.5 some refractoring has been done (thanks [aspeteRakete](https://github.com/aspeteRakete)), namespaces have been added and we are thinking about introducing a code style for this project.
As of Release 0.2.0 some refractoring has been done (thanks [aspeteRakete](https://github.com/aspeteRakete)), namespaces have been added and we are thinking about introducing a code style for this project. Still improving on the overal structure.
Licence
-------
@ -39,6 +39,8 @@ cd ~/openFrameworks/addons
git clone https://github.com/kr15h/ofxPiMapper.git
```
Before moving on, make sure that you have all the dependencies installed. Refer to the **Dependencies** section to see what you need.
To test the addon, you will have to compile and run it:
```bash
@ -46,11 +48,7 @@ cd ~/openFrameworks/addons/ofxPiMapper/example
make
```
After it compiles, run it by executing it directly instead of using `make run`:
```
./bin/example
```
After it compiles, run it with either `make run` or `./bin/example`
It will take a while first, but once it runs, press 1, 2, 3 and 4 keys to switch between modes of the software. Switch to mode 3 at first to select a surface. Afterwards you will be able to edit the texture mapping of it in mode 2 and choose a source in mode 4. Mode 1 is the presentation mode. It is activated on start by default.
@ -82,7 +80,7 @@ In this mode you can adjust the texture coordinates of the surface you have sele
Here you can select, move and distort the surfaces you have created.
####Souce assignment mode
####Source assignment mode
After you select a surface in surface editing mode, activate this mode to be able to choose a source for the surface. Afterwards you might want to go to the texture mapping mode to adjust texture coordinates.
@ -93,38 +91,82 @@ These other shortcuts that you can use while using the example app. Remember tha
Key | Function
:--- | :---
i | Show info
n | Add triangle surface
t | Add triangle surface
q | Add quad surface
r | Add random triangle surface
f | Toggle fullscreen
s | Save composition
BACKSPACE | Delete surface
Dependencies
------------
ofxGui
ofxXmlSettings
ofxOMXPlayer
- ofxGui
- ofxXmlSettings
- [ofxIO](https://github.com/bakercp/ofxIO)
- [ofxOMXPlayer](https://github.com/jvcleave/ofxOMXPlayer)
To install dependencies, `cd` into `openFrameworks/addons` directory and execute the following:
```
git clone https://github.com/jvcleave/ofxOMXPlayer.git
... many lines inbetween
git clone https://github.com/bakercp/ofxIO.git
... many lines here as well
```
And you are good to go!
Compatibility
------------
Tested with 0.8.0, 0.8.1 (OS X and Raspbian)
Tested with 0.8.1 - 0.8.4 (OS X and Raspbian)
Known issues
------------
When launching the example with `make run` keyboard and mouse input is being lost sometimes. Executing the example directly by using `./bin/example` might solve the problem. Not sure how and why.
Keyboard and mouse input is being lost sometimes on the Raspberry Pi. Not sure how and why. Probably because of bad drivers and it seems that Raspberry Pi keyboard and mouse code in openFrameworks is not quite ready yet. Some claim that the following commands solves the issue:
```
sudo apt-get update && sudo apt-get dist-upgrade
sudo rpi-update
```
[ofxOMXPlayer](https://github.com/jvcleave/ofxOMXPlayer) has an issue, it throws an error when compiling:
```
fatal error: libavcodec/opt.h: No such file or directory
```
To fix that, create a file `opt.h` in `addons/ofxOMXPlayer/libs/ffmpeg/libavcodec/` with the following contents:
**opt.h**
```
#ifndef AVCODEC_OPT_H
#define AVCODEC_OPT_H
#include "libavcodec/version.h"
#if FF_API_OPT_H
#include "libavutil/opt.h"
#endif
#endif // AVCODEC_OPT_H
```
More about this issue [here](https://github.com/jvcleave/ofxOMXPlayer/issues/34).
Version history
---------------
###TODO
A short wishlist for the next releases:
- Refined directoryWatcher mechanism, source lists should react on added and removed files
- OSC remote control module
- Even better structure
### Version 0.1.4 (2014-08-xx):
### Version 0.2.0 (2014-10-18):
- Added logo (thanks [Irina Spicaka](http://irina.spicaka.info/))
- Added perspective warping for quad surfaces
- Added mesh warping to quad surfaces (TODO)
- Added perspective warping for quad surfaces (thanks [aspeteRakete](https://github.com/aspeteRakete))
- Added namespaces
- Replaced ofxUI with ofxGui dependency
- Added video source (TODO)
- ...
- Replaced ofxUI with ofxGui
- Added media server (thanks [aspeteRakete](https://github.com/aspeteRakete))
- Added source types and reworked all relevant classes to support them instead of ofTexture directly
- Added video source (based on [ofxOMXPlayer](https://github.com/jvcleave/ofxOMXPlayer))
### Version 0.1.4 (2014-07-10):
- Added fbo texture example

5
example/.gitignore

@ -1,6 +1,5 @@
obj
*.xcodeproj
*.plist
*.xcconfig
*.xcworkspace
*.xcuserdatad
*~
config.make

17
example/Project.xcconfig

@ -0,0 +1,17 @@
//THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
//THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
OF_PATH = ../../..
//THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
#include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
//ICONS - NEW IN 0072
ICON_NAME_DEBUG = icon-debug.icns
ICON_NAME_RELEASE = icon.icns
ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
//IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
//ICON_FILE_PATH = bin/data/
OTHER_LDFLAGS = $(OF_CORE_LIBS)
HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)

1145
example/example.xcodeproj/project.pbxproj

File diff suppressed because it is too large

86
example/example.xcodeproj/xcshareddata/xcschemes/example Debug.xcscheme

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Debug"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

86
example/example.xcodeproj/xcshareddata/xcschemes/example Release.xcscheme

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0460"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Release">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "E4B69B5A0A3A1756003C02F2"
BuildableName = "example.app"
BlueprintName = "example"
ReferencedContainer = "container:example.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Release">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

22
example/openFrameworks-Info.plist

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>cc.openFrameworks.ofapp</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>CFBundleIconFile</key>
<string>${ICON}</string>
</dict>
</plist>

161
example/src/ofApp.cpp

@ -1,32 +1,20 @@
#include "ofApp.h"
void ofApp::setup() {
bShowInfo = false;
// Pass pointers to our media server instance to both:
// surface manager and it's gui, only then we will be able to
// load surface data from xml settings files
surfaceManager.setMediaServer(&mediaServer);
gui.setMediaServer(&mediaServer);
// check if the surfaces.xml file is there
// if not - load defaultSurfaces.xml
if (ofFile::doesFileExist("surfaces.xml")) {
surfaceManager.loadXmlSettings("surfaces.xml");
} else {
surfaceManager.loadXmlSettings("defaultSurfaces.xml");
}
// Pass the surface manager to the mapper graphical user interface
gui.setSurfaceManager(&surfaceManager);
// Create FBO
// The ofxPiMapper is being set up automatically before the first
// ofApp setup call
piMapper.showInfo(); // The info layer is hidden by default, press <i> to toggle
// Create our custom FBO
fbo = new ofFbo();
fbo->allocate(500, 500);
fboSource = new ofx::piMapper::BaseSource(&fbo->getTextureReference());
setFboAsSource();
// Assign the FBO's texture to one of the surfaces ofxPiMapper has created
piMapper.getSurfaceManager().getSurface(0)->setSource(fboSource);
// Genereate rects
// Genereate rects to be rendered into the FBO
int numRects = 20; // change this to add more or less rects
for (int i = 0; i < numRects; i++) {
rects.push_back(ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(),
@ -36,6 +24,7 @@ void ofApp::setup() {
}
void ofApp::update() {
// Move rects
for (int i = 0; i < rects.size(); i++) {
rects[i].y += rectSpeeds[i];
@ -44,7 +33,7 @@ void ofApp::update() {
}
}
// Fill FBO
// Fill FBO with our rects
fbo->begin();
ofClear(0);
ofBackground(0);
@ -56,135 +45,9 @@ void ofApp::update() {
}
void ofApp::draw() {
// Draw the piMapper GUI
gui.draw();
if (bShowInfo) {
// Draw instructions
stringstream ss;
ss << "There are 4 modes:\n\n";
ss << " 1. Presentation mode\n";
ss << " 2. Texture mapping mode\n";
ss << " 3. Projection mapping mode\n";
ss << " 4. Source selection mode\n\n";
ss << "You can switch between the modes by using <1>, <2>, <3> and <4> "
"keys on the keyboard.\n\n";
ss << "Press <r> or <n> to add random or normal surface.\n";
ss << "Press <q> to add a new quad surface.\n";
ss << "Press <s> to save the composition.\n";
ss << "Press <f> to toggle fullscreen.\n";
ss << "Press <a> to reassign the fbo texture to the first surface\n";
ss << "Hit <i> to hide this message.";
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100),
ofColor(255, 255, 255, 200));
}
piMapper.draw();
}
void ofApp::exit() {
// Clear FBO from mem
delete fbo;
}
void ofApp::keyPressed(int key) {
cout << "Key pressed: " << static_cast<char>(key) << endl;
switch (key) {
case '1':
gui.setMode(ofx::piMapper::GuiMode::NONE);
break;
case '2':
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING);
break;
case '3':
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING);
break;
case '4':
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION);
break;
case 'i':
bShowInfo = !bShowInfo;
break;
case 'r':
addRandomSurface();
break;
case 'q':
addQuadSurface();
break;
case 'n':
addSurface();
break;
case 'f':
ofToggleFullscreen();
break;
case 's':
surfaceManager.saveXmlSettings("surfaces.xml");
break;
case 'a':
setFboAsSource();
break;
case OF_KEY_BACKSPACE:
surfaceManager.removeSelectedSurface();
break;
default:
break;
}
}
void ofApp::addRandomSurface() {
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices;
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight()));
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight()));
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight()));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofRandomuf(), ofRandomuf()));
texCoords.push_back(ofVec2f(ofRandomuf(), ofRandomuf()));
texCoords.push_back(ofVec2f(ofRandomuf(), ofRandomuf()));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
}
void ofApp::addQuadSurface() {
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices;
int border = 50;
vertices.push_back(ofVec2f(border, border));
vertices.push_back(ofVec2f(ofGetWidth() - border, border));
vertices.push_back(ofVec2f(ofGetWidth() - border, ofGetHeight() - border));
vertices.push_back(ofVec2f(border, ofGetHeight() - border));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f)));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
}
void ofApp::addSurface() {
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, 0.0f));
vertices.push_back(ofVec2f((float)ofGetWidth(), (float)ofGetHeight()));
vertices.push_back(ofVec2f(0.0f, (float)ofGetHeight()));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
}
void ofApp::setFboAsSource() {
surfaceManager.getSurface(0)->setSource(fboSource);
}

16
example/src/ofApp.h

@ -5,24 +5,16 @@
#include "BaseSource.h"
class ofApp : public ofBaseApp {
public:
public:
void setup();
void update();
void draw();
void exit();
void keyPressed(int key);
void addRandomSurface();
void addQuadSurface();
void addSurface();
void setFboAsSource();
ofxPiMapper piMapper;
// Custom FBO surface variables
ofImage image;
ofx::piMapper::MediaServer mediaServer;
ofx::piMapper::SurfaceManager surfaceManager;
ofx::piMapper::SurfaceManagerGui gui;
bool bShowInfo;
ofFbo* fbo;
ofx::piMapper::BaseSource* fboSource;
vector<ofRectangle> rects;

0
src/SurfaceManager.cpp → src/Surfaces/SurfaceManager.cpp

0
src/SurfaceManager.h → src/Surfaces/SurfaceManager.h

0
src/SurfaceManagerGui.cpp → src/Surfaces/SurfaceManagerGui.cpp

0
src/SurfaceManagerGui.h → src/Surfaces/SurfaceManagerGui.h

0
src/SurfaceType.h → src/Surfaces/SurfaceType.h

158
src/ofxPiMapper.cpp

@ -0,0 +1,158 @@
#include "ofxPiMapper.h"
ofxPiMapper::ofxPiMapper():
bShowInfo(false),
isSetUp(false){
ofAddListener(ofEvents().setup, this, &ofxPiMapper::setup, OF_EVENT_ORDER_BEFORE_APP);
ofAddListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed);
}
ofxPiMapper::~ofxPiMapper() {
ofRemoveListener(ofEvents().setup, this, &ofxPiMapper::setup, OF_EVENT_ORDER_BEFORE_APP);
ofRemoveListener(ofEvents().keyPressed, this, &ofxPiMapper::keyPressed);
}
void ofxPiMapper::setup(ofEventArgs& args) {
ofLogNotice("ofxPiMapper") << "Setting up...";
// Assign media server to other pi mapper components
surfaceManager.setMediaServer(&mediaServer);
gui.setMediaServer(&mediaServer);
// Check if we have user surfaces defined, if not - load default
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)) {
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
} else {
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE;
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE);
}
// The GUI needs something to interface with
gui.setSurfaceManager(&surfaceManager);
isSetUp = true;
ofLogNotice("ofxPiMapper") << "Done setting up";
}
void ofxPiMapper::draw() {
if (!isSetUp) {
return;
}
// Draw the piMapper GUI
gui.draw();
if (bShowInfo) {
// Draw instructions
stringstream ss;
ss << "There are 4 modes:\n\n";
ss << " 1. Presentation mode\n";
ss << " 2. Texture mapping mode\n";
ss << " 3. Projection mapping mode\n";
ss << " 4. Source selection mode\n\n";
ss << "You can switch between the modes by using <1>, <2>, <3> and <4> "
"keys on the keyboard.\n\n";
ss << "Press <t> to add new triangle surface\n";
ss << "Press <q> to add new quad surface\n";
ss << "Press <s> to save the composition\n";
ss << "Press <f> to toggle fullscreen\n";
ss << "Press <i> to hide this message";
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100),
ofColor(255, 255, 255, 200));
}
} // draw
void ofxPiMapper::keyPressed(ofKeyEventArgs &args) {
ofLogNotice("ofxPiMapper") << "Key pressed: " << static_cast<char>(args.key);
switch (args.key) {
case '1':
gui.setMode(ofx::piMapper::GuiMode::NONE);
break;
case '2':
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING);
break;
case '3':
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING);
break;
case '4':
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION);
break;
case 'i':
bShowInfo = !bShowInfo;
break;
case 'q':
addQuadSurface();
break;
case 't':
addTriangleSurface();
break;
case 'f':
ofToggleFullscreen();
break;
case 's':
surfaceManager.saveXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
break;
case OF_KEY_BACKSPACE:
surfaceManager.removeSelectedSurface();
break;
default:
break;
}
} // keyPressed
void ofxPiMapper::addTriangleSurface() {
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// Select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addTriangleSurface
void ofxPiMapper::addQuadSurface() {
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices;
float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin));
vector<ofVec2f> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f)));
surfaceManager.addSurface(surfaceType, vertices, texCoords);
// select this surface right away
surfaceManager.selectSurface(surfaceManager.size() - 1);
} // addQuadSurface
ofx::piMapper::MediaServer& ofxPiMapper::getMediaServer() {
return mediaServer;
}
ofx::piMapper::SurfaceManager& ofxPiMapper::getSurfaceManager() {
return surfaceManager;
}

34
src/ofxPiMapper.h

@ -1,6 +1,38 @@
#pragma once
#include "ofMain.h"
#include "SurfaceManager.h"
#include "SurfaceManagerGui.h"
#include "MediaServer.h"
#include "MediaServer.h"
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml"
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"
class ofxPiMapper {
public:
ofxPiMapper();
~ofxPiMapper();
void setup(ofEventArgs& args);
void draw(); // Called manually to make custom layering possible
void keyPressed(ofKeyEventArgs& args);
// TODO: Move these methods to SurfaceManager
void addTriangleSurface();
void addQuadSurface();
// Toggle help / info
void showInfo() { bShowInfo = true; };
void hideInfo() { bShowInfo = false; };
// Getters
ofx::piMapper::MediaServer& getMediaServer();
ofx::piMapper::SurfaceManager& getSurfaceManager();
private:
bool isSetUp;
bool bShowInfo;
ofx::piMapper::MediaServer mediaServer;
ofx::piMapper::SurfaceManager surfaceManager;
ofx::piMapper::SurfaceManagerGui gui;
};
Loading…
Cancel
Save