#include "OGLPlatformSpecific.h"
#include "cCamera.h"
#include <math.h>

cCamera::cCamera(cBall* ball)
{
    ball_ = ball;
    phi_ = 3.1415;
    theta_ = -3.1415/4;
    radius_ = 100;
    position_ = cVector(0,120,0);
    lookAt_ = cVector(0,0,0);
    upDir_ = cVector(0,1,0);
    ticker_ = 0;//3.1415/2 + .5;
}

void cCamera::update(float dt)
{
    ticker_ += dt * .1;
   // position_ = cVector(50*sin(ticker_), 100, 50 * cos(ticker_) );
    //lookAt_ = cVector(30*cos(ticker_), 100, 40*sin(ticker_));
    //float r = 40 + 5 * cos(ticker_ * 2);
    if(radius_ == 0) radius_ = .1;
    //lookAt_ = (ball_->position_ + 15 * lookAt_) / 16;
    lookAt_ = cVector(-25.868240, 39.265205, 7.689216);
    //position_ = cVector(0, height_, 0);
    position_ = lookAt_ + cVector(	-radius_*cos(theta_)*sin(phi_), 
                                        -radius_*sin(theta_),
                                        radius_*cos(phi_)*cos(theta_));
    cVector lookAtToPos = (position_ - lookAt_);
    lookAtToPos.normalize();
    upDir_ = cVector(0,1,0) - lookAtToPos;
    upDir_.normalize();
    
    //position_ = cVector(r*cos(ticker_)+ball_->position_.x_, 50 + 10 * cos(ticker_), r*sin(ticker_)+ball_->position_.y_);
}

void cCamera::look()
{
    glLoadIdentity(); // clear the last transformation
    gluLookAt(	position_.x_, position_.y_, position_.z_,
                lookAt_.x_, lookAt_.y_, lookAt_.z_,
                upDir_.x_, upDir_.y_, upDir_.z_);
}
