Advertisement

Help understanding raycast system

Started by August 23, 2020 06:24 AM
3 comments, last by JoeJ 4 years, 3 months ago

Raycast (in sense of finding an object in the game world) nowdays is done mostly by the physics engine. It is specialized anyways in locating interactions between two objects by various techniques and algorithms and so also capable of handling the ray intersection tests more proper than simly walking through a list of objects.

I guess it depends on the implementation side but objects may be for example located by a usual tree structure like quad-, R- or octrees and so a ray is first checking against the bounding box of a cell and on hit, fine graining the detection to deeper levels of that cell to find the object it targets to. If either of that fails, move on to the next cell and repeat.

But for a deeper know, you can visit GitHub and look either for

NVidia's PhysX Engine

Bullet Physics

Advertisement

(Sorry for double posting due to some lack of the website)

I assume you mean raycasting in the sense of Wolfenstein / Doom, but no raytracing used by physics engines?

heeraachemicals said:
So when you shoot a raycast line you have to go thought the list of objects in the scene

Yes, but you may want to do this quickly so you do not have to iterate the whole world for each ray.

Doom engine did this by using BSP trees (Binary Space Partition). This slices the space into two half spaces and recurses the process on both halves. You get convex cells at the leafs, and every time you cross a cell boundary you can find adjacent cells using traversal. So you get an efficient way to traverse the scene fornt to back for each ray, intersecting only what's needed.
See Michael Abrashs Graphics Programming Blackbook, which is online and free.

Other engines (like Ken Silvermans Build engine, that was used for more games than id softwares Doom engine) did not use BSP trees.
I don't know how they solved this problem, but probably easy to find out.

For the start, using a regular grid sounds the easiest solution.

This topic is closed to new replies.

Advertisement