{"id":16147457,"url":"https://github.com/edap/ofxraycaster","last_synced_at":"2026-02-10T02:31:50.266Z","repository":{"id":145594149,"uuid":"129632426","full_name":"edap/ofxRaycaster","owner":"edap","description":"Plane, 2D and 3D Ray objects for openFrameworks.It checks for the intersection of a ray with a segment, a sphere, a triangle, a plane, an ofPrimitive, an ofPolyline an with an ofMesh.","archived":false,"fork":false,"pushed_at":"2025-06-23T11:01:46.000Z","size":8777,"stargazers_count":63,"open_issues_count":1,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-08-18T05:35:37.466Z","etag":null,"topics":["2d-ray","addon","intersection","intersection-methods","intersection-point","openframeworks","plane","ray","raycasting"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-04-15T17:08:53.000Z","updated_at":"2025-06-24T08:40:55.000Z","dependencies_parsed_at":"2025-08-18T05:26:43.850Z","dependency_job_id":"641b110a-97f2-44b7-a2aa-0f08d78eb572","html_url":"https://github.com/edap/ofxRaycaster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/edap/ofxRaycaster","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edap%2FofxRaycaster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edap%2FofxRaycaster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edap%2FofxRaycaster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edap%2FofxRaycaster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edap","download_url":"https://codeload.github.com/edap/ofxRaycaster/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edap%2FofxRaycaster/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29289470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T21:57:15.303Z","status":"online","status_checked_at":"2026-02-10T02:00:07.935Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-ray","addon","intersection","intersection-methods","intersection-point","openframeworks","plane","ray","raycasting"],"created_at":"2024-10-10T00:25:21.840Z","updated_at":"2026-02-10T02:31:50.246Z","avatar_url":"https://github.com/edap.png","language":"C++","readme":"# ofxRaycaster\n\n[![Build status](https://travis-ci.org/edap/ofxRaycaster.svg?branch=master)](https://travis-ci.org/edap/ofxRaycaster)\n[![Build status](https://ci.appveyor.com/api/projects/status/p7l03tb6m1ctxbju?svg=true)](https://ci.appveyor.com/project/edap/ofxraycaster)\n\n## Donation:\n\nIf you find this project useful please consider a donation.\n\n[![paypal](https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gi)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=DUA4FYWCMFDSG)\n\n##### Table of Contents\n[How to use it](#how-to)\n\n[Methods for 2D and 3D rays](#generics)\n\n[2D Intersection Methods](#2d-intersections)\n\n[3D Intersection Methods](#3d-intersections)\n\n[Mouse Picker](#mousepicker)\n\n[Showcase](#showcase)\n\n\n![img](img/screenshot.png)\n\n\nThis 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.\n\n\u003ca name=\"how-to\"/\u003e\n\n## How to use it:\n\n\u003c/a\u003e\n\nDownload this addon in your `addons` folder. Create a new project with the project generator and add as addon `ofxRaycaster`.\nIn your project, add at the top of your `ofApp.h` file\n\n```cpp\n#include \"ofxRaycaster.h\"\n```\nTo get started using a 2D ray in your project, declare a `ray` variable in your `ofApp.h` header file:\n\n```cpp\nofxraycaster::Ray2D ray;\n```\n\nIf you want to use a 3D ray, declare the ray like this.\n\n```cpp\nofxraycaster::Ray ray;\n```\n\n\u003ca name=\"generics\"/\u003e\n\n## Generic methods, for both 2D and 3D rays:\n\n\u003c/a\u003e\n\n#### setup\n\n```cpp\nvoid setup(glm::vec2 origin, glm::vec2 direction)\n```\nSet the origin and direction of a ray. For example, for a 2D ray:\n\n```\nray.setup(glm::vec2(10,5), glm::vec2(1,0));\n```\n\n#### getOrigin\n\n```cpp\nglm::vec2 getOrigin();\n```\nReturn the origin of the vector. For example, for the 2D ray previously greated:\n```cpp\nray.getOrigin(); // returns glm::vec2(10,5)\n```\n\n#### getDirection\n\n```cpp\nglm::vec2 getDirection();\n```\nReturn the direction of the vector. For example, for the 2D ray previously greated:\n```cpp\nray.getDirection(); // returns glm::vec2(1,0)\n```\n\n#### setOrigin\n\n```cpp\nvoid setOrigin(glm::vec3 origin);\n```\n\nSet the origin of the ray;\n\n#### setDirection\n\n```cpp\nvoid setDirection(glm::vec2 _origin);\n```\n\nSet the direction of the ray;\n\n#### draw\n\n```cpp\nvoid draw(float radius = 20.);\n```\n\nDraw 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.\n\n\u003ca name=\"2d-intersections\"/\u003e\n\n## 2D intersection methods:\n\n\u003c/a\u003e\n\n| `example-polyline-intersection` | `example-segment-intersection`  |\n|     :---:      |      :---:    |\n|   ![img](img/polyline.gif )   | ![img](img/segment.gif )    |\n\n\n#### intersectsPolyline\nSee example `example-polyline-intersection`\n\n```cpp\nbool intersectsPolyline(const ofPolyline \u0026 poly, float \u0026 distance, glm::vec2\u0026 surfaceNormal);\n```\n\nCheck 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.\n\n```cpp\nofxraycaster::Ray2D ray;\nofPolyline poly;\n\nglm::vec2 surfaceNormal; // store the intersection value\nfloat distance; // store the intersection value\n\nif (ray.intersectsPolyline(poly, distance, surfaceNormal)) {\n    glm::vec2 intersection = ray.getOrigin() + ray.getDirection() * distance;\n    ofDrawLine(ray.getOrigin(), intersection);\n}\n```\n\n#### intersectsSegment\nSee example `example-segment-intersection`\n\n```cpp\nbool intersectsSegment(const glm::vec2 \u0026 a, const glm::vec2 \u0026 b, float \u0026 distance)\n```\n\nCheck 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.\n\n\n```cpp\nofxraycaster::Ray2D ray;\nauto a = glm::vec2(10, 30);\nauto b = glm::vec2(50, 50);\n// the segment goes from point a to point b\n\nfloat distance; // store the intersection value\n\nif (ray.intersectsSegment(a, b, distance)) {\n    glm::vec2 intersection = ray.getOrigin() + ray.getDirection() * distance;\n    ofDrawLine(ray.getOrigin(), intersection);\n}\n```\n\n\u003ca name=\"3d-intersections\"/\u003e\n\n## 3D intersection methods:\n\n\u003c/a\u003e\n\n\n| `example-multiple-rays` | `example-mesh-intersection` | `example-3D` |\n| :---:         |     :---:      |          :---: |\n| ![img](img/multiple-rays.gif )   | ![img](img/mesh-intersection.gif )     | ![img](img/3D.gif )    |\n\n\n\n#### intersectsTriangle\n\nCheck the intersection between a ray and a triangle. See `example-3D`.\n\n```cpp\nbool intersectsTriangle(glm::vec3 const \u0026 vert0, glm::vec3 const \u0026 vert1, glm::vec3 const \u0026 vert2, glm::vec2 \u0026 baryPosition, float \u0026 distance)\n```\n\n\n#### intersectsSphere\n\nCheck the intersection between a ray and a sphere. See `example-3D`.\n\n```cpp\nbool intersectsSphere(const glm::vec3 \u0026 _center, const float \u0026 _radius, glm::vec3\u0026 _position, glm::vec3 \u0026 _normal)\n```\n\n#### intersectsPrimitive\n\nCheck the intersection between a ray and an `ofPrimitive`. See `example-3D`.\n\n```cpp\nbool intersectsPrimitive(const of3dPrimitive\u0026 primitive,  glm::vec2 \u0026 baricentricCoords, float \u0026 distance, glm::vec3 \u0026 intNormal)\n```\n\n#### intersectsPlane\n\nCheck the intersection between a ray and an `ofxraycaster::Plane`. See `example-3D`.\n\n```cpp\nbool intersectsPlane(ofxraycaster::Plane plane, float \u0026 distance);\n```\n\n#### intersectsMesh\n\nCheck the intersection between a ray and a mesh. See `example-mesh-intersection`.\n\n\n```\nbool intersectsMesh(const ofMesh\u0026 mesh,  glm::vec2 \u0026 baricentricCoords, float \u0026 distance, glm::vec3 \u0026 intNormal);\n```\n\nExample:\n\n```cpp\nvoid ofApp::draw(){\n    cam.begin();\n    mesh.draw();\n    ray.draw();\n\n    glm::vec2 baricentricCoordinates; // stores the barycentric coordinate of the triangle hit by the ray.\n    float distance;\n    glm::vec3 surfaceNormal; // stores the normal of the surface hit by the ray.\n    bool intersects = ray.intersectsMesh(mesh, baricentricCoordinates, distance, surfaceNormal);\n\n    // is there an intersection between the mesh and the ray?\n    if (intersects) {\n        auto intersection =\n            ray.getOrigin() + ray.getDirection() * distance;\n        // draw the ray hitting the mesh\n        ofDrawLine(ray.getOrigin(), intersection);\n        // draw the intersection point\n        ofDrawSphere(intersection, 5);\n\n        // draw the reflected light\n        auto reflLight = glm::reflect(ray.getDirection(), surfaceNormal);\n        ofDrawLine(intersection, intersection + 100 * reflLight);\n    }\n    cam.end();\n}\n```\n\nWhen 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`.\n\n```\nbool intersectsMesh(const ofMesh\u0026 mesh, const glm::mat4\u0026 transformationMatrix,  glm::vec2 \u0026 baricentricCoords, float \u0026 distance, glm::vec3 \u0026 intNormal);\n```\n\n\u003ca name=\"mousepicker\"/\u003e\n\n## Mousepicker:\n\n| `example-mousepicker` |\n|     :---:      |\n|   ![img](img/mousepicker.gif )| \n\n\n\n#### setFromCamera\n\n```cpp\nvoid setFromCamera(const glm::vec2 mouseCoords, const ofCamera camera);\n```\n\nSet the origin and the direction of the ray giving as argument an `ofCamera` and the mouse coordinates. See example `example-mousepicker`.\n\n#### draw\n\n```cpp\nvoid draw(const float radius = 20);\n```\n\nDraw a sphere under the mouse.\n\n#### getRay\n\n```cpp\nRay\u0026 getRay();\n```\n\nReturn the 3D ray that goes from the camera towards the mouse.\n\n\n\u003c/a\u003e\n\n\n\u003ca name=\"showcase\"/\u003e\n\n## Showcase:\n\n\u003c/a\u003e\n\nThis addon was used in the following projects:\n\n- [Border Tuner / Sintonizador Fronterizo](https://www.lozano-hemmer.com/border_tuner__sintonizador_fronterizo.php)\n\n- [Sphere Packing - Bach](https://www.lozano-hemmer.com/sphere_packing_bach.php)\n\n- [Sun and Moon](http://dominofactory.net/client_works/sun_and_moon.html)\n\nIf you want to add your project to this list, please open an issue.\n\n\n\n","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=DUA4FYWCMFDSG"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedap%2Fofxraycaster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedap%2Fofxraycaster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedap%2Fofxraycaster/lists"}