#include "ExampleApplication.h"

class TutorialApplication : public ExampleApplication
{
protected:
public:
    TutorialApplication()
    {
    }

    ~TutorialApplication() 
    {
    }
protected:
    void chooseSceneManager(void)
    {
        // Use the terrain scene manager.
        mSceneMgr = mRoot->createSceneManager(ST_EXTERIOR_CLOSE);
    }

	virtual void createCamera(void)
    {   
	// create the camera
        mCamera = mSceneMgr->createCamera("PlayerCam");
	// set its position, direction 
        mCamera->setPosition(Vector3(300,300,-550));
        mCamera->lookAt(Vector3(0,100,0));
        mCamera->setNearClipDistance(5);
	mCamera->setFarClipDistance(1000);
    }

    virtual void createViewports(void)
    {
	// Create one viewport, entire window
        Viewport* vp = mWindow->addViewport(mCamera);
        vp->setBackgroundColour(ColourValue(0,0,0));
        // Alter the camera aspect ratio to match the viewport
	mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));   
    }

    void createScene(void)
    {
        Entity *ent; //Загружаемый объект
        Light *light; //Свет
		
		////////SkyBox!
		//mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
		mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox");

		////////Общий свет
       		mSceneMgr->setAmbientLight( ColourValue( 0, 0, 0 ) ); //Белый свет
       		mSceneMgr->setShadowTechnique( SHADOWTYPE_STENCIL_ADDITIVE ); //Тени
        
		///////Грузим модель
		ent = mSceneMgr->createEntity("model", "RZR-002.mesh");
        	ent->setCastShadows(true);
		SceneNode *Nmodel = mSceneMgr->getRootSceneNode()->createChildSceneNode( "NmodelN" );
		Nmodel->attachObject( ent );
		Nmodel->scale(4, 4, 4);
		Nmodel->setPosition(Vector3(0, 55, 0));
		Nmodel->yaw(Degree(120));

		//////////Свет
		light = mSceneMgr->createLight("Light1");
        	light->setType(Light::LT_POINT); //тип света точка
       		light->setPosition(Vector3(0, 300, -250));
       		light->setDiffuseColour(1, 1, .7);
       		light->setSpecularColour(1, 1, .7);	
    }
};

#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
    // Create application object
    TutorialApplication app;

    try {
        app.go();
    } catch(Exception& e) {
#if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        fprintf(stderr, "An exception has occurred: %s\n",
            e.getFullDescription().c_str());
#endif
    }

    return 0;
}
