예제 #1
0
void LoadTestScene()
{
    Scene* firstScene = new Scene();
    engine->AddScene(firstScene);

    Transform* t = nullptr;
    
    PerspectiveCamera* camera = new PerspectiveCamera(Color::Red(), 1.f, 1000.f, 45.f, Screen::AspectRatio());
    firstScene->AddGameObject(camera);
    firstScene->RegisterCamera(camera);
    t = camera->GetTransform();
    t->SetRotation(glm::vec3(0, 180.f, 0));

    GameObject* triangle = new GameObject();
    firstScene->AddGameObject(triangle);
    
    triangle->SetName("Triangle");
    triangle->ModifyMeshRenderer(Mesh::Triangle(), Shader::GetDefaultShader(Shader::DefaultShaderName::UNLIT_COLOR));
    
    t = triangle->GetTransform();
    t->Translate(glm::vec3(0.f, 0, 3.f));

    auto mr = triangle->GetMeshRenderer();
    mr->mesh->Colorize(Color::Yellow());
    glm::vec4 colors[3]{ Color::Red() , Color::Green() ,Color::Blue() };
    mr->mesh->Colorize(colors, 3);
}
예제 #2
0
// Creates the UI
void GameManager::CreateUI()
{
    Scene* scene = Scene::GetInstance();



    // Create the line renderer
    GameObject* lineObj = _gameObject->AddChild( _gameObject->GetName() + "_UILine" );
    _line = lineObj->AddComponent<LineRenderer>();
    _line->SetEnabled( false );
    lineObj->AddComponent<LineMaterial>()->SetLineColor( XMFLOAT4( Colors::White ) );

    // Load our font
    std::shared_ptr<Font> font = std::make_shared<Font>( _gameObject->GetDevice(), _gameObject->GetDeviceContext() );
    std::shared_ptr<Font> bigFont = std::make_shared<Font>( _gameObject->GetDevice(), _gameObject->GetDeviceContext() );
    assert( font   ->LoadFromFile( "Fonts\\OpenSans-Regular.ttf" ) &&
            bigFont->LoadFromFile( "Fonts\\OpenSans-Regular.ttf" ) );
    font->SetCurrentSize( 21U );
    bigFont->SetCurrentSize( 80U );

    // Create the text renderer
    GameObject* textObj = _gameObject->AddChild( _gameObject->GetName() + "_UIText" );
    _lineText = textObj->AddComponent<TextRenderer>();
    _lineText->SetFont( font );
    _lineText->SetEnabled( false );
    textObj->AddComponent<TextMaterial>()->SetTextColor( XMFLOAT4( Colors::White ) );



    // Create the UI for player 1
    GameObject* obj = scene->AddGameObject( _gameObject->GetName() + "_UIP1Health" );
    obj->GetTransform()->SetPosition( XMFLOAT3( 10, 10, 0 ) );
    _player1HealthUI = obj->AddComponent<TextRenderer>();
    _player1HealthUI->SetFont( font );
    obj->AddComponent<TextMaterial>()->SetTextColor( XMFLOAT4( Colors::White ) );

    // Create the UI for player 2
    obj = scene->AddGameObject( _gameObject->GetName() + "_UIP2Health" );
    obj->GetTransform()->SetPosition( XMFLOAT3( 1100, 10, 0 ) );
    _player2HealthUI = obj->AddComponent<TextRenderer>();
    _player2HealthUI->SetFont( font );
    obj->AddComponent<TextMaterial>()->SetTextColor( XMFLOAT4( Colors::White ) );



    // Create the UI for the turn indicator
    obj = scene->AddGameObject( _gameObject->GetName() + "_UITurnIndicator" );
    obj->GetTransform()->SetPosition( XMFLOAT3( 540, 670, 0 ) );
    obj->GetTransform()->SetScale( XMFLOAT3( 0.25f, 0.25f, 0.25f ) );
    _turnIndicator = obj->AddComponent<TextRenderer>();
    _turnIndicator->SetFont( bigFont );
    obj->AddComponent<TextMaterial>()->SetTextColor( XMFLOAT4( Colors::White ) );
}
예제 #3
0
// Creates a player
GameObject* GameManager::CreatePlayer( uint32_t index, const XMFLOAT3& position, const XMFLOAT3& scale )
{
    Scene* scene = Scene::GetInstance();
    GameObject* player = scene->AddGameObject( "Player_" + std::to_string( index ) );
    ID3D11Device* device = player->GetDevice();
    ID3D11DeviceContext* deviceContext = player->GetDeviceContext();

    // Set the player's transform info
    Transform* transform = player->GetTransform();
    transform->SetPosition( position );
    transform->SetScale( scale );

    // Add the collider to the player
    BoxCollider* collider = player->AddComponent<BoxCollider>();
    collider->SetSize( XMFLOAT3( 1, 1, 1 ) );

    // Add the rigid body to the player
    Rigidbody* rigidbody = player->AddComponent<Rigidbody>();
    rigidbody->SetMass( 0 );

    // Add the default material to the player
    DefaultMaterial* material = player->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\Rocks2.jpg" );
    material->LoadNormalMap( "Textures\\Rocks2Normals.jpg" );
    material->SetDirectionalLight( StageLight );

    // Add the mesh renderer to the player
    MeshRenderer* meshRenderer = player->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\cube.obj", device, deviceContext ) );

    return player;
}
예제 #4
0
// Creates an arrow game object
GameObject* GameManager::CreateArrow( const XMFLOAT3& position, const XMFLOAT3& force )
{
    static const XMFLOAT3 ArrowSize = { 1, 0.1f, 1.0f };

    Scene* scene = Scene::GetInstance();
    ID3D11Device* device = _gameObject->GetDevice();
    ID3D11DeviceContext* deviceContext = _gameObject->GetDeviceContext();

    // Create the arrow object
    GameObject* arrow = scene->AddGameObject( _gameObject->GetName() + "_Arrow_" + std::to_string( _arrowCount++ ) );
    
    // Set some transform info
    Transform* transform = arrow->GetTransform();
    transform->SetPosition( position );

    // Add the arrow's collider
    BoxCollider* collider = arrow->AddComponent<BoxCollider>();
    collider->SetSize( ArrowSize );

    // Add the arrow's rigidbody
    Rigidbody* rigidbody = arrow->AddComponent<Rigidbody>();
    rigidbody->SetMass( 1.0f );

    // Set the arrow's collision callback
    GameObject::CollisionCallback callback = std::bind( &GameManager::OnArrowCollide, this, _1 );
    arrow->AddEventListener( "OnArrowCollide", callback );

    // Add a default material
    DefaultMaterial* material = arrow->AddComponent<DefaultMaterial>();
    material->LoadDiffuseMap( "Textures\\SolidWhite.png" );
    material->SetDirectionalLight( StageLight );

    // Add a mesh renderer
    MeshRenderer* meshRenderer = arrow->AddComponent<MeshRenderer>();
    meshRenderer->SetMaterial( material );
    meshRenderer->SetMesh( MeshLoader::Load( "Models\\arrow.obj", device, deviceContext ) );

    return arrow;
}