├── ofxRay_example
├── addons.make
├── ofxRay_example.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── ofxRay_example Debug.xcscheme
│ │ └── ofxRay_example Release.xcscheme
├── src
│ ├── main.cpp
│ ├── ofApp.h
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
└── config.make
├── ofxRay_ofPlaneExample
├── addons.make
├── screenshot.png
├── ofxRay_ofPlaneExample.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── ofxRay_ofPlaneExample Debug.xcscheme
│ │ └── ofxRay_ofPlaneExample Release.xcscheme
├── src
│ ├── main.cpp
│ ├── ofApp.h
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
├── emptyExample.xcodeproj
│ ├── xcshareddata
│ │ └── xcschemes
│ │ │ ├── emptyExample Debug.xcscheme
│ │ │ └── emptyExample Release.xcscheme
│ └── project.pbxproj
└── config.make
├── ofxRay_ofProjectorExample
├── addons.make
├── ofxRay_ofProjectorExample.xcodeproj
│ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── ofxRay_ofProjectorExample Debug.xcscheme
│ │ └── ofxRay_ofProjectorExample Release.xcscheme
├── src
│ ├── main.cpp
│ ├── ofApp.h
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
├── ofxRay-ofProjectorExample.sln
└── config.make
├── ofxRay_ofPlanePrimitiveExample
├── addons.make
├── screenshot.png
├── ofxRay_ofPlanePrimitiveExample.xcodeproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── my_ofPlaneExample.xccheckout
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── my_ofPlaneExample Debug.xcscheme
│ │ └── my_ofPlaneExample Release.xcscheme
├── src
│ ├── main.cpp
│ ├── ofApp.h
│ └── ofApp.cpp
├── Makefile
├── Project.xcconfig
├── openFrameworks-Info.plist
└── config.make
├── ofxRayLib
├── ofxRay.props
├── ofxRayLib.vcxproj.filters
└── ofxRayLib.vcxproj
├── src
├── ofxRay.h
└── ofxRay
│ ├── Camera.h
│ ├── Base.cpp
│ ├── Base.h
│ ├── Camera.cpp
│ ├── AABB.h
│ ├── Ray.h
│ ├── Plane.h
│ ├── AABB.cpp
│ ├── Ray.cpp
│ ├── Projector.h
│ ├── Plane.cpp
│ ├── Plane_fitToPoints.cpp
│ └── Projector.cpp
├── .gitignore
└── readme.md
/ofxRay_example/addons.make:
--------------------------------------------------------------------------------
1 | ofxRay
2 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/addons.make:
--------------------------------------------------------------------------------
1 | ofxRay
2 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/addons.make:
--------------------------------------------------------------------------------
1 | ofxRay
2 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/addons.make:
--------------------------------------------------------------------------------
1 | ofxRay
2 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elliotwoods/ofxRay/HEAD/ofxRay_ofPlaneExample/screenshot.png
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/elliotwoods/ofxRay/HEAD/ofxRay_ofPlanePrimitiveExample/screenshot.png
--------------------------------------------------------------------------------
/ofxRay_example/ofxRay_example.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/ofxRay_ofPlaneExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/ofxRay_ofProjectorExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/ofxRay_ofPlanePrimitiveExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ofxRay_example/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
7 |
8 | // this kicks off the running of my app
9 | // can be OF_WINDOW or OF_FULLSCREEN
10 | // pass in width and height too:
11 | ofRunApp(new ofApp());
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/ofxRay_example/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/ofxRayLib/ofxRay.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | ..\..\..\addons\ofxRay\src;%(AdditionalIncludeDirectories)
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 |
5 | #include "ofxRay.h"
6 |
7 | class ofApp : public ofBaseApp{
8 |
9 | public:
10 | void setup();
11 | void update();
12 | void draw();
13 | void drawSelection();
14 |
15 | void keyPressed (int key);
16 | void updatePlane();
17 |
18 | ofEasyCam camera;
19 | map data;
20 | map::iterator dataCursor;
21 |
22 | ofPlane plane;
23 |
24 | glm::vec3 center;
25 | glm::vec3 normal;
26 | glm::vec3 up;
27 | glm::vec3 scale; // only 2D
28 | };
29 |
--------------------------------------------------------------------------------
/src/ofxRay.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | //
3 | // ofxRay.h
4 | // ofxRay
5 | //
6 | // Elliot Woods (C) 2012, MIT license
7 | // http://www.kimchiandchips.com
8 | //
9 |
10 | //include me in your project
11 | //and i'll include everything else
12 |
13 | #include "ofMain.h"
14 |
15 | #include "ofxRay/Ray.h"
16 | #include "ofxRay/Plane.h"
17 | #include "ofxRay/AABB.h"
18 | #include "ofxRay/Projector.h"
19 | #include "ofxRay/Camera.h"
20 |
21 | typedef ofxRay::Ray ofRay;
22 | typedef ofxRay::Plane ofPlane;
23 | typedef ofxRay::AABB ofAABB;
24 | typedef ofxRay::Projector ofProjector;
25 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 |
5 | #include "ofxRay.h"
6 |
7 | class ofApp : public ofBaseApp{
8 |
9 | public:
10 | void setup();
11 | void update();
12 | void draw();
13 | void drawSelection();
14 |
15 | void keyPressed (int key);
16 | void updateProjector();
17 |
18 | ofEasyCam camera;
19 | map data;
20 | map::iterator dataCursor;
21 |
22 | ofProjector projector;
23 | vector pixels;
24 | vector rays;
25 |
26 | ofVec3f position;
27 | ofVec2f resolution;
28 | float throwRatio;
29 | ofVec2f lensOffset;
30 | };
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | libs/
2 | docs/
3 |
4 | *.depend
5 | *.layout
6 | *.mode*v3
7 | *.pbxuser
8 | *.app*
9 | *.DS_*
10 | ._*.*
11 |
12 | .svn/
13 | obj/
14 | bin/
15 | build/
16 | !data/
17 |
18 | ipch/
19 | *.suo
20 | *.opensdf
21 | *.vcxproj.user
22 |
23 | *.obj
24 | *.tlog
25 | *.sdf
26 | *.pdb
27 | *.idb
28 | *.pch
29 | Debug/
30 | Release/
31 |
32 | #XCode
33 | *.pbxuser
34 | *.perspective
35 | *.perspectivev3
36 | *.mode1v3
37 | *.mode2v3
38 | #XCode 4
39 | xcuserdata
40 | *.xcworkspace
41 |
42 | *~.xml
43 |
44 | #VS Studio
45 | *.VC.db
46 |
47 | #Example solutions
48 | *Example/**/*.vcxproj
49 | *Example/**/*.sln
50 | *Example/**/*.filters
51 | *Example/**/.vs
52 | *Example/**/icon.rc
--------------------------------------------------------------------------------
/ofxRay_example/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxRay.h"
5 |
6 | class ofApp : public ofBaseApp{
7 |
8 | public:
9 | void setup();
10 | void update();
11 | void draw();
12 | void drawSelection();
13 |
14 | void keyPressed (int key);
15 |
16 | ofEasyCam camera;
17 |
18 | map drawEnabled;
19 | map::iterator drawEnabledCursor;
20 |
21 | ofxRay::Plane plane;
22 | ofxRay::Ray ray;
23 | ofxRay::Projector projector;
24 | ofxRay::Ray pRay;
25 |
26 | ofxRay::Ray corners[4];
27 | unsigned int i, j;
28 |
29 | void drawRayIntersection(ofRay & r, ofColor onIntersectColor);
30 |
31 | void randomiseRay();
32 |
33 | };
34 |
--------------------------------------------------------------------------------
/src/ofxRay/Camera.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | //
3 | // Camera.h
4 | // ofxRay
5 | //
6 | // Elliot Woods (C) 2012, MIT license
7 | // http://www.kimchiandchips.com
8 | //
9 | #include "Ray.h"
10 | #include "Projector.h"
11 |
12 | namespace ofxRay {
13 | class Camera;
14 | }
15 | ostream& operator<<(ostream &, const ofxRay::Camera &);
16 | istream& operator>>(istream & is, ofxRay::Camera &);
17 |
18 | namespace ofxRay {
19 | class Camera : public Projector {
20 | public:
21 | Camera();
22 | Camera(const glm::vec2 & focalLength, const glm::vec2 & center, float w, float h);
23 |
24 | friend ostream & (::operator<<) (ostream &, const Camera &);
25 | friend istream & (::operator>>) (istream &, Camera &);
26 | };
27 | }
28 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_LDFLAGS = $(OF_CORE_LIBS)
17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
18 |
--------------------------------------------------------------------------------
/ofxRay_example/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_CFLAGS = $(OF_CORE_CFLAGS)
17 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
18 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
19 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_CFLAGS = $(OF_CORE_CFLAGS)
17 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
18 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
19 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 |
5 | #include "ofxRay.h"
6 |
7 | class ofApp : public ofBaseApp{
8 |
9 | public:
10 | void setup();
11 | void update();
12 | void draw();
13 | void drawLabels();
14 |
15 | void keyPressed (int key);
16 |
17 | ofEasyCam camera;
18 |
19 | ofPlanePrimitive planePrimitive; // the plane to display
20 |
21 | //ofxRay objects
22 | ofPlane plane; // the plane to check intersection
23 | ofRay mouseRay;
24 | bool doesIntersect;
25 | ofVec3f intersectionPosition;
26 |
27 | // vectors
28 | ofVec3f screenMouse;
29 | ofVec3f worldMouse;
30 | ofVec3f worldMouseEnd;
31 | ofVec3f worldMouseTransmissionVector;
32 |
33 | float rotationSpeedX;
34 | float rotationSpeedY;
35 | ofVec3f rotation;
36 | };
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/Project.xcconfig:
--------------------------------------------------------------------------------
1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT.
2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED
3 | OF_PATH = ../../..
4 |
5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE
6 | #include "../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig"
7 |
8 | //ICONS - NEW IN 0072
9 | ICON_NAME_DEBUG = icon-debug.icns
10 | ICON_NAME_RELEASE = icon.icns
11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/
12 |
13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to:
14 | //ICON_FILE_PATH = bin/data/
15 |
16 | OTHER_CFLAGS = $(OF_CORE_CFLAGS)
17 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS)
18 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS)
19 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.openFrameworks
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/ofxRay/Base.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Base.cpp
3 | // ofxRay
4 | //
5 | // Elliot Woods (C) 2012, MIT license
6 | // http://www.kimchiandchips.com
7 | //
8 | #include "ofxRay/Base.h"
9 |
10 | ostream& operator<<(ostream & os, const ofxRay::Base & base) {
11 | os << base.color;
12 | return os;
13 | }
14 |
15 | istream& operator>>(istream & is, ofxRay::Base & base) {
16 | is >> base.color;
17 | return is;
18 | }
19 |
20 | namespace ofxRay {
21 | Base::Base() {
22 | randomiseColor();
23 | }
24 |
25 | Base::Base(ofColor color) {
26 | this->color = color;
27 | }
28 |
29 | void Base::randomiseColor() {
30 | color = ofColor(150.0f + 100.0f * ofRandomuf(), 150.0f + 100.0f * ofRandomuf(), 150.0f + 100.0f * ofRandomuf(), 255);
31 | }
32 |
33 | void Base::randomise(float amplitude) {
34 | randomiseVectors(amplitude);
35 | randomiseColor();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/ofxRay_example/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 | NSCameraUsageDescription
22 | This app needs to access the camera
23 | NSMicrophoneUsageDescription
24 | This app needs to access the microphone
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 | NSCameraUsageDescription
22 | This app needs to access the camera
23 | NSMicrophoneUsageDescription
24 | This app needs to access the microphone
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/openFrameworks-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | cc.openFrameworks.ofapp
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 | CFBundleIconFile
20 | ${ICON}
21 | NSCameraUsageDescription
22 | This app needs to access the camera
23 | NSMicrophoneUsageDescription
24 | This app needs to access the microphone
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/ofxRay/Base.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | //
3 | // Base.h
4 | // ofxRay
5 | //
6 | // Elliot Woods (C) 2012, MIT license
7 | // http://www.kimchiandchips.com
8 | //
9 |
10 | #include "ofMain.h"
11 |
12 | #if OF_VERSION_MINOR < 9
13 | #define ofDrawLine ofLine
14 | #define OFXRAY_GET_TEXTURE getTextureReference()
15 | #else
16 | #define OFXRAY_GET_TEXTURE getTexture()
17 | #endif
18 |
19 | namespace ofxRay {
20 | class Base;
21 | }
22 | ostream& operator<<(ostream & os, const ofxRay::Base &);
23 | istream& operator>>(istream & is, ofxRay::Base &);
24 |
25 | namespace ofxRay {
26 | class Base {
27 | public:
28 | Base();
29 | Base(ofColor color);
30 | virtual ~Base(){ };
31 |
32 | void randomiseColor();
33 | void randomise(float amplitude=1.0f);
34 |
35 | virtual void draw() const = 0;
36 | virtual void randomiseVectors(float amplitude=1.0f) = 0;
37 |
38 | friend ostream & (::operator<<) (ostream &, const Base &);
39 | friend istream & (::operator>>) (istream &, Base &);
40 |
41 | ofColor color;
42 | };
43 | }
44 |
--------------------------------------------------------------------------------
/src/ofxRay/Camera.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Camera.cpp
3 | // ofxRay
4 | //
5 | // Elliot Woods (C) 2012, MIT license
6 | // http://www.kimchiandchips.com
7 | //
8 |
9 | #include "ofxRay/Camera.h"
10 |
11 | ostream& operator<<(ostream & os, const ofxRay::Camera & camera) {
12 | os << (const ofxRay::Projector &) camera;
13 | return os;
14 | }
15 |
16 | istream& operator>>(istream & is, ofxRay::Camera & camera) {
17 | is >> (ofxRay::Projector &)camera;
18 | return is;
19 | }
20 |
21 | namespace ofxRay {
22 | Camera::Camera() :
23 | Projector(1.0f, glm::vec2(0.0f, 0.0f), 1024, 768) {
24 |
25 | }
26 |
27 | Camera::Camera(const glm::vec2 & focalLength, const glm::vec2 & center, float w, float h)
28 | : Projector(w, h) {
29 | ofMatrix4x4 projection;
30 |
31 | projection(0, 0) = focalLength.x / w * 2.0f;
32 | projection(1, 1) = focalLength.y / h * 2.0f;
33 |
34 | projection(2, 0) = (center.x - w / 2) / w;
35 | projection(2, 1) = (center.y - h / 2) / h;
36 | projection(2, 2) = -1.0f;
37 | projection(2, 3) = -1.0f;
38 |
39 | projection(3, 3) = 0.0f;
40 |
41 | setProjection(projection);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/ofxRay/AABB.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | //
3 | // AABB.hpp
4 | //
5 | // Created by Franck Youdine on 24/10/2019.
6 | //
7 |
8 |
9 | #include "Base.h"
10 | #include "Ray.h"
11 |
12 |
13 | namespace ofxRay {
14 | class AABB : public Base {
15 | public:
16 | AABB();
17 | AABB( const glm::vec3 &min, const glm::vec3 &max );
18 | AABB( const glm::vec3 &min, const glm::vec3 &max, const ofColor &color );
19 |
20 | void set( const glm::vec3 &min, const glm::vec3 &max );
21 | void setCenter( const glm::vec3 ¢er );
22 | void setSize( const glm::vec3 &size );
23 |
24 | //ofGeometric
25 | void draw() const override;
26 | void randomiseVectors(float amplitude=1.0f);
27 | //-
28 |
29 | bool intersect(const Ray &ray) const;
30 | bool intersect(const Ray &ray, float tmin, float tmax) const;
31 | bool intersect(const AABB &other) const;
32 |
33 | glm::vec3 min;
34 | glm::vec3 max;
35 | glm::vec3 scale;
36 | glm::vec3 center;
37 | protected:
38 | void _calcMinMax();
39 | static ofMesh & getView();
40 | };
41 | }
42 |
--------------------------------------------------------------------------------
/src/ofxRay/Ray.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | //
3 | // Ray.h
4 | // ofxRay
5 | //
6 | // Elliot Woods (C) 2012, MIT license
7 | // http://www.kimchiandchips.com
8 | //
9 |
10 | #include "Base.h"
11 |
12 | namespace ofxRay {
13 | class Ray;
14 | }
15 | ostream& operator<<(ostream & os, const ofxRay::Ray &);
16 | istream& operator>>(istream & is, ofxRay::Ray &);
17 |
18 | namespace ofxRay {
19 | class Ray : public Base {
20 | public:
21 | Ray();
22 | Ray(glm::vec3 s, glm::vec3 t, bool infinite=true);
23 | Ray(glm::vec3 s, glm::vec3 t, ofColor color, bool infinite=true);
24 |
25 | //-
26 | //ofGeometric
27 | void draw() const override;
28 | void randomiseVectors(float amplitude = 1.0f) override;
29 | //-
30 |
31 | ///NOTE : does not account for non-infinite lines
32 | Ray intersect(const Ray &other) const;
33 |
34 | float distanceTo(const glm::vec3& point) const;
35 | glm::vec3 closestPointOnRayTo(const glm::vec3& point) const;
36 |
37 | Ray& operator*=(const glm::mat4 &m);
38 | Ray operator*(const glm::mat4 &m) const;
39 |
40 | glm::vec3 getMidpoint() const;
41 | float getLength() const;
42 | float getLengthSquared() const;
43 |
44 | void setStart(const glm::vec3 &);
45 | void setEnd(const glm::vec3 &);
46 | void setTransmissionVector(const glm::vec3 &);
47 |
48 | const glm::vec3 & getStart() const;
49 | glm::vec3 getEnd() const;
50 | const glm::vec3 & getTransmissionVector() const;
51 |
52 | Ray operator*(float other) const;
53 | glm::vec3 operator()(float other) const;
54 |
55 | friend ostream& (::operator<<) (ostream&, const Ray &);
56 | friend istream& (::operator>>) (istream&, Ray &);
57 |
58 | //vectors
59 | glm::vec3 s, t;
60 | bool infinite;
61 | bool defined;
62 |
63 | //draw styles
64 | float width;
65 | };
66 | }
67 |
--------------------------------------------------------------------------------
/ofxRayLib/ofxRayLib.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {d575631a-fa8c-41f5-adb1-b1e9d712da99}
6 |
7 |
8 | {8ccc0a37-4519-4e7f-a1ca-95f99fb5bd0a}
9 |
10 |
11 |
12 |
13 | src
14 |
15 |
16 | src\ofxRay
17 |
18 |
19 | src\ofxRay
20 |
21 |
22 | src\ofxRay
23 |
24 |
25 | src\ofxRay
26 |
27 |
28 | src\ofxRay
29 |
30 |
31 |
32 |
33 | src\ofxRay
34 |
35 |
36 | src\ofxRay
37 |
38 |
39 | src\ofxRay
40 |
41 |
42 | src\ofxRay
43 |
44 |
45 | src\ofxRay
46 |
47 |
48 | src\ofxRay
49 |
50 |
51 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # ofxRay
2 |
3 | ## Introduction
4 |
5 | A lightweight set of tools for intersection testings (e.g. does a ray intersect a plane).
6 |
7 | ## Note
8 |
9 | The current code in this repository is designed for openFrameworks 0.10.0.
10 | If you are looking for a version of ofxRay which is compatible with previous versions of openFrameworks, please check [https://github.com/elliotwoods/ofxRay/tree/0.9.8](https://github.com/elliotwoods/ofxRay/tree/0.9.8) .
11 |
12 | ## Objects
13 |
14 | ### ofxRay::Ray
15 |
16 | A _Ray_ is defined by the starting point __s__ and the transmission vector __t__ . Check equation (5) at http://mathworld.wolfram.com/Line.html
17 |
18 | We define a ray as an infinite line (continuing infinitely forwards and backwards along the line __t__ and - __t__ starting at __s__ .
19 |
20 | The line is defined by points __s__ + __u__ * __t__ , where {-inf < _u_ < +inf}.
21 |
22 | A _Line segment_ is a line which has finite length. We denote a line segment as a ofRay between __s__ and __t__ where __infinite__ is set to _false_ , i.e. a _Line segment_ is a finite section along a ray
23 |
24 | ### ofxRay::Plane
25 |
26 | A _Plane_ is defined by a position on the plane __c__ and a normal vector __n__ .
27 |
28 | We can also define the plane using the notation _a_ x + _b_ y + _c_ z + _d_ = 0 (by using the appropriate constructor).
29 |
30 | For a non-infinite plane, we define the bounds of the _Plane segment_ with the 2D vector __bounds__, and the up vector __up__. We presume that the __up__ vector and __n__ vectors are perpendicular.
31 |
32 | ### ofxRay::Projector
33 |
34 | A _Projector_ is defined by __projection__ matrix and its pose (defined by ofNode which it inherits from).
35 |
36 | We can use a projector to preview a projector or camera in a scene, and to generate pixel _ofRay_s.
37 |
38 | ### ofxRay::Camera
39 |
40 | A _Camera_ is defined the same as a _Projector_, but has distortion coefficients also.
41 |
42 | ### ofxRay::Base
43 |
44 | All objects within ofxRay inherit from ofxRay::Base.
45 |
46 | ## Authors
47 |
48 | * [Elliot Woods](http://github.com/elliotwoods) (main author)
49 | * [Roy Macdonald](http://github.com/roymacdonald) (improvements and glm refactoring)
--------------------------------------------------------------------------------
/src/ofxRay/Plane.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | //
3 | // Plane.h
4 | // ofxRay
5 | //
6 | // Elliot Woods (C) 2012, MIT license
7 | // http://www.kimchiandchips.com
8 | //
9 |
10 | #include "Base.h"
11 | #include "Ray.h"
12 |
13 | namespace ofxRay {
14 | class Plane : public Base {
15 | public:
16 | Plane();
17 | Plane(float a, float b, float c, float d);
18 | Plane(const glm::vec3 & center, const glm::vec3& normal);
19 | Plane(const glm::vec3 & center, const glm::vec3& normal, const glm::vec3& up, const glm::vec2& scale);
20 |
21 | //-
22 | //ofGeometric
23 | void draw() const;
24 | void randomiseVectors(float amplitude=1.0f);
25 | //-
26 |
27 | bool intersect(const Ray &ray) const;
28 | bool intersect(const Ray &ray, glm::vec3 &position) const;
29 |
30 | glm::vec3 reflect(const glm::vec3 & position) const;
31 |
32 | const glm::vec3& getCenter() const;
33 | const glm::vec3& getNormal() const;
34 | const glm::vec3& getUp() const;
35 | const glm::vec2& getScale() const;
36 | glm::vec4 getABCD() const; ///< http://mathworld.wolfram.com/Point-PlaneDistance.html
37 | bool getInfinite() const;
38 |
39 | void setCenter(const glm::vec3& center);
40 | void setNormal(const glm::vec3& normal);
41 | void setUp(const glm::vec3& up);
42 | void setScale(const glm::vec2& scale);
43 | void setInfinite(const bool b);
44 | void setFrom(ofPlanePrimitive &);
45 |
46 | ///fills rays{0..3} with rays starting from corners and going to target
47 | void getCornerRaysTo(const glm::vec3 &target, Ray* rays) const;
48 | ///fills rays{0..3} with rays starting from source and going to corners
49 | void getCornerRaysFrom(const glm::vec3 &source, Ray* rays) const;
50 |
51 | float getDistanceTo(const glm::vec3 &) const;
52 | bool fitToPoints(const vector &, float & residual);
53 |
54 | glm::vec3 getRight() const;
55 |
56 | Ray getUpRay() const;
57 | Ray getRightRay() const;
58 | protected:
59 | glm::vec3 center;
60 | glm::vec3 normal;
61 |
62 | bool infinite;
63 | glm::vec3 up;
64 | glm::vec2 scale;
65 |
66 | static ofMesh & getViewGrid();
67 | static ofMesh & getViewPlane();
68 | };
69 | }
70 |
71 | ostream& operator<<(ostream & os, const ofxRay::Plane &);
72 | istream& operator >> (istream & is, ofxRay::Plane &);
73 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/ofxRay_ofPlanePrimitiveExample.xcodeproj/project.xcworkspace/xcshareddata/my_ofPlaneExample.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | 8757F128-9BDF-40DD-B547-2FC2EEDAEA3F
9 | IDESourceControlProjectName
10 | my_ofPlaneExample
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | 4B53268F-F653-473B-9B99-6F91779ED479
14 | ssh://github.com/elliotwoods/openFrameworks.git
15 | 6DE1FE71-7F04-483F-8AF7-AA384D7B1977
16 | ssh://github.com/elliotwoods/ofxRay.git
17 |
18 | IDESourceControlProjectPath
19 | addons/ofxRay/ofxRay_ofPlanePrimitiveExample/my_ofPlaneExample.xcodeproj/project.xcworkspace
20 | IDESourceControlProjectRelativeInstallPathDictionary
21 |
22 | 4B53268F-F653-473B-9B99-6F91779ED479
23 | ../../../../..
24 | 6DE1FE71-7F04-483F-8AF7-AA384D7B1977
25 | ../../..
26 |
27 | IDESourceControlProjectURL
28 | ssh://github.com/elliotwoods/ofxRay.git
29 | IDESourceControlProjectVersion
30 | 110
31 | IDESourceControlProjectWCCIdentifier
32 | 4B53268F-F653-473B-9B99-6F91779ED479
33 | IDESourceControlProjectWCConfigurations
34 |
35 |
36 | IDESourceControlRepositoryExtensionIdentifierKey
37 | public.vcs.git
38 | IDESourceControlWCCIdentifierKey
39 | 6DE1FE71-7F04-483F-8AF7-AA384D7B1977
40 | IDESourceControlWCCName
41 | ofxRay
42 |
43 |
44 | IDESourceControlRepositoryExtensionIdentifierKey
45 | public.vcs.git
46 | IDESourceControlWCCIdentifierKey
47 | 4B53268F-F653-473B-9B99-6F91779ED479
48 | IDESourceControlWCCName
49 | openFrameworks
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/ofxRay-ofProjectorExample.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 11.00
2 | # Visual Studio 2010
3 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxRay-ofProjectorExample", "emptyExample_vs2010.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}"
4 | EndProject
5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\..\libs\openFrameworksCompiled\project\vs2010\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}"
6 | EndProject
7 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ofxRayLib", "..\ofxRayLib\ofxRayLib.vcxproj", "{2A907B97-C962-435B-80D0-F141C042F066}"
8 | EndProject
9 | Global
10 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
11 | Debug|Win32 = Debug|Win32
12 | Release|Win32 = Release|Win32
13 | RemoteDebug|Win32 = RemoteDebug|Win32
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32
17 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32
18 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32
19 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32
20 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.RemoteDebug|Win32.ActiveCfg = Debug|Win32
21 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.RemoteDebug|Win32.Build.0 = Debug|Win32
22 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32
23 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32
24 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32
25 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32
26 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.RemoteDebug|Win32.ActiveCfg = RemoteDebug|Win32
27 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.RemoteDebug|Win32.Build.0 = RemoteDebug|Win32
28 | {2A907B97-C962-435B-80D0-F141C042F066}.Debug|Win32.ActiveCfg = Debug|Win32
29 | {2A907B97-C962-435B-80D0-F141C042F066}.Debug|Win32.Build.0 = Debug|Win32
30 | {2A907B97-C962-435B-80D0-F141C042F066}.Release|Win32.ActiveCfg = Release|Win32
31 | {2A907B97-C962-435B-80D0-F141C042F066}.Release|Win32.Build.0 = Release|Win32
32 | {2A907B97-C962-435B-80D0-F141C042F066}.RemoteDebug|Win32.ActiveCfg = RemoteDebug|Win32
33 | {2A907B97-C962-435B-80D0-F141C042F066}.RemoteDebug|Win32.Build.0 = RemoteDebug|Win32
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | // Example by Jordi Puig
4 |
5 | //--------------------------------------------------------------
6 | void ofApp::setup(){
7 |
8 | // let the axis oclude
9 | ofEnableDepthTest();
10 |
11 | // set attributes to our displayed plane
12 | planePrimitive.setPosition(0 ,0, 0);
13 | planePrimitive.setScale(1,2,1);
14 |
15 | //set the rotation speeds
16 | rotationSpeedX = 0.33;
17 | rotationSpeedY = 0.2;
18 |
19 | // get the attributes from the plane primitive
20 | // and apply them to the intersection plane
21 | plane.setFrom(planePrimitive);
22 | }
23 |
24 | //--------------------------------------------------------------
25 | void ofApp::update(){
26 |
27 | // the mouse position on screen coordinates
28 | screenMouse = ofVec3f(ofGetMouseX(),ofGetMouseY(),0);
29 |
30 | // the mouse position on world coordinates
31 | worldMouse = camera.screenToWorld(ofVec3f(screenMouse.x, screenMouse.y, 0.0f));
32 |
33 | // a point right in front of the mouse (used to get mouse direction)
34 | worldMouseEnd = camera.screenToWorld(ofVec3f(screenMouse.x, screenMouse.y, 1.0f));
35 |
36 | // a vector representing the mouse direction (from camera to infinity?)
37 | worldMouseTransmissionVector = worldMouseEnd - worldMouse;
38 |
39 | // set attributes to the ray
40 | mouseRay.s = worldMouse;
41 | mouseRay.t = worldMouseTransmissionVector;
42 |
43 | // rotate the plane
44 | rotation.x += rotationSpeedX;
45 | rotation.y += rotationSpeedY;
46 | planePrimitive.setOrientation(rotation);
47 |
48 | // update intersection plane
49 | plane.setFrom(planePrimitive);
50 |
51 | // check for intersection
52 | // all the good stuff is done here!
53 | doesIntersect = plane.intersect(mouseRay, intersectionPosition);
54 |
55 | }
56 |
57 | //--------------------------------------------------------------
58 | void ofApp::draw(){
59 |
60 | ofBackgroundGradient(100, 50);
61 |
62 | camera.begin();
63 |
64 | ofDrawGrid(1000.0f, 1.0f);
65 |
66 | // this will be drawn as a dot at your mouse cursor
67 | // because it's a line going away from the camera
68 | // under your mouse
69 | mouseRay.draw();
70 |
71 | plane.draw();
72 |
73 | ofSetColor(0, 250, 250, 100);
74 | planePrimitive.draw(OF_MESH_FILL);
75 | planePrimitive.drawAxes(100);
76 |
77 | camera.end();
78 |
79 | drawLabels();
80 | }
81 |
82 | void ofApp::drawLabels(){
83 |
84 | string label;
85 | int y = ofGetHeight() - 70;
86 | label = doesIntersect ? "hits" : "misses";
87 | label += + " at world position " + ofToString(intersectionPosition);
88 | ofDrawBitmapStringHighlight(label, 40, y);
89 | }
90 |
91 | //--------------------------------------------------------------
92 | void ofApp::keyPressed(int key){
93 |
94 | }
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofBackground(100, 100, 100);
6 | ofEnableSmoothing();
7 |
8 | data.insert(pair("center", center));
9 | data.insert(pair("normal", normal));
10 | data.insert(pair("up", up));
11 | data.insert(pair("scale xy", scale));
12 | dataCursor = data.begin();
13 |
14 | center = glm::vec3(50.0f, 50.0f, 0.0f);
15 | normal = glm::normalize(glm::vec3(1.0f, 1.0f, 1.0f));
16 | up = glm::normalize(glm::vec3(0.0f, 1.0f, 0.0f));
17 | scale = glm::vec3(200.0f, 200.0f,1);
18 |
19 | updatePlane();
20 | plane.setInfinite(false);
21 |
22 | plane.color = ofColor::white;
23 |
24 | }
25 |
26 | //--------------------------------------------------------------
27 | void ofApp::update(){
28 | }
29 |
30 | //--------------------------------------------------------------
31 | void ofApp::draw(){
32 | camera.begin();
33 |
34 | ofDrawGrid(50,5,true);
35 | ofPushStyle();
36 | ofSetLineWidth(2);
37 | plane.draw();
38 | ofPopStyle();
39 | camera.end();
40 |
41 | drawSelection();
42 | }
43 |
44 | //--------------------------------------------------------------
45 | void ofApp::drawSelection() {
46 | int nItems = data.size();
47 | string instruction = "[RETURN] to move selection, [UP]/[DOWN],[LEFT]/[RIGHT],[A]/[Z] to edit";
48 |
49 | int stringWidth = 0;
50 | map::iterator it;
51 | for(it = data.begin(); it != data.end(); it++) {
52 | stringWidth = MAX(stringWidth, (it->first).length());
53 | }
54 |
55 | ofPushStyle();
56 | ofFill();
57 | ofSetColor(200, 100, 100);
58 | int y = ofGetHeight() - nItems*10 - 70;
59 | ofDrawRectangle(20, y, MAX(stringWidth, instruction.length()) * 8 + 40, nItems*10 + 50);
60 |
61 | ofSetColor(255, 255, 255);
62 | y += 20;
63 | ofDrawBitmapString(instruction, 40, y);
64 | y += 20;
65 | ofSetColor(200, 200, 200);
66 | string result;
67 | for(it = data.begin(); it != data.end(); it++) {
68 | result = dataCursor == it ? "> " : " ";
69 | result += it->first;
70 | while (result.length() < stringWidth+4)
71 | result.push_back(' ');
72 | result += ofToString(it->second, 2);
73 | ofDrawBitmapString(result, 40, y);
74 | y += 10;
75 | }
76 | ofPopStyle();
77 | }
78 |
79 | //--------------------------------------------------------------
80 | void ofApp::keyPressed(int key){
81 |
82 | if (key==OF_KEY_LEFT)
83 | dataCursor->second.x += -0.1;
84 | if (key==OF_KEY_RIGHT)
85 | dataCursor->second.x += +0.1;
86 |
87 | if (key==OF_KEY_UP)
88 | dataCursor->second.y += +0.1;
89 | if (key==OF_KEY_DOWN)
90 | dataCursor->second.y += -0.1;
91 |
92 | if (key=='a')
93 | dataCursor->second.z += +0.1;
94 | if (key=='z')
95 | dataCursor->second.z += -0.1;
96 |
97 | updatePlane();
98 |
99 |
100 | if (key=='f')
101 | ofToggleFullscreen();
102 |
103 | if (key==OF_KEY_RETURN) {
104 | if (dataCursor == data.end())
105 | dataCursor = data.begin();
106 | else
107 | dataCursor++;
108 | }
109 | }
110 |
111 | //--------------------------------------------------------------
112 | void ofApp::updatePlane() {
113 | plane.setCenter(center);
114 | plane.setNormal(normal);
115 | plane.setUp(up);
116 | plane.setScale(scale);
117 |
118 | normal = plane.getNormal();
119 | up = plane.getUp();
120 | }
121 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/emptyExample.xcodeproj/xcshareddata/xcschemes/emptyExample Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/emptyExample.xcodeproj/xcshareddata/xcschemes/emptyExample Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_example/ofxRay_example.xcodeproj/xcshareddata/xcschemes/ofxRay_example Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_example/ofxRay_example.xcodeproj/xcshareddata/xcschemes/ofxRay_example Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/ofxRay_ofPlaneExample.xcodeproj/xcshareddata/xcschemes/ofxRay_ofPlaneExample Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/ofxRay_ofPlaneExample.xcodeproj/xcshareddata/xcschemes/ofxRay_ofPlaneExample Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/ofxRay_ofProjectorExample.xcodeproj/xcshareddata/xcschemes/ofxRay_ofProjectorExample Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/ofxRay_ofProjectorExample.xcodeproj/xcshareddata/xcschemes/ofxRay_ofProjectorExample Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/ofxRay_ofPlanePrimitiveExample.xcodeproj/xcshareddata/xcschemes/my_ofPlaneExample Debug.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/ofxRay_ofPlanePrimitiveExample.xcodeproj/xcshareddata/xcschemes/my_ofPlaneExample Release.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofBackground(100, 100, 100);
6 | ofEnableSmoothing();
7 |
8 | data.insert(pair("position.x", position.x));
9 | data.insert(pair("position.y", position.y));
10 | data.insert(pair("position.z", position.z));
11 | data.insert(pair("resolution.x", resolution.x));
12 | data.insert(pair("resolution.y", resolution.y));
13 | data.insert(pair("throwRatio", throwRatio));
14 | data.insert(pair("lensOffset.x", lensOffset.x));
15 | data.insert(pair("lensOffset.y", lensOffset.y));
16 |
17 | dataCursor = data.begin();
18 |
19 | position = ofVec3f(1.0f, 1.0f, 0.0f);
20 | resolution = ofVec2f(1024, 768);
21 | throwRatio = 2.0f;
22 | lensOffset = ofVec2f(0.0f, 0.5f);
23 |
24 | updateProjector();
25 | }
26 |
27 | //--------------------------------------------------------------
28 | void ofApp::update(){
29 | }
30 |
31 | //--------------------------------------------------------------
32 | void ofApp::draw(){
33 | camera.begin();
34 |
35 | ofPushStyle();
36 | ofSetColor(200, 100, 100);
37 | ofDrawGrid(10,5,true);
38 | ofPopStyle();
39 |
40 | projector.draw();
41 |
42 | for (const auto & ray : this->rays) {
43 | ray.draw();
44 | }
45 |
46 | camera.end();
47 |
48 | drawSelection();
49 | }
50 |
51 | //--------------------------------------------------------------
52 | void ofApp::drawSelection() {
53 | int nItems = data.size();
54 | string instruction = "[UP]/[DOWN] to move selection, [LEFT]/[RIGHT] to edit";
55 |
56 | int stringWidth = 0;
57 | map::iterator it;
58 | for(it = data.begin(); it != data.end(); it++) {
59 | stringWidth = MAX(stringWidth, (it->first).length());
60 | }
61 |
62 | ofPushStyle();
63 | ofFill();
64 | ofSetColor(200, 100, 100);
65 | int y = ofGetHeight() - nItems*10 - 70;
66 | ofDrawRectangle(20, y, MAX(stringWidth, instruction.length()) * 8 + 40, nItems*10 + 50);
67 |
68 | ofSetColor(255, 255, 255);
69 | y += 20;
70 | ofDrawBitmapString(instruction, 40, y);
71 | y += 20;
72 | ofSetColor(200, 200, 200);
73 | string result;
74 | for(it = data.begin(); it != data.end(); it++) {
75 | result = dataCursor == it ? "> " : " ";
76 | result += it->first;
77 | while (result.length() < stringWidth+4)
78 | result.push_back(' ');
79 | result += ofToString(it->second, 2);
80 | ofDrawBitmapString(result, 40, y);
81 | y += 10;
82 | }
83 | ofPopStyle();
84 | }
85 |
86 | //--------------------------------------------------------------
87 | void ofApp::keyPressed(int key){
88 |
89 | if (key==OF_KEY_LEFT)
90 | dataCursor->second += -0.1;
91 | if (key==OF_KEY_RIGHT)
92 | dataCursor->second += +0.1;
93 |
94 | if (key==OF_KEY_UP) {
95 | if (dataCursor == data.begin())
96 | dataCursor = data.end();
97 | dataCursor--;
98 | }
99 | if (key==OF_KEY_DOWN) {
100 | dataCursor++;
101 | if (dataCursor == data.end())
102 | dataCursor = data.begin();
103 | }
104 |
105 | updateProjector();
106 |
107 |
108 | if (key=='f')
109 | ofToggleFullscreen();
110 | }
111 |
112 | //--------------------------------------------------------------
113 | void ofApp::updateProjector() {
114 | projector.setWidth(this->resolution.x);
115 | projector.setHeight(this->resolution.y);
116 | projector.setProjection(this->throwRatio, this->lensOffset);
117 | projector.setPosition(this->position);
118 | pixels.clear();
119 | for (int i = 0; i < this->resolution.x; i += 32) {
120 | for (int j = 0; j < this->resolution.y; j += 32) {
121 | pixels.push_back(glm::vec2(i, j));
122 | }
123 | }
124 |
125 | projector.castPixels(pixels, rays);
126 | }
127 |
--------------------------------------------------------------------------------
/src/ofxRay/AABB.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // AABB.cpp
3 | //
4 | // Created by Franck Youdine on 24/10/2019.
5 | //
6 |
7 | #include "AABB.h"
8 |
9 | ofxRay::AABB::AABB(){
10 | this->randomiseVectors();
11 | }
12 | ofxRay::AABB::AABB( const glm::vec3 &min, const glm::vec3 &max ){
13 | this->set(min, max);
14 | }
15 | ofxRay::AABB::AABB( const glm::vec3 &min, const glm::vec3 &max, const ofColor &color ){
16 | this->set(min, max);
17 | this->color = color;
18 | }
19 | void ofxRay::AABB::set( const glm::vec3 &min, const glm::vec3 &max ) {
20 | for (int a = 0; a < 3; ++a){
21 | bool b = min[a] < max[a];
22 | this->min[a] = b ? min[a] : max[a];
23 | this->max[a] = b ? max[a] : min[a];
24 | }
25 |
26 | this->scale = this->max - this->min;
27 | this->center = this->min + (this->scale * .5f);
28 | }
29 |
30 |
31 | void ofxRay::AABB::setCenter( const glm::vec3 ¢er ) {
32 | this->center = center;
33 | _calcMinMax();
34 | }
35 | void ofxRay::AABB::setSize( const glm::vec3 &size ) {
36 | this->scale = size;
37 | _calcMinMax();
38 | }
39 |
40 |
41 | //ofGeometric
42 | void ofxRay::AABB::draw() const {
43 | // draw a cube
44 |
45 | ofPushStyle();
46 | ofSetColor(color);
47 | ofPushMatrix();
48 |
49 | ofTranslate(this->center);
50 | ofScale(this->scale.x, this->scale.y, this->scale.z);
51 |
52 | auto & viewGrid = AABB::getView();
53 | viewGrid.draw();
54 |
55 | ofPopMatrix();
56 | ofPopStyle();
57 |
58 | }
59 |
60 | void ofxRay::AABB::randomiseVectors( float amplitude ) {
61 | this->set(
62 | glm::vec3( ofRandom(-1.f, 1.f), ofRandom(-1.f, 1.f), ofRandom(-1.f, 1.f) ) * amplitude,
63 | glm::vec3( ofRandom(-1.f, 1.f), ofRandom(-1.f, 1.f), ofRandom(-1.f, 1.f) ) * amplitude
64 | );
65 | }
66 |
67 | ofMesh & ofxRay::AABB::getView() {
68 | static unique_ptr viewGrid;
69 | if (!viewGrid) {
70 | vector vertices(8);
71 | int i = 0;
72 |
73 | vertices[i++] = glm::vec3(-.5f, -.5f, .5f);
74 | vertices[i++] = glm::vec3( .5f, -.5f, .5f);
75 | vertices[i++] = glm::vec3( .5f, .5f, .5f);
76 | vertices[i++] = glm::vec3(-.5f, .5f, .5f);
77 |
78 | vertices[i++] = glm::vec3(-.5f, -.5f, -.5f);
79 | vertices[i++] = glm::vec3( .5f, -.5f, -.5f);
80 | vertices[i++] = glm::vec3( .5f, .5f, -.5f);
81 | vertices[i++] = glm::vec3(-.5f, .5f, -.5f);
82 |
83 | // 4 - 5
84 | // | / |
85 | // 4 - 0 - 1 - 5 - 4
86 | // | / | \ | / | \ |
87 | // 7 - 3 - 2 - 6 - 7
88 | // | / |
89 | // 7 - 6
90 |
91 | viewGrid = make_unique();
92 | viewGrid->addVertices(vertices);
93 | //top
94 | viewGrid->addTriangle(0, 1, 2);
95 | viewGrid->addTriangle(0, 2, 3);
96 | //left
97 | viewGrid->addTriangle(0, 3, 7);
98 | viewGrid->addTriangle(0, 7, 4);
99 | //rear
100 | viewGrid->addTriangle(0, 4, 5);
101 | viewGrid->addTriangle(0, 5, 1);
102 | //right
103 | viewGrid->addTriangle(1, 5, 2);
104 | viewGrid->addTriangle(2, 5, 6);
105 | //front
106 | viewGrid->addTriangle(2, 6, 7);
107 | viewGrid->addTriangle(3, 2, 7);
108 | //bottom
109 | viewGrid->addTriangle(5, 4, 7);
110 | viewGrid->addTriangle(5, 7, 6);
111 |
112 | viewGrid->setMode(OF_PRIMITIVE_LINES);
113 | }
114 |
115 | return *viewGrid;
116 | }
117 |
118 | //-
119 |
120 |
121 | bool ofxRay::AABB::intersect(const ofxRay::Ray &ray) const {
122 | float tmin = std::numeric_limits::min();
123 | float tmax = std::numeric_limits::max();
124 |
125 | return this->intersect(ray, tmin, tmax);
126 | }
127 |
128 | bool ofxRay::AABB::intersect(const ofxRay::Ray &ray, float tmin, float tmax) const {
129 |
130 | for (int a = 0; a < 3; ++a)
131 | {
132 | float invD = 1.0f / ray.t[a];
133 | float t0 = (this->min[a] - ray.s[a]) * invD;
134 | float t1 = (this->max[a] - ray.s[a]) * invD;
135 |
136 | if (invD < 0.0f) {
137 | float temp = t1;
138 | t1 = t0;
139 | t0 = temp;
140 | }
141 |
142 | tmin = t0 > tmin ? t0 : tmin;
143 | tmax = t1 < tmax ? t1 : tmax;
144 |
145 | if (tmax <= tmin)
146 | return false;
147 | }
148 |
149 | return true;
150 | }
151 |
152 | bool ofxRay::AABB::intersect(const AABB &other) const
153 | {
154 | return min.x < other.max.x &&
155 | min.y < other.max.y &&
156 | min.z < other.max.z &&
157 | other.min.x < max.x &&
158 | other.min.y < max.y &&
159 | other.min.z < max.z;
160 | }
161 |
162 | void ofxRay::AABB::_calcMinMax()
163 | {
164 | this->min = this->center - (this->scale*.5);
165 | this->max = this->min + this->scale;
166 | }
167 |
--------------------------------------------------------------------------------
/ofxRay_example/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofBackground(100, 100, 100);
6 | ofEnableSmoothing();
7 |
8 | plane = ofPlane(glm::vec3(0,100,400),//Center
9 | glm::vec3(1,0,-1), //Normal
10 | glm::vec3(0,1,0), //Up vector
11 | glm::vec2(100,100)); //Scale
12 | plane.color = ofColor::white;
13 |
14 | randomiseRay();
15 | ray.color = ofColor::yellow;
16 | ray.width = 3;
17 |
18 | projector.setPosition(glm::vec3(0,0,0));
19 | projector.setOrientation(glm::angleAxis(ofDegToRad(180), glm::vec3(0,1,0)));
20 | i = j = 0;
21 |
22 | drawEnabled.insert(pair("ofGrid", true));
23 | drawEnabled.insert(pair("ofRay", true));
24 | drawEnabled.insert(pair("ofPlane", true));
25 | drawEnabled.insert(pair("ofProjector", false));
26 | drawEnabledCursor = drawEnabled.begin();
27 | }
28 | //--------------------------------------------------------------
29 | void ofApp::randomiseRay(){
30 | float s = 100;
31 | ray.setStart({ofRandom(-s,s),ofRandom(-s,s),ofRandom(-s, s)});
32 | float t = 500;
33 | ray.setTranmissionVector({ofRandom(-t, t),ofRandom(-t,t),ofRandom(-t, t)});
34 | }
35 | //--------------------------------------------------------------
36 | void ofApp::update(){
37 | i+=32;
38 | if (i >= projector.getWidth()) {
39 | i = 0;
40 | j++;
41 | }
42 | if (j >= projector.getHeight())
43 | j = 0;
44 |
45 | pRay = projector.castPixel(i, j);
46 | plane.getCornerRaysTo(glm::vec3(0,0,0), corners);
47 | }
48 | //--------------------------------------------------------------
49 | void ofApp::drawRayIntersection(ofRay & r, ofColor onIntersectColor){
50 | glm::vec3 intersect;
51 | bool intersects = plane.intersect(r, intersect);
52 |
53 | ofPushStyle();
54 | if (intersects)
55 | ofSetColor(onIntersectColor);
56 | else
57 | ofSetColor(ofColor::white);
58 | ofDrawSphere(intersect, 10);
59 | ofPopStyle();
60 | }
61 | //--------------------------------------------------------------
62 | void ofApp::draw(){
63 | camera.begin();
64 |
65 | if (drawEnabled["ofGrid"]) {
66 | ofPushStyle();
67 | ofDrawGrid(50.0f, 10, true);
68 | ofPopStyle();
69 | }
70 |
71 | if (drawEnabled["ofRay"])
72 | ray.draw();
73 |
74 | if (drawEnabled["ofPlane"]) {
75 | ofPushStyle();
76 | ofSetLineWidth(2);
77 | plane.draw();
78 | ofPopStyle();
79 | for (int i=0; i<4; i++)
80 | corners[i].draw();
81 | }
82 |
83 | if (drawEnabled["ofProjector"]) {
84 | projector.draw();
85 | drawRayIntersection(pRay, ofColor::red);
86 | pRay.draw();
87 | }
88 |
89 | if (drawEnabled["ofRay"]) {
90 | drawRayIntersection(ray, ofColor::blue);
91 | ray.draw();
92 | ofPushStyle();
93 | ofSetColor(0);
94 | ofDrawSphere(ray.getEnd(), 5);
95 | ofPopStyle();
96 | }
97 |
98 | camera.end();
99 |
100 | drawSelection();
101 |
102 |
103 | }
104 |
105 | //--------------------------------------------------------------
106 | void ofApp::drawSelection() {
107 | int nItems = drawEnabled.size();
108 | string instruction = "[UP]/[DOWN] to select, [LEFT]/[RIGHT] to disable/enable";
109 |
110 | int stringWidth = 0;
111 | for(auto& it: drawEnabled){
112 | stringWidth = MAX(stringWidth, (it.first).length());
113 | }
114 |
115 | ofPushStyle();
116 | ofFill();
117 | ofSetColor(200, 100, 100);
118 | int y = ofGetHeight() - nItems*10 - 70;
119 | ofDrawRectangle(20, y, MAX(stringWidth, instruction.length()) * 8 + 40, nItems*10 + 50);
120 |
121 | ofSetColor(255, 255, 255);
122 | y += 20;
123 | ofDrawBitmapString(instruction, 40, y);
124 | y += 20;
125 | ofSetColor(200, 200, 200);
126 | string result;
127 | for(auto& it: drawEnabled){
128 | result = (drawEnabledCursor->first == it.first) ? "> " : " ";
129 | result += it.first;
130 | while (result.length() < stringWidth+2)
131 | result.push_back(' ');
132 | result += it.second ? " [O]" : " [ ]";
133 | ofDrawBitmapString(result, 40, y);
134 | y += 10;
135 | }
136 | ofPopStyle();
137 | }
138 |
139 | //--------------------------------------------------------------
140 | void ofApp::keyPressed(int key){
141 |
142 | if (ofGetKeyPressed(OF_KEY_SHIFT)) {
143 | if (key==OF_KEY_LEFT)
144 | ray.s += ofVec3f(-1,0,0);
145 | if (key==OF_KEY_RIGHT)
146 | ray.s += ofVec3f(1,0,0);
147 | if (key==OF_KEY_UP)
148 | ray.s += ofVec3f(0,1,0);
149 | if (key==OF_KEY_DOWN)
150 | ray.s += ofVec3f(0,-1,0);
151 | }else{
152 | if (key==' ') {
153 | randomiseRay();
154 | }
155 | if (key==OF_KEY_UP) {
156 | if (drawEnabledCursor == drawEnabled.begin())
157 | {
158 | drawEnabledCursor = drawEnabled.end();
159 | drawEnabledCursor--;
160 | }
161 | else
162 | drawEnabledCursor--;
163 | }
164 | if (key==OF_KEY_DOWN) {
165 | if (drawEnabledCursor == drawEnabled.end())
166 | drawEnabledCursor = drawEnabled.begin();
167 | else
168 | drawEnabledCursor++;
169 | }
170 | if (key==OF_KEY_LEFT)
171 | if (drawEnabledCursor != drawEnabled.end())
172 | drawEnabledCursor->second = false;
173 | if (key==OF_KEY_RIGHT)
174 | if (drawEnabledCursor != drawEnabled.end())
175 | drawEnabledCursor->second = true;
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/src/ofxRay/Ray.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Ray.cpp
3 | // ofxRay
4 | //
5 | // Elliot Woods (C) 2012, MIT license
6 | // http://www.kimchiandchips.com
7 | //
8 |
9 | #include "ofxRay/Ray.h"
10 |
11 | ostream& operator<<(ostream & os, const ofxRay::Ray & ray) {
12 | os << ray.s;
13 | os << "; ";
14 | os << ray.t;
15 | os << "; ";
16 | os << (const ofxRay::Base &)ray;
17 | return os;
18 | }
19 | istream& operator>>(istream & is, ofxRay::Ray & ray) {
20 | is >> ray.s;
21 | is.ignore(2);
22 | is >> ray.t;
23 | is.ignore(2);
24 | is >> (ofxRay::Base &)ray;
25 | return is;
26 | }
27 |
28 | namespace ofxRay {
29 | Ray::Ray() {
30 | this->defined = false;
31 | this->width = 2.0f;
32 | }
33 |
34 | Ray::Ray(glm::vec3 s, glm::vec3 t, bool infinite) {
35 | this->defined = true;
36 | this->s = s;
37 | this->t = t;
38 | this->infinite = infinite;
39 | this->width = 2.0f;
40 | }
41 |
42 | Ray::Ray(glm::vec3 s, glm::vec3 t, ofColor color, bool infinite) : ofxRay::Base(color) {
43 | this->defined = true;
44 | this->s = s;
45 | this->t = t;
46 | this->infinite = infinite;
47 | this->width = 2.0f;
48 | }
49 |
50 | void Ray::draw() const {
51 | if (!this->defined)
52 | return;
53 |
54 | ofPushStyle();
55 | {
56 | ofEnableSmoothing();
57 | ofSetColor(color);
58 |
59 | if (infinite) {
60 | //'infinite' line
61 |
62 | //inner line
63 | if (width > 2.0f) {
64 | ofPushStyle();
65 | {
66 | ofSetLineWidth(1.0f);
67 | ofSetColor(255, 255, 255);
68 | ofDrawLine(s - 100 * t, s + 100 * t);
69 | }
70 | ofPopStyle();
71 | }
72 |
73 |
74 | ofSetLineWidth(width == 0.0f ? 1.0f : width);
75 | ofDrawLine(s - 100 * t, s + 100 * t);
76 | }
77 |
78 | //arrow
79 | ofDrawArrow(s, s + t, 0.01f);
80 | }
81 | ofPopStyle();
82 | }
83 |
84 | void Ray::randomiseVectors(float amplitude) {
85 | infinite = true;
86 | s = glm::vec3(ofRandomf(), ofRandomf(), ofRandomf()) * amplitude;
87 | t = glm::vec3(ofRandomf(), ofRandomf(), ofRandomf()) * amplitude;
88 | this->defined = true;
89 | }
90 |
91 | Ray& Ray::operator*=(const glm::mat4 &m) {
92 | auto sOld = s;
93 | auto tmp = m * glm::vec4(s, 1.0);
94 | s = glm::vec3(tmp)/tmp.w;
95 | // s = s * m;
96 | tmp = m * glm::vec4(t+sOld, 1.0);
97 | auto tmp2 = glm::vec3(tmp)/tmp.w;
98 | // tmp = s;
99 | // t = (t+sOld) * m - s;
100 | t = tmp2 -s;
101 | return *this;
102 | }
103 |
104 | Ray Ray::operator*(const glm::mat4 &m) const {
105 | Ray ray = *this;
106 | return ray *= m;
107 | }
108 |
109 | // from http://paulbourke.net/geometry/lineline3d/lineline.c
110 | // int LineLineIntersect(
111 | // XYZ p1,XYZ p2,XYZ p3,XYZ p4,XYZ *pa,XYZ *pb,
112 | // double *mua, double *mub)
113 | Ray Ray::intersect(const Ray &other) const {
114 | Ray intersectRay;
115 |
116 | const glm::vec3 p1(s), p2(s+t), p3(other.s), p4(other.s+other.t);
117 | const float EPS(1.0E-15);
118 |
119 | glm::vec3 p13,p43,p21;
120 | float d1343,d4321,d1321,d4343,d2121;
121 | float numer,denom;
122 |
123 | p13.x = p1.x - p3.x;
124 | p13.y = p1.y - p3.y;
125 | p13.z = p1.z - p3.z;
126 | p43.x = p4.x - p3.x;
127 | p43.y = p4.y - p3.y;
128 | p43.z = p4.z - p3.z;
129 | if (fabs(p43.x) < EPS && fabs(p43.y) < EPS && fabs(p43.z) < EPS)
130 | return(Ray());
131 | p21.x = p2.x - p1.x;
132 | p21.y = p2.y - p1.y;
133 | p21.z = p2.z - p1.z;
134 | if (fabs(p21.x) < EPS && fabs(p21.y) < EPS && fabs(p21.z) < EPS)
135 | return(Ray());
136 |
137 | d1343 = p13.x * p43.x + p13.y * p43.y + p13.z * p43.z;
138 | d4321 = p43.x * p21.x + p43.y * p21.y + p43.z * p21.z;
139 | d1321 = p13.x * p21.x + p13.y * p21.y + p13.z * p21.z;
140 | d4343 = p43.x * p43.x + p43.y * p43.y + p43.z * p43.z;
141 | d2121 = p21.x * p21.x + p21.y * p21.y + p21.z * p21.z;
142 |
143 | denom = d2121 * d4343 - d4321 * d4321;
144 | if (fabs(denom) < EPS)
145 | return(Ray());
146 | numer = d1343 * d4321 - d1321 * d4343;
147 |
148 | float ma = numer / denom;
149 | float mb = (d1343 + d4321 * (ma)) / d4343;
150 |
151 | glm::vec3 s;
152 | glm::vec3 t;
153 |
154 | s.x = p1.x + ma * p21.x;
155 | s.y = p1.y + ma * p21.y;
156 | s.z = p1.z + ma * p21.z;
157 | t.x = p3.x + mb * p43.x;
158 | t.y = p3.y + mb * p43.y;
159 | t.z = p3.z + mb * p43.z;
160 | t = t - s;
161 |
162 | return Ray(s, t, false);
163 | }
164 |
165 | // using http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
166 | float Ray::distanceTo(const glm::vec3& point) const {
167 | return glm::length(glm::cross(point - s, point - (s+t))) / glm::length(t);
168 | }
169 | // untested but makes sense
170 | glm::vec3 Ray::closestPointOnRayTo(const glm::vec3& point) const {
171 | return s + (t * glm::dot(point - s, t) / glm::length2(t));
172 | }
173 |
174 | glm::vec3 Ray::getMidpoint() const {
175 | return s + t*0.5;
176 | }
177 |
178 | float Ray::getLength() const {
179 | return glm::length(t);
180 | }
181 |
182 | float Ray::getLengthSquared() const {
183 | return glm::length2(t);
184 | }
185 |
186 | void Ray::setStart(const glm::vec3 & start) {
187 | this->s = start;
188 | }
189 |
190 | void Ray::setEnd(const glm::vec3 & end) {
191 | this->setTransmissionVector(end - this->s);
192 | }
193 |
194 | void Ray::setTransmissionVector(const glm::vec3 & tranmissionVector) {
195 | this->t = tranmissionVector;
196 | this->defined = true;
197 | }
198 |
199 | const glm::vec3 & Ray::getStart() const {
200 | return this->s;
201 | }
202 |
203 | glm::vec3 Ray::getEnd() const {
204 | return this->t + this->s;
205 | }
206 |
207 | const glm::vec3 & Ray::getTransmissionVector() const {
208 | return this->t;
209 | }
210 |
211 | Ray Ray::operator*(float other) const {
212 | return Ray(s, t * other, color, infinite);
213 | }
214 |
215 | glm::vec3 Ray::operator()(float other) const {
216 | return s + other * t;
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/src/ofxRay/Projector.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | //
3 | // Projector.h
4 | // ofxRay
5 | //
6 | // Elliot Woods (C) 2012, MIT license
7 | // http://www.kimchiandchips.com
8 | //
9 | #include "Ray.h"
10 | #include "Base.h"
11 |
12 | namespace ofxRay {
13 | class Projector;
14 | }
15 | ostream& operator<<(ostream &, const ofxRay::Projector &);
16 | istream& operator>>(istream & is, ofxRay::Projector &);
17 |
18 | namespace ofxRay {
19 | typedef std::function(const vector&)> UndistortFunction;
20 |
21 | class Plane;
22 |
23 | ///A class to generate rays given parameters for a projector or camera
24 | ///NB: ofProjector inherits from ofNode, and therefore ofNode stores its view matrix
25 | class Projector : public Base, public ofNode {
26 | public:
27 | Projector(int width=1024, int height=768);
28 | Projector(float throwRatio, const glm::vec2& lensOffset, int width, int height);
29 | Projector(const glm::mat4 & projection, int width, int height);
30 | Projector(const glm::mat4 & view, const glm::mat4 & projection, int width, int height);
31 |
32 | //--
33 | //ofGeometric
34 | //--
35 | //
36 | void draw() const;
37 | void randomiseVectors(float amplitude=1.0f);
38 | //
39 | //--
40 |
41 | ///Choose a random pose, for the projector with scale factor
42 | void randomisePose(float scale=1.0f);
43 |
44 | glm::vec2 distortedPixelToCoordinate(const glm::vec2& xy) const;
45 | glm::vec2 undistortedPixelToCoordinate(const glm::vec2 & xy) const;
46 |
47 | ///Generate a ray for the given pixel coordinates x,y within the projector's image
48 | Ray castPixel(int x, int y, bool isDistorted) const;
49 | Ray castPixel(const glm::vec2& xy, bool isDistorted) const;
50 | void castPixels(const vector& xy, vector& rays, bool isDistorted) const;
51 |
52 | ///Generate a ray for the given normalised coordinate x,y where {-1.0f& xy, vector& rays) const;
55 |
56 | // Generate a ray for the projection center
57 | Ray getProjectionCenterRay() const;
58 |
59 | // Generate a ray for the projector itself (differs from the above if we have lens offset)
60 | Ray getProjectorRay(float distance) const;
61 |
62 | // returns a plane, perpendicular to the projector ray, at the specified distance
63 | Plane getProjectionPlaneAt(float distance, bool infinite = false) const;
64 |
65 | // convert world coordinates, to signed normalized (-1...1) coordinates
66 | glm::vec3 getNormalizedSCoordinateOfWorldPosition(glm::vec3 pointWorld) const;
67 |
68 | // convert world coordinates, to unsigned normalized (0...1) coordinates
69 | glm::vec3 getNormalizedUCoordinateOfWorldPosition(glm::vec3 pointWorld) const;
70 |
71 | // convert world coordinates to screen pixel coordinates
72 | glm::vec3 getScreenCoordinateOfWorldPosition(glm::vec3 pointWorld) const;
73 |
74 | // convert signed normalized (-1...1) coordiantes to world coordinates (pointNorm.z contains distance to projector plane)
75 | glm::vec3 getWorldPositionOfNormalizedSCoordinate(glm::vec3 pointNormS) const;
76 |
77 | // convert unsigned normalized (0...1) coordiantes to world coordinates (pointNorm.z contains distance to projector plane)
78 | glm::vec3 getWorldPositionOfNormalizedUCoordinate(glm::vec3 pointNormU) const;
79 |
80 | // convert screen pixel coordinates to world coordinates (pointScreen.z contains distance to projector plane)
81 | glm::vec3 getWorldPositionOfScreenCoordinate(glm::vec3 pointScreen) const;
82 |
83 |
84 | // void setView(const glm::mat4& m) {
85 | // ofNode::setTransformMatrix(m.getInverse());
86 | // }
87 | void setView(const glm::mat4&);
88 | void setProjection(float throwRatio, const glm::vec2& lensOffset);
89 | void setProjection(const glm::mat4& projection);
90 |
91 | ///Set width of projector. Warning: we will forget our throwRatio and lensOffset
92 | void setWidth(int width);
93 | ///Set height of projector. Warning: we will forget our throwRatio and lensOffset
94 | void setHeight(int height);
95 | int getWidth() const;
96 | int getHeight() const;
97 |
98 | float getThrowRatio() const;
99 | glm::vec2 getLensOffset() const;
100 |
101 | glm::mat4 getViewMatrix() const;
102 | glm::mat4 getProjectionMatrix() const;
103 |
104 | bool isProjectionMatrixInfinite() const;
105 | glm::mat4 getClippedProjectionMatrix() const; ///>) (istream &, Projector &);
128 | protected:
129 | int width;
130 | int height;
131 |
132 | glm::mat4 projection;
133 | static ofMesh* drawBox;
134 |
135 | float nearClip = 0.5f;
136 | float farClip = 20.0f;
137 |
138 | UndistortFunction undistortFunction;
139 |
140 | private:
141 | static void makeBox();
142 |
143 | float throwRatio;
144 | glm::vec2 lensOffset;
145 | };
146 | }
147 |
148 |
--------------------------------------------------------------------------------
/ofxRay_example/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/ofxRay_ofProjectorExample/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/ofxRay_ofPlanePrimitiveExample/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/ofxRayLib/ofxRayLib.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | Release
14 | Win32
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | {048E1EC4-64FE-4AAC-B524-1BD56A1FC726}
23 | ofxRayLib
24 | 10.0
25 |
26 |
27 |
28 | StaticLibrary
29 | true
30 | v142
31 | MultiByte
32 |
33 |
34 | StaticLibrary
35 | true
36 | v142
37 | MultiByte
38 |
39 |
40 | StaticLibrary
41 | false
42 | v142
43 | true
44 | MultiByte
45 |
46 |
47 | StaticLibrary
48 | false
49 | v142
50 | true
51 | MultiByte
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | Level3
80 | Disabled
81 | ..\..\..\addons\ofxRay\src;%(AdditionalIncludeDirectories)
82 | false
83 |
84 |
85 | true
86 |
87 |
88 |
89 |
90 | Level3
91 | Disabled
92 | ..\..\..\addons\ofxRay\src;%(AdditionalIncludeDirectories)
93 | false
94 |
95 |
96 | true
97 |
98 |
99 |
100 |
101 | Level3
102 | MaxSpeed
103 | true
104 | true
105 | ..\..\..\addons\ofxRay\src;%(AdditionalIncludeDirectories)
106 |
107 |
108 | true
109 | true
110 | true
111 |
112 |
113 |
114 |
115 | Level3
116 | MaxSpeed
117 | true
118 | true
119 | ..\..\..\addons\ofxRay\src;%(AdditionalIncludeDirectories)
120 |
121 |
122 | true
123 | true
124 | true
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/src/ofxRay/Plane.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Plane.cpp
3 | // ofxRay
4 | //
5 | // Elliot Woods (C) 2012, MIT license
6 | // http://www.kimchiandchips.com
7 | //
8 |
9 | #include "Plane.h"
10 |
11 | namespace ofxRay {
12 |
13 | Plane::Plane() {
14 | infinite = true;
15 | randomiseVectors();
16 | }
17 |
18 | Plane::Plane(float a, float b, float c, float d) {
19 | // Define plane using
20 | // Ax + By + Cz + D = 0
21 |
22 | glm::vec3 direction(a,b,c);
23 | auto u = -d / glm::dot(direction, direction);
24 | this->setCenter(u * direction);
25 | this->setNormal(glm::normalize(direction));
26 | this->setScale(glm::vec2(1.0f, 1.0f));
27 | infinite = true;
28 | }
29 |
30 | Plane::Plane(const glm::vec3& center, const glm::vec3& normal) {
31 | setCenter(center);
32 | setNormal(normal);
33 | infinite = true;
34 | }
35 |
36 | Plane::Plane(const glm::vec3& center, const glm::vec3& normal, const glm::vec3& up, const glm::vec2& scale){
37 | setCenter(center);
38 | setNormal(normal);
39 | setUp(up);
40 | setScale(scale);
41 | infinite = false;
42 | }
43 |
44 | void Plane::draw() const {
45 | ofPushStyle();
46 | ofSetColor(color);
47 | ofPushMatrix();
48 |
49 | ofTranslate(center);
50 | ofQuaternion q, r;
51 | q.makeRotate(ofVec3f(0,0,1), normal);
52 | r.makeRotate(ofVec3f(0,1,0) * q, up);
53 | float angle, x, y, z;
54 | (q * r).getRotate(angle, x, y, z);
55 | ofRotate(angle, x, y, z);
56 | ofScale(this->scale.x, this->scale.y, 1.0f);
57 |
58 | auto & viewGrid = Plane::getViewGrid();
59 | auto & viewPlane = Plane::getViewPlane();
60 |
61 | viewGrid.draw();
62 |
63 | if (this->infinite) {
64 | ofPushStyle();
65 | ofEnableAlphaBlending();
66 | ofSetColor(color.r, color.g, color.b, 50);
67 | viewPlane.draw();
68 | ofPopStyle();
69 | }
70 |
71 | ofPopMatrix();
72 |
73 | ofDrawArrow(getCenter(), getCenter() + getNormal(), 0.01f);
74 | ofDrawArrow(getCenter(), getCenter() + getUp(), 0.01f);
75 | ofDrawArrow(getCenter(), getCenter() + getRight(), 0.01f);
76 | ofPopStyle();
77 | }
78 |
79 | void Plane::randomiseVectors(float amplitude) {
80 | center = glm::vec3(ofRandom(-1.0f, 1.0f),
81 | ofRandom(-1.0f, 1.0f),
82 | ofRandom(-1.0f, 1.0f)) * amplitude;
83 | normal = glm::vec3(ofRandom(-1.0f, 1.0f),
84 | ofRandom(-1.0f, 1.0f),
85 | ofRandom(-1.0f, 1.0f));
86 | up = glm::vec3(ofRandom(-1.0f, 1.0f),
87 | ofRandom(-1.0f, 1.0f),
88 | ofRandom(-1.0f, 1.0f));
89 | scale = glm::vec2(ofRandom(-1.0f, 1.0f),
90 | ofRandom(-1.0f, 1.0f)) * amplitude;
91 | normal = glm::normalize(normal);
92 | infinite = true;
93 | }
94 |
95 | bool Plane::intersect(const Ray &ray) const {
96 | glm::vec3 position;
97 | return intersect(ray, position);
98 | }
99 |
100 | bool Plane::intersect(const Ray &ray, glm::vec3 &position) const {
101 | //check if line is parallel to plane
102 | //if so, die young
103 | if (glm::dot(ray.t, normal) == 0.0f)
104 | return false;
105 |
106 | float u = glm::dot(normal, center - ray.s) / glm::dot(normal, ray.t);
107 | position = ray.s + u * ray.t;
108 |
109 |
110 | if (!ray.infinite) {
111 | //check within line segment
112 | if (u < 0.0f || u > 1.0f)
113 | return false;
114 | }
115 |
116 | if (!this->infinite) {
117 | //check within plane segment
118 |
119 | //define up as ray, find distance between this ray and ray<> plane intersection point to get x position in plane
120 | float r2 = glm::length2(center - position);
121 | float x = getUpRay().distanceTo(position);
122 | float y2 = r2 - x * x;
123 | float y = y2 >= 0 ? sqrt(y2) : sqrt(-y2);
124 |
125 | //if length along this ray < height and distance of point to ray < width then we're in the plane
126 | if (abs(x) <= scale.x && abs(y) <= scale.y)
127 | return true;
128 | else
129 | return false;
130 |
131 | } else
132 | return true;
133 | }
134 |
135 | glm::vec3 Plane::reflect(const glm::vec3 & position) const {
136 | auto distance = glm::dot(position - this->center,this->normal);
137 | return position - 2 * distance * this->normal;
138 | }
139 |
140 | const glm::vec3& Plane::getCenter() const {
141 | return this->center;
142 | }
143 |
144 | const glm::vec3& Plane::getNormal() const {
145 | return this->normal;
146 | }
147 |
148 | const glm::vec3& Plane::getUp() const {
149 | return this->up;
150 | }
151 |
152 | const glm::vec2& Plane::getScale() const{
153 | return this->scale;
154 | }
155 |
156 | glm::vec4 Plane::getABCD() const {
157 | glm::vec4 ABCD;
158 | ABCD.x = this->normal.x;
159 | ABCD.y = this->normal.y;
160 | ABCD.z = this->normal.z;
161 | ABCD.w = - glm::dot(this->normal, this->center);
162 | return ABCD;
163 | }
164 |
165 | bool Plane::getInfinite() const {
166 | return this->infinite;
167 | }
168 |
169 | void Plane::setCenter(const glm::vec3& center) {
170 | this->center = center;
171 | }
172 |
173 | void Plane::setNormal(const glm::vec3& normal) {
174 | this->normal = glm::normalize(normal);
175 | setUp(this->up); //reset up (to ensure orthogonal to normal)
176 | }
177 |
178 | void Plane::setUp(const glm::vec3& up) {
179 | this->up = up;
180 | //remove component of up which is parallel to the normal
181 | this->up = this->up - this->normal * glm::dot(this->up,this->normal);
182 | this->up = glm::normalize(this->up);
183 | }
184 |
185 | void Plane::setScale(const glm::vec2& scale) {
186 | this->scale = scale;
187 | }
188 |
189 | void Plane::setInfinite(const bool b) {
190 | infinite = b;
191 | }
192 |
193 | void Plane::setFrom(ofPlanePrimitive & planePrimitive) {
194 | // const ofMatrix4x4 transform = planePrimitive.getLocalTransformMatrix();
195 | glm::vec3 translation = planePrimitive.getGlobalPosition();
196 | glm::vec3 scale = planePrimitive.getGlobalScale();
197 | glm::quat rotation = planePrimitive.getGlobalOrientation();
198 | // transform.decompose(translation, rotation, scale, so);
199 |
200 | this->setScale(scale * glm::vec2(planePrimitive.getWidth(), planePrimitive.getHeight()) / 2.0f);
201 | this->setCenter(translation);
202 |
203 | this->setNormal(rotation * glm::vec3(0.0f, 0.0f, 1.0f));
204 | this->setUp(rotation * glm::vec3(0.0f, 1.0f, 0.0f));
205 |
206 | this->setInfinite(false);
207 | }
208 |
209 | void Plane::getCornerRaysTo(const glm::vec3 &target, Ray* rays) const {
210 | glm::vec3 up = this->up * scale.y;
211 | glm::vec3 right = getRight() * scale.x;
212 | glm::vec3 corner;
213 |
214 | corner = center - up - right;
215 | *rays++ = Ray(corner, target - corner, color, false);
216 |
217 | corner = center - up + right;
218 | *rays++ = Ray(corner, target - corner, color, false);
219 |
220 | corner = center + up + right;
221 | *rays++ = Ray(corner, target - corner, color, false);
222 |
223 | corner = center + up - right;
224 | *rays++ = Ray(corner, target - corner, color, false);
225 | }
226 |
227 | void Plane::getCornerRaysFrom(const glm::vec3 &source, Ray* rays) const {
228 | glm::vec3 up = this->up * scale.y;
229 | glm::vec3 right = getRight() * scale.x;
230 | glm::vec3 corner;
231 |
232 | corner = center - up - right;
233 | *rays++ = Ray(source, corner - source, color, false);
234 |
235 | corner = center - up + right;
236 | *rays++ = Ray(source, corner - source, color, false);
237 |
238 | corner = center + up + right;
239 | *rays++ = Ray(source, corner - source, color, false);
240 |
241 | corner = center + up - right;
242 | *rays++ = Ray(source, corner - source, color, false);
243 | }
244 |
245 | //http://mathinsight.org/distance_point_plane
246 | float Plane::getDistanceTo(const glm::vec3 & point) const {
247 | const auto ABCD = this->getABCD();
248 | const auto ABC = glm::vec3(ABCD.x, ABCD.y, ABCD.z);
249 | const auto numerator = abs(glm::dot(normal, point) + ABCD.w);
250 | const auto denominator = glm::length(ABC);
251 | return numerator / denominator;
252 | }
253 |
254 | ofMesh & Plane::getViewGrid() {
255 | static unique_ptr viewGrid;
256 | if (!viewGrid) {
257 | vector vertices((2.0f / 0.25 + 1) * 4);
258 | int i = 0;
259 | for (float y = -1.0f; y <= 1.0f; y += 0.25f) {
260 | vertices[i++] = glm::vec3(-1.0f, y, 0.0f);
261 | vertices[i++] = glm::vec3(+1.0f, y, 0.0f);
262 | }
263 | cout << endl;
264 | for (float x = 1.0f; x >= -1.0f; x -= 0.25f) {
265 | vertices[i++] = glm::vec3(x, 1.0f, 0.0f);
266 | vertices[i++] = glm::vec3(x, -1.0f, 0.0f);
267 | }
268 |
269 | viewGrid = make_unique();
270 | viewGrid->addVertices(vertices);
271 | viewGrid->setMode(OF_PRIMITIVE_LINES);
272 | }
273 |
274 | return *viewGrid;
275 | }
276 |
277 |
278 | ofMesh & Plane::getViewPlane() {
279 | static unique_ptr viewPlane;
280 | if (!viewPlane) {
281 | viewPlane = make_unique();
282 | vector vertices(4);
283 | vertices[0] = glm::vec3(-1000.0f, -1000.0f, 0.0f);
284 | vertices[1] = glm::vec3(+1000.0f, -1000.0f, 0.0f);
285 | vertices[2] = glm::vec3(-1000.0f, +1000.0f, 0.0f);
286 | vertices[3] = glm::vec3(-1000.0f, +1000.0f, 0.0f);
287 | viewPlane->addVertices(vertices);
288 | viewPlane->setMode(OF_PRIMITIVE_TRIANGLE_FAN);
289 | }
290 | return *viewPlane;
291 | }
292 |
293 | glm::vec3 Plane::getRight() const {
294 | return glm::normalize(glm::cross(up, normal));
295 | // return up.getCrossed(normal).normalize();
296 | }
297 |
298 | Ray Plane::getUpRay() const {
299 | return Ray(this->center, this->up);
300 | }
301 |
302 | Ray Plane::getRightRay() const {
303 | return Ray(this->center, getRight());
304 | }
305 | }
306 |
307 | ostream& operator<<(ostream & os, const ofxRay::Plane & plane) {
308 | os << plane.getCenter();
309 | os << "; ";
310 | os << plane.getNormal();
311 | os << "; ";
312 | os << plane.getInfinite();
313 | os << "; ";
314 | os << plane.getUp();
315 | os << "; ";
316 | os << plane.getScale();
317 | os << "; ";
318 | os << (const ofxRay::Base &)plane;
319 | return os;
320 | }
321 |
322 | istream& operator >> (istream & is, ofxRay::Plane & plane) {
323 | glm::vec3 center;
324 | glm::vec3 normal;
325 | bool infinite;
326 | glm::vec3 up;
327 | glm::vec2 scale;
328 |
329 | is >> center;
330 | is.ignore(2);
331 | is >> normal;
332 | is.ignore(2);
333 | is >> infinite;
334 | is.ignore(2);
335 | is >> up;
336 | is.ignore(2);
337 | is >> scale;
338 | is.ignore(2);
339 |
340 | plane.setCenter(center);
341 | plane.setNormal(normal);
342 | plane.setInfinite(infinite);
343 | plane.setUp(up);
344 | plane.setScale(scale);
345 |
346 | is >> (ofxRay::Base &)plane;
347 | return is;
348 | }
349 |
--------------------------------------------------------------------------------
/src/ofxRay/Plane_fitToPoints.cpp:
--------------------------------------------------------------------------------
1 | #include "Plane.h"
2 |
3 | #ifndef UINT
4 | #define UINT unsigned int
5 | #endif
6 |
7 | using namespace std;
8 |
9 | /* This routine finds the scatter matrix of a number of points equal
10 | ** to "Points_Total". The x,y and z coordinates of the points are
11 | ** stored in the "X_Coord", "Y_Coord" and "Z_Coord" arrays. "Centroid"
12 | ** is a 3-element array containing the center of gravity of the set
13 | ** of points. The scatter matrix will be returned in the 3x3 array
14 | ** called "ScatterMatrix". The xyz placement in the Scatter Matrix
15 | ** will be returned by the 3 element array "Order", where the index
16 | ** of Order indicates the column (and row) in "ScatterMatrix", and
17 | ** a value of 0 means x, 1 means y, and 2 means z.
18 | */
19 |
20 | void Find_ScatterMatrix(
21 | const vector &Points,
22 | const glm::vec3 &Centroid,
23 | float ScatterMatrix[3][3],
24 | int Order[3]
25 | ){
26 | int i, TempI;
27 | float TempD;
28 |
29 | /* To compute the correct scatter matrix, the centroid must be
30 | ** subtracted from all points. If the plane is to be forced to pass
31 | ** through the origin (0,0,0), then the Centroid was earlier set
32 | ** equal to (0,0,0). This, of course, is NOT the true Centroid of
33 | ** the set of points! Since the matrix is symmetrical about its
34 | ** diagonal, one-third of it is redundant and is simply found at
35 | ** the end.
36 | */
37 | for (i = 0; i<3; i++){
38 | ScatterMatrix[i][0] = ScatterMatrix[i][1] = ScatterMatrix[i][2] = 0;
39 | }
40 |
41 | for (UINT i = 0; i < Points.size(); i++)
42 | {
43 | const glm::vec4 &P = Points[i];
44 | glm::vec3 d = glm::vec3(P.x, P.y, P.z) - Centroid;
45 | float Weight = P.w;
46 | ScatterMatrix[0][0] += d.x*d.x*Weight;
47 | ScatterMatrix[0][1] += d.x*d.y*Weight;
48 | ScatterMatrix[0][2] += d.x*d.z*Weight;
49 | ScatterMatrix[1][1] += d.y*d.y*Weight;
50 | ScatterMatrix[1][2] += d.y*d.z*Weight;
51 | ScatterMatrix[2][2] += d.z*d.z*Weight;
52 | }
53 | ScatterMatrix[1][0] = ScatterMatrix[0][1];
54 | ScatterMatrix[2][0] = ScatterMatrix[0][2];
55 | ScatterMatrix[2][1] = ScatterMatrix[1][2];
56 |
57 | /* Now, perform a sort of "Matrix-sort", whereby all the larger elements
58 | ** in the matrix are relocated towards the lower-right portion of the
59 | ** matrix. This is done as a requisite of the tred2 and tqli algorithms,
60 | ** for which the scatter matrix is being computed as an input.
61 | ** "Order" is a 3 element array that will keep track of the xyz order
62 | ** in the ScatterMatrix.
63 | */
64 | Order[0] = 0; /* Beginning order is x-y-z, as found above */
65 | Order[1] = 1;
66 | Order[2] = 2;
67 | if (ScatterMatrix[0][0] > ScatterMatrix[1][1]){
68 | TempD = ScatterMatrix[0][0];
69 | ScatterMatrix[0][0] = ScatterMatrix[1][1];
70 | ScatterMatrix[1][1] = TempD;
71 | TempD = ScatterMatrix[0][2];
72 | ScatterMatrix[0][2] = ScatterMatrix[2][0] = ScatterMatrix[1][2];
73 | ScatterMatrix[1][2] = ScatterMatrix[2][1] = TempD;
74 | TempI = Order[0];
75 | Order[0] = Order[1];
76 | Order[1] = TempI;
77 | }
78 | if (ScatterMatrix[1][1] > ScatterMatrix[2][2]){
79 | TempD = ScatterMatrix[1][1];
80 | ScatterMatrix[1][1] = ScatterMatrix[2][2];
81 | ScatterMatrix[2][2] = TempD;
82 | TempD = ScatterMatrix[0][1];
83 | ScatterMatrix[0][1] = ScatterMatrix[1][0] = ScatterMatrix[0][2];
84 | ScatterMatrix[0][2] = ScatterMatrix[2][0] = TempD;
85 | TempI = Order[1];
86 | Order[1] = Order[2];
87 | Order[2] = TempI;
88 | }
89 | if (ScatterMatrix[0][0] > ScatterMatrix[1][1]){
90 | TempD = ScatterMatrix[0][0];
91 | ScatterMatrix[0][0] = ScatterMatrix[1][1];
92 | ScatterMatrix[1][1] = TempD;
93 | TempD = ScatterMatrix[0][2];
94 | ScatterMatrix[0][2] = ScatterMatrix[2][0] = ScatterMatrix[1][2];
95 | ScatterMatrix[1][2] = ScatterMatrix[2][1] = TempD;
96 | TempI = Order[0];
97 | Order[0] = Order[1];
98 | Order[1] = TempI;
99 | }
100 | }
101 |
102 |
103 |
104 | /*
105 | ** This code is taken from ``Numerical Recipes in C'', 2nd
106 | ** and 3rd editions, by Press, Teukolsky, Vetterling and
107 | ** Flannery, Cambridge University Press, 1992, 1994.
108 | **
109 | */
110 |
111 | /*
112 | ** tred2 Householder reduction of a float, symmetric matrix a[1..n][1..n].
113 | ** On output, a is replaced by the orthogonal matrix q effecting the
114 | ** transformation. d[1..n] returns the diagonal elements of the
115 | ** tridiagonal matrix, and e[1..n] the off-diagonal elements, with
116 | ** e[1]=0.
117 | **
118 | ** For my problem, I only need to handle a 3x3 symmetric matrix,
119 | ** so it can be simplified.
120 | ** Therefore n=3.
121 | **
122 | ** Attention: in the book, the index for array starts from 1,
123 | ** but in C, index should start from zero. so I need to modify it.
124 | ** I think it is very simple to modify, just substract 1 from all the
125 | ** index.
126 | */
127 |
128 | #define SIGN(a,b) ((b)<0? -fabs(a):fabs(a))
129 |
130 | void tred2(float a[3][3], float d[3], float e[3]){
131 | int l, k, i, j;
132 | float scale, hh, h, g, f;
133 |
134 | for (i = 3; i >= 2; i--)
135 | {
136 | l = i - 1;
137 | h = scale = 0.0;
138 | if (l>1)
139 | {
140 | for (k = 1; k <= l; k++)
141 | scale += fabs(a[i - 1][k - 1]);
142 | if (scale == 0.0) /* skip transformation */
143 | e[i - 1] = a[i - 1][l - 1];
144 | else
145 | {
146 | for (k = 1; k <= l; k++)
147 | {
148 | a[i - 1][k - 1] /= scale; /* use scaled a's for transformation. */
149 | h += a[i - 1][k - 1] * a[i - 1][k - 1]; /* form sigma in h. */
150 | }
151 | f = a[i - 1][l - 1];
152 | g = f>0 ? -sqrt(h) : sqrt(h);
153 | e[i - 1] = scale*g;
154 | h -= f*g; /* now h is equation (11.2.4) */
155 | a[i - 1][l - 1] = f - g; /* store u in the ith row of a. */
156 | f = 0.0;
157 | for (j = 1; j <= l; j++)
158 | {
159 | a[j - 1][i - 1] = a[i - 1][j - 1] / h; /* store u/H in ith column of a. */
160 | g = 0.0; /* form an element of A.u in g */
161 | for (k = 1; k <= j; k++)
162 | g += a[j - 1][k - 1] * a[i - 1][k - 1];
163 | for (k = j + 1; k <= l; k++)
164 | g += a[k - 1][j - 1] * a[i - 1][k - 1];
165 | e[j - 1] = g / h; /* form element of p in temorarliy unused element of e. */
166 | f += e[j - 1] * a[i - 1][j - 1];
167 | }
168 | hh = f / (h + h); /* form K, equation (11.2.11) */
169 | for (j = 1; j <= l; j++) /* form q and store in e overwriting p. */
170 | {
171 | f = a[i - 1][j - 1]; /* Note that e[l]=e[i-1] survives */
172 | e[j - 1] = g = e[j - 1] - hh*f;
173 | for (k = 1; k <= j; k++) /* reduce a, equation (11.2.13) */
174 | a[j - 1][k - 1] -= (f*e[k - 1] + g*a[i - 1][k - 1]);
175 | }
176 | }
177 | }
178 | else
179 | e[i - 1] = a[i - 1][l - 1];
180 | d[i - 1] = h;
181 | }
182 |
183 |
184 | /*
185 | ** For computing eigenvector.
186 | */
187 | d[0] = 0.0;
188 | e[0] = 0.0;
189 |
190 | for (i = 1; i <= 3; i++)/* begin accumualting of transfomation matrices */
191 | {
192 | l = i - 1;
193 | if (d[i - 1]) /* this block skipped when i=1 */
194 | {
195 | for (j = 1; j <= l; j++)
196 | {
197 | g = 0.0;
198 | for (k = 1; k <= l; k++) /* use u and u/H stored in a to form P.Q */
199 | g += a[i - 1][k - 1] * a[k - 1][j - 1];
200 | for (k = 1; k <= l; k++)
201 | a[k - 1][j - 1] -= g*a[k - 1][i - 1];
202 | }
203 | }
204 | d[i - 1] = a[i - 1][i - 1];
205 | a[i - 1][i - 1] = 1.0; /* reset row and column of a to identity matrix for next iteration */
206 | for (j = 1; j <= l; j++)
207 | a[j - 1][i - 1] = a[i - 1][j - 1] = 0.0;
208 | }
209 | }
210 |
211 |
212 |
213 | /*
214 | ** QL algo with implicit shift, to determine the eigenvalues and
215 | ** eigenvectors of a float,symmetric tridiagonal matrix, or of a float,
216 | ** symmetric matrix previously reduced by algo tred2.
217 | ** On input , d[1..n] contains the diagonal elements of the tridiagonal
218 | ** matrix. On output, it returns the eigenvalues. The vector e[1..n]
219 | ** inputs the subdiagonal elements of the tridiagonal matrix, with e[1]
220 | ** arbitrary. On output e is destroyed. If the eigenvectors of a
221 | ** tridiagonal matrix are desired, the matrix z[1..n][1..n] is input
222 | ** as the identity matrix. If the eigenvectors of a matrix that has
223 | ** been reduced by tred2 are required, then z is input as the matrix
224 | ** output by tred2. In either case, the kth column of z returns the
225 | ** normalized eigenvector corresponding to d[k].
226 | **
227 | */
228 | void tqli(float d[3], float e[3], float z[3][3]){
229 | int m, l, iter, i, k;
230 | float s, r, p, g, f, dd, c, b;
231 |
232 | for (i = 2; i <= 3; i++)
233 | e[i - 2] = e[i - 1]; /* convenient to renumber the elements of e */
234 | e[2] = 0.0;
235 | for (l = 1; l <= 3; l++)
236 | {
237 | iter = 0;
238 | do
239 | {
240 | for (m = l; m <= 2; m++)
241 | {
242 | /*
243 | ** Look for a single small subdiagonal element
244 | ** to split the matrix.
245 | */
246 | dd = fabs(d[m - 1]) + fabs(d[m]);
247 | if (fabs(e[m - 1]) + dd == dd)
248 | break;
249 | }
250 | if (m != l)
251 | {
252 | if (iter++ == 30)
253 | {
254 | printf("\nToo many iterations in TQLI");
255 | }
256 | g = (d[l] - d[l - 1]) / (2.0f*e[l - 1]); /* form shift */
257 | r = sqrt((g*g) + 1.0f);
258 | g = d[m - 1] - d[l - 1] + e[l - 1] / (g + SIGN(r, g)); /* this is dm-ks */
259 | s = c = 1.0;
260 | p = 0.0;
261 | for (i = m - 1; i >= l; i--)
262 | {
263 | /*
264 | ** A plane rotation as in the original
265 | ** QL, followed by Givens rotations to
266 | ** restore tridiagonal form.
267 | */
268 | f = s*e[i - 1];
269 | b = c*e[i - 1];
270 | if (fabs(f) >= fabs(g))
271 | {
272 | c = g / f;
273 | r = sqrt((c*c) + 1.0f);
274 | e[i] = f*r;
275 | c *= (s = 1.0f / r);
276 | }
277 | else
278 | {
279 | s = f / g;
280 | r = sqrt((s*s) + 1.0f);
281 | e[i] = g*r;
282 | s *= (c = 1.0f / r);
283 | }
284 | g = d[i] - p;
285 | r = (d[i - 1] - g)*s + 2.0f*c*b;
286 | p = s*r;
287 | d[i] = g + p;
288 | g = c*r - b;
289 | for (k = 1; k <= 3; k++)
290 | {
291 | /*
292 | ** Form eigenvectors
293 | */
294 | f = z[k - 1][i];
295 | z[k - 1][i] = s*z[k - 1][i - 1] + c*f;
296 | z[k - 1][i - 1] = c*z[k - 1][i - 1] - s*f;
297 | }
298 | }
299 | d[l - 1] = d[l - 1] - p;
300 | e[l - 1] = g;
301 | e[m - 1] = 0.0f;
302 | }
303 | } while (m != l);
304 | }
305 | }
306 |
307 | bool isValid(const glm::vec3 & vector) {
308 | for (int i = 0; i < 3; i++) {
309 | if (vector[i] != vector[i]) {
310 | return false;
311 | }
312 | }
313 | return true;
314 | }
315 |
316 | bool FitPlaneToPoints(ofxRay::Plane & plane, const vector &Points, glm::vec3 &Basis1, glm::vec3 &Basis2, float &NormalEigenvalue, float &ResidualError)
317 | {
318 | glm::vec3 Centroid, Normal;
319 |
320 | float ScatterMatrix[3][3];
321 | int Order[3];
322 | float DiagonalMatrix[3];
323 | float OffDiagonalMatrix[3];
324 |
325 | // Find centroid
326 | Centroid = glm::vec3();
327 | float TotalWeight = 0.0f;
328 | for (UINT i = 0; i < Points.size(); i++)
329 | {
330 | TotalWeight += Points[i].w;
331 | Centroid += glm::vec3(Points[i].x, Points[i].y, Points[i].z) * Points[i].w;
332 | }
333 | Centroid /= TotalWeight;
334 |
335 | // Compute scatter matrix
336 | Find_ScatterMatrix(Points, Centroid, ScatterMatrix, Order);
337 |
338 | tred2(ScatterMatrix, DiagonalMatrix, OffDiagonalMatrix);
339 | tqli(DiagonalMatrix, OffDiagonalMatrix, ScatterMatrix);
340 |
341 | /*
342 | ** Find the smallest eigenvalue first.
343 | */
344 | float Min = DiagonalMatrix[0];
345 | float Max = DiagonalMatrix[0];
346 | UINT MinIndex = 0;
347 | UINT MiddleIndex = 0;
348 | UINT MaxIndex = 0;
349 | for (UINT i = 1; i < 3; i++)
350 | {
351 | if (DiagonalMatrix[i] < Min)
352 | {
353 | Min = DiagonalMatrix[i];
354 | MinIndex = i;
355 | }
356 | if (DiagonalMatrix[i] > Max)
357 | {
358 | Max = DiagonalMatrix[i];
359 | MaxIndex = i;
360 | }
361 | }
362 | for (UINT i = 0; i < 3; i++)
363 | {
364 | if (MinIndex != i && MaxIndex != i)
365 | {
366 | MiddleIndex = i;
367 | }
368 | }
369 | /*
370 | ** The normal of the plane is the smallest eigenvector.
371 | */
372 | for (UINT i = 0; i < 3; i++)
373 | {
374 | Normal[Order[i]] = ScatterMatrix[i][MinIndex];
375 | Basis1[Order[i]] = ScatterMatrix[i][MiddleIndex];
376 | Basis2[Order[i]] = ScatterMatrix[i][MaxIndex];
377 | }
378 | NormalEigenvalue = abs(DiagonalMatrix[MinIndex]);
379 | Basis1 *= (DiagonalMatrix[MiddleIndex]) / length(Basis1);
380 | Basis2 *= (DiagonalMatrix[MaxIndex]) / glm::length(Basis2);
381 |
382 | if (!isValid(Basis1) || !isValid(Basis2) || !isValid(Normal))
383 | {
384 | plane.setCenter(Centroid);
385 | plane.setNormal(glm::vec3(1, 0, 0));
386 | Basis1 = glm::vec3(0, 1, 0);
387 | Basis2 = glm::vec3(0, 0, 1);
388 | }
389 | else
390 | {
391 | plane.setCenter(Centroid);
392 | plane.setNormal(Normal);
393 | }
394 |
395 | ResidualError = 0.0f;
396 | for (UINT i = 0; i < Points.size(); i++)
397 | {
398 | ResidualError += plane.getDistanceTo(glm::vec3(Points[i].x, Points[i].y, Points[i].z));
399 | }
400 | ResidualError /= Points.size();
401 |
402 | return true;
403 | }
404 |
405 | bool FitPlaneToPoints(ofxRay::Plane & plane, const vector &Points, float &ResidualError)
406 | {
407 | glm::vec3 Basis1, Basis2;
408 | vector WeightedPoints(Points.size());
409 | for (UINT i = 0; i < Points.size(); i++)
410 | {
411 | WeightedPoints[i] = glm::vec4(Points[i].x, Points[i].y, Points[i].z, 1.0f);
412 | }
413 | float NormalEigenvalue;
414 | return FitPlaneToPoints(plane, WeightedPoints, Basis1, Basis2, NormalEigenvalue, ResidualError);
415 | }
416 |
417 | namespace ofxRay {
418 | bool Plane::fitToPoints(const vector & points, float & residual) {
419 | return FitPlaneToPoints(*this, points, residual);
420 | }
421 | }
422 |
--------------------------------------------------------------------------------
/src/ofxRay/Projector.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Projector.cpp
3 | // ofxRay
4 | //
5 | // Elliot Woods (C) 2012, MIT license
6 | // http://www.kimchiandchips.com
7 | //
8 | #include "ofxRay/Projector.h"
9 | #include "ofxRay/Plane.h"
10 |
11 | #include
12 |
13 | ostream& operator<<(ostream & os, const ofxRay::Projector & projector) {
14 | const auto & node = (ofNode &)projector;
15 |
16 | os << node.getOrientationQuat();//.asVec4(); // handle that no oF serialisation operator for quat
17 | os << ";\n";
18 | os << node.getPosition();
19 | os << ";\n";
20 | os << node.getScale();
21 | // os << node.getLocalTransformMatrix();
22 | os << ";\n";
23 |
24 | os << projector.width << ", " << projector.height;
25 | os << ";\n";
26 | os << projector.throwRatio;
27 | os << ";\n";
28 | os << projector.lensOffset;
29 | os << ";\n";
30 | os << projector.nearClip << ", " << projector.farClip;
31 | os << ";\n";
32 | os << projector.getClippedProjectionMatrix();
33 | os << ";\n";
34 | os << projector.getViewMatrix();
35 | os << ";\n";
36 |
37 |
38 | os << (const ofxRay::Base &) projector;
39 |
40 | return os;
41 | }
42 |
43 | istream& operator>>(istream & is, ofxRay::Projector & projector) {
44 | auto & node = (ofNode &)projector;
45 |
46 | {
47 | glm::quat orientation;
48 | glm::vec3 position;
49 | glm::vec3 scale;
50 |
51 | is >> orientation; // handle that no oF serialisation operator for quat
52 | is.ignore(2);
53 | is >> position;
54 | is.ignore(2);
55 | is >> scale;
56 | is.ignore(2);
57 |
58 | node.setOrientation(orientation);
59 | node.setPosition(position);
60 | node.setScale(scale);
61 | // node.setTransformMatrix(transform);
62 | }
63 |
64 | {
65 | is >> projector.width;
66 | is.ignore(2);
67 | is >> projector.height;
68 | is.ignore(2);
69 | is >> projector.throwRatio;
70 | is.ignore(2);
71 | is >> projector.lensOffset;
72 | is.ignore(2);
73 | is >> projector.nearClip;
74 | is.ignore(2);
75 | is >> projector.farClip;
76 | is.ignore(2);
77 | is >> projector.projection;
78 | is.ignore(2);
79 |
80 | glm::mat4 viewMatrix;
81 | is >> viewMatrix;
82 | is.ignore(2);
83 | }
84 |
85 | is >> (ofxRay::Base &)projector;
86 |
87 | return is;
88 | }
89 |
90 | namespace ofxRay {
91 | ofMesh* Projector::drawBox = 0;
92 |
93 | Projector::Projector(int width, int height) {
94 | *this = Projector(2.0f, glm::vec2(0.0f, 0.5f), width, height);
95 | }
96 |
97 | Projector::Projector(float throwRatio, const glm::vec2& lensOffset, int width, int height) {
98 | this->width = width;
99 | this->height = height;
100 | this->setProjection(throwRatio, lensOffset);
101 | Projector::makeBox();
102 | }
103 |
104 | Projector::Projector(const glm::mat4& projection, int width, int height) {
105 | this->projection = projection;
106 | this->width = width;
107 | this->height = height;
108 | Projector::makeBox();
109 | }
110 |
111 | void Projector::draw() const {
112 | ofPushStyle();
113 | ofSetColor(color);
114 | ofSetLineWidth(3.0f);
115 |
116 | ofPushMatrix();
117 | ofMultMatrix(glm::inverse(getViewMatrix()));
118 | ofMultMatrix(glm::inverse(getClippedProjectionMatrix()));
119 | drawBox->draw();
120 | ofDrawLine(glm::vec3(0.0f,0.0f,-1.0f), glm::vec3(2.0f,0.0f,-1.0f));
121 | ofDrawLine(glm::vec3(0.0f,0.0f,-1.0f), glm::vec3(0.0f,2.0f,-1.0f));
122 | ofPopMatrix();
123 |
124 | ofPopStyle();
125 | }
126 |
127 | void Projector::randomiseVectors(float amplitude) {
128 | randomisePose(amplitude);
129 | }
130 |
131 | void Projector::randomisePose(float scale) {
132 | ((ofNode*)(this))->setGlobalPosition(glm::vec3(ofRandom(-scale, scale),
133 | ofRandom(-scale, scale),
134 | ofRandom(-scale, scale)));
135 | ((ofNode*)(this))->setOrientation(ofQuaternion(ofRandom(360.0f), 0.0f, 1.0f, 0.0f));
136 | }
137 |
138 | glm::vec2 Projector::distortedPixelToCoordinate(const glm::vec2& xy) const {
139 | if (!this->undistortFunction) {
140 | ofLogError("ofxRay::Projector") << "Cannot undistort pixels because no undistort function has been set. First initialise by calling setUndistortFunction(...)";
141 | return this->undistortedPixelToCoordinate(xy);
142 | }
143 | else {
144 | vector distortedImagePoints(1, xy);
145 | auto undistortedImagePoints = this->undistortFunction(distortedImagePoints);
146 | return this->undistortedPixelToCoordinate(undistortedImagePoints.front());
147 | }
148 | }
149 |
150 | glm::vec2 Projector::undistortedPixelToCoordinate(const glm::vec2& xy) const {
151 | return glm::vec2((xy.x + 0.5f) / (float)width * 2.0f - 1.0f
152 | , 1.0f - (xy.y + 0.5f) / (float)height * 2.0f);
153 | }
154 |
155 | Ray Projector::castPixel(int x, int y, bool isDistorted) const {
156 | return castPixel(glm::vec2(x, y), isDistorted);
157 | }
158 |
159 | Ray Projector::castPixel(const glm::vec2& xy, bool isDistorted) const {
160 | if (isDistorted) {
161 | auto coordinate = this->distortedPixelToCoordinate(xy);
162 | return this->castCoordinate(coordinate);
163 | }
164 | else {
165 | return castCoordinate(this->undistortedPixelToCoordinate(xy));
166 | }
167 | }
168 |
169 | void Projector::castPixels(const vector& xy, vector& rays, bool isDistorted) const {
170 | vector undistortedImagePoints;
171 | if (isDistorted) {
172 | if (!this->undistortFunction) {
173 | ofLogError("ofxRay::Projector") << "Cannot undistort pixels because no undistort function has been set. First initialise by calling setUndistortFunction(...)";
174 | undistortedImagePoints = xy;
175 | }
176 | else {
177 | undistortedImagePoints = this->undistortFunction(xy);
178 | }
179 | }
180 | else {
181 | undistortedImagePoints = xy;
182 | }
183 |
184 | vector xyNormalised;
185 | xyNormalised.reserve(xy.size());
186 | vector::const_iterator in;
187 |
188 | for (const auto & undistortedImagePoint : undistortedImagePoints) {
189 | xyNormalised.push_back(this->undistortedPixelToCoordinate(undistortedImagePoint));
190 | }
191 | this->castCoordinates(xyNormalised, rays);
192 | }
193 |
194 | Ray Projector::castCoordinate(const glm::vec2& xy) const {
195 | glm::mat4 matrix = this->getClippedProjectionMatrix();
196 | // matrix.preMult(this->getViewMatrix());
197 | matrix = matrix * this->getViewMatrix();
198 | //sometimes we need to switch that +1.0f for -1.0f in the z
199 | //opengl should be -1.0f, directx should be +1.0f, i think opencv might be +?
200 |
201 | glm::vec4 PosW = glm::inverse(matrix) * glm::vec4(xy.x, xy.y, +1.0f, 1.0f) ;
202 | glm::vec3 t = glm::vec3(PosW / PosW.w) - this->getPosition();
203 | return Ray(this->getPosition(), t, ofColor(255.0f * (xy.x + 1.0f) / 2.0f, 255.0f * (xy.x + 1.0f) / 2.0f, 0.0f), false);
204 | }
205 |
206 | void Projector::castCoordinates(const vector& coordinates, vector& rays) const {
207 | glm::mat4 inverseMatrix = glm::inverse(this->getClippedProjectionMatrix() * this->getViewMatrix());
208 |
209 | glm::vec4 s = glm::vec4(this->getPosition(), 0);
210 | glm::vec4 PosW;
211 | glm::vec3 t;
212 |
213 | rays.clear();
214 | rays.reserve(coordinates.size());
215 |
216 |
217 | for (auto& xy : coordinates){
218 | //we're using OpenGL standard here, i.e. -1.0f is far plane
219 | //in DirectX, +1.0f is far plane
220 | PosW = inverseMatrix * glm::vec4(xy.x, xy.y, +1.0f, 1.0f);
221 | t = (PosW / PosW.w) - s;
222 | rays.push_back(Ray(s, t, ofColor(255.0f * (xy.x + 1.0f) / 2.0f, 255.0f * (xy.y + 1.0f) / 2.0f, 0.0f), false));
223 | }
224 | }
225 |
226 | Ray Projector::getProjectionCenterRay() const {
227 | return Ray(castCoordinate(glm::vec2(0, 0)));
228 | }
229 |
230 | Ray Projector::getProjectorRay(float distance) const {
231 | return Ray(getPosition(), getLookAtDir() * distance, false); // TODO: default distance?
232 | }
233 |
234 | Plane Projector::getProjectionPlaneAt(float distance, bool infinite) const {
235 | Plane plane(getPosition() + getLookAtDir() * distance, -getLookAtDir()); // TODO: not working?
236 | // TODO:
237 | if(!infinite) {} // find corners?
238 | plane.setInfinite(infinite);
239 | plane.setScale(glm::vec2(distance / throwRatio, distance / throwRatio * height / width)); // TODO: better way of doing this?
240 | // TODO: account for lens offset?
241 |
242 | return plane;
243 | }
244 |
245 |
246 |
247 | glm::vec3 Projector::getNormalizedSCoordinateOfWorldPosition(glm::vec3 pointWorld) const {
248 | auto tmp = getClippedProjectionMatrix() * getViewMatrix() * glm::vec4(pointWorld,1);
249 | return glm::vec3(tmp)/tmp.w;
250 | }
251 |
252 | glm::vec3 Projector::getNormalizedUCoordinateOfWorldPosition(glm::vec3 pointWorld) const {
253 | glm::vec3 normS(getNormalizedSCoordinateOfWorldPosition(pointWorld));
254 | return glm::vec3(ofMap(normS.x, -1, 1, 0, 1), ofMap(normS.y, 1, -1, 0, 1), normS.z);
255 | }
256 |
257 | glm::vec3 Projector::getScreenCoordinateOfWorldPosition(glm::vec3 pointWorld) const {
258 | return getNormalizedUCoordinateOfWorldPosition(pointWorld) * glm::vec3(width, height, 1);
259 | }
260 |
261 | glm::vec3 Projector::getWorldPositionOfNormalizedSCoordinate(glm::vec3 pointNormS) const {
262 | auto tmp = glm::inverse(getClippedProjectionMatrix() * getViewMatrix()) * glm::vec4(pointNormS,1);
263 | return glm::vec3(tmp)/tmp.w;
264 | }
265 |
266 | glm::vec3 Projector::getWorldPositionOfNormalizedUCoordinate(glm::vec3 pointNormU) const {
267 | glm::vec3 pointNormS(ofMap(pointNormU.x, 0, 1, -1, 1), ofMap(pointNormU.y, 0, 1, -1, 1), pointNormU.z);
268 | return getWorldPositionOfNormalizedSCoordinate(pointNormS);
269 | }
270 |
271 | glm::vec3 Projector::getWorldPositionOfScreenCoordinate(glm::vec3 pointScreen) const {
272 | return getWorldPositionOfNormalizedUCoordinate(pointScreen / glm::vec3(width, height, 1));
273 | }
274 |
275 | void Projector::setView(const glm::mat4& viewMatrix) {
276 | auto viewInverse = glm::inverse(viewMatrix);
277 | {
278 | glm::vec3 scale;
279 | glm::quat orientation;
280 | glm::vec3 translation, skew;
281 | glm::vec4 perspective;
282 |
283 | glm::decompose(viewInverse
284 | , scale
285 | , orientation
286 | , translation
287 | , skew
288 | , perspective);
289 |
290 | this->setOrientation(orientation);
291 | this->setPosition(translation);
292 | }
293 | }
294 |
295 | void Projector::setProjection(float throwRatio, const glm::vec2& lensOffset) {
296 |
297 |
298 | this->throwRatio = throwRatio;
299 | this->lensOffset = lensOffset;
300 |
301 | //throwRatio, aspectRatio
302 | const float aspectRatio = (float)width / (float)height;
303 | const float fovy = 2.0f * atan(0.5f / (throwRatio * aspectRatio));
304 |
305 |
306 | glm::mat4 projection = glm::perspective(fovy, aspectRatio, 0.1f, 50.0f);
307 | projection = glm::translate(glm::mat4(), {-lensOffset.x* 2.0f, -lensOffset.y * 2.0f, 0.f}) * projection;
308 |
309 | this->projection = projection;
310 | }
311 |
312 | void Projector::setProjection(const glm::mat4& projection) {
313 | this->throwRatio = projection[0][0] / 2.0f;
314 | this->lensOffset = - glm::vec2(projection[2][0], projection[2][1]) / 2.0f;
315 | this->projection = projection;
316 | }
317 |
318 | void Projector::setWidth(int width) {
319 | this->width = width;
320 | }
321 |
322 | void Projector::setHeight(int height) {
323 | this->height = height;
324 | }
325 |
326 | int Projector::getWidth() const {
327 | return this->width;
328 | }
329 |
330 | int Projector::getHeight() const {
331 | return this->height;
332 | }
333 |
334 | float Projector::getThrowRatio() const {
335 | return throwRatio;
336 | }
337 |
338 | glm::vec2 Projector::getLensOffset() const {
339 | return lensOffset;
340 | }
341 |
342 | bool Projector::isProjectionMatrixInfinite() const {
343 | return this->projection[3][2] == 0.0f;
344 | }
345 |
346 | glm::mat4 Projector::getViewMatrix() const {
347 | return glm::inverse(this->getGlobalTransformMatrix());
348 | }
349 |
350 | glm::mat4 Projector::getProjectionMatrix() const {
351 | return this->projection;
352 | }
353 |
354 | glm::mat4 Projector::getClippedProjectionMatrix() const {
355 | if ( this->isProjectionMatrixInfinite() ) {
356 | const float n(this->nearClip);
357 | const float f(this->farClip);
358 | glm::mat4 projection = this->getProjectionMatrix();
359 | projection[2][2] *= (f + n) / (f - n);
360 | projection[3][2] = - (f * n / (f - n));
361 | return projection;
362 | } else
363 | return this->getProjectionMatrix();
364 | }
365 |
366 | void Projector::drawOnNearPlane(ofBaseHasTexture & image, bool nearPlaneFlipped) const {
367 | this->drawOnNearPlane(image.getTexture());
368 | }
369 |
370 | void Projector::drawOnNearPlane(ofTexture & texture, bool nearPlaneFlipped) const {
371 | ofMesh plane;
372 |
373 | glm::mat4 inversed = glm::inverse(this->getClippedProjectionMatrix() * this->getViewMatrix());
374 |
375 | float z = nearPlaneFlipped ? 1.0f : -1.0f;
376 | plane.addVertex(glm::vec3(-1.0f, +1.0f, z));
377 | plane.addTexCoord(glm::vec2(0, 0));
378 | plane.addVertex(glm::vec3(+1.0f, +1.0f, z));
379 | plane.addTexCoord(glm::vec2(this->getWidth(), 0));
380 | plane.addVertex(glm::vec3(-1.0f, -1.0f, z));
381 | plane.addTexCoord(glm::vec2(0, this->getHeight()));
382 | plane.addVertex(glm::vec3(+1.0f, -1.0f, z));
383 | plane.addTexCoord(glm::vec2(this->getWidth(), this->getHeight()));
384 |
385 | plane.addIndex(0);
386 | plane.addIndex(1);
387 | plane.addIndex(2);
388 | plane.addIndex(2);
389 | plane.addIndex(1);
390 | plane.addIndex(3);
391 |
392 | texture.bind();
393 | ofPushMatrix();
394 | ofMultMatrix(inversed);
395 | plane.draw();
396 | ofPopMatrix();
397 | texture.unbind();
398 | }
399 |
400 | void Projector::beginAsCamera(bool flipY) const {
401 | ofPushView();
402 | ofSetMatrixMode(ofMatrixMode::OF_MATRIX_PROJECTION);
403 | ofLoadIdentityMatrix();
404 | if (flipY) {
405 | ofScale(1.0f, -1.0f, 1.0f);
406 | }
407 | ofMultMatrix(getClippedProjectionMatrix());
408 | ofSetMatrixMode(ofMatrixMode::OF_MATRIX_MODELVIEW);
409 | ofLoadMatrix(getViewMatrix());
410 | }
411 |
412 | void Projector::endAsCamera() const {
413 | ofPopView();
414 | }
415 |
416 | void Projector::makeBox() {
417 | if (drawBox != 0)
418 | return;
419 |
420 | vector vertices;
421 | vertices.push_back(glm::vec3(-1, -1, -1));
422 | vertices.push_back(glm::vec3(-1, -1, +1));
423 | vertices.push_back(glm::vec3(-1, +1, +1));
424 | vertices.push_back(glm::vec3(+1, +1, +1));
425 | vertices.push_back(glm::vec3(+1, -1, +1));
426 | vertices.push_back(glm::vec3(+1, -1, -1));
427 | vertices.push_back(glm::vec3(+1, +1, -1));
428 | vertices.push_back(glm::vec3(-1, +1, -1));
429 |
430 | vector indices;
431 | indices.push_back(0);
432 | indices.push_back(1);
433 | indices.push_back(1);
434 | indices.push_back(2);
435 | indices.push_back(2);
436 | indices.push_back(3);
437 | indices.push_back(3);
438 | indices.push_back(4);
439 | indices.push_back(4);
440 | indices.push_back(5);
441 | indices.push_back(5);
442 | indices.push_back(6);
443 | indices.push_back(6);
444 | indices.push_back(7);
445 | indices.push_back(7);
446 | indices.push_back(0);
447 |
448 | indices.push_back(7);
449 | indices.push_back(2);
450 |
451 | indices.push_back(6);
452 | indices.push_back(3);
453 |
454 | indices.push_back(1);
455 | indices.push_back(4);
456 |
457 | indices.push_back(0);
458 | indices.push_back(5);
459 |
460 | drawBox = new ofMesh();
461 | drawBox->addVertices(vertices);
462 | drawBox->addIndices(indices);
463 | drawBox->setMode(OF_PRIMITIVE_LINES);
464 | }
465 |
466 | glm::vec2 Projector::getCoordinateFromIndex(const uint32_t pixelIndex) const {
467 | uint32_t x = pixelIndex % width;
468 | uint32_t y = pixelIndex / width;
469 | return getCoordinateFromIndex(x, y);
470 | }
471 |
472 | glm::vec2 Projector::getCoordinateFromIndex(const uint32_t x, const uint32_t y) const {
473 | return glm::vec2(2.0f * (float(x) + 0.5) / float(width) - 1.0f,
474 | 1.0f - 2.0f * (float(y) + 0.5) / float(height));
475 | }
476 |
477 | glm::vec2 Projector::getIndexFromCoordinate(const glm::vec2& coord) const {
478 | glm::vec2 result = coord;
479 | result.y *= -1.0f;
480 | result += 1.0f;
481 | result *= glm::vec2(this->width, this->height) / 2.0f;
482 | return result;
483 | }
484 |
485 | void Projector::setNearClip(float nearClip) {
486 | this->nearClip = nearClip;
487 | }
488 |
489 | void Projector::setFarClip(float farClip) {
490 | this->farClip = farClip;
491 | }
492 |
493 | void Projector::setUndistortFunction(const UndistortFunction& undistortFunction) {
494 | this->undistortFunction = undistortFunction;
495 | }
496 |
497 | float Projector::getNearClip() const {
498 | return this->nearClip;
499 | }
500 |
501 | float Projector::getFarClip() const {
502 | return this->farClip;
503 | }
504 | }
505 |
--------------------------------------------------------------------------------
/ofxRay_ofPlaneExample/emptyExample.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | B02C49C81B53BE9700AAC853 /* ofxGrabCam.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B02C49C61B53BE9700AAC853 /* ofxGrabCam.cpp */; };
11 | B02C49D81B53BEA400AAC853 /* Base.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B02C49CC1B53BEA400AAC853 /* Base.cpp */; };
12 | B02C49D91B53BEA400AAC853 /* Camera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B02C49CE1B53BEA400AAC853 /* Camera.cpp */; };
13 | B02C49DA1B53BEA400AAC853 /* Plane.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B02C49D01B53BEA400AAC853 /* Plane.cpp */; };
14 | B02C49DB1B53BEA400AAC853 /* Plane_fitToPoints.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B02C49D21B53BEA400AAC853 /* Plane_fitToPoints.cpp */; };
15 | B02C49DC1B53BEA400AAC853 /* Projector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B02C49D31B53BEA400AAC853 /* Projector.cpp */; };
16 | B02C49DD1B53BEA400AAC853 /* Ray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B02C49D51B53BEA400AAC853 /* Ray.cpp */; };
17 | E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E4328148138ABC890047C5CB /* openFrameworksDebug.a */; };
18 | E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1D0A3A1BDC003C02F2 /* main.cpp */; };
19 | E4B69E210A3A1BDC003C02F2 /* ofApp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B69E1E0A3A1BDC003C02F2 /* ofApp.cpp */; };
20 | /* End PBXBuildFile section */
21 |
22 | /* Begin PBXContainerItemProxy section */
23 | E4328147138ABC890047C5CB /* PBXContainerItemProxy */ = {
24 | isa = PBXContainerItemProxy;
25 | containerPortal = E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */;
26 | proxyType = 2;
27 | remoteGlobalIDString = E4B27C1510CBEB8E00536013;
28 | remoteInfo = openFrameworks;
29 | };
30 | E4EEB9AB138B136A00A80321 /* PBXContainerItemProxy */ = {
31 | isa = PBXContainerItemProxy;
32 | containerPortal = E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */;
33 | proxyType = 1;
34 | remoteGlobalIDString = E4B27C1410CBEB8E00536013;
35 | remoteInfo = openFrameworks;
36 | };
37 | /* End PBXContainerItemProxy section */
38 |
39 | /* Begin PBXCopyFilesBuildPhase section */
40 | E4C2427710CC5ABF004149E2 /* CopyFiles */ = {
41 | isa = PBXCopyFilesBuildPhase;
42 | buildActionMask = 2147483647;
43 | dstPath = "";
44 | dstSubfolderSpec = 10;
45 | files = (
46 | );
47 | runOnlyForDeploymentPostprocessing = 0;
48 | };
49 | /* End PBXCopyFilesBuildPhase section */
50 |
51 | /* Begin PBXFileReference section */
52 | B02C49C61B53BE9700AAC853 /* ofxGrabCam.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ofxGrabCam.cpp; sourceTree = ""; };
53 | B02C49C71B53BE9700AAC853 /* ofxGrabCam.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ofxGrabCam.h; sourceTree = ""; };
54 | B02C49CC1B53BEA400AAC853 /* Base.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Base.cpp; sourceTree = ""; };
55 | B02C49CD1B53BEA400AAC853 /* Base.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Base.h; sourceTree = ""; };
56 | B02C49CE1B53BEA400AAC853 /* Camera.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Camera.cpp; sourceTree = ""; };
57 | B02C49CF1B53BEA400AAC853 /* Camera.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Camera.h; sourceTree = ""; };
58 | B02C49D01B53BEA400AAC853 /* Plane.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Plane.cpp; sourceTree = ""; };
59 | B02C49D11B53BEA400AAC853 /* Plane.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Plane.h; sourceTree = ""; };
60 | B02C49D21B53BEA400AAC853 /* Plane_fitToPoints.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Plane_fitToPoints.cpp; sourceTree = ""; };
61 | B02C49D31B53BEA400AAC853 /* Projector.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Projector.cpp; sourceTree = ""; };
62 | B02C49D41B53BEA400AAC853 /* Projector.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Projector.h; sourceTree = ""; };
63 | B02C49D51B53BEA400AAC853 /* Ray.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Ray.cpp; sourceTree = ""; };
64 | B02C49D61B53BEA400AAC853 /* Ray.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Ray.h; sourceTree = ""; };
65 | B02C49D71B53BEA400AAC853 /* ofxRay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ofxRay.h; sourceTree = ""; };
66 | E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = openFrameworksLib.xcodeproj; path = ../../../libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj; sourceTree = SOURCE_ROOT; };
67 | E4B69B5B0A3A1756003C02F2 /* emptyExampleDebug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = emptyExampleDebug.app; sourceTree = BUILT_PRODUCTS_DIR; };
68 | E4B69E1D0A3A1BDC003C02F2 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = main.cpp; path = src/main.cpp; sourceTree = SOURCE_ROOT; };
69 | E4B69E1E0A3A1BDC003C02F2 /* ofApp.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; fileEncoding = 30; name = ofApp.cpp; path = src/ofApp.cpp; sourceTree = SOURCE_ROOT; };
70 | E4B69E1F0A3A1BDC003C02F2 /* ofApp.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ofApp.h; path = src/ofApp.h; sourceTree = SOURCE_ROOT; };
71 | E4B6FCAD0C3E899E008CF71C /* openFrameworks-Info.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.xml; path = "openFrameworks-Info.plist"; sourceTree = ""; };
72 | E4EB691F138AFCF100A09F29 /* CoreOF.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = CoreOF.xcconfig; path = ../../../libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig; sourceTree = SOURCE_ROOT; };
73 | E4EB6923138AFD0F00A09F29 /* Project.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Project.xcconfig; sourceTree = ""; };
74 | /* End PBXFileReference section */
75 |
76 | /* Begin PBXFrameworksBuildPhase section */
77 | E4B69B590A3A1756003C02F2 /* Frameworks */ = {
78 | isa = PBXFrameworksBuildPhase;
79 | buildActionMask = 2147483647;
80 | files = (
81 | E4328149138ABC9F0047C5CB /* openFrameworksDebug.a in Frameworks */,
82 | );
83 | runOnlyForDeploymentPostprocessing = 0;
84 | };
85 | /* End PBXFrameworksBuildPhase section */
86 |
87 | /* Begin PBXGroup section */
88 | B02C49C41B53BE9700AAC853 /* ofxGrabCam */ = {
89 | isa = PBXGroup;
90 | children = (
91 | B02C49C51B53BE9700AAC853 /* src */,
92 | );
93 | name = ofxGrabCam;
94 | sourceTree = "";
95 | };
96 | B02C49C51B53BE9700AAC853 /* src */ = {
97 | isa = PBXGroup;
98 | children = (
99 | B02C49C61B53BE9700AAC853 /* ofxGrabCam.cpp */,
100 | B02C49C71B53BE9700AAC853 /* ofxGrabCam.h */,
101 | );
102 | name = src;
103 | path = ../../ofxGrabCam/src;
104 | sourceTree = "";
105 | };
106 | B02C49C91B53BEA400AAC853 /* ofxRay */ = {
107 | isa = PBXGroup;
108 | children = (
109 | B02C49CA1B53BEA400AAC853 /* src */,
110 | );
111 | name = ofxRay;
112 | sourceTree = "";
113 | };
114 | B02C49CA1B53BEA400AAC853 /* src */ = {
115 | isa = PBXGroup;
116 | children = (
117 | B02C49CB1B53BEA400AAC853 /* ofxRay */,
118 | B02C49D71B53BEA400AAC853 /* ofxRay.h */,
119 | );
120 | name = src;
121 | path = ../src;
122 | sourceTree = "";
123 | };
124 | B02C49CB1B53BEA400AAC853 /* ofxRay */ = {
125 | isa = PBXGroup;
126 | children = (
127 | B02C49CC1B53BEA400AAC853 /* Base.cpp */,
128 | B02C49CD1B53BEA400AAC853 /* Base.h */,
129 | B02C49CE1B53BEA400AAC853 /* Camera.cpp */,
130 | B02C49CF1B53BEA400AAC853 /* Camera.h */,
131 | B02C49D01B53BEA400AAC853 /* Plane.cpp */,
132 | B02C49D11B53BEA400AAC853 /* Plane.h */,
133 | B02C49D21B53BEA400AAC853 /* Plane_fitToPoints.cpp */,
134 | B02C49D31B53BEA400AAC853 /* Projector.cpp */,
135 | B02C49D41B53BEA400AAC853 /* Projector.h */,
136 | B02C49D51B53BEA400AAC853 /* Ray.cpp */,
137 | B02C49D61B53BEA400AAC853 /* Ray.h */,
138 | );
139 | path = ofxRay;
140 | sourceTree = "";
141 | };
142 | BB4B014C10F69532006C3DED /* addons */ = {
143 | isa = PBXGroup;
144 | children = (
145 | B02C49C41B53BE9700AAC853 /* ofxGrabCam */,
146 | B02C49C91B53BEA400AAC853 /* ofxRay */,
147 | );
148 | name = addons;
149 | sourceTree = "";
150 | };
151 | E4328144138ABC890047C5CB /* Products */ = {
152 | isa = PBXGroup;
153 | children = (
154 | E4328148138ABC890047C5CB /* openFrameworksDebug.a */,
155 | );
156 | name = Products;
157 | sourceTree = "";
158 | };
159 | E4B69B4A0A3A1720003C02F2 = {
160 | isa = PBXGroup;
161 | children = (
162 | E4B6FCAD0C3E899E008CF71C /* openFrameworks-Info.plist */,
163 | E4EB6923138AFD0F00A09F29 /* Project.xcconfig */,
164 | E4B69E1C0A3A1BDC003C02F2 /* src */,
165 | E4EEC9E9138DF44700A80321 /* openFrameworks */,
166 | BB4B014C10F69532006C3DED /* addons */,
167 | E4B69B5B0A3A1756003C02F2 /* emptyExampleDebug.app */,
168 | );
169 | sourceTree = "";
170 | };
171 | E4B69E1C0A3A1BDC003C02F2 /* src */ = {
172 | isa = PBXGroup;
173 | children = (
174 | E4B69E1D0A3A1BDC003C02F2 /* main.cpp */,
175 | E4B69E1E0A3A1BDC003C02F2 /* ofApp.cpp */,
176 | E4B69E1F0A3A1BDC003C02F2 /* ofApp.h */,
177 | );
178 | path = src;
179 | sourceTree = SOURCE_ROOT;
180 | };
181 | E4EEC9E9138DF44700A80321 /* openFrameworks */ = {
182 | isa = PBXGroup;
183 | children = (
184 | E4EB691F138AFCF100A09F29 /* CoreOF.xcconfig */,
185 | E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */,
186 | );
187 | name = openFrameworks;
188 | sourceTree = "";
189 | };
190 | /* End PBXGroup section */
191 |
192 | /* Begin PBXNativeTarget section */
193 | E4B69B5A0A3A1756003C02F2 /* emptyExample */ = {
194 | isa = PBXNativeTarget;
195 | buildConfigurationList = E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "emptyExample" */;
196 | buildPhases = (
197 | E4B69B580A3A1756003C02F2 /* Sources */,
198 | E4B69B590A3A1756003C02F2 /* Frameworks */,
199 | E4B6FFFD0C3F9AB9008CF71C /* ShellScript */,
200 | E4C2427710CC5ABF004149E2 /* CopyFiles */,
201 | );
202 | buildRules = (
203 | );
204 | dependencies = (
205 | E4EEB9AC138B136A00A80321 /* PBXTargetDependency */,
206 | );
207 | name = emptyExample;
208 | productName = myOFApp;
209 | productReference = E4B69B5B0A3A1756003C02F2 /* emptyExampleDebug.app */;
210 | productType = "com.apple.product-type.application";
211 | };
212 | /* End PBXNativeTarget section */
213 |
214 | /* Begin PBXProject section */
215 | E4B69B4C0A3A1720003C02F2 /* Project object */ = {
216 | isa = PBXProject;
217 | attributes = {
218 | LastUpgradeCheck = 0600;
219 | };
220 | buildConfigurationList = E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "emptyExample" */;
221 | compatibilityVersion = "Xcode 3.2";
222 | developmentRegion = English;
223 | hasScannedForEncodings = 0;
224 | knownRegions = (
225 | English,
226 | Japanese,
227 | French,
228 | German,
229 | );
230 | mainGroup = E4B69B4A0A3A1720003C02F2;
231 | productRefGroup = E4B69B4A0A3A1720003C02F2;
232 | projectDirPath = "";
233 | projectReferences = (
234 | {
235 | ProductGroup = E4328144138ABC890047C5CB /* Products */;
236 | ProjectRef = E4328143138ABC890047C5CB /* openFrameworksLib.xcodeproj */;
237 | },
238 | );
239 | projectRoot = "";
240 | targets = (
241 | E4B69B5A0A3A1756003C02F2 /* emptyExample */,
242 | );
243 | };
244 | /* End PBXProject section */
245 |
246 | /* Begin PBXReferenceProxy section */
247 | E4328148138ABC890047C5CB /* openFrameworksDebug.a */ = {
248 | isa = PBXReferenceProxy;
249 | fileType = archive.ar;
250 | path = openFrameworksDebug.a;
251 | remoteRef = E4328147138ABC890047C5CB /* PBXContainerItemProxy */;
252 | sourceTree = BUILT_PRODUCTS_DIR;
253 | };
254 | /* End PBXReferenceProxy section */
255 |
256 | /* Begin PBXShellScriptBuildPhase section */
257 | E4B6FFFD0C3F9AB9008CF71C /* ShellScript */ = {
258 | isa = PBXShellScriptBuildPhase;
259 | buildActionMask = 2147483647;
260 | files = (
261 | );
262 | inputPaths = (
263 | );
264 | outputPaths = (
265 | );
266 | runOnlyForDeploymentPostprocessing = 0;
267 | shellPath = /bin/sh;
268 | shellScript = "cp -f ../../../libs/fmodex/lib/osx/libfmodex.dylib \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/libfmodex.dylib\"; install_name_tool -change ./libfmodex.dylib @executable_path/libfmodex.dylib \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME\";\nmkdir -p \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/\"\ncp -f \"$ICON_FILE\" \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Resources/\"\n";
269 | };
270 | /* End PBXShellScriptBuildPhase section */
271 |
272 | /* Begin PBXSourcesBuildPhase section */
273 | E4B69B580A3A1756003C02F2 /* Sources */ = {
274 | isa = PBXSourcesBuildPhase;
275 | buildActionMask = 2147483647;
276 | files = (
277 | B02C49DD1B53BEA400AAC853 /* Ray.cpp in Sources */,
278 | B02C49DA1B53BEA400AAC853 /* Plane.cpp in Sources */,
279 | B02C49D81B53BEA400AAC853 /* Base.cpp in Sources */,
280 | E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */,
281 | B02C49D91B53BEA400AAC853 /* Camera.cpp in Sources */,
282 | E4B69E210A3A1BDC003C02F2 /* ofApp.cpp in Sources */,
283 | B02C49C81B53BE9700AAC853 /* ofxGrabCam.cpp in Sources */,
284 | B02C49DC1B53BEA400AAC853 /* Projector.cpp in Sources */,
285 | B02C49DB1B53BEA400AAC853 /* Plane_fitToPoints.cpp in Sources */,
286 | );
287 | runOnlyForDeploymentPostprocessing = 0;
288 | };
289 | /* End PBXSourcesBuildPhase section */
290 |
291 | /* Begin PBXTargetDependency section */
292 | E4EEB9AC138B136A00A80321 /* PBXTargetDependency */ = {
293 | isa = PBXTargetDependency;
294 | name = openFrameworks;
295 | targetProxy = E4EEB9AB138B136A00A80321 /* PBXContainerItemProxy */;
296 | };
297 | /* End PBXTargetDependency section */
298 |
299 | /* Begin XCBuildConfiguration section */
300 | E4B69B4E0A3A1720003C02F2 /* Debug */ = {
301 | isa = XCBuildConfiguration;
302 | baseConfigurationReference = E4EB6923138AFD0F00A09F29 /* Project.xcconfig */;
303 | buildSettings = {
304 | CONFIGURATION_BUILD_DIR = "$(SRCROOT)/bin/";
305 | COPY_PHASE_STRIP = NO;
306 | DEAD_CODE_STRIPPING = YES;
307 | GCC_AUTO_VECTORIZATION = YES;
308 | GCC_ENABLE_SSE3_EXTENSIONS = YES;
309 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS = YES;
310 | GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
311 | GCC_OPTIMIZATION_LEVEL = 0;
312 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
313 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES;
314 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = NO;
315 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = NO;
316 | GCC_WARN_UNINITIALIZED_AUTOS = NO;
317 | GCC_WARN_UNUSED_VALUE = NO;
318 | GCC_WARN_UNUSED_VARIABLE = NO;
319 | HEADER_SEARCH_PATHS = (
320 | "$(OF_CORE_HEADERS)",
321 | ../../../addons/libs,
322 | ../../../addons/src,
323 | src,
324 | );
325 | MACOSX_DEPLOYMENT_TARGET = 10.8;
326 | ONLY_ACTIVE_ARCH = YES;
327 | OTHER_CPLUSPLUSFLAGS = (
328 | "-D__MACOSX_CORE__",
329 | "-lpthread",
330 | "-mtune=native",
331 | );
332 | SDKROOT = macosx;
333 | };
334 | name = Debug;
335 | };
336 | E4B69B4F0A3A1720003C02F2 /* Release */ = {
337 | isa = XCBuildConfiguration;
338 | baseConfigurationReference = E4EB6923138AFD0F00A09F29 /* Project.xcconfig */;
339 | buildSettings = {
340 | CONFIGURATION_BUILD_DIR = "$(SRCROOT)/bin/";
341 | COPY_PHASE_STRIP = YES;
342 | DEAD_CODE_STRIPPING = YES;
343 | GCC_AUTO_VECTORIZATION = YES;
344 | GCC_ENABLE_SSE3_EXTENSIONS = YES;
345 | GCC_ENABLE_SUPPLEMENTAL_SSE3_INSTRUCTIONS = YES;
346 | GCC_INLINES_ARE_PRIVATE_EXTERN = NO;
347 | GCC_OPTIMIZATION_LEVEL = 3;
348 | GCC_SYMBOLS_PRIVATE_EXTERN = NO;
349 | GCC_UNROLL_LOOPS = YES;
350 | GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES;
351 | GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = NO;
352 | GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = NO;
353 | GCC_WARN_UNINITIALIZED_AUTOS = NO;
354 | GCC_WARN_UNUSED_VALUE = NO;
355 | GCC_WARN_UNUSED_VARIABLE = NO;
356 | HEADER_SEARCH_PATHS = (
357 | "$(OF_CORE_HEADERS)",
358 | ../../../addons/libs,
359 | ../../../addons/src,
360 | src,
361 | );
362 | MACOSX_DEPLOYMENT_TARGET = 10.8;
363 | OTHER_CPLUSPLUSFLAGS = (
364 | "-D__MACOSX_CORE__",
365 | "-lpthread",
366 | "-mtune=native",
367 | );
368 | SDKROOT = macosx;
369 | };
370 | name = Release;
371 | };
372 | E4B69B600A3A1757003C02F2 /* Debug */ = {
373 | isa = XCBuildConfiguration;
374 | baseConfigurationReference = E4EB6923138AFD0F00A09F29 /* Project.xcconfig */;
375 | buildSettings = {
376 | COMBINE_HIDPI_IMAGES = YES;
377 | COPY_PHASE_STRIP = NO;
378 | FRAMEWORK_SEARCH_PATHS = (
379 | "$(inherited)",
380 | "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
381 | );
382 | FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../../../libs/glut/lib/osx\"";
383 | GCC_DYNAMIC_NO_PIC = NO;
384 | GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
385 | GCC_MODEL_TUNING = NONE;
386 | HEADER_SEARCH_PATHS = (
387 | "$(OF_CORE_HEADERS)",
388 | ../../../addons/libs,
389 | ../../../addons/src,
390 | src,
391 | ../../../addons/ofxRay/src,
392 | );
393 | ICON = "$(ICON_NAME_DEBUG)";
394 | ICON_FILE = "$(ICON_FILE_PATH)$(ICON)";
395 | INFOPLIST_FILE = "openFrameworks-Info.plist";
396 | INSTALL_PATH = "$(HOME)/Applications";
397 | LIBRARY_SEARCH_PATHS = "$(inherited)";
398 | PRODUCT_NAME = "$(TARGET_NAME)Debug";
399 | USER_HEADER_SEARCH_PATHS = "";
400 | WRAPPER_EXTENSION = app;
401 | };
402 | name = Debug;
403 | };
404 | E4B69B610A3A1757003C02F2 /* Release */ = {
405 | isa = XCBuildConfiguration;
406 | baseConfigurationReference = E4EB6923138AFD0F00A09F29 /* Project.xcconfig */;
407 | buildSettings = {
408 | COMBINE_HIDPI_IMAGES = YES;
409 | COPY_PHASE_STRIP = YES;
410 | FRAMEWORK_SEARCH_PATHS = (
411 | "$(inherited)",
412 | "$(FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1)",
413 | );
414 | FRAMEWORK_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../../../libs/glut/lib/osx\"";
415 | GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
416 | GCC_MODEL_TUNING = NONE;
417 | HEADER_SEARCH_PATHS = (
418 | "$(OF_CORE_HEADERS)",
419 | ../../../addons/libs,
420 | ../../../addons/src,
421 | src,
422 | ../../../addons/ofxRay/src,
423 | );
424 | ICON = "$(ICON_NAME_RELEASE)";
425 | ICON_FILE = "$(ICON_FILE_PATH)$(ICON)";
426 | INFOPLIST_FILE = "openFrameworks-Info.plist";
427 | INSTALL_PATH = "$(HOME)/Applications";
428 | LIBRARY_SEARCH_PATHS = "$(inherited)";
429 | PRODUCT_NAME = "$(TARGET_NAME)";
430 | USER_HEADER_SEARCH_PATHS = "";
431 | WRAPPER_EXTENSION = app;
432 | baseConfigurationReference = E4EB6923138AFD0F00A09F29;
433 | };
434 | name = Release;
435 | };
436 | /* End XCBuildConfiguration section */
437 |
438 | /* Begin XCConfigurationList section */
439 | E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "emptyExample" */ = {
440 | isa = XCConfigurationList;
441 | buildConfigurations = (
442 | E4B69B4E0A3A1720003C02F2 /* Debug */,
443 | E4B69B4F0A3A1720003C02F2 /* Release */,
444 | );
445 | defaultConfigurationIsVisible = 0;
446 | defaultConfigurationName = Release;
447 | };
448 | E4B69B5F0A3A1757003C02F2 /* Build configuration list for PBXNativeTarget "emptyExample" */ = {
449 | isa = XCConfigurationList;
450 | buildConfigurations = (
451 | E4B69B600A3A1757003C02F2 /* Debug */,
452 | E4B69B610A3A1757003C02F2 /* Release */,
453 | );
454 | defaultConfigurationIsVisible = 0;
455 | defaultConfigurationName = Release;
456 | };
457 | /* End XCConfigurationList section */
458 | };
459 | rootObject = E4B69B4C0A3A1720003C02F2 /* Project object */;
460 | }
461 |
--------------------------------------------------------------------------------