Jump to content

isVisible-function for object-classes


photo

Recommended Posts

Hi there,

 

I am currently looking in a way to detect, if a surface is visible or not. I found this thread, but I am more convinced if there is a way to just get access to an already implemented variable. When debugging, I can see that the object-class already holds some data about each surface, one is "visible" which is true or false, based on its LOD-data. It would be nice if you can have access to those variable (and maybe "faded" would be also a nice to have).

The reason is, that there are multiple AI logic based on the object distance to the player or camera. So closer entities get a more frequent or more complex AI update than entities further away. For now I can only calculate the distance between player and object and using getMinVisibleDistance/getMaxVisibleDistance() to fit my needs. But this does an unnecessary distance-check, the engine has already done. So a more convenient way (at least for me) is to have access to those data and thread those values by myself.

 

Cheers

Christian

Link to comment

Hi silent,

 

actually it is pretty straightforward for a C++API. I have an object with 3 LODs, so LOD0, LOD1 and LOD2. My current code is something like that:

	void Entity::update(float iFPS)
	{
		Scalar doubleDistance = Unigine::Math::length2(object->getWorldPosition() - player->getWorldPosition());

		if (object->getMaxVisibleDistance(0) * object->getMaxVisibleDistance(0) < doubleDistance)
		{
			//LOD-0
			updateCloseLogic(iFPS);
		}
		else if (object->getMaxVisibleDistance(1) * object->getMaxVisibleDistance(1) < doubleDistance)
		{
			//LOD-1
			updateMediumLogic(iFPS);
		}
		else if (object->getMaxVisibleDistance(2) * object->getMaxVisibleDistance(2) < doubleDistance)
		{
			//LOD-2
			updateFarLogic(iFPS);
		}
		else
		{
			//object is out of range
			updateOffScreenLogic(iFPS);
		}
		
	}

I have to make an distance calculation and decide on that, which LOD will be active or if the object is completely not drawn. When implementing access to the already existing variables, the code changes to something like:

 

void Entity::update(float iFPS)
{
  if (node->isSurfaceVisible(0))
  {
  //LOD-0
  updateCloseLogic(iFPS);
  }
  else if (node->isSurfaceVisible(1))
  {
  //LOD-1
  updateMediumLogic(iFPS);
  }
  else if (node->isSurfaceVisible(2))
  {
  //LOD-2
  updateFarLogic(iFPS);
  }
  else
  {
  //object is out of range
  updateOffScreenLogic(iFPS);
  }

}

This avoids the distance calculation and safes a couple of CPU-cycles. I know it is not much but trying to render and update a large amount of entities may safe some performance. And it is (from an outside-view) not very performance critical, because the variables are already there and the engine already needs to know which surface will be currently rendered or not.

surface.thumb.jpg.7538e165062c26643137377f64c1907f.jpg

Best

Christian

Link to comment
×
×
  • Create New...