/*
 *
 * Copyright (C) 2008 Fontaine Clément
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * this program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "camera.h"

void cameraClavier(const hauteur altitude, const SDL_KeyboardEvent event, int *x, int *y, int *z)
{
        switch(event.keysym.sym)
        {
                case SDLK_UP:
                        *z += 50;
                        break;
                
                case SDLK_DOWN:
                        if((*z) > 10)
                        {
                                *z -= 50;
                        }
                        break;
                
                case SDLK_t:
                        if(((*x) == 0) && ((*y) == 0))
                        {
                                *y = altitude.taille.y;
                        }
                        else if(((*x) == 0) && ((*y) != 0))
                        {
                                *x = altitude.taille.x;
                        }
                        else if(((*x) != 0) && ((*y) != 0))
                        {
                                *y = 0;
                        }
                        else if(((*x) != 0) && ((*y) == 0))
                        {
                                *x = 0;
                        }
                        break;
        }
}

void cameraRegarder(const hauteur altitude, int x, int y, int z)
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity(); /* initialisation */
        
        /* on place la camera */
        gluLookAt(x, y, z, altitude.taille.x - x, altitude.taille.y - y, 0, 0, 0, 1);
        
        glEnable(GL_DEPTH_TEST);
}
