|
More efficient way to capture mouse position? |
Mishtiff
Member #15,776
October 2014
|
@Aikei Sounds good. I think i was confused on what boost does, now i understand that boost does insertion, a tree and checks for collision. i thought it only did the first two so i also added this to it: 1for(iter = objects.begin(); iter != objects.end(); ++iter)
2 {
3 std::vector<GameObject*> results;
4 //find all actors intersecting with the current one and insert results into the "results" vector:
5 pRTree->query(bgi::intersects((*iter)->GetBoundingBox()),std::back_inserter(results));
6 int size = 0;
7 size = results.size();
8 if(size <= 1) continue;
9
10 for(int i = 0; i < size; i++)
11 {
12 if(i == 0) continue;
13 if((*iter)->CheckCollisions(results[i]))
14 {
15 results[i]->Collided((*iter)->GetID(), rand() % 10 + -5, rand() % 10 + -5);
16 }
17 }
18 }
This is the version i was using, which wouldnt make sense if the query is returning all actors that intersect each other... . 1for(iter = objects.begin(); iter != objects.end(); ++iter)
2 {
3 std::vector<GameObject*> results;
4 //find all actors intersecting with the current one and insert results into the "results" vector:
5 pRTree->query(bgi::intersects((*iter)->GetBoundingBox()),std::back_inserter(results));
6 int size = 0;
7 size = results.size();
8 if(size <= 1) continue;
9
10 for(int i = 1; i < size; i++)
11 {
12 results[i]->Collided((*iter)->GetID(), rand() % 10 + -5, rand() % 10 + -5);
13 }
14 }
new code, tell me if that works. Also, i will fix the code for Collided. instead of random movements it will just push in the opposite direction. |
Aikei_c
Member #14,871
January 2013
|
This should work, however you are making an assumption here that the object itself you are checking collision with will always be the first to be returned, which I don't think boost guarantees, since the manual doesn't specify any order in which results are returned. |
Mishtiff
Member #15,776
October 2014
|
@Aikei good point, will implement it now. Ill update this post in a couple hours with the progress Update: Im not sure what happened, but i hit a critical error. I closed my program to spend some time with the family today, and got an error, so i had to copy and paste the entire program over again. Something about running git. It somehow moved files or something when i went to push them. Happened on my desktop as well (on accident). all of my folders are gone that i had created... Anyways, all is well and ill update soon. |
|
|