Esempio n. 1
0
//////////////////////////////////////////////////////////////////
/// methods for DebugState:
///
//////////////////////////////////////////////////////////////////
DebugState::DebugState(Engine* engine)
    : State(engine)
{
    mEngine->SetUpdateFrequency(30.0f);
    count = 0;
    if(mPhysics.Initialize())
    {
        std::cout << "physics initialized\n";
    }


    std::cout << sizeof(physx::PxVec3) << std::endl;

    mRootNode = new SceneObjectNode();
    Engine3d::Light* light = new Light(mEngine->GetShader()->GetProgramID());
    light->SetPosition(2.1f,5.0f,-18.0f);
    light->SetDiffuse(10,10,10);
    light->SetSpecular(10,10,10);
    light->SetConstAttenuation(.01);
    light->SetAmbient(0.2f,0.2f,0.2f);
    mGimble = new SceneObjectNode();
    mRootNode->AddChild(mGimble);

    mGimble->AddAsset(light);

    CameraLocationUpdater* cam = new CameraLocationUpdater(mEngine->GetShader()->GetProgramID());
    mGimble->AddDrawInterface(cam);


    SceneObjectNode* node = new SceneObjectNode();
    ModelMesh<SimpleVertex>* mesh = Primitives::MakeBox(40,1,40);
    mesh->SetShader(mEngine->GetShader());
    Material* mat = new Material(mEngine->GetShader()->GetProgramID());
    mesh->AddAsset(mat);
    Model* model = new Model("plane");
    model->AddMesh(mesh);
    DrawModel* drawmodel = new DrawModel(model);
    node->AddDrawInterface(drawmodel);
    mGimble->AddChild(node);
    node->SetLocalPosition(glm::vec3(2.1f,0,-18));

    PhysicsCallback* physicscbplane = new PhysicsCallback("plane", node, mesh);
    physicscbplane->SetIsStatic(true);
    physicscbplane->Initialize(&mPhysics);




//    Model* ship = new Model("models/Armadillo/armadillo.3DS");
//    ModelLoader::Load(ship, mEngine->GetShader(), &mPhysics);
//    Texture* texture = new Texture("models/Armadillo/armadillotex.bmp");
//    texture->SetProgramID(mEngine->GetShader()->GetProgramID());
//    texture->Load();
//    ship->GetMesh(2)->AddAsset(mat);
//    ship->GetMesh(2)->AddAsset(texture);
//    SceneObjectNode* shipnode = new SceneObjectNode();
//    DrawModel* drawship = new DrawModel(ship);
//    shipnode->AddDrawInterface(drawship);

//    mGimble->AddChild(shipnode);
//    shipnode->Translate(glm::vec3(5,5,-20));
//    PhysicsCallback* physicscbship1 = new PhysicsCallback("ship1", shipnode, ship->GetMesh(2));
//    physicscbship1->Initialize(&mPhysics);


//    Model* ship2 = new Model("models/Armadillo/armadillo.3DS");
//    ModelLoader::Load(ship2, mEngine->GetShader(), &mPhysics);
//    Texture* texture2 = new Texture("models/Armadillo/armadillotex.bmp");
//    texture2->SetProgramID(mEngine->GetShader()->GetProgramID());
//    texture2->Load();
//    ship2->GetMesh(2)->AddAsset(mat);
//    ship2->GetMesh(2)->AddAsset(texture2);
//    SceneObjectNode* shipnode2 = new SceneObjectNode();
//    DrawModel* drawship2 = new DrawModel(ship2);
//    shipnode2->AddDrawInterface(drawship2);
//    mGimble->AddChild(shipnode2);
//    shipnode2->Translate(glm::vec3(3,5,-20));
//    PhysicsCallback* physicscbship = new PhysicsCallback("ship2", shipnode2, ship2->GetMesh(2));
//    physicscbship->Initialize(&mPhysics);


//    CreateRandomObject();



    SceneObjectNode* node1 = new SceneObjectNode();

    ModelMesh<SimpleVertex>* box = Primitives::MakeBox(1,1,1);
    Material* mat1 = new Engine3d::Material(mEngine->GetShader()->GetProgramID());
    mat1->SetDiffuse(1.0f,0.0f,0.0f);
    mat1->SetShininess(200);
    box->AddAsset(mat1);
    box->SetShader(mEngine->GetShader());
    DrawMesh* drawmesh = new DrawMesh(box);
    node1->AddDrawInterface(drawmesh);
    node1->SetLocalPosition(glm::vec3(3.0f,20.0f,-20.0f));
    PhysicsCallback* phys = new PhysicsCallback("box", node1, box);
    phys->Initialize(&mPhysics);

    mGimble->AddChild(node1);


    for(int i = 0; i < 255; i++)
        mKeysDown[i] = 0;


    mCameraTransform = new UniformMat4("cameratransform", mEngine->GetShader()->GetProgramID());





    glClearColor(0.0, 1.0f, 1.0f, 1.0f); // Clear the background of our window to whitex
}