/***************************************************************************
 *   Copyright (C) 2004-2005 by                                            *
 *     Paolo Sacconier   <axa1981@tin.it>                                  *
 *     Francesco Tamagni <minchiahead@hacari.org>                          *
 *                                                                         *
 *   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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "cube.h"

namespace gillo {

Cube::Cube(Context& c)
 : Entity(c)
{
	sgVec3 center = { 0,0,0 };
	sgVec3 dim = { 0.5, 0.5, 0.5 };
	
	type = CUBE;
	bid = dBodyCreate(c.getWid());
	gid = dCreateBox (c.getSid(), dim[0], dim[1], dim[2]);
	Entity::Init();
	
	ssgSimpleState * state = new ssgSimpleState () ;
// 	state -> setTexture        ( TEX_GOAL ) ;
// 	state -> enable            ( GL_TEXTURE_2D ) ;
// 	state -> setShadeModel     ( GL_SMOOTH ) ;
// 	state -> enable            ( GL_CULL_FACE ) ;
// 	state -> enable            ( GL_BLEND ) ;
	state -> enable            ( GL_LIGHTING ) ;
	state -> setColourMaterial ( GL_AMBIENT ) ;
	state -> setMaterial       ( GL_EMISSION, 0, 0, 0, 1 ) ;
	state -> setMaterial       ( GL_SPECULAR, 1, 1, 1, 1 ) ;
	state -> setMaterial       ( GL_DIFFUSE,  1, 1, 1, 1 ) ;
// 	state -> setShininess      ( 2 ) ;

	dGeomSetPosition (gid, (dReal) center[0], (dReal) center[1], (dReal) center[2]);
		
	ssgaCube * e_obj =  new ssgaCube     () ;
	e_obj -> setSize          ( dim ) ;
	e_obj -> setCenter        ( center ) ;
	e_obj -> setKidState      ( state ) ;
	e_obj -> regenerate       () ;
	trans.addKid( e_obj );
	
	dMassSetBoxTotal (&mass, ODE_CAR_MASS, dim[0], dim[1], dim[2]);
	dBodySetMass(bid, &mass);
	dBodySetPosition(bid, center[0], center[1], center[2]);
}


Cube::~Cube()
{
}

void Cube::update(float dt) {
	Entity::update(dt);
	Entity::odeTrans2ssgTrans(this->bid, this->trans);
}

};
