Raycast query on polygon level?

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
z is up
Gnoblar
Posts: 9
Joined: Fri Nov 26, 2021 10:52 am
x 1

Raycast query on polygon level?

Post by z is up »

Hello,

I'm trying to figure out how Ogre could assist me in finding the point where the player's click ray hits a surface. I found this guide, but it is for the old Ogre and uses a function named OgreVE::GetMeshInformation. I don't even konw, what OgreVE is and googling it didn't get me any answers.

I assume, however, that it is not possible to get the mesh information in Ogre Next at all, because the vertex buffer is transferred to the GPU write-only and then freed, isn't it? So I thought, maybe there is a clever solution for this using a shader (and let the GPU calculate the ray) and maybe it is even implemented already.

Anyway, I'm open for any tips on how to achieve this. What I have is the player's cursor position and an Ogre camera and what I need is the world position of the intersection with the first hit polygon. My only idea so far is to keep my model data in an appropriate format and manually implement an algorithm doing it on th CPU (after narrowing it down with the still available raycast query, which gives me a list of hit bounding boxes).

User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 156

Re: Raycast query on polygon level?

Post by sercero »

Do you really need to have the raycast at the polygon level?

Because if you want this for selecting entities for example, there is another way using shaders.

The idea is to color each object differently and use the color to select the object.

Here is a tutorial: https://ogldev.org/www/tutorial29/tutorial29.html

z is up
Gnoblar
Posts: 9
Joined: Fri Nov 26, 2021 10:52 am
x 1

Re: Raycast query on polygon level?

Post by z is up »

Thank you for your reply. Sounds interesting, although I don't know yet what difficulties would arise if I try to create and install a custom shader in Ogre. What you suggested can be used to raycast to the polygon level, if I understand it correctly. After all the shader is for indexing the fragments of an object.

User avatar
sercero
Bronze Sponsor
Bronze Sponsor
Posts: 449
Joined: Sun Jan 18, 2015 4:20 pm
Location: Buenos Aires, Argentina
x 156

Re: Raycast query on polygon level?

Post by sercero »

This is a common technique for selecting entities in games.

The idea is to use a shader to have each entity drawn in a different color (the entity would be drawn in a single solid color) to a texture.

Then you get the position of the mouse and use that position to reference the texture.

The color you get from the texture corresponds to the entity that was selected.

Post Reply