Jump to content

[SOLVED] Visibility test


Laurens
 Share

Recommended Posts

Hello,

 

I have two entities that I need to perform a visibility test on.

 

if (EntityVisible(source, destination) == 1)
{
// Do stuff with the source and the destination
}

 

The visibility test fails every time even though the source and the destination have a completely clear view of each other. A point visibility test using the position of the entities fails likewise.

 

Do collisions need to be enabled for this? They weren't in any of the examples on the wiki. I got not results with collisions on either though so I am not entirely sure now.

 

Anyone who can shed a light on this?

 

Thanks!

Link to comment
Share on other sites

The only thing you need to make sure is, that both entities you pass to EntityVisible() are meshes.

Apart from that your code should work, but i have not used that command for a while.

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

Thanks for your quick response DaDonik.

 

I won't be in a position to try it out this weekend, but how does a mesh differ from an entity? In my testing code, I am actually creating both the source and the destination with the CreateSphere command, of which the wiki states returns a TMesh. I am however storing the sphere as a TEntity. Is this where I could be wrong?

 

And if I were to eventually replace the CreateSphere with an actual object, how would I retrieve the mesh from the entity?

 

Thanks!

Link to comment
Share on other sites

i havent tried it yet, but perhaps the issue is the collisiontype that you are setting the two individual entities is the problem? Are you setting these two entities to have a collisiontype? And perhaps the EntityVisible's collisiontype parameter is like the Pick's collisiontype parameter, whereas the collisiontype being set is really being applied to the raycast and not an actual filter for what types of entitytypes. This requires that the Collisions() response be set for the two entities if you expect a reaction.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

I have tried setting all entity types to 1 for testing but still no luck.

 

I have been over the tutorial on collisions and raycasting again (http://www.leadwerks.com/files/Tutorials/CPP/Collision_And_Raycasting.pdf) but the code is not using collisions at all. It does state that you can specify a collision type so only entities of that type will be tested, but it appears to be completely optional.

 

Has anything changed since the tutorial was written that altered the behaviour perhaps?

Link to comment
Share on other sites

Well like I said, I haven't tested it for entityvisible command, but the collisiontype parameter for picks is a little misleading. Instead of that parameter setting what type of collisiontype you are looking for, its actually setting the collisiontype of the pick's raycast itself. So if you do not have the Collisions() response set for the entitytype you set for the raycast and what you set for the entity you are trying to capture, then it will fail.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Thanks for all the suggestions macklebee, sadly I have not been able to get it working. I tried the code in the Collisions and Raycasting tutorial which does not use collisions at all and it works flawlessly so the error must be something with me. Here is some more code:

 

	ForEachEntityInAABBDo(aabb, (BP)ForEachEntityInAABBDoCallback, (BP)entities); //  Write all entities in AABB to a vector called "entities".

	for (vector<TEntity>::iterator i = entities->begin(); i < entities->end(); i++)
	{
		if (strcmp(GetEntityKey((*i), "type"), "Tower") == 0
			&& (*i) != node->GetEntity())                     // If entity key "type" equals "Tower".
		{
			if (EntityVisible(node->GetEntity(), (*i)) == 1) // This does not work, always returns 0.
			{
				// Do stuff with the entity.
			}
		}
	}

 

Hopefully someone can tell me where I went wrong.

 

Thanks!

Link to comment
Share on other sites

Funny.

 

Instead of EntityVisible I tried PointVisible passing the EntityPosition to see if it made any difference. It didn't. But when I hardcoded two positions in it did work. So I thought the source- and destination entity were actually preventing the visibility test. Now before calling EntityVisible again I hid both entities and showed them again afterwards. That did the trick.

 

I can understand this behaviour for PointVisible but for EntityVisible it is a little weird I have to actually hide the entities for it to work. I know EntityVisible just calls PointVisible underwater but it would have been nicer if EntityVisible would have done the hiding for me.

 

Josh? Perhaps this is something you can change in the next release. It would have saved me a lot of confusion :)

 

Thanks everyone!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...