/*
MainControl.cpp
Written by Matthew Fisher

MainControl includes everything that changes often between applications, such as what meshes to load,
and also determines what is rendered each frame.
*/

//All source files include Main.h
#include "Main.h"

void MainControl::ReInit(GraphicsDevice &GD, WindowManager &WM)
{
    if(GD.GetFullScreen())
    {
        C.Mouse(0.0f);  //move the mouse to the middle of the screen
    }

    MC.Perspective.PerspectiveFov(60.0f * PIf / 180.0f,                             //the field of view = 60 degrees
                                    float(WM.GetWidth()) / float(WM.GetHeight()),   //the aspect ratio
                                    0.1f,                                           //near Z-plane
                                    20.0f);                                         //far Z-plane
}

void MainControl::Init(GraphicsDevice &GD, WindowManager &WM)
{
    ReInit(GD, WM);

    MC.World.Identity();    //zero the world and view matrices
    MC.View.Identity();

    SphereMesh.SetGD(GD);               //associate the mesh with the graphics device
    SphereMesh.CreateSphere(1.0f, 3);
    SphereMesh.Translate(eZ * -3.0f);
    SphereMesh.GCNormals();             //color the sphere based upon the normals

    Time = 0.0f;            //reset the time to 0
}

void MainControl::Render(GraphicsDevice &GD, WindowManager &WM)
{
    Time += T.SPF();                                //advance the current time
    if(KeyCheckOnce(KEY_F)) GD.ToggleWireframe();   //toggle wireframe if the user presses "F"

    C.WindowKeyboard(1.0f,1.0f);                    //move based upon the keyboard
    if(GD.GetFullScreen()) C.Mouse(0.001f);         //move based upon the mouse, if we're in full-screen mode
    C.Update(MC, GD);                               //update the camera and load it into the current graphics device

    SphereMesh.Render();                            //render the sphere.  It will be transformed by the camera matrix.

    GD.DrawVector("Camera - > ", C.VecEye, 0, 20);  //draw the camera position as text on the screen
}

void MainControl::FreeMemory()
{

}

Top