ofxRay | Lightweight Ray class and operations for openFrameworks
kandi X-RAY | ofxRay Summary
kandi X-RAY | ofxRay Summary
A lightweight set of tools for intersection testings (e.g. does a ray intersect a plane).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ofxRay
ofxRay Key Features
ofxRay Examples and Code Snippets
Community Discussions
Trending Discussions on ofxRay
QUESTION
I've tried many examples of code from the openframeworks forum and documentation, but I couldn't get one to do what I want.
I have an ofRay (from ofxRay), and a list of of3dPrimitive. I am trying to figure out if the ray intersects a primitive, and if so, to know which primitive the ray intersected with "first" (as in, which one is the closest to the screen).
...ANSWER
Answered 2017-Apr-06 at 20:53Assuming plenty of triangle/mesh raycasting code on the internet you have tried would have solved your problem, I think your problem is in the first method, in which you set a "found" variable, but do not return from the method if found or pick the object with min distance.
The code you've provided will just return the last primitive's hit test result.
If you have over-simplified your code, please post again with more detail.
Edit:
The coordinates you get from the mesh's faces are in object space. You need to convert them to world space before any calculations, or better, convert the ray to object space.
See this code for a working implementation: https://github.com/mrdoob/three.js/blob/master/src/objects/Mesh.js
Notice the applyMatrix4 calls that apply a world matrix to bring them to the same space.
QUESTION
I am working in a 3D space. I have a ray, or more specifically the start and transmission vector of a ray in 3D space. I also have a triangle, which I know for a fact is hit by the ray. By triangle I of course mean I have three 3D points. I can also calculate a normal vector from this triangle easily.
Now I need to get a new ray, which would be the reflection after that specific hit.
I also don't know exacltly where on the triangle the point of contact is, but it obviously has to be taken into account to get the reflected ray. That point would be the start of that new ray.
This is trivial to do in 2D, but I can't figure out how to do it in 3D.
I am using C++ and OpenFrameworks with the ofxRay add-on.
...ANSWER
Answered 2017-Apr-16 at 16:26This problem splits cleanly into two problems: find the point where the ray meets the triangle -- which is the point of origin of the reflected ray -- and find the direction (vector) of the reflected ray.
Let the normal vector of the triangle be n. The equation describing the plane of the triangle is
nx = k
You can determine k by plugging one of the triangle vertices into that equation. The equation of the incident ray is
x = tv + p
where p is the point of origin of the ray, and v is its (normalized) direction. To find the point of intersection of the ray, just solve this pair of equations, which comes down to solving
n(tv + p) = k
for t, then plugging that back into the equation for the ray.
To find the direction of the reflected ray, we must reverse the component of the incident ray parallel to the triangle's normal:
vr = v + 2(vn)v
(Watch out for the sign-- I assumed that the normal points out of the face which the ray hits.)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ofxRay
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page