Shard Posted July 26, 2010 Share Posted July 26, 2010 Is there a way to find objects in a scene? For example, I'm trying to locate all the objects (meshes,models) that are within a certain radius of a different model without keeping track of each thing (which is hard to do with Lua scene loading) Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
ZioRed Posted July 26, 2010 Share Posted July 26, 2010 I haven't tried, but from its description it seems ForEachEntityInAABBDo is useful for this. Quote ?? FRANCESCO CROCETTI ?? http://skaredcreations.com Link to comment Share on other sites More sharing options...
Laurens Posted July 26, 2010 Share Posted July 26, 2010 I do this in my tower defense game to find towers within range of each other so they can link. First create a callback function: void _stdcall ForEachEntityInAABBDoCallback(TEntity entity, BP extra) { reinterpret_cast<vector<TEntity>*>(extra)->push_back(entity); } Note that extra contains a vector of TEntity's and the entity that is passed in the callback function is pushed back into this vector. Then, somewhere in your calling code: TVec3 p = EntityPosition(node->GetEntity()); TVec6 aabb; aabb.X0 = p.X - node->GetRadius() / 2; aabb.Y0 = 0; aabb.Z0 = p.Z - node->GetRadius() / 2; aabb.X1 = p.X + node->GetRadius() / 2; aabb.Y1 = 0; aabb.Z1 = p.Z + node->GetRadius() / 2; vector<TEntity> *entities = new vector<TEntity>(); ForEachEntityInAABBDo(aabb, reinterpret_cast<byte*>(ForEachEntityInAABBDoCallback), reinterpret_cast<byte*>(entities)); entities should now contain all the entities that are in the AABB. Cheers! Quote Link to comment Share on other sites More sharing options...
Shard Posted July 27, 2010 Author Share Posted July 27, 2010 I do this in my tower defense game to find towers within range of each other so they can link. First create a callback function: void _stdcall ForEachEntityInAABBDoCallback(TEntity entity, BP extra) { reinterpret_cast<vector<TEntity>*>(extra)->push_back(entity); } Note that extra contains a vector of TEntity's and the entity that is passed in the callback function is pushed back into this vector. Then, somewhere in your calling code: TVec3 p = EntityPosition(node->GetEntity()); TVec6 aabb; aabb.X0 = p.X - node->GetRadius() / 2; aabb.Y0 = 0; aabb.Z0 = p.Z - node->GetRadius() / 2; aabb.X1 = p.X + node->GetRadius() / 2; aabb.Y1 = 0; aabb.Z1 = p.Z + node->GetRadius() / 2; vector<TEntity> *entities = new vector<TEntity>(); ForEachEntityInAABBDo(aabb, reinterpret_cast<byte*>(ForEachEntityInAABBDoCallback), reinterpret_cast<byte*>(entities)); entities should now contain all the entities that are in the AABB. Cheers! Thanks for that. While that definitely works, it turns out I actually need different functionality. Instead of a radius, it need it to affect every object on the map and the strength of the effect would be dependent on the distance from the object. So basically what I need is to be able to iterate through all the objects in a map, do a distance formula and then do the effect. Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Laurens Posted July 27, 2010 Share Posted July 27, 2010 Well, there is also ForEachEntityDo that iterates over all objects. You can use the same callback (well, maybe change its name to ForEachEntityDoCallback to avoid confusion) and the same calling code except change this line: ForEachEntityInAABBDo(aabb, reinterpret_cast<byte*>(ForEachEntityInAABBDoCallback), reinterpret_cast<byte*>(entities)); in this line: ForEachEntityDo(reinterpret_cast<byte*>(ForEachEntityDoCallback), reinterpret_cast<byte*>(entities)); and then simply iterate over entities and do EntityDistance(source, destination). Cheers! Quote Link to comment Share on other sites More sharing options...
Shard Posted July 28, 2010 Author Share Posted July 28, 2010 Well, there is also ForEachEntityDo that iterates over all objects. You can use the same callback (well, maybe change its name to ForEachEntityDoCallback to avoid confusion) and the same calling code except change this line: ForEachEntityInAABBDo(aabb, reinterpret_cast<byte*>(ForEachEntityInAABBDoCallback), reinterpret_cast<byte*>(entities)); in this line: ForEachEntityDo(reinterpret_cast<byte*>(ForEachEntityDoCallback), reinterpret_cast<byte*>(entities)); and then simply iterate over entities and do EntityDistance(source, destination). Cheers! Thanks. Just realized I needed another bit of functionality. I need it to only affect physics bodies >,> How would I do that? Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Laurens Posted July 28, 2010 Share Posted July 28, 2010 There are several ways to go about. You can either set a key and check the key after getting the list of entities or you can specify an entity type in the calling code. I'm not sure how this works but it is on the wiki for the ForEachEntityInAABBDo command. ForEachEntity seems incomplete. Quote Link to comment Share on other sites More sharing options...
cocopino Posted July 28, 2010 Share Posted July 28, 2010 You could use Entity::GetParent to get the physics body of the entity. Quote desktop: Quad core Q6600 + 4GB + ATI HD4890 + XP laptop: Dual core T6400 + 4 GB + NVidia 9600M GT + Vista 32 Link to comment Share on other sites More sharing options...
Canardia Posted July 28, 2010 Share Posted July 28, 2010 Gamelib has FindFirstEntityByKey("keyname","value"). Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ 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.