Laurens Posted June 18, 2010 Share Posted June 18, 2010 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! Quote Link to comment Share on other sites More sharing options...
DaDonik Posted June 18, 2010 Share Posted June 18, 2010 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. Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
Laurens Posted June 18, 2010 Author Share Posted June 18, 2010 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! Quote Link to comment Share on other sites More sharing options...
Laurens Posted June 21, 2010 Author Share Posted June 21, 2010 I have been looking for a way to pass the meshes to the EntityVisible command but there does not seem to be a GetMesh(entity) command or something similar. Is there such a command or did I went wrong elsewhere? Thanks! Quote Link to comment Share on other sites More sharing options...
macklebee Posted June 21, 2010 Share Posted June 21, 2010 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. Quote 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 More sharing options...
Laurens Posted June 21, 2010 Author Share Posted June 21, 2010 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? Quote Link to comment Share on other sites More sharing options...
macklebee Posted June 21, 2010 Share Posted June 21, 2010 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. Quote 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 More sharing options...
Laurens Posted June 25, 2010 Author Share Posted June 25, 2010 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! Quote Link to comment Share on other sites More sharing options...
ZioRed Posted June 25, 2010 Share Posted June 25, 2010 May be you missed something from macklebee? Try to set the EntityType of the entities to "1", set Collisions(1,1,true) and finally try the EntityVisible with "1" as entitype of raycasting. Collisions(1,1,true); EntityType(ent1, 1); EntityType(ent2, 1); int visible = EntityVisible(ent1, ent2, 0, 1); Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Laurens Posted June 25, 2010 Author Share Posted June 25, 2010 Hi ZR, I have already tried that. It does not make any difference Which is what I expected though, visibility tests do not need to have collisions enabled. Quote Link to comment Share on other sites More sharing options...
Laurens Posted June 26, 2010 Author Share Posted June 26, 2010 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.