[solved] Problem with Camera IsVisible

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

[solved] Problem with Camera IsVisible

Post by Niubbo »

Ogre Version: 1.12.8
Operating System: Win10
Render System: dx9


I want to use the camera::isvisible function in order to identify which one of my 2d trees entity have to rotate or no; I created this code

Code: Select all

	
	
	if (mNode)
	{ 
		Ogre::SceneNode::ObjectMap map = mNode->getAttachedObjects();
		if (!map.empty())
		{
			Ogre::Camera* camera = theApp.m_scnMgr->getCamera(CAMERA);
			return camera->isVisible(map[0]->getWorldBoundingBox());

		}			
	}
	return false;
	
unluckily it seems to return always false also if I the camera has entities before her; the boudingboxes around the entities seems ok, but probably some other settings is wrong. Any suggestion about what I can check? thanks.
Last edited by Niubbo on Mon Dec 20, 2021 11:06 pm, edited 1 time in total.
rpgplayerrobin
Gnoll
Posts: 617
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: Problem with Camera IsVisible

Post by rpgplayerrobin »

You can see if there is any difference between "getWorldBoundingBox()" and "getWorldBoundingBox(true)".
In my game, I have to use the "true" variant since otherwise the AABB is not correct.

Also, sometimes you need to update the node before a valid AABB can be generated:
node->_update(true, false);

Sometimes you even need to do this:
node->_updateBounds();

And at other times, you can also get the bounds directly from the node instead:
node->_getWorldAABB();
Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with Camera IsVisible

Post by Niubbo »

thanks, tried all the commands, but they doens't work. Can it be related to the check moment? I'm making it in the framerenderingqueue calling
rpgplayerrobin
Gnoll
Posts: 617
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: Problem with Camera IsVisible

Post by rpgplayerrobin »

I don't think it matters much where it is, as long as your camera position/orientation and the objects positions/orientations are final.

You should debug the world AABB you get from the functions and see if they are actually correct.
Just displaying their AABB won't be enough, you have to specifically debug the exact world AABB you get from the functions. So if you place an object at [100, 0, 0], its AABB should be something like this if it has a radius of 1:
Minimum = [99, -1, -1]
Maximum = [101, 1, 1]
Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with Camera IsVisible

Post by Niubbo »

thanks I'll prepare a predetermined position entity to check, and I'll tell you the result. Could it be something related to the ogre terraingroup? the entities are not in a plane bu in a map generated using ogitor.
rpgplayerrobin
Gnoll
Posts: 617
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: Problem with Camera IsVisible

Post by rpgplayerrobin »

I don't know how the code looks for creating the mesh of the entities.
If the mesh does not have a bounds set, you will get invalid world AABB:s. Best thing is to just debug the code and see what it outputs first.
Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with Camera IsVisible

Post by Niubbo »

I made some test:

- 1 entity near my camera area; it seems to works perfectly

- I insert 100 entity distants and i moved the camera until make them visibile (I setup a 50000 as far distant area in the frustum), I obtain a very strange result; some entities give an immediate positive results to the visibile test, others (some immediatly near the previous one) takes some time to give positive result, sometime only after moving for a while the camera.

I have to do additional tests, perhaps the problem is not the visible test result but the delay is due to the autotracking set which has not an immediate effect.
rpgplayerrobin
Gnoll
Posts: 617
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: Problem with Camera IsVisible

Post by rpgplayerrobin »

You must debug it in the code to be able to understand what happens. It is impossible to debug something by only checking its results.
You could however debug the world AABB result you get by rendering those bounds yourself.
Niubbo
Goblin
Posts: 211
Joined: Sat Jan 23, 2016 11:26 am
x 17

Re: Problem with Camera IsVisible

Post by Niubbo »

Just to confirm, I reset better the code and this time the check worked fine. thanks you
Post Reply