void ObstacleSpawner::Deserialize() { JValue* obstacleData = ResourceManager::GetInstance()->GetJson("ObstacleConfig"); JValue & obstacleArray = (*obstacleData)["obstacles"]; _numOfObtacles = obstacleArray.GetLength(); for (int i = 0; i <_numOfObtacles;i++ ) { std::string name = obstacleArray[i]["name"].ToString(); SDL_Texture * texture = ResourceManager::GetInstance()->GetTexture(name); Drawable * drawable = new Drawable(); drawable->SetTexture(texture); AABB * aabb = new AABB(); aabb->SetRect(drawable->GetRect()); Obstacles * newObstacle = new Obstacles(); newObstacle->SetCollider(aabb); newObstacle->SetDrawable(drawable); newObstacle->weight = obstacleArray[i]["weight"].ToInt(); _obstacleArray.InsertAtLast(newObstacle); } DEBUGLOG("%s","ObstacleSpawner init success"); }
void ObstacleSpawner::GenerateObstacle(const Vector2D & pos,int i) { Obstacles * obstacle = _obstacleArray[i]->Clone(); Vector2D scenePos = Vector2D::ZERO; scenePos.x = pos.x; scenePos.y = pos.y-2*obstacle->GetCenter().y; obstacle->SetPosition(scenePos); SceneManager::GetInstance()->AddActorToLayer("obstacle", obstacle); _nextpos.x+=2*obstacle->GetCenter().x; }
ObstacleObject::ObstacleObject(Ogre::SceneManager * sceneMgr, Obstacles p): Object::Object( sceneMgr, 100, p.getId()) { float r; float g; float b; p.getColor(&r,&g,&b); initObstacle(p.getId(), Ogre::Vector3(p.getX(),p.getY(),p.getZ()), Ogre::Vector3(p.getWidth(),p.getHeight(),p.getLength()), Ogre::ColourValue(r,g,b)); }
int main() { g_app->Init(); Obstacles obstacles; Bird bird(&obstacles); sf::Clock clock; while (g_app->window.isOpen()) { sf::Event event; while (g_app->window.pollEvent(event)) { g_input->HandleEvent(event); } sf::Time elapsed = clock.restart(); g_app->window.clear(sf::Color(95, 158, 160)); bird.Update(elapsed.asSeconds()); if (!bird.GameOver()) { obstacles.Update(elapsed.asSeconds()); } bird.Draw(); obstacles.Draw(); g_input->Reset(); g_app->window.display(); } return 0; }
void ObstacleObject::updateState(Obstacles &p){ //Ogre::ColourValue color; //p.getColor(color.r,color.g,color.b); //setColor(color.r,color.g,color.b); setScale(Ogre::Vector3(p.getWidth(),p.getHeight(),p.getLength())); setPosition(p.getX(),p.getY(),p.getZ()); }
void configure(const omni_vision::OmniVisionConfig & config, uint32_t level) { ROS_INFO("Reconfigure request received"); is_show_ball_ = config.ball; is_show_whites_ = config.white; is_show_obstacles_ = config.obstacle; is_show_scan_points = config.scan; is_show_result_ = config.show; int obstacle_thres = config.obsthres; double obstacle_length_thres = config.obs_length_thres; double obstacle_basic_thres = config.obs_basic_thres; obstacles_->setObsThres(obstacle_thres,obstacle_length_thres,obstacle_basic_thres); ROS_INFO("Reconfigure request end"); }
bool Bomberman::collision(Obstacles obs) { if(obs.getISExist()==0) return 0; if(y + width <= obs.getY()) return 0; if(x + length <= obs.getX()) return 0; if(y >= obs.getY() + obs.getWidth()) return 0; if(x >= obs.getX() + obs.getLength()) return 0; return 1; }
void PlayerManager::checkCollision(vector< InteractiveObject* > &objectsonScreen) { unsigned int i; InteractiveObject *interactiveObj; Car* car; Obstacles *obstacle; for(i = 0 ; i < objectsonScreen.size(); i++) { interactiveObj = objectsonScreen.at(i); collisionSide collSide = player->isCollidingThenFromWhere(interactiveObj); if(collSide && interactiveObj->getOnScreen()) { lprintf("collision detected\n"); //Handle all obstacle cases. if(interactiveObj->getObectType().compare("Obstacle") == 0) { obstacle = (Obstacles*)interactiveObj; obstacleType myObsType = obstacle->getObstacleType(); interactiveObj->setState(READY); interactiveObj->setOnScreen(no); player->bumpAction(myObsType); } //Handle all car cases. else { car = (Car*)interactiveObj; if(car->getCarType() != BONUS_CAR) { //In the case of car, we are interested in from where we are having the collision switch(collSide) { case COLLIDING_TOP_LEFT: player->setSlideDirection(DIRECTION_LEFT); break; case COLLIDING_TOP_RIGHT: player->setSlideDirection(DIRECTION_RIGHT); break; case COLLIDING_BOTTOM_LEFT: player->setSlideDirection(DIRECTION_LEFT); break; case COLLIDING_BOTTOM_RIGHT: player->setSlideDirection(DIRECTION_RIGHT); break; } } carType mycarType = car->getCarType(); if(car->isActive()) { car->setSlideDirection(player->getSlideDirection() == DIRECTION_LEFT ? DIRECTION_RIGHT : DIRECTION_LEFT); car->bumpAction(); player->bumpAction(mycarType); } } } } }
void process() { if(!colorsegment_->Segment(imginfo_->yuv_image_)) return; //get the colors of the scan_points scanpts_->process(); //detect the white points whites_->process(); if(whites_->img_white_.size()<=0) { // is_restart_=true; ROS_WARN("don't detect the white points"); return ; } if(!is_power_off_) is_restart_=true; if(is_restart_) { is_restart_=false; robot.isglobal_=true; } //localization if(robot.isglobal_) { ROS_INFO("start global localization"); robot.isglobal_=glocation_->process(whites_->weights_,whites_->robot_white_,robot.visual_location_,robot.angle_); } else { DPoint delta_loc=odometry_->getWorldLocaton(); Angle delta_ang=odometry_->getDeltaAngle(); odometry_->clear(robot.angle_); robot.realvtrans_ = odometry_->getRealVelocity(); robot.worldvtrans_ = odometry_->getWorldVelocity(); robot.angular_velocity_ = odometry_->getAngularVelocity(); location_->process(whites_->weights_,whites_->robot_white_,robot.visual_location_,robot.angle_,delta_loc,delta_ang); } PPoint correct_pt = PPoint(tranfer_->get_offset().angle(),tranfer_->get_offset().norm()); tranfer_->calculateWorldCoordinates(correct_pt,robot.visual_location_,robot.angle_,robot.final_location_); obstacles_->process(colorsegment_->segment_result_,robot.final_location_,robot.angle_); ball_info_.pos_known=ball_finder_->Process(colorsegment_->segment_result_,robot.final_location_,robot.angle_); if(is_show_whites_ || is_show_obstacles_ || is_show_ball_ ) { if(field_image_.empty()) ROS_INFO("Field.bmp is empty"); cv::Mat image = field_image_.clone(); cv::Mat orgnal = imginfo_->getBGRImage().clone(); static double length = 1920; static double width = 1314; if(WIDTH_RATIO<1) { length = 1920; width = 882; } if(is_show_scan_points) scanpts_->showScanPoints(); if(is_show_obstacles_) { obstacles_->showObstacles(orgnal); if(!field_image_.empty()) obstacles_->showObstacles(image,robot.final_location_,robot.angle_,length,width); } if(is_show_whites_) { whites_->showWhitePoints(orgnal); if(!field_image_.empty()) whites_->showWhitePoints(image,robot.final_location_,robot.angle_,length,width); } if(is_show_ball_) { ball_finder_->showBall(orgnal); if(!field_image_.empty()) ball_finder_->showBall(image,robot.final_location_,robot.angle_,length,width); } } }
void CarManager::checkCollision(vector< InteractiveObject* > &objectsonScreen) { unsigned int i, j;; InteractiveObject *interactiveObj; Car *car; Car* otherCar; Obstacles *obstacle; for(i = 0 ; i < cars.size(); i++) { car = cars.at(i); for(j = 0 ; j < objectsonScreen.size(); j++) { interactiveObj = objectsonScreen.at(j); //preventing collision from itself if(interactiveObj->getObectType().compare("Car") == 0 && i == j) { break; } Logical colliding = car->isCollidingWith(interactiveObj); if(colliding && interactiveObj->getOnScreen()) { //Handle all obstacle cases. if(interactiveObj->getObectType().compare("Obstacle") == 0) { obstacle = (Obstacles*)interactiveObj; obstacleType myObsType = obstacle->getObstacleType(); interactiveObj->setState(READY); interactiveObj->setOnScreen(no); car->bumpAction(); } //Handle all car cases. else { otherCar = (Car*)interactiveObj; if(otherCar->isActive()) { if(car->getCarType() == BONUS_CAR && otherCar->getCarType() != TRUCK_CAR) { otherCar->destroy(); } else if(otherCar->getCarType() == BONUS_CAR && car->getCarType() != TRUCK_CAR) { car->destroy(); } else if(car->getCarType() != TRUCK_CAR && otherCar->getCarType() != TRUCK_CAR) { otherCar->destroy(); } else if(car->getCarType() == TRUCK_CAR && otherCar->getCarType() != TRUCK_CAR) { otherCar->destroy(); } else if(otherCar->getCarType() == TRUCK_CAR && car->getCarType() != TRUCK_CAR) { car->destroy(); } } } } } } }