├── .appveyor.yml
├── .gitignore
├── .travis.yml
├── README.md
├── example-3d
├── Makefile
├── Project.xcconfig
├── addons.make
├── bin
│ └── data
│ │ └── .gitkeep
├── config.make
├── example-3d.qbs
├── example-3d.xcodeproj
│ ├── project.pbxproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── example-3d Debug.xcscheme
│ │ └── example-3d Release.xcscheme
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── example-mesh-intersection
├── Makefile
├── Project.xcconfig
├── addons.make
├── bin
│ └── data
│ │ └── .gitkeep
├── config.make
├── example-mesh-intersection.qbs
├── example-mesh-intersection.xcodeproj
│ ├── project.pbxproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── example-mesh-intersection Debug.xcscheme
│ │ └── example-mesh-intersection Release.xcscheme
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── example-mouse-picker
├── Makefile
├── Project.xcconfig
├── addons.make
├── bin
│ └── data
│ │ └── .gitkeep
├── config.make
├── example-mouse-picker.qbs
├── example-mouse-picker.xcodeproj
│ ├── project.pbxproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── example-mouse-picker Debug.xcscheme
│ │ └── example-mouse-picker Release.xcscheme
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── example-multiple-rays
├── Makefile
├── Project.xcconfig
├── addons.make
├── bin
│ └── data
│ │ └── .gitkeep
├── config.make
├── example-multiple-rays.qbs
├── example-multiple-rays.xcodeproj
│ ├── project.pbxproj
│ └── xcshareddata
│ │ └── xcschemes
│ │ ├── example-multiple-rays Debug.xcscheme
│ │ └── example-multiple-rays Release.xcscheme
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── example-polyline-intersection
├── Makefile
├── Project.xcconfig
├── addons.make
├── bin
│ └── data
│ │ └── .gitkeep
├── config.make
├── example-polyline-intersection.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ └── da1.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ ├── xcshareddata
│ │ └── xcschemes
│ │ │ ├── example-polyline-intersection Debug.xcscheme
│ │ │ └── example-polyline-intersection Release.xcscheme
│ └── xcuserdata
│ │ └── da1.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── example-segment-intersection
├── Makefile
├── Project.xcconfig
├── addons.make
├── bin
│ └── data
│ │ └── .gitkeep
├── config.make
├── example-segment-intersection.qbs
├── example-segment-intersection.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ └── da1.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ ├── xcshareddata
│ │ └── xcschemes
│ │ │ ├── example-segment-intersection Debug.xcscheme
│ │ │ └── example-segment-intersection Release.xcscheme
│ └── xcuserdata
│ │ └── da1.xcuserdatad
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
├── openFrameworks-Info.plist
└── src
│ ├── main.cpp
│ ├── ofApp.cpp
│ └── ofApp.h
├── img
├── 3D.gif
├── example-3d.png
├── example-multiple-rays.png
├── example-polyline-intersection.png
├── example-segment-intersection.png
├── mesh-intersection.gif
├── mousepicker.gif
├── multiple-rays.gif
├── polyline.gif
├── screenshot.png
└── segment.gif
└── src
├── Mousepicker.cpp
├── Mousepicker.h
├── Plane.cpp
├── Plane.h
├── Ray.cpp
├── Ray.h
├── Ray2D.cpp
├── Ray2D.h
└── ofxRaycaster.h
/.appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 1.0.{build}
2 |
3 | environment:
4 | global:
5 | APPVEYOR_OS_NAME: windows
6 | matrix:
7 | #MSYS2 Building
8 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
9 | platform: x86
10 | BUILDER: MSYS2
11 |
12 | #VisualStudio Building
13 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
14 | platform: x86
15 | BUILDER : VS
16 | BITS: 32
17 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
18 | platform: x64
19 | BUILDER : VS
20 | BITS: 64
21 |
22 | configuration: Debug
23 | shallow_clone: true
24 | clone_depth: 10
25 |
26 | init:
27 | - set MSYS2_PATH=c:\msys64
28 | - set CHERE_INVOKING=1
29 | - if "%BUILDER%_%PLATFORM%"=="MSYS2_x86" set MSYSTEM=MINGW32
30 | - if "%BUILDER%_%PLATFORM%"=="MSYS2_x64" set MSYSTEM=MINGW64
31 | - '%MSYS2_PATH%\usr\bin\bash -lc "pacman --noconfirm -S --needed unzip rsync"'
32 | - if "%BUILDER%"=="VS" set PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin;%PATH%
33 |
34 | install:
35 | - cd ..
36 | - git clone --depth=1 --branch=master https://github.com/openframeworks/openFrameworks
37 | - call openFrameworks\scripts\ci\addons\install.cmd
38 |
39 | build_script:
40 | - cd %OF_PATH%
41 | - scripts\ci\addons\build.cmd
42 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.xcuserstate
3 | *.xcscmblueprint
4 | */bin/*
5 | *.app
6 | !*/bin/data
7 | */obj
8 | RemoteSystemsTempFiles/
9 | .metadata
10 | */.project
11 | */.cproject
12 | */.settings
13 | */*/project.xcworkspace/**
14 | */*/xcuserdata
15 | .cproject
16 | .project
17 | .settings
18 | *.qbs.user
19 | build-example-segment-intersection-Desktop-Debug/
20 | build-example-3d-Desktop-Debug/
21 | build-example-mesh-intersection-Desktop-Debug/
22 | build-example-mouse-picker-Desktop-Debug/
23 | build-example-multiple-rays-Desktop-Debug
24 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # This file allows testing your addon using travis CI servers to use it you'll need to
2 | # create an account in travis.org and enable your addon there.
3 | #
4 | # By default it will test linux 64bit and osx against the master and stable OF branches.
5 | # Other platforms can be enabled by uncommenting the corresponding sections.
6 | #
7 | # If any extra install is needed to use the addon it can be included in the corresponding
8 | # install script in:
9 | #
10 | # scripts/ci/$TARGET/install.sh
11 | #
12 |
13 |
14 | language: c++
15 | compiler: gcc
16 | sudo: true
17 | matrix:
18 | include:
19 | # fully specify builds, include can't dynamically expand matrix entries
20 | # relative order of sudo and env is important so that addons: is recognized
21 |
22 | # Linux 64bit, OF master
23 | - os: linux
24 | dist: trusty
25 | sudo: required
26 | env: TARGET="linux64" OF_BRANCH="master"
27 | addons:
28 | apt:
29 | sources:
30 | - ubuntu-toolchain-r-test
31 | packages:
32 | - gcc-4.9
33 | - g++-4.9
34 | - gdb
35 |
36 | # Linux 64bit, OF stable: Not supported yet
37 | # - os: linux
38 | # dist: trusty
39 | # sudo: required
40 | # env: TARGET="linux64" OF_BRANCH="stable"
41 | # addons:
42 | # apt:
43 | # sources:
44 | # - ubuntu-toolchain-r-test
45 | # packages:
46 | # - gcc-4.9
47 | # - g++-4.9
48 | # - gdb
49 |
50 | # OSX, OF master
51 | - os: osx
52 | osx_image: xcode9.4
53 | compiler: clang
54 | env: TARGET="osx" OF_BRANCH="master"
55 |
56 | # OSX, OF stable: Not supported yet
57 | # - os: osx
58 | # osx_image: xcode9.4
59 | # compiler: clang
60 | # env: TARGET="osx" OF_BRANCH="stable"
61 |
62 | # Linux ARM6, OF master: Uncomment following lines to enable
63 | # - os: linux
64 | # sudo: required
65 | # dist: trusty
66 | # env: TARGET="linuxarmv6l" OF_BRANCH="master"
67 |
68 |
69 | # Linux ARM6, OF stable: Not supported yet
70 | # - os: linux
71 | # sudo: required
72 | # dist: trusty
73 | # env: TARGET="linuxarmv6l" OF_BRANCH="stable"
74 |
75 | # Linux ARM7, OF master: Uncomment following lines to enable
76 | # - os: linux
77 | # sudo: false
78 | # env: TARGET="linuxarmv7l" OF_BRANCH="master"
79 | # cache:
80 | # directories:
81 | # - ~/rpi2_toolchain
82 | # - ~/firmware-master
83 | # - ~/archlinux
84 |
85 | # Linux ARM7, OF stable: Not supported yet
86 | # - os: linux
87 | # sudo: false
88 | # env: TARGET="linuxarmv7l" OF_BRANCH="stable"
89 | # cache:
90 | # directories:
91 | # - ~/rpi2_toolchain
92 | # - ~/firmware-master
93 | # - ~/archlinux
94 |
95 |
96 | # Emscripten, OF master: Uncomment following lines to enable
97 | # - os: linux
98 | # sudo: false
99 | # env: TARGET="emscripten" OF_BRANCH="master"
100 | # addons:
101 | # apt:
102 | # sources:
103 | # - ubuntu-toolchain-r-test
104 | # packages:
105 | # - libstdc++6
106 |
107 |
108 | # Emscripten, OF stable: Not supported yet
109 | # - os: linux
110 | # sudo: false
111 | # env: TARGET="emscripten" OF_BRANCH="stable"
112 | # addons:
113 | # apt:
114 | # sources:
115 | # - ubuntu-toolchain-r-test
116 | # packages:
117 | # - libstdc++6
118 |
119 |
120 | # iOS, OF master: Not supported yet
121 | # - os: osx
122 | # osx_image: xcode8
123 | # compiler: clang
124 | # env: TARGET="ios" OF_BRANCH="master"
125 |
126 |
127 | # iOS, OF stable: Not supported yet
128 | # - os: osx
129 | # osx_image: xcode8
130 | # compiler: clang
131 | # env: TARGET="ios" OF_BRANCH="stable"
132 |
133 |
134 | # tvOS, OF master: Not supported yet
135 | # - os: osx
136 | # osx_image: xcode8
137 | # compiler: clang
138 | # env: TARGET="tvos" OF_BRANCH="master"
139 |
140 |
141 | # tvOS, OF stable: Not supported yet
142 | # - os: osx
143 | # osx_image: xcode8
144 | # compiler: clang
145 | # env: TARGET="tvos" OF_BRANCH="stable"
146 |
147 |
148 | # Android armv7, OF master: Uncomment following lines to enable
149 | # - os: linux
150 | # sudo: false
151 | # env: TARGET="android" OPT="armv7" OF_BRANCH="master"
152 | # cache:
153 | # directories:
154 | # - ~/android-ndk-r12b
155 |
156 |
157 | # Android armv7, OF stable: Not supported yet
158 | # - os: linux
159 | # sudo: false
160 | # env: TARGET="android" OPT="armv7" OF_BRANCH="stable"
161 | # cache:
162 | # directories:
163 | # - ~/android-ndk-r12b
164 |
165 |
166 | # Android x86, OF master: Uncomment following lines to enable
167 | # - os: linux
168 | # sudo: false
169 | # env: TARGET="android" OPT="x86" OF_BRANCH="master"
170 | # cache:
171 | # directories:
172 | # - ~/android-ndk-r12b
173 |
174 |
175 | # Android x86, OF stable: Not supported yet
176 | # - os: linux
177 | # sudo: false
178 | # env: TARGET="android" OPT="x86" OF_BRANCH="stable"
179 | # cache:
180 | # directories:
181 | # - ~/android-ndk-r12b
182 |
183 |
184 | # Exclude the default build that would otherwise be generated
185 | # see https://github.com/travis-ci/travis-ci/issues/1228
186 | exclude:
187 | - compiler: gcc
188 |
189 | install:
190 | - cd ~
191 | - git clone --depth=1 --branch=$OF_BRANCH https://github.com/openframeworks/openFrameworks
192 | - cd openFrameworks
193 | - scripts/ci/addons/install.sh
194 |
195 | script:
196 | - scripts/ci/addons/build.sh
197 |
198 | git:
199 | depth: 10
200 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ofxRaycaster
2 |
3 | [](https://travis-ci.org/edap/ofxRaycaster)
4 | [](https://ci.appveyor.com/project/edap/ofxraycaster)
5 |
6 | ## Donation:
7 |
8 | If you find this project useful please consider a donation.
9 |
10 | [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DUA4FYWCMFDSG)
11 |
12 | ##### Table of Contents
13 | [How to use it](#how-to)
14 |
15 | [Methods for 2D and 3D rays](#generics)
16 |
17 | [2D Intersection Methods](#2d-intersections)
18 |
19 | [3D Intersection Methods](#3d-intersections)
20 |
21 | [Mouse Picker](#mousepicker)
22 |
23 | [Showcase](#showcase)
24 |
25 |
26 | 
27 |
28 |
29 | This addon contains a c++ class to works with rays in 2D and 3D dimension, and it includes methods to check the intersection with segments, spheres, triangles, planes, ofPrimitive, ofPolyline and ofMesh, wrapping the methods already presents in the [glm](https://github.com/g-truc/glm) library, the default math library oin OF.
30 |
31 |
32 |
33 | ## How to use it:
34 |
35 |
36 |
37 | Download this addon in your `addons` folder. Create a new project with the project generator and add as addon `ofxRaycaster`.
38 | In your project, add at the top of your `ofApp.h` file
39 |
40 | ```cpp
41 | #include "ofxRaycaster.h"
42 | ```
43 | To get started using a 2D ray in your project, declare a `ray` variable in your `ofApp.h` header file:
44 |
45 | ```cpp
46 | ofxraycaster::Ray2D ray;
47 | ```
48 |
49 | If you want to use a 3D ray, declare the ray like this.
50 |
51 | ```cpp
52 | ofxraycaster::Ray ray;
53 | ```
54 |
55 |
56 |
57 | ## Generic methods, for both 2D and 3D rays:
58 |
59 |
60 |
61 | #### setup
62 |
63 | ```cpp
64 | void setup(glm::vec2 origin, glm::vec2 direction)
65 | ```
66 | Set the origin and direction of a ray. For example, for a 2D ray:
67 |
68 | ```
69 | ray.setup(glm::vec2(10,5), glm::vec2(1,0));
70 | ```
71 |
72 | #### getOrigin
73 |
74 | ```cpp
75 | glm::vec2 getOrigin();
76 | ```
77 | Return the origin of the vector. For example, for the 2D ray previously greated:
78 | ```cpp
79 | ray.getOrigin(); // returns glm::vec2(10,5)
80 | ```
81 |
82 | #### getDirection
83 |
84 | ```cpp
85 | glm::vec2 getDirection();
86 | ```
87 | Return the direction of the vector. For example, for the 2D ray previously greated:
88 | ```cpp
89 | ray.getDirection(); // returns glm::vec2(1,0)
90 | ```
91 |
92 | #### setOrigin
93 |
94 | ```cpp
95 | void setOrigin(glm::vec3 origin);
96 | ```
97 |
98 | Set the origin of the ray;
99 |
100 | #### setDirection
101 |
102 | ```cpp
103 | void setDirection(glm::vec2 _origin);
104 | ```
105 |
106 | Set the direction of the ray;
107 |
108 | #### draw
109 |
110 | ```cpp
111 | void draw(float radius = 20.);
112 | ```
113 |
114 | Draw a red circle indicating the position and a blue line indicating the direction, useful when debugging. It accepts a parameter to scale the dimension of the line representing the direction.
115 |
116 |
117 |
118 | ## 2D intersection methods:
119 |
120 |
121 |
122 | | `example-polyline-intersection` | `example-segment-intersection` |
123 | | :---: | :---: |
124 | |  |  |
125 |
126 |
127 | #### intersectsPolyline
128 | See example `example-polyline-intersection`
129 |
130 | ```cpp
131 | bool intersectsPolyline(const ofPolyline & poly, float & distance, glm::vec2& surfaceNormal);
132 | ```
133 |
134 | Check the intersection between a ray and an `ofPolyline`. If there is an intersection, it stores in `distance` and `surfaceNormal` respectively the distance from the origin to the intersection point, and a 2D normal of the segment of the polyline hit by the ray.
135 |
136 | ```cpp
137 | ofxraycaster::Ray2D ray;
138 | ofPolyline poly;
139 |
140 | glm::vec2 surfaceNormal; // store the intersection value
141 | float distance; // store the intersection value
142 |
143 | if (ray.intersectsPolyline(poly, distance, surfaceNormal)) {
144 | glm::vec2 intersection = ray.getOrigin() + ray.getDirection() * distance;
145 | ofDrawLine(ray.getOrigin(), intersection);
146 | }
147 | ```
148 |
149 | #### intersectsSegment
150 | See example `example-segment-intersection`
151 |
152 | ```cpp
153 | bool intersectsSegment(const glm::vec2 & a, const glm::vec2 & b, float & distance)
154 | ```
155 |
156 | Check the intersection between a ray and a segment. If there is an intersection, it stores in the variable `distance` the distance from the origin to the intersection point.
157 |
158 |
159 | ```cpp
160 | ofxraycaster::Ray2D ray;
161 | auto a = glm::vec2(10, 30);
162 | auto b = glm::vec2(50, 50);
163 | // the segment goes from point a to point b
164 |
165 | float distance; // store the intersection value
166 |
167 | if (ray.intersectsSegment(a, b, distance)) {
168 | glm::vec2 intersection = ray.getOrigin() + ray.getDirection() * distance;
169 | ofDrawLine(ray.getOrigin(), intersection);
170 | }
171 | ```
172 |
173 |
174 |
175 | ## 3D intersection methods:
176 |
177 |
178 |
179 |
180 | | `example-multiple-rays` | `example-mesh-intersection` | `example-3D` |
181 | | :---: | :---: | :---: |
182 | |  |  |  |
183 |
184 |
185 |
186 | #### intersectsTriangle
187 |
188 | Check the intersection between a ray and a triangle. See `example-3D`.
189 |
190 | ```cpp
191 | bool intersectsTriangle(glm::vec3 const & vert0, glm::vec3 const & vert1, glm::vec3 const & vert2, glm::vec2 & baryPosition, float & distance)
192 | ```
193 |
194 |
195 | #### intersectsSphere
196 |
197 | Check the intersection between a ray and a sphere. See `example-3D`.
198 |
199 | ```cpp
200 | bool intersectsSphere(const glm::vec3 & _center, const float & _radius, glm::vec3& _position, glm::vec3 & _normal)
201 | ```
202 |
203 | #### intersectsPrimitive
204 |
205 | Check the intersection between a ray and an `ofPrimitive`. See `example-3D`.
206 |
207 | ```cpp
208 | bool intersectsPrimitive(const of3dPrimitive& primitive, glm::vec2 & baricentricCoords, float & distance, glm::vec3 & intNormal)
209 | ```
210 |
211 | #### intersectsPlane
212 |
213 | Check the intersection between a ray and an `ofxraycaster::Plane`. See `example-3D`.
214 |
215 | ```cpp
216 | bool intersectsPlane(ofxraycaster::Plane plane, float & distance);
217 | ```
218 |
219 | #### intersectsMesh
220 |
221 | Check the intersection between a ray and a mesh. See `example-mesh-intersection`.
222 |
223 |
224 | ```
225 | bool intersectsMesh(const ofMesh& mesh, glm::vec2 & baricentricCoords, float & distance, glm::vec3 & intNormal);
226 | ```
227 |
228 | Example:
229 |
230 | ```cpp
231 | void ofApp::draw(){
232 | cam.begin();
233 | mesh.draw();
234 | ray.draw();
235 |
236 | glm::vec2 baricentricCoordinates; // stores the barycentric coordinate of the triangle hit by the ray.
237 | float distance;
238 | glm::vec3 surfaceNormal; // stores the normal of the surface hit by the ray.
239 | bool intersects = ray.intersectsMesh(mesh, baricentricCoordinates, distance, surfaceNormal);
240 |
241 | // is there an intersection between the mesh and the ray?
242 | if (intersects) {
243 | auto intersection =
244 | ray.getOrigin() + ray.getDirection() * distance;
245 | // draw the ray hitting the mesh
246 | ofDrawLine(ray.getOrigin(), intersection);
247 | // draw the intersection point
248 | ofDrawSphere(intersection, 5);
249 |
250 | // draw the reflected light
251 | auto reflLight = glm::reflect(ray.getDirection(), surfaceNormal);
252 | ofDrawLine(intersection, intersection + 100 * reflLight);
253 | }
254 | cam.end();
255 | }
256 | ```
257 |
258 | When a `glm::mat4` containing the transformation matrix of the mesh is given as second argument, it takes the transformation into account. See `example-mesh-intersection`.
259 |
260 | ```
261 | bool intersectsMesh(const ofMesh& mesh, const glm::mat4& transformationMatrix, glm::vec2 & baricentricCoords, float & distance, glm::vec3 & intNormal);
262 | ```
263 |
264 |
265 |
266 | ## Mousepicker:
267 |
268 | | `example-mousepicker` |
269 | | :---: |
270 | | |
271 |
272 |
273 |
274 | #### setFromCamera
275 |
276 | ```cpp
277 | void setFromCamera(const glm::vec2 mouseCoords, const ofCamera camera);
278 | ```
279 |
280 | Set the origin and the direction of the ray giving as argument an `ofCamera` and the mouse coordinates. See example `example-mousepicker`.
281 |
282 | #### draw
283 |
284 | ```cpp
285 | void draw(const float radius = 20);
286 | ```
287 |
288 | Draw a sphere under the mouse.
289 |
290 | #### getRay
291 |
292 | ```cpp
293 | Ray& getRay();
294 | ```
295 |
296 | Return the 3D ray that goes from the camera towards the mouse.
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 | ## Showcase:
305 |
306 |
307 |
308 | This addon was used in the following projects:
309 |
310 | - [Border Tuner / Sintonizador Fronterizo](https://www.lozano-hemmer.com/border_tuner__sintonizador_fronterizo.php)
311 |
312 | - [Sphere Packing - Bach](https://www.lozano-hemmer.com/sphere_packing_bach.php)
313 |
314 | - [Sun and Moon](http://dominofactory.net/client_works/sun_and_moon.html)
315 |
316 | If you want to add your project to this list, please open an issue.
317 |
318 |
319 |
320 |
--------------------------------------------------------------------------------
/example-3d/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=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-3d/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 |
--------------------------------------------------------------------------------
/example-3d/addons.make:
--------------------------------------------------------------------------------
1 | ofxRaycaster
2 |
--------------------------------------------------------------------------------
/example-3d/bin/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-3d/bin/data/.gitkeep
--------------------------------------------------------------------------------
/example-3d/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 |
--------------------------------------------------------------------------------
/example-3d/example-3d.qbs:
--------------------------------------------------------------------------------
1 | import qbs
2 | import qbs.Process
3 | import qbs.File
4 | import qbs.FileInfo
5 | import qbs.TextFile
6 | import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp
7 |
8 | Project{
9 | property string of_root: '../../..'
10 |
11 | ofApp {
12 | name: { return FileInfo.baseName(sourceDirectory) }
13 |
14 | files: [
15 | 'src/main.cpp',
16 | 'src/ofApp.cpp',
17 | 'src/ofApp.h',
18 | ]
19 |
20 | // This project is using addons.make to include the addons
21 | // since it was imported from old code. To change it to include
22 | // the addons from the qbs file change the following lines to
23 | // the list of used addons in array format. eg:
24 | //
25 | // of.addons: [
26 | // 'ofxGui',
27 | // 'ofxOpenCv',
28 | // ]
29 |
30 | // additional flags for the project. the of module sets some
31 | // flags by default to add the core libraries, search paths...
32 | // this flags can be augmented through the following properties:
33 | of.pkgConfigs: [] // list of additional system pkgs to include
34 | of.includePaths: [] // include search paths
35 | of.cFlags: [] // flags passed to the c compiler
36 | of.cxxFlags: [] // flags passed to the c++ compiler
37 | of.linkerFlags: [] // flags passed to the linker
38 | of.defines: [] // defines are passed as -D to the compiler
39 | // and can be checked with #ifdef or #if in the code
40 | of.frameworks: [] // osx only, additional frameworks to link with the project
41 | of.staticLibraries: [] // static libraries
42 | of.dynamicLibraries: [] // dynamic libraries
43 |
44 | // create a console window when the application start
45 | consoleApplication: false
46 |
47 | // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html
48 | // eg: this will enable ccache when compiling
49 | //
50 | // cpp.compilerWrapper: 'ccache'
51 |
52 | Depends{
53 | name: "cpp"
54 | }
55 |
56 | // common rules that parse the include search paths, core libraries...
57 | Depends{
58 | name: "of"
59 | }
60 |
61 | // dependency with the OF library
62 | Depends{
63 | name: "openFrameworks"
64 | }
65 | }
66 |
67 | property bool makeOF: true // use makfiles to compile the OF library
68 | // will compile OF only once for all your projects
69 | // otherwise compiled per project with qbs
70 |
71 | property bool precompileOfMain: false // precompile ofMain.h
72 | // faster to recompile when including ofMain.h
73 | // but might use a lot of space per project
74 |
75 | references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")]
76 | }
77 |
--------------------------------------------------------------------------------
/example-3d/example-3d.xcodeproj/xcshareddata/xcschemes/example-3d 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 |
--------------------------------------------------------------------------------
/example-3d/example-3d.xcodeproj/xcshareddata/xcschemes/example-3d 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 |
--------------------------------------------------------------------------------
/example-3d/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 |
--------------------------------------------------------------------------------
/example-3d/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofGLFWWindowSettings settings;
7 | settings.setGLVersion(3, 2);
8 | settings.setSize(1280, 720);
9 | ofCreateWindow(settings);
10 |
11 | ofRunApp(new ofApp());
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/example-3d/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofBackground(col3);
6 | center.setPosition(0, 200, 0);
7 | sphere.setPosition(0, 200, 0);
8 | light.setPosition(200, 600, 400);
9 | light.setDiffuseColor(col4);
10 | light.tiltDeg(-45);
11 | light.setup();
12 |
13 | material.setAmbientColor(col4);
14 |
15 | rayDirection = glm::vec3(0,1,0);
16 | rayOrigin = glm::vec3(0, -150, 0);
17 | ray.setup(rayOrigin, rayDirection);
18 |
19 | //triangle
20 | triangleLookAt.setPosition(0,0, 100);
21 | triangleLookAt.setParent(center);
22 |
23 | //sphere
24 | sphere.setResolution(100);
25 | sphere.setRadius(sphereRadius);
26 |
27 | //box
28 | box.set(sphereRadius);
29 | box.setParent(center);
30 |
31 | //plane
32 | // A plane is infinite, therefore the ofPlanePrimitive is not correct,
33 | // but it is useful to visualize the plane
34 | planePrimitive = ofPlanePrimitive(ofGetWidth()*2, ofGetHeight()*2, 20, 20);
35 | planePrimitive.setPosition(planeOrigin);
36 | planePrimitive.tiltDeg(90);
37 | plane.setup(planeOrigin, planeNormal);
38 |
39 | center.rollDeg(30.0f);
40 | }
41 |
42 | //--------------------------------------------------------------
43 | void ofApp::update(){
44 | lookAtRay.x= ofMap(sin(ofGetElapsedTimef()), -1, 1, -300, 300);
45 | rayDirection = glm::normalize(lookAtRay - rayOrigin);
46 | ray.setDirection(rayDirection);
47 |
48 | if(scene == 4){
49 | center.setPosition(0, 200, 0);
50 | center.rollDeg(0.5f);
51 | }else if(scene == 1){
52 | sphere.truck(sin(ofGetElapsedTimef()));
53 | }else if(scene == 2 || scene == 3){
54 | center.setPosition(0, 200, 0);
55 | center.panDeg(0.2);
56 | center.tiltDeg(0.2);
57 | }
58 |
59 | }
60 |
61 | //--------------------------------------------------------------
62 | void ofApp::draw(){
63 | ofDrawBitmapString("press 1 to 4 to change the intersection modes. Current mode: "+ mode, 10, 20);
64 | ofEnableDepthTest();
65 | camera.begin();
66 |
67 | light.draw();
68 | ray.draw();
69 |
70 | switch(scene) {
71 | case 1:
72 | mode = "Sphere";
73 | drawSphereIntersection();
74 | break;
75 | case 2:
76 | mode = "Plane";
77 | drawPlaneIntersection();
78 | break;
79 | case 3:
80 | mode = "Triangle";
81 | drawTriangleIntersection();
82 | break;
83 | case 4:
84 | mode = "Primitive";
85 | drawPrimitiveIntersection();
86 | break;
87 | default:
88 | mode = "Sphere";
89 | drawSphereIntersection();
90 | break;
91 | }
92 | camera.end();
93 | }
94 |
95 | void ofApp::drawSphereIntersection(){
96 | material.begin();
97 | sphere.draw();
98 | material.end();
99 |
100 | glm::vec3 intersection;
101 | glm::vec3 surfaceNormal;
102 |
103 | if(ray.intersectsSphere(sphere.getGlobalPosition(),
104 | sphereRadius,
105 | intersection,
106 | surfaceNormal)){
107 | // ray hits
108 | ofPushStyle();
109 | ofSetColor(col1);
110 | ofDrawSphere(intersection, 5);
111 | ofDrawLine(ray.getOrigin(), intersection);
112 | // reflected light
113 | auto reflDir = glm::reflect(ray.getDirection(),surfaceNormal);
114 | ofSetColor(col2);
115 | ofDrawLine(intersection, intersection + 100 * reflDir);
116 | ofPopStyle();
117 | }
118 | };
119 |
120 | void ofApp::drawPlaneIntersection(){
121 | material.begin();
122 | planePrimitive.draw();
123 | material.end();
124 |
125 | float distance;
126 | if(ray.intersectsPlane(plane, distance)){
127 | auto intersection = ray.getOrigin() + ray.getDirection() * distance;
128 | // ray hits
129 | ofPushStyle();
130 | ofSetColor(col1);
131 | ofDrawSphere(intersection, 5);
132 | ofDrawLine(ray.getOrigin(), intersection);
133 |
134 | // reflected light
135 | auto reflDir = glm::reflect(ray.getDirection(),planeNormal);
136 | ofSetColor(col2);
137 | ofDrawLine(intersection, intersection + 100 * reflDir);
138 | ofPopStyle();
139 | }
140 | };
141 |
142 | void ofApp::drawTriangleIntersection(){
143 | glm::vec2 baryCoordinates;
144 | float d;
145 | ofNode v1,v2,v3;
146 |
147 | v1.setPosition(-200, -100, 0);
148 | v2.setPosition(0, 100, 0);
149 | v3.setPosition(+200, -100, 0);
150 | v1.setParent(center);
151 | v2.setParent(center);
152 | v3.setParent(center);
153 |
154 | material.begin();
155 | ofDrawTriangle(v1.getGlobalPosition(),
156 | v2.getGlobalPosition(),
157 | v3.getGlobalPosition());
158 |
159 | auto a = v1.getGlobalPosition();
160 | auto b = v2.getGlobalPosition();
161 | auto c = v3.getGlobalPosition();
162 | ofDrawTriangle(a,b,c);
163 | //triangleLookAt.draw();
164 | material.end();
165 |
166 | if(ray.intersectsTriangle(a,b,c, baryCoordinates, d)){
167 | auto intersection = ray.getOrigin() + ray.getDirection() * d;
168 | ofPushStyle();
169 | ofSetColor(col1);
170 | ofDrawLine(ray.getOrigin(), intersection);
171 | // reflected light
172 | auto triangleNormal = glm::normalize(triangleLookAt.getGlobalPosition() - center.getGlobalPosition());
173 | auto reflLight = glm::reflect(ray.getDirection(), triangleNormal);
174 | ofSetColor(col2);
175 | ofDrawLine(intersection, intersection + 100 * reflLight);
176 | ofPopStyle();
177 | }
178 | };
179 |
180 | void ofApp::drawPrimitiveIntersection(){
181 | material.begin();
182 | box.draw();
183 | material.end();
184 |
185 | glm::vec2 baricentricCoordinates;
186 | float dist;
187 | glm::vec3 surfaceNormal;
188 | if(ray.intersectsPrimitive(box, baricentricCoordinates, dist, surfaceNormal)){
189 |
190 | auto intersection = ray.getOrigin() + ray.getDirection() * dist;
191 |
192 | ofPushStyle();
193 | ofSetColor(col1);
194 | ofDrawSphere(intersection, 5);
195 | ofDrawLine(ray.getOrigin(), intersection);
196 | // reflected light
197 | auto reflLight = glm::reflect(ray.getDirection(),surfaceNormal);
198 | ofSetColor(col2);
199 | ofDrawLine(intersection, intersection + 100 * reflLight);
200 | ofPopStyle();
201 | }
202 | };
203 |
204 | //--------------------------------------------------------------
205 | void ofApp::keyPressed(int key){
206 | switch(key) {
207 | case '1':
208 | scene = 1;
209 | break;
210 | case '2':
211 | scene = 2;
212 | break;
213 | case '3':
214 | scene = 3;
215 | break;
216 | case '4':
217 | scene = 4;
218 | break;
219 | default:
220 | scene = 1;
221 | break;
222 | }
223 | }
224 |
225 | void ofApp::drawLine(glm::vec3 a, glm::vec3 b, ofColor color){
226 | ofPushStyle();
227 | ofSetLineWidth(20);
228 | ofSetColor(color);
229 | ofDrawLine(a, b);
230 | ofPopStyle();
231 | };
232 |
233 |
--------------------------------------------------------------------------------
/example-3d/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxRaycaster.h"
5 |
6 | class ofApp : public ofBaseApp{
7 | public:
8 | void setup();
9 | void update();
10 | void draw();
11 |
12 | void keyPressed(int key);
13 |
14 | void drawSphereIntersection();
15 | void drawPlaneIntersection();
16 | void drawTriangleIntersection();
17 | void drawPrimitiveIntersection();
18 | void drawLine(glm::vec3 a, glm::vec3 b, ofColor color);
19 |
20 | ofEasyCam camera;
21 | ofLight light;
22 | ofMaterial material;
23 | int scene = 4;
24 | std::string mode = "Primitive";
25 | glm::vec3 lookAtRay = glm::vec3(0, 200, 0);
26 |
27 | ofNode center;
28 | float sphereRadius = 100;
29 | ofSpherePrimitive sphere;
30 | ofBoxPrimitive box;
31 | ofPlanePrimitive planePrimitive;
32 | glm::vec3 planeOrigin = glm::vec3(0,500,0);
33 | glm::vec3 planeNormal = glm::vec3(0,-1,0);
34 | ofNode triangleLookAt;
35 |
36 | glm::vec3 rayDirection;
37 | glm::vec3 rayOrigin;
38 | ofxraycaster::Ray ray;
39 | ofxraycaster::Plane plane;
40 |
41 | ofFloatColor col1 = ofFloatColor(ofColor(246,233,101));
42 | ofFloatColor col2 = ofFloatColor(ofColor(85,255,60));
43 | ofFloatColor col3 = ofFloatColor(ofColor(20,164,204));
44 | ofFloatColor col4 = ofFloatColor(ofColor(180,0,131));
45 | ofFloatColor col5 = ofFloatColor(ofColor(0,0,0));
46 | };
47 |
--------------------------------------------------------------------------------
/example-mesh-intersection/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=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-mesh-intersection/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 |
--------------------------------------------------------------------------------
/example-mesh-intersection/addons.make:
--------------------------------------------------------------------------------
1 | ofxRaycaster
2 |
--------------------------------------------------------------------------------
/example-mesh-intersection/bin/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-mesh-intersection/bin/data/.gitkeep
--------------------------------------------------------------------------------
/example-mesh-intersection/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 |
--------------------------------------------------------------------------------
/example-mesh-intersection/example-mesh-intersection.qbs:
--------------------------------------------------------------------------------
1 | import qbs
2 | import qbs.Process
3 | import qbs.File
4 | import qbs.FileInfo
5 | import qbs.TextFile
6 | import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp
7 |
8 | Project{
9 | property string of_root: '../../..'
10 |
11 | ofApp {
12 | name: { return FileInfo.baseName(sourceDirectory) }
13 |
14 | files: [
15 | 'src/main.cpp',
16 | 'src/ofApp.cpp',
17 | 'src/ofApp.h',
18 | ]
19 |
20 | // This project is using addons.make to include the addons
21 | // since it was imported from old code. To change it to include
22 | // the addons from the qbs file change the following lines to
23 | // the list of used addons in array format. eg:
24 | //
25 | // of.addons: [
26 | // 'ofxGui',
27 | // 'ofxOpenCv',
28 | // ]
29 |
30 | // additional flags for the project. the of module sets some
31 | // flags by default to add the core libraries, search paths...
32 | // this flags can be augmented through the following properties:
33 | of.pkgConfigs: [] // list of additional system pkgs to include
34 | of.includePaths: [] // include search paths
35 | of.cFlags: [] // flags passed to the c compiler
36 | of.cxxFlags: [] // flags passed to the c++ compiler
37 | of.linkerFlags: [] // flags passed to the linker
38 | of.defines: [] // defines are passed as -D to the compiler
39 | // and can be checked with #ifdef or #if in the code
40 | of.frameworks: [] // osx only, additional frameworks to link with the project
41 | of.staticLibraries: [] // static libraries
42 | of.dynamicLibraries: [] // dynamic libraries
43 |
44 | // create a console window when the application start
45 | consoleApplication: false
46 |
47 | // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html
48 | // eg: this will enable ccache when compiling
49 | //
50 | // cpp.compilerWrapper: 'ccache'
51 |
52 | Depends{
53 | name: "cpp"
54 | }
55 |
56 | // common rules that parse the include search paths, core libraries...
57 | Depends{
58 | name: "of"
59 | }
60 |
61 | // dependency with the OF library
62 | Depends{
63 | name: "openFrameworks"
64 | }
65 | }
66 |
67 | property bool makeOF: true // use makfiles to compile the OF library
68 | // will compile OF only once for all your projects
69 | // otherwise compiled per project with qbs
70 |
71 | property bool precompileOfMain: false // precompile ofMain.h
72 | // faster to recompile when including ofMain.h
73 | // but might use a lot of space per project
74 |
75 | references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")]
76 | }
77 |
--------------------------------------------------------------------------------
/example-mesh-intersection/example-mesh-intersection.xcodeproj/xcshareddata/xcschemes/example-mesh-intersection 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 |
--------------------------------------------------------------------------------
/example-mesh-intersection/example-mesh-intersection.xcodeproj/xcshareddata/xcschemes/example-mesh-intersection 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 |
--------------------------------------------------------------------------------
/example-mesh-intersection/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 |
--------------------------------------------------------------------------------
/example-mesh-intersection/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofGLFWWindowSettings settings;
7 | settings.setSize(1024,768);
8 | settings.setGLVersion(3, 2);
9 | ofCreateWindow(settings);
10 | ofRunApp(new ofApp());
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/example-mesh-intersection/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | void ofApp::setup(){
4 | ray.setup(glm::vec3(350, 0, 100), glm::vec3(-1, 0, 0));
5 |
6 | icosphere.set(200, 1);
7 | mesh.append(icosphere.getMesh());
8 |
9 | light.setAmbientColor(col4);
10 | light.setup();
11 | light.setPosition(200,600,400);
12 | light.enable();
13 |
14 | material.setAmbientColor(col4);
15 |
16 | ofEnableDepthTest();
17 | }
18 |
19 | void ofApp::update(){;
20 | float time = ofGetElapsedTimef();
21 | float cosedTime = cos(ofGetElapsedTimef()* 1.3) * 0.5;
22 | ray.setDirection(glm::normalize(glm::vec3(-1, cosedTime, 0)));
23 |
24 | node.panDeg(1);
25 | node.boom(sin(time)*2.5);
26 | }
27 |
28 | void ofApp::draw(){
29 | ofBackground(col3);
30 | cam.begin();
31 | light.draw();
32 | ray.draw(5);
33 |
34 | glm::vec2 baricentricCoordinates;
35 | float distance;
36 | glm::vec3 intNormal;
37 | bool intersects;
38 |
39 | if (transformation) {
40 | node.transformGL();
41 | material.begin();
42 | mesh.draw();
43 | material.end();
44 | ofSetColor(col5);
45 | mesh.drawWireframe();
46 | intersects = ray.intersectsMesh(mesh,
47 | node.getGlobalTransformMatrix(),
48 | baricentricCoordinates,
49 | distance,
50 | intNormal);
51 | node.restoreTransformGL();
52 | } else {
53 | material.begin();
54 | mesh.draw();
55 | material.end();
56 | ofSetColor(col5);
57 | mesh.drawWireframe();
58 | intersects = ray.intersectsMesh(mesh,baricentricCoordinates,distance,intNormal);
59 | }
60 |
61 |
62 |
63 | // is there an intersection between the segment and the ray?
64 | if (intersects) {
65 | ofPushStyle();
66 |
67 | auto intersection =
68 | ray.getOrigin() + ray.getDirection() * distance;
69 |
70 | // draw the ray that hits the icosphere
71 | ofSetColor(col1);
72 | ofDrawLine(ray.getOrigin(), intersection);
73 | // draw the intersection point
74 | ofDrawSphere(intersection, 5);
75 |
76 | // draw the reflected light
77 | auto reflLight = glm::reflect(ray.getDirection(),intNormal);
78 | ofSetColor(col2);
79 | ofDrawLine(intersection, intersection + 100 * reflLight);
80 | ofPopStyle();
81 | }
82 | cam.end();
83 |
84 | string mode = transformation ? "intersect mesh with transformation applied" : "intersect mesh" ;
85 | string msg = "press 'm' to change the mode. Current mode: "+mode;
86 | ofDrawBitmapString(msg, 20, 20);
87 | }
88 |
89 | void ofApp::keyPressed(int key){
90 | if (key == 'm') {
91 | transformation = !transformation;
92 | }
93 | };
94 |
95 |
--------------------------------------------------------------------------------
/example-mesh-intersection/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxRaycaster.h"
5 |
6 | class ofApp : public ofBaseApp{
7 |
8 | public:
9 | void setup();
10 | void update();
11 | void draw();
12 | void keyPressed(int key);
13 |
14 | ofxraycaster::Ray ray;
15 | glm::vec2 p1 = glm::vec2(400, 80);
16 | glm::vec2 p2 = glm::vec2(600, 600);
17 | ofFloatColor col1 = ofFloatColor(ofColor(246,233,101));
18 | ofFloatColor col2 = ofFloatColor(ofColor(85,255,60));
19 | ofFloatColor col3 = ofFloatColor(ofColor(20,164,204));
20 | ofFloatColor col4 = ofFloatColor(ofColor(180,0,131));
21 | ofFloatColor col5 = ofFloatColor(ofColor(0,0,0));
22 |
23 | ofMesh mesh;
24 | ofNode node;
25 | ofEasyCam cam;
26 | ofLight light;
27 | ofMaterial material;
28 | ofIcoSpherePrimitive icosphere;
29 |
30 | bool transformation = false;
31 |
32 |
33 |
34 | };
35 |
--------------------------------------------------------------------------------
/example-mouse-picker/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=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-mouse-picker/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 |
--------------------------------------------------------------------------------
/example-mouse-picker/addons.make:
--------------------------------------------------------------------------------
1 | ofxRaycaster
2 |
--------------------------------------------------------------------------------
/example-mouse-picker/bin/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-mouse-picker/bin/data/.gitkeep
--------------------------------------------------------------------------------
/example-mouse-picker/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 |
--------------------------------------------------------------------------------
/example-mouse-picker/example-mouse-picker.qbs:
--------------------------------------------------------------------------------
1 | import qbs
2 | import qbs.Process
3 | import qbs.File
4 | import qbs.FileInfo
5 | import qbs.TextFile
6 | import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp
7 |
8 | Project{
9 | property string of_root: '../../..'
10 |
11 | ofApp {
12 | name: { return FileInfo.baseName(sourceDirectory) }
13 |
14 | files: [
15 | 'src/main.cpp',
16 | 'src/ofApp.cpp',
17 | 'src/ofApp.h',
18 | ]
19 |
20 | // This project is using addons.make to include the addons
21 | // since it was imported from old code. To change it to include
22 | // the addons from the qbs file change the following lines to
23 | // the list of used addons in array format. eg:
24 | //
25 | // of.addons: [
26 | // 'ofxGui',
27 | // 'ofxOpenCv',
28 | // ]
29 |
30 | // additional flags for the project. the of module sets some
31 | // flags by default to add the core libraries, search paths...
32 | // this flags can be augmented through the following properties:
33 | of.pkgConfigs: [] // list of additional system pkgs to include
34 | of.includePaths: [] // include search paths
35 | of.cFlags: [] // flags passed to the c compiler
36 | of.cxxFlags: [] // flags passed to the c++ compiler
37 | of.linkerFlags: [] // flags passed to the linker
38 | of.defines: [] // defines are passed as -D to the compiler
39 | // and can be checked with #ifdef or #if in the code
40 | of.frameworks: [] // osx only, additional frameworks to link with the project
41 | of.staticLibraries: [] // static libraries
42 | of.dynamicLibraries: [] // dynamic libraries
43 |
44 | // create a console window when the application start
45 | consoleApplication: false
46 |
47 | // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html
48 | // eg: this will enable ccache when compiling
49 | //
50 | // cpp.compilerWrapper: 'ccache'
51 |
52 | Depends{
53 | name: "cpp"
54 | }
55 |
56 | // common rules that parse the include search paths, core libraries...
57 | Depends{
58 | name: "of"
59 | }
60 |
61 | // dependency with the OF library
62 | Depends{
63 | name: "openFrameworks"
64 | }
65 | }
66 |
67 | property bool makeOF: true // use makfiles to compile the OF library
68 | // will compile OF only once for all your projects
69 | // otherwise compiled per project with qbs
70 |
71 | property bool precompileOfMain: false // precompile ofMain.h
72 | // faster to recompile when including ofMain.h
73 | // but might use a lot of space per project
74 |
75 | references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")]
76 | }
77 |
--------------------------------------------------------------------------------
/example-mouse-picker/example-mouse-picker.xcodeproj/xcshareddata/xcschemes/example-mouse-picker 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 |
--------------------------------------------------------------------------------
/example-mouse-picker/example-mouse-picker.xcodeproj/xcshareddata/xcschemes/example-mouse-picker 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 |
--------------------------------------------------------------------------------
/example-mouse-picker/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 |
--------------------------------------------------------------------------------
/example-mouse-picker/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 |
--------------------------------------------------------------------------------
/example-mouse-picker/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | void ofApp::setup(){
4 | cam.setPosition(0,50, 1000);
5 |
6 | icosphere.set(200, 1);
7 | mesh.append(icosphere.getMesh());
8 |
9 | light.setAmbientColor(col4);
10 | light.setup();
11 | light.setPosition(200,600,400);
12 | light.enable();
13 |
14 | material.setAmbientColor(col4);
15 |
16 | for (unsigned int i = 0; i < 140; i++) {
17 | ofIcoSpherePrimitive ico(50, 1);
18 | ico.setPosition(ofRandom(-ofGetWidth()/2.0f, ofGetWidth()/2.0f),
19 | ofRandom(ofGetHeight()/2.0f, -ofGetHeight()/2.0f),
20 | ofRandom(400, -400));
21 | icospheres.push_back(ico);
22 | }
23 |
24 | ofEnableDepthTest();
25 | }
26 |
27 | void ofApp::update(){
28 |
29 | }
30 |
31 | void ofApp::draw(){
32 | ofBackground(col3);
33 | cam.begin();
34 | light.draw();
35 |
36 | material.begin();
37 |
38 | glm::vec2 baricentricCoordinates;
39 | float distance;
40 | glm::vec3 surfaceNormal;
41 | bool found = false;
42 | unsigned int indexIntersectedPrimitive = 0;
43 | float distanceToClosestIntersection = numeric_limits::max();
44 |
45 | // iterates through all the primitives and find the closest one.
46 | for (unsigned int i = 0; i icospheres;
27 | ofxraycaster::Mousepicker mousepicker;
28 |
29 | };
30 |
--------------------------------------------------------------------------------
/example-multiple-rays/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=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-multiple-rays/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 |
--------------------------------------------------------------------------------
/example-multiple-rays/addons.make:
--------------------------------------------------------------------------------
1 | ofxGui
2 | ofxRaycaster
3 |
--------------------------------------------------------------------------------
/example-multiple-rays/bin/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-multiple-rays/bin/data/.gitkeep
--------------------------------------------------------------------------------
/example-multiple-rays/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 |
--------------------------------------------------------------------------------
/example-multiple-rays/example-multiple-rays.qbs:
--------------------------------------------------------------------------------
1 | import qbs
2 | import qbs.Process
3 | import qbs.File
4 | import qbs.FileInfo
5 | import qbs.TextFile
6 | import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp
7 |
8 | Project{
9 | property string of_root: '../../..'
10 |
11 | ofApp {
12 | name: { return FileInfo.baseName(sourceDirectory) }
13 |
14 | files: [
15 | 'src/main.cpp',
16 | 'src/ofApp.cpp',
17 | 'src/ofApp.h',
18 | ]
19 |
20 | // This project is using addons.make to include the addons
21 | // since it was imported from old code. To change it to include
22 | // the addons from the qbs file change the following lines to
23 | // the list of used addons in array format. eg:
24 | //
25 | // of.addons: [
26 | // 'ofxGui',
27 | // 'ofxOpenCv',
28 | // ]
29 |
30 | // additional flags for the project. the of module sets some
31 | // flags by default to add the core libraries, search paths...
32 | // this flags can be augmented through the following properties:
33 | of.pkgConfigs: [] // list of additional system pkgs to include
34 | of.includePaths: [] // include search paths
35 | of.cFlags: [] // flags passed to the c compiler
36 | of.cxxFlags: [] // flags passed to the c++ compiler
37 | of.linkerFlags: [] // flags passed to the linker
38 | of.defines: [] // defines are passed as -D to the compiler
39 | // and can be checked with #ifdef or #if in the code
40 | of.frameworks: [] // osx only, additional frameworks to link with the project
41 | of.staticLibraries: [] // static libraries
42 | of.dynamicLibraries: [] // dynamic libraries
43 |
44 | // create a console window when the application start
45 | consoleApplication: false
46 |
47 | // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html
48 | // eg: this will enable ccache when compiling
49 | //
50 | // cpp.compilerWrapper: 'ccache'
51 |
52 | Depends{
53 | name: "cpp"
54 | }
55 |
56 | // common rules that parse the include search paths, core libraries...
57 | Depends{
58 | name: "of"
59 | }
60 |
61 | // dependency with the OF library
62 | Depends{
63 | name: "openFrameworks"
64 | }
65 | }
66 |
67 | property bool makeOF: true // use makfiles to compile the OF library
68 | // will compile OF only once for all your projects
69 | // otherwise compiled per project with qbs
70 |
71 | property bool precompileOfMain: false // precompile ofMain.h
72 | // faster to recompile when including ofMain.h
73 | // but might use a lot of space per project
74 |
75 | references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")]
76 | }
77 |
--------------------------------------------------------------------------------
/example-multiple-rays/example-multiple-rays.xcodeproj/xcshareddata/xcschemes/example-multiple-rays 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 |
--------------------------------------------------------------------------------
/example-multiple-rays/example-multiple-rays.xcodeproj/xcshareddata/xcschemes/example-multiple-rays 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 |
--------------------------------------------------------------------------------
/example-multiple-rays/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 |
--------------------------------------------------------------------------------
/example-multiple-rays/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofApp.h"
3 |
4 | //========================================================================
5 | int main( ){
6 | ofGLFWWindowSettings settings;
7 | settings.setGLVersion(3, 2);
8 | settings.setSize(1280, 720);
9 | ofCreateWindow(settings);
10 |
11 | // this kicks off the running of my app
12 | // can be OF_WINDOW or OF_FULLSCREEN
13 | // pass in width and height too:
14 | ofRunApp(new ofApp());
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/example-multiple-rays/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofApp::setup(){
5 | ofBackground(col3);
6 | //center.setPosition(0, 200, 0);
7 | light.setPosition(0, 250, 250);
8 | ofSetSmoothLighting(true);
9 | light.setSpotlight();
10 | light.setDiffuseColor(col4);
11 | light.tiltDeg(-45);
12 | light.setup();
13 |
14 | material.setAmbientColor(col4);
15 | box.set(100);
16 |
17 | for(int i = 0; i< 300; i++){
18 | auto d = getRandomDir();
19 | auto pos = d * 200.0f;
20 | auto invDir = glm::normalize(glm::vec3(0.0f,0.0f,0.0f)-
21 | pos);
22 | ofxraycaster::Ray ray;
23 | ray.setup(pos, invDir);
24 | rays.push_back(ray);
25 | }
26 | gui.setup();
27 |
28 | gui.add(drawReflected);
29 | gui.add(reflectedLength);
30 | gui.add(drawPrimitive);
31 | gui.add(drawRays);
32 | gui.add(drawIntersections);
33 | }
34 |
35 | glm::vec3 ofApp::getRandomDir() const{
36 | float x = ofRandom(-1.0f, 1.0f);
37 | float y = ofRandom(-1.0f, 1.0f);
38 | float z = ofRandom(-1.0f, 1.0f);
39 | return glm::normalize(glm::vec3(x, y, z));
40 | }
41 |
42 | //--------------------------------------------------------------
43 | void ofApp::update(){
44 | ofSetWindowTitle(ofToString(ofGetFrameRate()));
45 | box.rollDeg(0.2f);
46 | box.panDeg(1.0f);
47 | box.tiltDeg(-1.0f);
48 | }
49 |
50 | //--------------------------------------------------------------
51 | void ofApp::draw(){
52 | ofEnableDepthTest();
53 | camera.begin();
54 | if (drawPrimitive) {
55 | material.begin();
56 | box.draw();
57 | material.end();
58 | }
59 |
60 | glm::vec2 baryCoord;
61 | float distance;
62 | glm::vec3 intersectionNormal;
63 | for (auto ray:rays) {
64 |
65 | if (ray.intersectsPrimitive(box, baryCoord, distance, intersectionNormal)) {
66 | auto intersection = ray.getOrigin() + ray.getDirection() * distance;
67 |
68 | // intersections points
69 | ofPushStyle();
70 | ofSetColor(col1);
71 | if (drawIntersections) {
72 | ofDrawSphere(intersection, 3);
73 | }
74 |
75 | //rays
76 | if (drawRays) {
77 | ofDrawLine(ray.getOrigin(), intersection);
78 | }
79 | ofPopStyle();
80 |
81 | ofPushStyle();
82 | ofSetColor(col2);
83 |
84 | // reflections
85 | if (drawReflected) {
86 | auto reflLightDir = glm::reflect(ray.getDirection(),intersectionNormal);
87 | ofDrawLine(intersection, intersection + reflectedLength.get() * reflLightDir);
88 | }
89 | ofPopStyle();
90 | }
91 |
92 | }
93 | camera.end();
94 |
95 | ofDisableDepthTest();
96 | gui.draw();
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/example-multiple-rays/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxRaycaster.h"
5 | #include "ofxGui.h"
6 |
7 | class ofApp : public ofBaseApp{
8 |
9 | public:
10 | void setup();
11 | void update();
12 | void draw();
13 |
14 | ofEasyCam camera;
15 | ofLight light;
16 | ofMaterial material;
17 | ofBoxPrimitive box;
18 | ofxPanel gui;
19 | ofParameter drawReflected = {"draw reflected rays", false};
20 | ofParameter reflectedLength = {"reflected rays length", 100, 10, 1000};
21 | ofParameter drawRays = {"draw rays", true};
22 | ofParameter drawIntersections = {"draw intersections", true};
23 | ofParameter drawPrimitive = {"draw cube", false};
24 |
25 |
26 | std::vector rays;
27 | private:
28 | glm::vec3 getRandomDir() const;
29 | ofFloatColor col1 = ofFloatColor(ofColor(246,233,101));
30 | ofFloatColor col2 = ofFloatColor(ofColor(85,255,60));
31 | ofFloatColor col3 = ofFloatColor(ofColor(20,164,204));
32 | ofFloatColor col4 = ofFloatColor(ofColor(180,0,131));
33 | ofFloatColor col5 = ofFloatColor(ofColor(0,0,0));
34 | };
35 |
--------------------------------------------------------------------------------
/example-polyline-intersection/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=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-polyline-intersection/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 |
--------------------------------------------------------------------------------
/example-polyline-intersection/addons.make:
--------------------------------------------------------------------------------
1 | ofxRaycaster
2 |
--------------------------------------------------------------------------------
/example-polyline-intersection/bin/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-polyline-intersection/bin/data/.gitkeep
--------------------------------------------------------------------------------
/example-polyline-intersection/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 |
--------------------------------------------------------------------------------
/example-polyline-intersection/example-polyline-intersection.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example-polyline-intersection/example-polyline-intersection.xcodeproj/project.xcworkspace/xcuserdata/da1.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-polyline-intersection/example-polyline-intersection.xcodeproj/project.xcworkspace/xcuserdata/da1.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/example-polyline-intersection/example-polyline-intersection.xcodeproj/xcshareddata/xcschemes/example-polyline-intersection 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 |
--------------------------------------------------------------------------------
/example-polyline-intersection/example-polyline-intersection.xcodeproj/xcshareddata/xcschemes/example-polyline-intersection 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 |
--------------------------------------------------------------------------------
/example-polyline-intersection/example-polyline-intersection.xcodeproj/xcuserdata/da1.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SuppressBuildableAutocreation
6 |
7 | E4B69B5A0A3A1756003C02F2
8 |
9 | primary
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/example-polyline-intersection/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 |
--------------------------------------------------------------------------------
/example-polyline-intersection/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 |
--------------------------------------------------------------------------------
/example-polyline-intersection/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | void ofApp::setup(){
4 | ofBackground(col3);
5 | ray.setup(glm::vec2(200, 400), glm::vec2(1, -0.5));
6 |
7 | yoff = 0;
8 | radius = 200;
9 | }
10 |
11 | void ofApp::update(){;
12 | float sinedTime = sin(ofGetElapsedTimef()* 0.5);
13 | ray.setDirection(glm::normalize(glm::vec2(1, sinedTime)));
14 | }
15 |
16 | void ofApp::draw(){
17 | poly.clear();
18 | xoff = 0;
19 | for(float angle = 0; angle < TWO_PI; angle+= 0.1 ){
20 | float newRadius = radius + ofMap(ofNoise(xoff+yoff), 0, 1, -25, 25);
21 | float x = offset.x + newRadius * cos(angle);
22 | float y = offset.y + newRadius * sin(angle);
23 | poly.addVertex(x, y);
24 |
25 | xoff += 0.15;
26 | }
27 | yoff += 0.05;
28 | poly.setClosed(true);
29 |
30 | ofPushStyle();
31 | ofSetColor(col4);
32 | poly.draw();
33 | ofPopStyle();
34 |
35 | ray.draw();
36 |
37 | glm::vec2 surfaceNormal; // store the intersection value
38 | float distance; // store the intersection value
39 | bool intersects = ray.intersectsPolyline(poly, distance, surfaceNormal);
40 | glm::vec2 intersection;
41 |
42 | ofPushStyle();
43 | // is there an intersection between the polyline and the ray?
44 | if (intersects) {
45 | // draw the ray that hits the polyline
46 | ofSetColor(col1);
47 | intersection = ray.getOrigin() + ray.getDirection() * distance;
48 | ofDrawLine(ray.getOrigin(), intersection);
49 | // draw the intersection point
50 | ofSetColor(col4);
51 | ofDrawCircle(intersection, 10);
52 | ofDrawBitmapString("intersection point", intersection.x+30, intersection.y+10);
53 |
54 | // draw the reflected ray
55 | ofSetColor(col2);
56 | auto reflectDir = glm::reflect(ray.getDirection(), surfaceNormal);
57 | ofDrawLine(intersection, intersection + reflectDir * ofGetWidth());
58 | ofDrawBitmapString("reflected light direction", intersection + reflectDir*80);
59 | }
60 | ofPopStyle();
61 | }
62 |
--------------------------------------------------------------------------------
/example-polyline-intersection/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ofMain.h"
3 | #include "ofxRaycaster.h"
4 |
5 | class ofApp : public ofBaseApp{
6 |
7 | public:
8 | void setup();
9 | void update();
10 | void draw();
11 |
12 | ofxraycaster::Ray2D ray;
13 | ofPolyline poly;
14 |
15 | ofFloatColor col1 = ofFloatColor(ofColor(246,233,101));
16 | ofFloatColor col2 = ofFloatColor(ofColor(85,255,60));
17 | ofFloatColor col3 = ofFloatColor(ofColor(20,164,204));
18 | ofFloatColor col4 = ofFloatColor(ofColor(180,0,131));
19 | ofFloatColor col5 = ofFloatColor(ofColor(0,0,0));
20 |
21 | glm::vec2 offset = glm::vec2(ofGetWidth()/2, ofGetHeight()/2);
22 | float angle;
23 | float xoff;
24 | float yoff;
25 | float radius;
26 | };
27 |
--------------------------------------------------------------------------------
/example-segment-intersection/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=$(realpath ../../..)
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-segment-intersection/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 |
--------------------------------------------------------------------------------
/example-segment-intersection/addons.make:
--------------------------------------------------------------------------------
1 | ofxRaycaster
2 |
--------------------------------------------------------------------------------
/example-segment-intersection/bin/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-segment-intersection/bin/data/.gitkeep
--------------------------------------------------------------------------------
/example-segment-intersection/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 |
--------------------------------------------------------------------------------
/example-segment-intersection/example-segment-intersection.qbs:
--------------------------------------------------------------------------------
1 | import qbs
2 | import qbs.Process
3 | import qbs.File
4 | import qbs.FileInfo
5 | import qbs.TextFile
6 | import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp
7 |
8 | Project{
9 | property string of_root: '../../..'
10 |
11 | ofApp {
12 | name: { return FileInfo.baseName(sourceDirectory) }
13 |
14 | files: [
15 | 'src/main.cpp',
16 | 'src/ofApp.cpp',
17 | 'src/ofApp.h',
18 | ]
19 |
20 | // This project is using addons.make to include the addons
21 | // since it was imported from old code. To change it to include
22 | // the addons from the qbs file change the following lines to
23 | // the list of used addons in array format. eg:
24 | //
25 | // of.addons: [
26 | // 'ofxGui',
27 | // 'ofxOpenCv',
28 | // ]
29 |
30 | // additional flags for the project. the of module sets some
31 | // flags by default to add the core libraries, search paths...
32 | // this flags can be augmented through the following properties:
33 | of.pkgConfigs: [] // list of additional system pkgs to include
34 | of.includePaths: [] // include search paths
35 | of.cFlags: [] // flags passed to the c compiler
36 | of.cxxFlags: [] // flags passed to the c++ compiler
37 | of.linkerFlags: [] // flags passed to the linker
38 | of.defines: [] // defines are passed as -D to the compiler
39 | // and can be checked with #ifdef or #if in the code
40 | of.frameworks: [] // osx only, additional frameworks to link with the project
41 | of.staticLibraries: [] // static libraries
42 | of.dynamicLibraries: [] // dynamic libraries
43 |
44 | // create a console window when the application start
45 | consoleApplication: false
46 |
47 | // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html
48 | // eg: this will enable ccache when compiling
49 | //
50 | // cpp.compilerWrapper: 'ccache'
51 |
52 | Depends{
53 | name: "cpp"
54 | }
55 |
56 | // common rules that parse the include search paths, core libraries...
57 | Depends{
58 | name: "of"
59 | }
60 |
61 | // dependency with the OF library
62 | Depends{
63 | name: "openFrameworks"
64 | }
65 | }
66 |
67 | property bool makeOF: true // use makfiles to compile the OF library
68 | // will compile OF only once for all your projects
69 | // otherwise compiled per project with qbs
70 |
71 | property bool precompileOfMain: false // precompile ofMain.h
72 | // faster to recompile when including ofMain.h
73 | // but might use a lot of space per project
74 |
75 | references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")]
76 | }
77 |
--------------------------------------------------------------------------------
/example-segment-intersection/example-segment-intersection.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example-segment-intersection/example-segment-intersection.xcodeproj/project.xcworkspace/xcuserdata/da1.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/example-segment-intersection/example-segment-intersection.xcodeproj/project.xcworkspace/xcuserdata/da1.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/example-segment-intersection/example-segment-intersection.xcodeproj/xcshareddata/xcschemes/example-segment-intersection 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 |
--------------------------------------------------------------------------------
/example-segment-intersection/example-segment-intersection.xcodeproj/xcshareddata/xcschemes/example-segment-intersection 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 |
--------------------------------------------------------------------------------
/example-segment-intersection/example-segment-intersection.xcodeproj/xcuserdata/da1.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SuppressBuildableAutocreation
6 |
7 | E4B69B5A0A3A1756003C02F2
8 |
9 | primary
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/example-segment-intersection/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 |
--------------------------------------------------------------------------------
/example-segment-intersection/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 |
--------------------------------------------------------------------------------
/example-segment-intersection/src/ofApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofApp.h"
2 |
3 | void ofApp::setup(){
4 | ray.setup(glm::vec2(270, 400), glm::vec2(1, -0.5));
5 | }
6 |
7 | void ofApp::update(){;
8 | float sinedTime = sin(ofGetElapsedTimef()* 1.5) * 0.3;
9 | ray.setDirection(glm::vec2(1, sinedTime));
10 | }
11 |
12 | void ofApp::draw(){
13 | ofBackground(col3);
14 | ray.draw();
15 | ofSetColor(col4);
16 | ofDrawLine(p1, p2);
17 |
18 | float distance; // store the distance value
19 | glm::vec2 intersection;
20 | bool intersects = ray.intersectsSegment(p1, p2, distance);
21 |
22 | ofPushStyle();
23 | // is there an intersection between the segment and the ray?
24 | if (intersects) {
25 | // draw the ray that hit the segment
26 | ofSetColor(col1);
27 | intersection = ray.getOrigin() + ray.getDirection() * distance;
28 | ofDrawLine(ray.getOrigin(), intersection);
29 | // draw the reflection
30 | // https://glm.g-truc.net/0.9.4/api/a00131.html
31 |
32 | //intersection
33 | ofDrawCircle(intersection, 10);
34 | //ofDrawBitmapString("intersection point", intersection.x + 30, intersection.y + 10);
35 | // reflection
36 | ofSetColor(col2);
37 |
38 | // There is not such a thing as a normal of a segment.
39 | // But we can fake it and make the segment acts as a surface reflecting light.
40 |
41 | // We first find the direction of the segment.
42 | glm::vec2 segmentDir = glm::normalize(p1 - p2);
43 | // and then we use as normal a vector orthogonal to direction.
44 | glm::vec2 segmentSurfaceNormal = glm::vec2(segmentDir.y, -segmentDir.x);
45 |
46 | auto reflectDir = glm::reflect(ray.getDirection(), segmentSurfaceNormal);
47 | ofDrawLine(intersection, intersection + reflectDir * ofGetWidth());
48 |
49 | //ofDrawBitmapString("reflected light", intersection + reflectDir * 100);
50 | }
51 | ofPopStyle();
52 | }
53 |
54 |
55 |
--------------------------------------------------------------------------------
/example-segment-intersection/src/ofApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxRaycaster.h"
5 |
6 | class ofApp : public ofBaseApp{
7 |
8 | public:
9 | void setup();
10 | void update();
11 | void draw();
12 |
13 | ofxraycaster::Ray2D ray;
14 | glm::vec2 p1 = glm::vec2(200, 80);
15 | glm::vec2 p2 = glm::vec2(400, 400);
16 | ofFloatColor col1 = ofFloatColor(ofColor(246,233,101));
17 | ofFloatColor col2 = ofFloatColor(ofColor(85,255,60));
18 | ofFloatColor col3 = ofFloatColor(ofColor(20,164,204));
19 | ofFloatColor col4 = ofFloatColor(ofColor(180,0,131));
20 | ofFloatColor col5 = ofFloatColor(ofColor(0,0,0));
21 | };
22 |
--------------------------------------------------------------------------------
/img/3D.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/3D.gif
--------------------------------------------------------------------------------
/img/example-3d.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/example-3d.png
--------------------------------------------------------------------------------
/img/example-multiple-rays.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/example-multiple-rays.png
--------------------------------------------------------------------------------
/img/example-polyline-intersection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/example-polyline-intersection.png
--------------------------------------------------------------------------------
/img/example-segment-intersection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/example-segment-intersection.png
--------------------------------------------------------------------------------
/img/mesh-intersection.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/mesh-intersection.gif
--------------------------------------------------------------------------------
/img/mousepicker.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/mousepicker.gif
--------------------------------------------------------------------------------
/img/multiple-rays.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/multiple-rays.gif
--------------------------------------------------------------------------------
/img/polyline.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/polyline.gif
--------------------------------------------------------------------------------
/img/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/screenshot.png
--------------------------------------------------------------------------------
/img/segment.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/edap/ofxRaycaster/64fd74b07837e30755c81bf499748792721ea13c/img/segment.gif
--------------------------------------------------------------------------------
/src/Mousepicker.cpp:
--------------------------------------------------------------------------------
1 | #include "Mousepicker.h"
2 |
3 | void ofxraycaster::Mousepicker::draw(const float radius){
4 | ofPushStyle();
5 | ofSetColor(255,0,0);
6 | ofDrawSphere(ray.getOrigin() + ray.getDirection() * farClip, radius);
7 | ofPopStyle();
8 | }
9 |
10 | ofxraycaster::Ray& ofxraycaster::Mousepicker::getRay(){
11 | return ray;
12 | }
13 |
14 | // http://antongerdelan.net/opengl/raycasting.html
15 | void ofxraycaster::Mousepicker::setFromCamera(const glm::vec2& mouse, const ofCamera& camera){
16 | // set far and clip plane. Not used atm
17 | // but will come later with orthographic camera support(TODO)
18 | farClip = camera.getFarClip();
19 | nearClip = camera.getNearClip();
20 |
21 | glm::vec3 screenMouse (mouse.x,mouse.y,0);
22 | auto worldMouse = camera.screenToWorld(screenMouse);
23 | auto worldMouseEnd = camera.screenToWorld(glm::vec3(screenMouse.x, screenMouse.y, 1.0f));
24 |
25 | auto worldMouseDirection = worldMouseEnd - worldMouse;
26 |
27 | ray.setup(camera.getGlobalPosition(), glm::normalize(worldMouseDirection));
28 | }
29 |
--------------------------------------------------------------------------------
/src/Mousepicker.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ofMain.h"
3 | #include "Ray.h"
4 |
5 | namespace ofxraycaster {
6 | class Mousepicker {
7 | public:
8 | Mousepicker(){};
9 | void setFromCamera(const glm::vec2& coords, const ofCamera& camera);
10 | void draw(const float radius = 20.0f);
11 | Ray& getRay();
12 |
13 | private:
14 | Ray ray;
15 | float nearClip=0.0f;
16 | float farClip=0.0f;
17 | };
18 | }
19 |
--------------------------------------------------------------------------------
/src/Plane.cpp:
--------------------------------------------------------------------------------
1 | #include "Plane.h"
2 |
3 | ofxraycaster::Plane::Plane(glm::vec3 _orig, glm::vec3 _normal){
4 | orig = _orig;
5 | normal = _normal;
6 | }
7 |
8 | void ofxraycaster::Plane::setup(glm::vec3 _orig, glm::vec3 _normal){
9 | orig = _orig;
10 | normal = _normal;
11 | }
12 |
13 | void ofxraycaster::Plane::updateNormal(glm::vec3 _normal){
14 | normal = _normal;
15 | }
16 |
17 | void ofxraycaster::Plane::updateOrigin(glm::vec3 _orig){
18 | orig = _orig;
19 | }
20 |
21 | const glm::vec3 ofxraycaster::Plane::getOrigin() {
22 | return orig;
23 | }
24 |
25 | const glm::vec3 ofxraycaster::Plane::getNormal() {
26 | return normal;
27 | }
28 |
29 | glm::vec3 ofxraycaster::Plane::arbitraryOrthogonal(const glm::vec3& vec){
30 | bool b0 = (vec.x < vec.y) && (vec.x < vec.z);
31 | bool b1 = (vec.y <= vec.x) && (vec.y < vec.z);
32 | bool b2 = (vec.z <= vec.x) && (vec.z <= vec.y);
33 |
34 | auto d = glm::cross(vec, glm::vec3(int(b0), int(b1), int(b2)));
35 | cout << d << endl;
36 | return d;
37 | }
38 |
39 |
40 | void ofxraycaster::Plane::draw(float radius){
41 | ofPushStyle();
42 | ofSetColor(0,255,0);
43 | // draw position of the plane
44 | // TODO, draw a frid with a normal;
45 | ofPopStyle();
46 | }
47 |
--------------------------------------------------------------------------------
/src/Plane.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ofMain.h"
3 |
4 | namespace ofxraycaster {
5 | class Plane {
6 | public:
7 | Plane(){};
8 | Plane(glm::vec3 _orig, glm::vec3 _normal);
9 |
10 | void draw(float radius = 20.);
11 | void setup(glm::vec3 _orig, glm::vec3 _normal);
12 | void updateNormal(glm::vec3 _normal);
13 | void updateOrigin(glm::vec3 _orig);
14 | const glm::vec3 getOrigin();
15 | const glm::vec3 getNormal();
16 | glm::vec3 arbitraryOrthogonal(const glm::vec3& vec);
17 |
18 | private:
19 | glm::vec3 orig;
20 | glm::vec3 normal;
21 | };
22 | }
23 |
--------------------------------------------------------------------------------
/src/Ray.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "Plane.h"
3 | #include "Ray.h"
4 |
5 |
6 | /// \brief it creates a ray given an origin T and a direction T
7 | /// @param [in] _origin
8 | /// @param [in] _direction
9 | ofxraycaster::Ray::Ray(glm::vec3 _origin, glm::vec3 _direction){
10 | origin = _origin;
11 | direction = glm::normalize(_direction);
12 | }
13 |
14 | /// \brief it sets the origin and direction of a ray. For example,
15 | /// for a 2D ray:
16 | ///
17 | /// ~~~~{.cpp}
18 | /// ofxraycaster::Ray ray;
19 | /// ray.setup(glm::vec2(10,5), glm::vec2(1,0));
20 | /// ~~~~
21 | void ofxraycaster::Ray::setup(glm::vec3 _origin, glm::vec3 _direction){
22 | origin = _origin;
23 | direction = glm::normalize(_direction);
24 | }
25 |
26 | /// \brief it returns the origin of the ray,
27 | const glm::vec3 ofxraycaster::Ray::getOrigin() {
28 | return origin;
29 | }
30 |
31 | void ofxraycaster::Ray::setOrigin(glm::vec3 _origin){
32 | origin = _origin;
33 | }
34 |
35 | const glm::vec3 ofxraycaster::Ray::getDirection() {
36 | return direction;
37 | }
38 |
39 | void ofxraycaster::Ray::setDirection(glm::vec3 _direction){
40 | direction = _direction;
41 | }
42 |
43 | void ofxraycaster::Ray::draw(float radius){
44 | ofPushStyle();
45 | // draw origin
46 | ofSetColor(246,233,101);
47 | ofDrawSphere(origin, radius);
48 |
49 | // draw direction
50 | auto end = origin + (direction * (radius*10.0f));
51 | ofSetLineWidth(3);
52 | ofDrawLine(origin,end);
53 | ofSetLineWidth(1);
54 | ofPopStyle();
55 | }
56 |
57 | bool ofxraycaster::Ray::intersectsPlane(ofxraycaster::Plane plane, float & distance){
58 | return glm::intersectRayPlane(origin, direction,
59 | plane.getOrigin(), plane.getNormal(),
60 | distance);
61 | }
62 |
63 | bool ofxraycaster::Ray::intersectsTriangle(glm::vec3 const & vert0, glm::vec3 const & vert1, glm::vec3 const & vert2, glm::vec2 & baryPosition, float &distance){
64 | return glm::intersectRayTriangle(origin, direction, vert0, vert1, vert2, baryPosition, distance);
65 | }
66 |
67 | bool ofxraycaster::Ray::intersectsSphere(const glm::vec3 & _center, const float & _radius, glm::vec3& _position, glm::vec3 & _normal){
68 |
69 | return glm::intersectRaySphere(origin, direction, _center, _radius, _position, _normal);
70 | }
71 |
72 | bool ofxraycaster::Ray::intersectsPrimitive(const of3dPrimitive& primitive, glm::vec2 & baricentricCoords, float &distance, glm::vec3 & intNormal) {
73 | // at the beginning, no intersection is found and the distance to the closest surface
74 | // is set to an high value;
75 | bool found = false;
76 | float distanceToTheClosestSurface = std::numeric_limits::max();
77 | for (const ofMeshFace& face : primitive.getMesh().getUniqueFaces()) {
78 | bool intersection = glm::intersectRayTriangle(
79 | origin, direction,
80 | glm::vec3(primitive.getGlobalTransformMatrix() * glm::vec4(face.getVertex(0), 1.f)),
81 | glm::vec3(primitive.getGlobalTransformMatrix() * glm::vec4(face.getVertex(1), 1.f)),
82 | glm::vec3(primitive.getGlobalTransformMatrix() * glm::vec4(face.getVertex(2), 1.f)),
83 | baricentricCoords,
84 | distance);
85 | // when an intersection is found, it updates the distanceToTheClosestSurface value
86 | // this value is used to order the new intersections, if a new intersection with a smaller baricenter.z
87 | // value is found, this one will become the new intersection
88 | if (intersection) {
89 | if (distance < distanceToTheClosestSurface) {
90 | found = true;
91 | distanceToTheClosestSurface = distance;
92 |
93 | intNormal = glm::normalize(
94 | glm::vec3(primitive.getGlobalTransformMatrix() *
95 | glm::vec4(face.getFaceNormal(), 1.0f))
96 | );
97 | }
98 | }
99 | }
100 | distance = distanceToTheClosestSurface;
101 | return found;
102 | }
103 |
104 | bool ofxraycaster::Ray::intersectsMesh(const ofMesh& mesh, glm::vec2 & baricentricCoords, float &distance, glm::vec3 & intNormal){
105 |
106 | // Guards. intersectsMesh only works with indexed geometries of
107 | // traingles
108 | if (mesh.getMode() != OF_PRIMITIVE_TRIANGLES) {
109 | ofLog() << "intersectsMesh works only with OF_PRIMITIVE_TRIANGLES";
110 | return false;
111 | }
112 |
113 | if (mesh.getNumIndices() < 3) {
114 | ofLog() << "mesh intersection works only with indexed geometries";
115 | return false;
116 | }
117 |
118 | if (mesh.getNumIndices()%3 != 0) {
119 | ofLog() << "the total number of the indices is not a multiple of 3";
120 | return false;
121 | }
122 |
123 | // at the beginning, no intersection is found and the distance
124 | // to the closest surface is set to an high value;
125 | bool found = false;
126 | float distanceToTheClosestSurface = std::numeric_limits::max();
127 | for (unsigned int i = 0; i< mesh.getNumIndices(); i+=3) {
128 | bool intersection = glm::intersectRayTriangle(
129 | origin, direction,
130 | mesh.getVertex(mesh.getIndex(i)),
131 | mesh.getVertex(mesh.getIndex(i+1)),
132 | mesh.getVertex(mesh.getIndex(i+2)),
133 | baricentricCoords,
134 | distance
135 | );
136 |
137 | // when an intersection is found, it updates the distanceToTheClosestSurface value
138 | // this value is used to order the new intersections, if a new intersection with a smaller baricenter.z
139 | // value is found, this one will become the new intersection
140 | if (intersection) {
141 | if (distance < distanceToTheClosestSurface) {
142 | found = true;
143 | distanceToTheClosestSurface = distance;
144 |
145 | const int ia = mesh.getIndex(i);
146 | const int ib = mesh.getIndex(i+1);
147 | const int ic = mesh.getIndex(i+2);
148 |
149 | glm::vec3 e1 = mesh.getVertex(ia) - mesh.getVertex(ib);
150 | glm::vec3 e2 = mesh.getVertex(ic) - mesh.getVertex(ib);
151 |
152 | intNormal = glm::cross(e1,e2);
153 | }
154 | }
155 | }
156 | distance = distanceToTheClosestSurface;
157 | return found;
158 | }
159 |
160 | bool ofxraycaster::Ray::intersectsMesh(const ofMesh& mesh, const glm::mat4& transformationMatrix, glm::vec2 & baricentricCoords, float &distance, glm::vec3 & intNormal){
161 |
162 | // Guards. intersectsMesh only works with indexed geometries of
163 | // traingles
164 | if (mesh.getMode() != OF_PRIMITIVE_TRIANGLES) {
165 | ofLog() << "intersectsMesh works only with OF_PRIMITIVE_TRIANGLES";
166 | return false;
167 | }
168 |
169 | if (mesh.getNumIndices() < 3) {
170 | ofLog() << "mesh intersection works only with indexed geometries";
171 | return false;
172 | }
173 |
174 | if (mesh.getNumIndices()%3 != 0) {
175 | ofLog() << "the total number of the indices is not a multiple of 3";
176 | return false;
177 | }
178 |
179 | // at the beginning, no intersection is found and the distance
180 | // to the closest surface is set to an high value;
181 | bool found = false;
182 | float distanceToTheClosestSurface = std::numeric_limits::max();
183 | for (unsigned int i = 0; i< mesh.getNumIndices(); i+=3) {
184 | bool intersection = glm::intersectRayTriangle(
185 | origin, direction,
186 | glm::vec3(transformationMatrix * glm::vec4(mesh.getVertex(mesh.getIndex(i)), 1.0f)),
187 | glm::vec3(transformationMatrix * glm::vec4(mesh.getVertex(mesh.getIndex(i+1)), 1.0f)),
188 | glm::vec3(transformationMatrix * glm::vec4(mesh.getVertex(mesh.getIndex(i+2)), 1.0f)),
189 | baricentricCoords,
190 | distance
191 | );
192 |
193 |
194 | if (intersection) {
195 | if (distance < distanceToTheClosestSurface) {
196 | found = true;
197 | distanceToTheClosestSurface = distance;
198 |
199 | const int ia = mesh.getIndex(i);
200 | const int ib = mesh.getIndex(i+1);
201 | const int ic = mesh.getIndex(i+2);
202 |
203 | glm::vec3 e1 = mesh.getVertex(ia) - mesh.getVertex(ib);
204 | glm::vec3 e2 = mesh.getVertex(ic) - mesh.getVertex(ib);
205 | glm::vec4 no = glm::vec4(glm::cross(e1,e2), 1.0f);
206 |
207 | intNormal = glm::vec3(transformationMatrix * no);
208 | }
209 | }
210 | }
211 | distance = distanceToTheClosestSurface;
212 | return found;
213 | }
214 |
--------------------------------------------------------------------------------
/src/Ray.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ofMain.h"
3 | #include "Plane.h"
4 | #include "glm/gtx/intersect.hpp"
5 |
6 | namespace ofxraycaster {
7 | class Ray {
8 | public:
9 | Ray(){};
10 | ///
11 | /// \brief it creates a ray given an origin T and a direction T
12 | /// @param [in] _origin
13 | /// @param [in] _direction
14 | /// ~~~~{.cpp}
15 | /// ofPixels p;
16 | /// ofLoadImage(p, "pathToImage.jpg");
17 | /// ~~~~
18 | Ray(glm::vec3 _origin, glm::vec3 _direction);
19 |
20 | /// \brief it sets the origin and direction of a ray. For example,
21 | /// for a 3D ray:
22 | ///
23 | /// ~~~~{.cpp}
24 | /// ofxraycaster::Ray3D ray;
25 | /// ray.setup(glm::vec3(10,5,0), glm::vec2(1,0,0));
26 | /// ~~~~
27 | void setup(glm::vec3 _origin, glm::vec3 _direction);
28 |
29 | const glm::vec3 getOrigin();
30 | void setOrigin(glm::vec3 _origin);
31 | const glm::vec3 getDirection();
32 | void setDirection(glm::vec3 _direction);
33 | void draw(float radius = 20.);
34 | bool intersectsPlane(ofxraycaster::Plane plane, float & distance);
35 | bool intersectsTriangle(glm::vec3 const &vert0, glm::vec3 const &vert1, glm::vec3 const &vert2, glm::vec2 &baryPosition, float &distance);
36 | bool intersectsSphere(const glm::vec3 & _center, const float & _radius, glm::vec3& _position, glm::vec3 & _normal);
37 | bool intersectsPrimitive(const of3dPrimitive& primitive, glm::vec2 & baricentricCoords, float &distance, glm::vec3 & intNormal);
38 | bool intersectsMesh(const ofMesh& mesh, glm::vec2 & baricentricCoords, float &distance, glm::vec3 & intNormal);
39 | bool intersectsMesh(const ofMesh& mesh, const glm::mat4& transformationMatrix, glm::vec2 & baricentricCoords, float &distance, glm::vec3 & intNormal);
40 |
41 | private:
42 | glm::vec3 origin;
43 | glm::vec3 direction;
44 | };
45 | }
46 |
--------------------------------------------------------------------------------
/src/Ray2D.cpp:
--------------------------------------------------------------------------------
1 | #include "Ray2D.h"
2 |
3 | ofxraycaster::Ray2D::Ray2D(glm::vec2 _origin, glm::vec2 _direction){
4 | origin = _origin;
5 | direction = glm::normalize(_direction);
6 | }
7 |
8 | /// \brief it sets the origin and direction of a ray. For example,
9 | /// for a 2D ray:
10 | ///
11 | /// ~~~~{.cpp}
12 | /// ofxraycaster::Ray2D ray;
13 | /// ray.setup(glm::vec2(10,5), glm::vec2(1,0));
14 | /// ~~~~
15 | void ofxraycaster::Ray2D::setup(glm::vec2 _origin, glm::vec2 _direction){
16 | origin = _origin;
17 | direction = glm::normalize(_direction);
18 | }
19 |
20 | /// \brief it returns the origin of the ray,
21 | const glm::vec2 ofxraycaster::Ray2D::getOrigin(){
22 | return origin;
23 | }
24 |
25 | void ofxraycaster::Ray2D::setOrigin(glm::vec2 _origin){
26 | origin = _origin;
27 | }
28 |
29 | const glm::vec2 ofxraycaster::Ray2D::getDirection(){
30 | return direction;
31 | }
32 |
33 | void ofxraycaster::Ray2D::setDirection(glm::vec2 _direction){
34 | direction = _direction;
35 | }
36 |
37 | void ofxraycaster::Ray2D::draw(float radius){
38 | ofPushStyle();
39 | // draw origin
40 | ofSetColor(246,233,101);
41 | ofDrawCircle(origin, radius);
42 |
43 | // draw direction
44 | auto end = origin + (direction * (radius*4.));
45 | ofSetLineWidth(3);
46 | ofDrawLine(origin,end);
47 | ofSetLineWidth(1);
48 | ofPopStyle();
49 | }
50 |
51 | bool ofxraycaster::Ray2D::intersectsSegment(const glm::vec2 & a, const glm::vec2 & b, float & distance){
52 | bool intersects = false;
53 | distance = std::numeric_limits::infinity();
54 |
55 | float x = origin.x;
56 | float y = origin.y;
57 | float dx = direction.x;
58 | float dy = direction.y;
59 |
60 | float s, denom;
61 | if (dy / dx != (b.y - a.y) / (b.x - a.x)){
62 | denom = ((dx * (b.y - a.y)) - dy * (b.x - a.x));
63 | if (denom != 0) {
64 | distance = (((y - a.y) * (b.x - a.x)) - (x - a.x) * (b.y - a.y)) / denom;
65 | s = (((y - a.y) * dx) - (x - a.x) * dy) / denom;
66 | if (distance >= 0 && s >= 0 && s <= 1) {
67 | intersects = true;
68 | //return { x: x + r * dx, y: y + r * dy };
69 | }
70 | }
71 | }
72 |
73 | return intersects;
74 | }
75 |
76 | bool ofxraycaster::Ray2D::intersectsPolyline(const ofPolyline & poly, float & distance, glm::vec2& surfaceNormal){
77 |
78 | vector container = poly.getVertices();
79 | distance = std::numeric_limits::infinity();
80 | bool intersects = false;
81 | for (int i = 0; i < container.size(); i++) {
82 | // If it is an opened polyline, do not check for the intersection
83 | // between the last point of the polyline and the first one
84 | if (!poly.isClosed() && i == container.size() -1) {
85 | continue;
86 | }
87 |
88 | // qui in realta' dovresti chiudere solo se la poly e' closed.
89 | auto endSegmentIndex = container.size() == (i + 1) ? 0 : i + 1;
90 |
91 | float tmpDistance = distance;
92 | bool tmpIntersect =
93 | intersectsSegment(container[i],
94 | container[endSegmentIndex],
95 | tmpDistance);
96 | if (tmpIntersect) {
97 | if (intersects == false) { intersects = true; };
98 | if (tmpDistance < distance) {
99 | //first find the direction of the segment.
100 | glm::vec2 segmentDir = glm::normalize(container[i] - container[endSegmentIndex]);
101 | // and then use as normal a vector orthogonal to the direction.
102 | surfaceNormal = glm::vec2(segmentDir.y, -segmentDir.x);
103 | distance = tmpDistance;
104 | }
105 | }
106 | }
107 |
108 | return intersects;
109 | }
110 |
--------------------------------------------------------------------------------
/src/Ray2D.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "ofMain.h"
3 |
4 | namespace ofxraycaster {
5 | class Ray2D {
6 | public:
7 | Ray2D(){};
8 | ///
9 | /// \brief it creates a ray given an origin T and a direction T
10 | /// @param [in] _origin
11 | /// @param [in] _direction
12 | /// ~~~~{.cpp}
13 | /// Ray2D p;
14 | /// ~~~~
15 | Ray2D(glm::vec2 _origin, glm::vec2 _direction);
16 |
17 | /// \brief it sets the origin and direction of a ray. For example,
18 | /// for a 2D ray:
19 | ///
20 | /// ~~~~{.cpp}
21 | /// ofxraycaster::Ray2D ray;
22 | /// ray.setup(glm::vec2(10,5), glm::vec2(1,0));
23 | /// ~~~~
24 | void setup(glm::vec2 _origin, glm::vec2 _direction);
25 | /// \brief it returns the origin of the ray,
26 | const glm::vec2 getOrigin();
27 | void setOrigin(glm::vec2 _origin);
28 | const glm::vec2 getDirection();
29 | void setDirection(glm::vec2 _direction);
30 | void draw(float radius = 20.);
31 | bool intersectsSegment(const glm::vec2 & a, const glm::vec2 & b, float & distance);
32 | bool intersectsPolyline(const ofPolyline & poly, float & distance, glm::vec2& surfaceNormal);
33 |
34 | private:
35 | glm::vec2 origin;
36 | glm::vec2 direction;
37 | };
38 |
39 | }// end namespace
40 |
--------------------------------------------------------------------------------
/src/ofxRaycaster.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "Ray2D.h"
4 | #include "Ray.h"
5 | #include "Plane.h"
6 | #include "Mousepicker.h"
7 |
--------------------------------------------------------------------------------