我想在低资源机器上测试1000个圆圈碰撞@ 60 FPS,Iphone(好吧,它绝不是低资源)。我知道这不是一个小问题。我从很多角度看过它,并觉得我没有黑客的东西来弄清楚,事实上我觉得有些人可能会立即回应PFFFFFFF 1000这是一个新秀。正是我正在祈祷的回应!
我希望能为这个简单的问题找到如此高质量的答案。
例如,这是非常精彩的,我以前从未听过BAMS一词。
https://stackoverflow.com/a/1049285/310678
和我一无所知的事情。
当你说20 30 50 100 200但1000 2000 5000 10000 20000时很容易!>请帮助我获得高分。
答案 0 :(得分:2)
euclideanDistance(x1, y1, x2, y2) <= r1 + r2
。答案 1 :(得分:0)
这是我最终提出的基础解决方案。
重点关注计算机的优点。
void Collider::test_one(Actor * actor){
std::sort(this->_stack->begin(),this->_stack->end(),*Collider::sort_x);
vector<Actor*>::iterator it_target = std::find(this->_stack->begin(),this->_stack->end(),actor);
vector<Actor *> possible_x;
vector<Actor *> possible_y;
int x = 1;
int count = 0;
Actor * one = *(it_target);
Actor * two;
/*
for(int x= 0; x < this->_stack->size(); x++){
cout << this->_stack->at(x)->x_loc << "\n";
}
*/
//cout << "***" << "\n";
while ( it_target +x != this->_stack->end()) {
two = *(it_target+x);
//cout << one->half_width+two->half_width+one->x_loc << "\n";
//cout << two->x_loc << "\n";
if(one->half_width+two->half_width+ one->x_loc > two->x_loc){
possible_x.push_back(two);
}else{
break;
}
count ++;
x++;
}
reverse_iterator<vector<Actor*>::iterator> rit_target(it_target);
x=0;
while (rit_target +x != this->_stack->rend()) {
two = *(rit_target+x);
if(two->half_width+one->half_width+ two->x_loc > one->x_loc){
possible_x.push_back(two);
}else{
break;
}
count ++;
x++;
}
//cout <<count <<" POSSIBLE X \n";
x=1;
count=0;
std::sort(this->_stack->begin(),this->_stack->end(),*Collider::sort_y);
it_target = std::find(this->_stack->begin(),this->_stack->end(),actor);
/*
for(int x= 0; x < this->_stack->size(); x++){
cout << this->_stack->at(x)->y_loc << "\n";
}
*/
while ( it_target +x != this->_stack->end()) {
two = *(it_target+x);
//cout << one->half_width+two->half_width+ one->y_loc << " DISTANCE\n";
//cout << two->y_loc << " Y_LOC \n";
if(one->half_width+two->half_width+ one->y_loc > two->y_loc){
possible_y.push_back(two);
}else{
break;
}
count ++;
x++;
}
reverse_iterator<vector<Actor*>::iterator> yrit_target(it_target);
x=0;
while (yrit_target +x != this->_stack->rend()) {
two = *(yrit_target+x);
if(two->half_width+one->half_width+ two->y_loc > one->y_loc){
possible_y.push_back(two);
}else{
break;
}
count ++;
x++;
}
//cout <<count <<" POSSIBLE Y \n";
vector<Actor *> result;
std::sort(possible_x.begin(),possible_x.end());
std::sort(possible_y.begin(), possible_y.end());
std::set_intersection(possible_x.begin(), possible_x.end(),possible_y.begin(),possible_y.end(),back_inserter(result));
for(int x=0; x< result.size();x++){
//cout << result.at(x) << " COLLISION";
result.at(x)->collision(*actor);
}
}
有关提高此速度的建议吗?我知道我在这里弄得一团糟我一周前甚至不知道如何用迭代器捣碎。