#include "Shader.h"
#include "Camera.h"
#include <windows.h>

Shader::Shader()
: g_WorldMatrix(0), g_ViewMatrix(0), g_ProjectionMatrix(0), g_NormalMatrix(0),
g_WorldMatrixInverse(0), g_ViewMatrixInverse(0), g_ProjectionMatrixInverse(0),
g_Eye(0), g_Center(0), g_Up(0), g_Viewport(0), g_Texture(0), g_NormalMap(0), 
g_DiffuseMaterial(0), g_SpecularMaterial(0)
{
    for (int i = 0; i < 16; ++i)
        g_MRT[i] = 0;
}

void Shader::notify(Observable* observable)
{
    if (Camera* camera = dynamic_cast<Camera*>(observable)) {
        if (g_ViewMatrix) g_ViewMatrix->setValue((float*)camera->getView()[0]);
        if (g_ProjectionMatrix) g_ProjectionMatrix->setValue((float*)camera->getProjection()[0]);

        if (g_ViewMatrixInverse) g_ViewMatrixInverse->setValue((float*)camera->getView().inverse()[0]);
        if (g_ProjectionMatrixInverse) g_ProjectionMatrixInverse->setValue((float*)camera->getProjection().inverse()[0]);

        if (g_Eye) {
            float eye[4] = { camera->getEye().x, camera->getEye().y, camera->getEye().z, 1.0 };
            g_Eye->setValue(eye);
        }

        if (g_Center) {
            float center[4] = { camera->getCenter().x, camera->getCenter().y, camera->getCenter().z, 1.0 };
            g_Center->setValue(center);
        }

        if (g_Up) {
            float up[4] = { camera->getUp().x, camera->getUp().y, camera->getUp().z, 1.0 };
            g_Up->setValue(up);
        }
    }
}