void PathFollowingScenario::Initialise()
{
	SteeringGame * game = (SteeringGame *) Game::Instance();
	Params::Load("default");

	shared_ptr<Ground> ground = make_shared<Ground>();
	game->Attach(ground);
	game->ground= ground;
	
	// Create the fighter
	shared_ptr<GameComponent> fighter = make_shared<GameComponent>();
	fighter->tag = "Steerable";
	fighter->scale = glm::vec3(4, 4, 4);
	shared_ptr<SteeringController> fighterController = make_shared<SteeringController>();
	fighterController->position = fighter->position = glm::vec3(-20, 50, 50);
	fighterController->TurnOffAll();
	fighterController->Initialise();

	fighter->Attach(fighterController);
	fighter->Attach(Content::LoadModel("cobramk3", glm::rotate(glm::mat4(1), 180.0f, GameComponent::basisUp)));
	game->Attach(fighter);

	// Now create the enemy
	shared_ptr<GameComponent> enemy = make_shared<GameComponent>();
	enemy->tag = "Steerable";
	enemy->scale = glm::vec3(4, 4, 4);
	shared_ptr<SteeringController> enemyController = make_shared<SteeringController>();
	enemyController->position = enemy->position = glm::vec3(10, 50, 0);
	enemyController->targetPos = fighterController->position + glm::vec3(-50, 0, -80);
	enemyController->TurnOffAll();
	enemyController->TurnOn(SteeringController::behaviour_type::arrive);
	this->leaderController = enemyController;
	enemy->Attach(enemyController);
	enemy->Attach(Content::LoadModel("python", glm::rotate(glm::mat4(1), 180.0f, GameComponent::basisUp)));

	game->Attach(enemy);

	// Now set up the state machine for the fighter..
	shared_ptr<StateMachine> stateMachine = make_shared<StateMachine>();
	fighter->Attach(stateMachine);
	stateMachine->SwicthState(make_shared<IdleState>(stateMachine, enemyController));
	

	// Now set up the camera
	game->camFollower = make_shared<GameComponent>();
	shared_ptr<SteeringController> camController = make_shared<SteeringController>();
	camController->offset = glm::vec3(0, 4, 4);
	camController->leader = fighterController;
	camController->position = game->camFollower->position = fighter->position + camController->offset;
	camController->TurnOffAll();
	camController->TurnOn(SteeringController::behaviour_type::offset_pursuit);
	camController->TurnOn(SteeringController::behaviour_type::sphere_constrain);
	//game->camFollower->Attach(make_shared<VectorDrawer>(glm::vec3(5,5,5)));

	game->Attach(game->camFollower);
	game->camFollower->Attach(camController);
	
	game->camera->position = camController->position;
}
Пример #2
0
void ObstacleAvoidanceScenario::Initialise()
{
    Params::Load("default");
    SteeringGame * game = (SteeringGame *) Game::Instance();

    shared_ptr<GameComponent> leader = make_shared<GameComponent>(true);
    leader->tag = "Steerable";
    shared_ptr<SteeringController> leaderController = make_shared<SteeringController>();
    leader->Attach(leaderController);
    leaderController->transform->position = glm::vec3(10, 120, 20);
    leaderController->TurnOn(SteeringController::behaviour_type::arrive);
    leaderController->TurnOn(SteeringController::behaviour_type::obstacle_avoidance);
    //leaderController->TurnOn(SteeringController::behaviour_type::separation);
    //leaderController->TurnOn(SteeringController::behaviour_type::wall_avoidance);
    leaderController->targetPos = glm::vec3(10, 100, -550);
    this->leaderController = leaderController;

    leader->Attach(Content::LoadModel("viper", glm::rotate(glm::mat4(1), 180.0f, Transform::basisUp)));
    leader->transform->scale = glm::vec3(5,5,5);
    game->Attach(leader);

    // Add some Obstacles
    vector<ObstacleParam> obsParams;
    obsParams.push_back(ObstacleParam(glm::vec3(5, 115, -30), 5));
    obsParams.push_back(ObstacleParam(glm::vec3(-10, 126, -80), 17));
    obsParams.push_back(ObstacleParam(glm::vec3(10, 115, -120), 10));
    obsParams.push_back(ObstacleParam(glm::vec3(5, 120, -150), 12));
    obsParams.push_back(ObstacleParam(glm::vec3(-2, 125, -200), 20));
    obsParams.push_back(ObstacleParam(glm::vec3(-25, 80, -250), 10));
    obsParams.push_back(ObstacleParam(glm::vec3(20, 80, -250), 10));
    obsParams.push_back(ObstacleParam(glm::vec3(5, 130, -350), 35));

    for (int i = 0 ; i < obsParams.size() ; i ++)
    {
        shared_ptr<Sphere> obstacle = make_shared<Sphere>(obsParams[i].radius);
        obstacle->tag = "obstacle";
        obstacle->transform->position = obsParams[i].pos;
        game->Attach(obstacle);
    }

    // Now make a fleet
    int fleetSize = 10;
    float xOff = 12;
    float zOff = 12;
    for (int i = 2; i < fleetSize; i++)
    {
        for (int j = 0; j < i; j++)
        {
            float z = (i - 1) * +zOff;
            shared_ptr<GameComponent> fleet = make_shared<GameComponent>(true);
            fleet->tag = "Steerable";
            shared_ptr<SteeringController> fleetController = make_shared<SteeringController>();
            fleet->Attach(fleetController);
            fleetController->leader = leaderController;
            fleetController->offset = glm::vec3((xOff * (-i / 2.0f)) + (j * xOff), 0, z);
            fleetController->transform->position = leaderController->transform->position + fleetController->offset;
            fleetController->TurnOn(SteeringController::behaviour_type::offset_pursuit);
            //fleetController->TurnOn(SteeringController::behaviour_type::separation);
            //fleetController->TurnOn(SteeringController::behaviour_type::wall_avoidance);
            fleetController->TurnOn(SteeringController::behaviour_type::obstacle_avoidance);
            fleet->transform->scale = glm::vec3(5,5,5);
            fleet->Attach(Content::LoadModel("cobramk1", glm::rotate(glm::mat4(1), 180.0f, Transform::basisUp)));
            game->Attach(fleet);
        }
    }

    game->camFollower = make_shared<GameComponent>(true);
    shared_ptr<SteeringController> camController = make_shared<SteeringController>();
    game->camFollower->Attach(camController);
    camController->offset = glm::vec3(0,0,3);
    camController->tag = "Steerable";
    camController->leader = leader;
    camController->transform->position = glm::vec3(0, 115, fleetSize * zOff);;
    camController->offset = glm::vec3(0, 5, fleetSize * zOff);
    camController->TurnOffAll();
    camController->TurnOn(SteeringController::behaviour_type::offset_pursuit);
    camController->TurnOn(SteeringController::behaviour_type::wall_avoidance);
    camController->TurnOn(SteeringController::behaviour_type::obstacle_avoidance);
    game->Attach(game->camFollower);
    game->camera->transform->position = camController->transform->position;
    shared_ptr<Ground> ground = make_shared<Ground>();
    game->Attach(ground);
    game->ground= ground;
}