void NormalMappingDelegate::onInit()
{
    scene = new Scene();
    this->move_forward=false;
    this->move_backward=false;
    this->move_left=false;
    this->move_right=false;
    this->move_up = false;
    this->move_down = false;
    scene->setRenderType (DEFERRED_SHADING);

    AmbientLight * ambient = scene->getAmbientLight ();
    ambient->setColor (QVector3D(1,1,1));
    ambient->setIntensity (0.5);

    auto sprite = new Sprite();
    sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png"));
    sprite->setCamera (scene->guiCamera ());
    sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0));
    scene->root ()->addChild (sprite);

    scene->setCamera (&camera);

    //set this scene as current scene
    scene->setAsCurrentScene();
    scene->root ()->addChild (&camera);

    //create a box
    auto the_head = new Entity("./res/model/scan_head/Infinite-Level_02.obj",Entity::LoadPolicy::LoadFromLoader);
    the_head->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
    the_head->scale (30,30,30);
    //set it's normal map
    auto material = the_head->getMesh (0)->getMaterial ();
    material->setNormalMap (TexturePool::getInstance ()->createOrGetTexture ("./res/model/scan_head/Infinite-Level_02_Tangent_SmoothUV.jpg"));
    the_head->setCamera (&camera);
    //this sample we don't use shadow
    the_head->setIsEnableShadow (false);

        //bob
        auto the_bob2 = new Entity("./res/model/bob/boblampclean.md5mesh",Entity::LoadPolicy::LoadFromLoader);
        the_bob2->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
        the_bob2->setCamera (&camera);
        the_bob2->setPos (QVector3D(-2,0,-10));
        the_bob2->setRotation (QVector3D(-90,0,0));
        scene->root ()->addChild (the_bob2);
        the_bob2->setIsEnableShadow (false);
        the_bob2->scale (0.05,0.05,0.05);
        the_bob2->getSkeleton ()->getEntityNodeRoot ()->findNode ("lamp")->addChild (the_head);
        //this sample we don't use shadow
        the_bob2->setIsEnableShadow (false);
        the_bob2->onRender = [](Entity * self, float dt){
            self->playAnimate (0,self->animateTime ()+ 0.02);
        };



        auto the_orc = new Entity("./res/model/orc/orc.FBX",Entity::LoadPolicy::LoadFromLoader);
        the_orc->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
        the_orc->setCamera (&camera);
        the_orc->setRotation (QVector3D(0,180,0));
        the_orc->setScalling (QVector3D(0.1,0.1,0.1));
        the_orc->setPos (QVector3D(0,0,-10));

        scene->root ()->addChild (the_orc);
        the_orc->onRender = [](Entity * self, float dt){
            self->playAnimate (0,self->animateTime () + 0.02);
        };

        auto the_orc_axe = new Entity("./res/model/orc/axe.FBX",Entity::LoadPolicy::LoadFromLoader);
        the_orc_axe->setShaderProgram (ShaderPool::getInstance ()->get ("deferred"));
        the_orc_axe->setCamera (&camera);
        the_orc->getSkeleton ()->getEntityNodeRoot ()->findNode ("Bip001 R Hand")->addChild (the_orc_axe);

        //then add  a Directional light
        auto directional_light = scene->getDirectionalLight ();
        directional_light->setIntensity (1);
        directional_light->setColor (QVector3D(1,1,1));
        directional_light->setDirection (QVector3D(0,0,-1));
}
Beispiel #2
0
void CSMDelegate::onInit()
{
    scene = new Scene();
    this->move_forward=false;
    this->move_backward=false;
    this->move_left=false;
    this->move_right=false;
    this->move_up = false;
    this->move_down = false;

    AmbientLight * ambient = scene->getAmbientLight ();
    ambient->setColor (QVector3D(1,1,1));
    ambient->setIntensity (0.5);

    auto sprite = new Sprite();
    sprite->setTexture (TexturePool::getInstance ()->createOrGetTexture ("./res/texture/mygame/fps/cross_hair.png"));
    sprite->setCamera (scene->guiCamera ());
    sprite->setPos (QVector3D(1024/2-sprite->texture ()->width ()/2,768/2-sprite->texture ()->height ()/2,0));
    scene->root ()->addChild (sprite);

    scene->setCamera (&camera);

    SkyBox * sky_box = new SkyBox("./res/texture/sky_box/right.jpg",
                                  "./res/texture/sky_box/left.jpg",
                                  "./res/texture/sky_box/top.jpg",
                                  "./res/texture/sky_box/bottom.jpg",
                                  "./res/texture/sky_box/front.jpg",
                                  "./res/texture/sky_box/back.jpg");
    sky_box->setCamera(&camera);
    scene->setSkyBox(sky_box);

    //set this scene as current scene
    scene->setAsCurrentScene();
    scene->root ()->addChild (&camera);

    camera.setPos (QVector3D(0,15,0));
    camera.setRotation (QVector3D(-60,0,0));

    Terrain a("./res/model/terrain/terrain.jpg");
    auto terrain_model = new Entity();
    terrain_model->setName ("terrain");
    terrain_model->setCamera(&camera);
    terrain_model->setShaderProgram (ShaderPool::getInstance()->get ("deferred"));
    a.mesh ()->getMaterial ()->getDiffuse ()->texture= TexturePool::getInstance ()->createOrGetTexture ("./res/model/terrain/sand.jpg");
    terrain_model->addMesh(a.mesh ());
    terrain_model->scale (10,10,10);
    terrain_model->setPos (QVector3D(0,-1,0));
    scene->root ()->addChild (terrain_model);

    for(int i = 0; i< 5; i++)
    {
        auto flight = new Entity("./res/model/spaceship/phoenix_ugv.md2");
        flight->setCamera (&camera);
        flight->setShaderProgram (ShaderPool::getInstance()->get ("deferred"));
        flight->setScalling (QVector3D(0.05,0.05,0.05));

        scene->root ()->addChild (flight);
        //flight->setIsEnableShadow (false);
        flight->setPos (QVector3D((rand()%5)*2,3,-2*i));
    }


    /*
    auto spotLight = scene->createSpotLight ();
    spotLight->setIntensity (1);
    spotLight->setColor (QVector3D(0,1,1));
    spotLight->setDirection (QVector3D(-1,-1,0));
    spotLight->setPos (QVector3D(10,10,-4));
    spotLight->setOutterAngle (35);
    spotLight->setAngle (20);
    spotLight->setRange (40);
    */

    //then add  a Directional light
    auto directional_light = scene->getDirectionalLight ();
    directional_light->setIntensity (0.5);
    directional_light->setColor (QVector3D(1,1,1));
    directional_light->setDirection (QVector3D(-1,-1,0));

}