Function to raycast for 3D object picking
npm install p5-raycast
`
or Install via the command line
`bash
npm i p5-raycast
`
Usage
Define a camera variable called cam in the setup function
`javascript
cam = createCamera();
`
The raycast function accepts three arguments:
- rayDistance: the length of the ray that will be cast into the 3D scene through the mouse position.
- objectPosition: An array [x, y, z] defining the position of the object you want to select in world space.
- objectRadius: The distance from the object's position which is considered a "hit".
`javascript
raycast(rayDistance, objectPosition, objectRadius); // Returns a boolean
`
Dependencies
The matrix math for un-projecing is done with math.js
Copy and paste this script tag into your index.html file
`
``