Problem with mouse raycasting

Problems building or running the engine, queries about how to use features etc.
Post Reply
Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Problem with mouse raycasting

Post by Niubbo »

Ogre Version: 1.11.8
Operating System: win10
Render System: dx9

I followed the intermediate tutorial 3 in order to make the entity picking using the bounding boxes; the entities I check are create sprites created from manual mesh and with texture rotation like the billboard, i created also the boundingbox around the entity a bounding box of more or less -60 as minimum and 60 as maximum.

All work fine until the entity is at short distance, but move far from the entity, gradually i have positive ray from outside the bounding box of entity, on the left or on the right, and negative clicking inside the the bounding box frame. Thia "offset" seems pretty much casual, it changes according the distance, and angle of entity respect the camera (in some case I have never positive return until i move the camera).

I wonder if I did something wrong or there're factors which influence the result: FOV value can impact? is necessary update the bounding box every update of vertex of entity (the dimension doens't change but I change rotation and texture coordinate), update the node world bounding? there're limits to the precision of raycasting for tiny entities at long distance?

thanks for every suggestion

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

Re: Problem with mouse raycasting

Post by sercero »

That tutorial uses a technique based on the BoundingBoxes of the OGRE Nodes, see if you can show the AABB in order to debug better.

There is another way of doing mouse picking which uses 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

This is more precise than using bounding boxes.

Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with mouse raycasting

Post by Niubbo »

Thanks. Yes I activated also the display of bounding boxes, and I noticed i have a false hit beyond the zone of boxes at long distance.

I debugged the code and it seems the problems are on two levels: in some case the node is not found in the octtree hit from the ray (I use octtree as scenariomanager with and box of -300.000-300.000 and depth 16. I wonder if there is some max distance problem in this case; i noticed that at the same distance if the object is near the border of the screen i have no result, if I rotate in order to have it in the center the same object give me positive result to the click. Check the zone of the click influence the octree nodes results?

In another situation (but I still to have to analize it) the problem is that the function mRay.intersects(m->getWorldBoundingBox()) where m is the object linked to the node return false.

Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with mouse raycasting

Post by Niubbo »

Definetely, something is strange; in some case I obtain the positive click in locations where I had a negative feedback few moments before, like things updated, and in anycase they don't correspond the bounding boxes of objects, when distance is not short and the object is not near the center of screen.

In the book of Grinblat\Peterson in the recipe of picking object I found the call to _updateSceneGraph , before execute the query. Can it be something I have to do too?

rpgplayerrobin
Gnoll
Posts: 620
Joined: Wed Mar 18, 2009 3:03 am
x 355

Re: Problem with mouse raycasting

Post by rpgplayerrobin »

I am not sure what you are using, but I do the picking in my game manually since that way I have 100% control over it, and it also means I can pick against meshes and not only their AABB:s.

Here is an old thread post I wrote about it: viewtopic.php?p=551881#p551881

Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with mouse raycasting

Post by Niubbo »

thanks; I used also the raycasting to poligon level https://wiki.ogre3d.org/Raycasting+to+the+polygon+level for be more accurate, but the problem is mainly why I cannot find the bouding box I'm clicking at video in first instance, or why it results present for the query in a zone different from that one I saw it "with the eyes". All of this when the object is beyond a specific distance or near the borders of game window.

I think the problem can be an error of the the octree settings ( I had to extended the default from 10000 to 300000); I made these settings after the scenemanager creation

Code: Select all

Ogre::Vector3 max(300000, 300000, 300000);
octtreebox.setExtents(-max, max);
m_scnMgr->setOption("Size", &octtreebox);
m_scnMgr->setOption("Depth", "16");

Increasing the scene bounding box, is better to increase or reduce the depth? the increment can change the precision?

rpgplayerrobin
Gnoll
Posts: 620
Joined: Wed Mar 18, 2009 3:03 am
x 355

Re: Problem with mouse raycasting

Post by rpgplayerrobin »

Since I have not used that internal Ogre code to do picking, I cannot help more regarding that.

But if you experience bugs with it, you can either debug the code or you can just do the picking yourself like in my example code (but without the per-triangle code, only against AABB:s).

Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with mouse raycasting

Post by Niubbo »

Yes i'm going to check better, at least to find a logic behind the problem. Stragenly the raycasting on the ground seems work well, with the correct point selected.

Post Reply