int Cull_OBJECT4D(OBJECT4D_PTR obj, CAM4D_PTR cam, int cull_flags) { Vector4d sphere_pos; sphere_pos = cam->mcam * obj->world_pos; if (cull_flags & CULL_OBJECT_Z_PLANE) { if (((sphere_pos(2) - obj->max_radius) > cam->far_clip_z) || ((sphere_pos(2) + obj->max_radius) < cam->near_clip_z)) { obj->state |= OBJECT4D_STATE_CULLED; return 1; } } if (cull_flags & CULL_OBJECT_X_PLANE) { float z_test = (0.5) * cam->viewplane_width * sphere_pos(2) / cam->view_dist; if (((sphere_pos(0) - obj->max_radius) > z_test) || ((sphere_pos(0) + obj->max_radius) < -z_test)) { obj->state |= OBJECT4D_STATE_CULLED; return 1; } } if (cull_flags & CULL_OBJECT_Y_PLANE) { float z_test = (0.5)*cam->viewplane_height*sphere_pos(2) / cam->view_dist; if (((sphere_pos(1) - obj->max_radius) > z_test) || ((sphere_pos(1) + obj->max_radius) < -z_test)) { obj->state |= OBJECT4D_STATE_CULLED; return 1; } } return 0; }
void Board::fallSpheres(std::function<void(Sphere*,PointGrid)> logic){ GroupSphere spheres_fall; std::vector<PointGrid> spheres_fall_old_pos; std::vector<PointGrid> spheres_fall_new_pos; _match_lock(); //esto correge error de mal cambio de columna 0 a 11 //imprevistamente spheres_fall.clear(); std::cout << "GridCols:" << _grid.getCols() << " GridRows:" << _grid.getRows() << std::endl; for(int col=_grid.getCols()-1; col >= 0; col--){ for(int row=0; row < _grid.getRows(); row++){ PointGrid sphere_pos(col, row); Sphere* sphere = _grid.get(sphere_pos); //std::cout << "TryingFallingSphere:" << sphere_pos.x << "," << sphere_pos.y << std::endl; if(_grid.Empty(sphere)) continue; std::cout << "FallingSphere:" << sphere->getPosition().x << "," << sphere->getPosition().y << " Col: " << col << std::endl; sphere->retain(); PointGrid sphere_new_pos = PointGrid::BAD; for(int row_row=row-1; row_row>=0; row_row--){ if(_grid.Empty(PointGrid(col, row_row))){ std::cout << "FallingSphere::newpos:" << sphere_pos.x << "," << row_row << std::endl; sphere_new_pos = PointGrid(col, row_row); }else{ break; } } if(sphere_new_pos != PointGrid::BAD){ sphere->retain(); spheres_fall.push_back(sphere); spheres_fall_new_pos.push_back(sphere_new_pos); spheres_fall_old_pos.push_back(sphere->getPosition()); std::cout << "FallingSphere::newpos sended:" << sphere_new_pos.x << "," << sphere_new_pos.y << std::endl; if(logic) logic(sphere, sphere_new_pos); _grid.move(sphere->getPosition(), sphere_new_pos); sphere->setPosition(sphere_new_pos); } } } _match_unlock(); for(auto ifunc = onAttachFall.begin(); ifunc != onAttachFall.end(); ifunc++){ (*ifunc)(spheres_fall, spheres_fall_old_pos, spheres_fall_new_pos); } std::cout << "FallingSphere::End" << std::endl; }