Contents
What can you do with Ray picking in OpenGL?
With ray picking we usually simplify a scene into bounding spheres or boxes. This makes the calculation a bit easier than testing all of the individual triangles. We don’t need to create a 3d sphere out of triangles that can be rendered; we just represent the sphere as a simple function.
How does mouse pick work in OpenGL 4?
Anton Gerdelan. Last Updated 2 October 2016 It can be useful to click on, or “pick” a 3d object in our scene using the mouse cursor. One way of doing this is to project a 3d ray from the mouse, through the camera, into the scene, and then check if that ray intersects with any objects. This is usually called ray casting.
What should the Z be in ray casting?
This should be in the ranges of x [-1:1] y [-1:1] and z [-1:1]. We have an x and y already, so we scale their range, and reverse the direction of y. We don’t actually need to specify a z yet, but I put one in (for the craic). We want our ray’s z to point forwards – this is usually the negative z direction in OpenGL style.
Which is the best way to draw with ray casting?
You can project this as a 2d distance along the ray direction (dot product) and compare the end point’s squared distance to the sphere origin (use Pythagoras’ theorem) with the squared radius. Generally, if you want to draw on a shape (e.g. dragging boxes) then ray-casting is a good choice.
Which is an object considered to have a bounding box?
An object in the world is considered to have a bounding box, rather than a bounding sphere. This has the weakness that irregularly shaped, rotating objects will create gigantic boxes, but it is quite easy to work out the extents, and use these to validate a set of ray-plane intersections.
Which is better ray casting or axis aligned box intersection?
If you want accuracy then you’re almost certainly better off using a colour-based picking method, which has the cost of one extra rendering pass, rather than 1-5 ray casts per selectable object in the scene . You can do ray versus axis-aligned box intersection, which is quite commonly used.
Can you do Ray intersections in any space?
We can do ray intersections in any space (world, eye, etc.), but everything needs to be in the same space – let’s assume that we are doing our calculations in world space. This means that our ray origin is going to be the world x,y,z position of the camera.