/*---------------------------------------------------------------------------
Name: materials.c (for use with space.c)
Author: Christopher Huyler
Date: April 30, 2002
Description:
Material and Lighting functions and definitions.
----------------------------------------------------------------------------*/

// a material structure ------------------------------------------------------
typedef struct materialStruct {
    GLfloat ambient[4];
    GLfloat diffuse[4];
    GLfloat specular[4];
    GLfloat shininess;
};

// a light structure ---------------------------------------------------------
typedef struct lightStruct {
    GLint number;
    GLfloat position[4];
    GLfloat ambient[4];
    GLfloat diffuse[4];
    GLfloat specular[4];
};

// function to change between materials --------------------------------------
void materials(struct materialStruct *materials)
{
    // define material properties for front face of all polygons
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, materials->ambient);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, materials->diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materials->specular);
    glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, materials->shininess);
}

// function to set light properties ------------------------------------------
void light_on(struct lightStruct *light) {
    glEnable(light->number);
    glLightfv(light->number,GL_POSITION, light->position);
    glLightfv(light->number,GL_AMBIENT, light->ambient);
    glLightfv(light->number,GL_DIFFUSE, light->diffuse);
    glLightfv(light->number,GL_SPECULAR, light->specular);
}
void light_off(struct lightStruct *light) {
    glDisable(light->number);
}
void position_spot(struct lightStruct *light, GLfloat *pos, GLfloat *dir) {
    int i;
    for(i=0;i<3;i++)
        light->position[i]=pos[i];
    glLightfv(light->number,GL_POSITION,light->position);
    glLightfv(light->number,GL_SPOT_DIRECTION,dir);
}

// my materials --------------------------------------------------------------
struct materialStruct yellowMaterials = {
    {0.33, 0.33, 0.0, 1.0},
    {0.66, 0.66, 0.0, 1.0},
    {0.66, 0.66, 0.0, 1.0},
    50.0
};
struct materialStruct darkYellowMaterials = {
    {0.33, 0.33, 0.0, 1.0},
    {0.33, 0.33, 0.0, 1.0},
    {0.33, 0.33, 0.0, 1.0},
    25.0
};
struct materialStruct blackMaterials = {
    {0.05, 0.05, 0.05, 1.0},
    {0.05, 0.05, 0.05, 1.0},
    {0.05, 0.05, 0.05, 1.0},
    5.0
};

struct materialStruct grayPlasticMaterials = {
    {0.4, 0.4, 0.4, 1.0},
    {0.6, 0.6, 0.6, 1.0},
    {0.6, 0.6, 0.6, 1.0},
    15.0
};

struct materialStruct brassMaterials = {
    {0.33, 0.22, 0.03, 1.0},
    {0.78, 0.78, 0.11, 1.0},
    {0.99, 0.91, 0.81, 1.0},
    27.8
};

struct materialStruct steelMaterials = {
    {0.22, 0.22, 0.25, 1.0},
    {0.66, 0.66, 0.69, 1.0},
    {0.95, 0.95, 0.99, 1.0},
    27.8
};
struct materialStruct bluePlasticMaterials = {
    {0.0, 0.0, 0.3, 1.0},
    {0.0, 0.0, 0.6, 1.0},
    {0.6, 0.6, 0.8, 1.0},
    32.0
};

struct materialStruct redPlasticMaterials = {
    {0.3, 0.0, 0.0, 1.0},
    {0.6, 0.0, 0.0, 1.0},
    {0.8, 0.6, 0.6, 1.0},
    32.0
};

struct materialStruct whiteShineyMaterials = {
    {0.5, 0.5, 0.5, 1.0},
    {0.9, 0.9, 0.9, 1.0},
    {1.0, 1.0, 1.0, 1.0},
    100.0
};

// my lights -----------------------------------------------------------------
struct lightStruct light0 = {
    GL_LIGHT0,
    {0.0,25.0,0.0,1.0},         // position
    {0.4,0.4,0.4,1.0},          // ambient
    {1.0,1.0,1.0,1.0},          // diffuse
    {0.8,0.8,0.8,1.0}           // specular
};
struct lightStruct light1 = {
    GL_LIGHT1,
    {0.0,0.0,0.0,1.0},
    {0.0,0.0,0.0,1.0},
    {1.0,1.0,1.0,1.0},
    {0.8,0.8,0.8,1.0}
};
struct lightStruct light2 = {
    GL_LIGHT2,
    {10.0,20.0,-15.0,1.0},
    {0.0,0.0,0.0,1.0},
    {1.0,0.0,0.0,1.0},
    {0.2,0.0,0.0,1.0}
};
struct lightStruct light3 = {
    GL_LIGHT3,
    {0.0,0.0,0.0,1.0},
    {0.0,0.0,0.0,1.0},
    {0.0,0.0,1.0,1.0},
    {0.0,0.0,1.0,1.0}
};

