reepblue Posted June 14, 2016 Share Posted June 14, 2016 Hey all, I've created a trigger class that on touch stores the entity in a list, and checks a listed entity left the bounds in UpdatePhysics. The code I have works fine, but I'm running into an issue that it seems that the extra padding for brushes are causing incorrect values. The entity has to leave the volume, plus a few centimeters for the onendTouch function to be called. Here is the UpdatePhysics code. void SimpleTrigger::UpdatePhysics() { if (!m_bEnabled) return; if (!m_bHadCollision) return; if (m_hTouchingEntities.size() <= 0) return; list<Entity*>::iterator iter = m_hTouchingEntities.begin(); for (iter; iter != m_hTouchingEntities.end(); iter++) { // zentity is the entity where looking for. Entity* zentity = *iter; if (zentity) { if (entity->GetDistance(zentity) > entity->GetAABB(Entity::GlobalAABB).size) { onendTouch(zentity); break; } } } While this works really well, again, I think the extra AABB padding is getting in the way. I also feel that the for loop is a bit over the top/expensive way of doing this. Any help to make this work better would be appreciated! Thanks. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
nick.ace Posted June 14, 2016 Share Posted June 14, 2016 Isn't the AABB box supposed to not be used for collisions? There's nothing really you can do about that. Personally, I would just use collisions for triggers. Otherwise, use some quick rectangular prism intersection test. In terms of the loop efficiency, it's hard to determine whether that would be a good setup or not depending on the application. But there are probably better techniques to use. You could use a KD-tree so that you don't need to test every entity. IDK how costly it is to set up each frame compared to your list approach though. I wouldn't use the "list" data structure. Use "vector" instead if you are going to use a list like you are using. With "list" you are going to be building a chain of pointers, so you will have fragmented memory and get more cache misses, so your loop will be less efficient. Also, I would avoid using GetDistance() and just square the second term. Implement your own distance function without the use of square-root. Quote Link to comment Share on other sites More sharing options...
reepblue Posted June 14, 2016 Author Share Posted June 14, 2016 I do use the collision hook for adding objects to the touch list. It's removing the object from the volume is my issue. I tried the Enter/Exit trigger script on the old wiki, but it only detects if all objects are out. I'm also using list because vector doesn't seem to have a way or removing an object from it. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
nick.ace Posted June 14, 2016 Share Posted June 14, 2016 Ah ok, I didn't know there were no hooks or anything for leaving an entity. Why not program a box intersection test yourself though? Then you'd have as much control as you would need. You would need to scan through all entities at startup and then calculate the highest +x, -x, +y -y, +z, and -z values for the vertices of a mesh. You can remove elements from a vector. You should just swap the element you want to remove with the last element and use pop_back(). Don't use the erase() method though. A vector is just an array behind the scenes whereas a list is not. 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.