#define STRICT

// Includes standard Windows
#include <windows.h>
#include <windowsx.h>
#include <time.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <stdio.h>

// Includes D3D
#define  D3D_OVERLOADS
#include <ddraw.h>
#include <d3d.h>
#include <d3dx.h>

// Includes utilitaires D3D
#include "d3dmath.h"
#include "d3dutil.h"
#include "D3DEnum.h"

// Ids Resources
#include "resource.h"

// Constantes
#include "const.h"

// Types
#include "types.h"

// Variables globales projet
#include "vars.h"

// Prototypes fonctions autres modules
#include "proto.h"

// Macros
#include "macros.h"

void vDemo(void)
{
    struct DateStamp sDS1, sDS2;

    vDeleteObjects();

    DateStamp(&sDS1);

    D3DVECTOR   v1 = D3DVECTOR( -1.,    -1.,    -1.);   // u : 0    v : 0
    D3DVECTOR   v2 = D3DVECTOR(  1.,    -1.,    -1.);   // u : 127  v : 0
    D3DVECTOR   v3 = D3DVECTOR(  1.,     1.,    -1.);   // u : 127  v : 127
    D3DVECTOR   v4 = D3DVECTOR( -1.,     1.,    -1.);   // u : 0    v : 127

    D3DVECTOR   v5 = D3DVECTOR( -1.,    -1.,     1.);   // u : 0    v : 0
    D3DVECTOR   v6 = D3DVECTOR(  1.,    -1.,     1.);   // u : 127  v : 0
    D3DVECTOR   v7 = D3DVECTOR(  1.,     1.,     1.);   // u : 127  v : 127
    D3DVECTOR   v8 = D3DVECTOR( -1.,     1.,     1.);   // u : 0    v : 127

    int         i1 = iMakeVertex(v1, XDC_FORCENEW);
    int         i2 = iMakeVertex(v2, XDC_FORCENEW);
    int         i3 = iMakeVertex(v3, XDC_FORCENEW);
    int         i4 = iMakeVertex(v4, XDC_FORCENEW);
    int         i5 = iMakeVertex(v5, XDC_FORCENEW);
    int         i6 = iMakeVertex(v6, XDC_FORCENEW);
    int         i7 = iMakeVertex(v7, XDC_FORCENEW);
    int         i8 = iMakeVertex(v8, XDC_FORCENEW);

    int         t1 = iMakeTriangle(i1, i2, i3, 0); bSetUV(t1, 0, 0, 127, 0, 127, 127);
    int         t2 = iMakeTriangle(i1, i3, i4, 0); bSetUV(t2, 0, 0, 127, 127, 0, 127);
    int         t3 = iMakeTriangle(i5, i6, i7, 0); bSetUV(t3, 0, 0, 127, 0, 127, 127);
    int         t4 = iMakeTriangle(i5, i7, i8, 0); bSetUV(t4, 0, 0, 127, 127, 0, 127);

    Materials[0].bTextured = TRUE;

    for (float fAlpha = 0 ; fAlpha < 2. * 2. * g_PI ; fAlpha += g_PI / 90.)
    {
        Observer.x = 9. * sin(fAlpha / 1.5);
        Observer.z = 9. * sin(fAlpha);
        Observer.y = 9. * cos(fAlpha);

		D3DUtil_SetViewMatrix(matView,
				  Observer,	// From
                  Target,	// To
				  Target);

		// Redessiner la scène 3D
		vForce3DRefresh(XDC_MODE_COMPLET);
    }
    DateStamp(&sDS2);
    if (sDS2.ds_Tick < sDS1.ds_Tick) sDS2.ds_Tick += 3000;
    vTrace("Temps écoulé : %f s", (sDS2.ds_Tick - sDS1.ds_Tick) / 50.);

    // Redessiner la scène 2D
	vForce2DRefresh(XDC_MODE_COMPLET);

/*
    int         t5 = iMakeTriangle(i1, i2, i3, 0);
    int         t6 = iMakeTriangle(i1, i2, i3, 0);
    int         t7 = iMakeTriangle(i1, i2, i3, 0);
    int         t8 = iMakeTriangle(i1, i2, i3, 0);
    int         t9 = iMakeTriangle(i1, i2, i3, 0);
    int        t10 = iMakeTriangle(i1, i2, i3, 0);
    int        t11 = iMakeTriangle(i1, i2, i3, 0);
    int        t12 = iMakeTriangle(i1, i2, i3, 0);
*/
}

