/***************************************************************************
 *   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.             *
 ***************************************************************************/
#ifndef GILLOOMNICAR_H
#define GILLOOMNICAR_H

#include "entity.h"
#include "iballpicker.h"
#include "simpleball.h"

namespace gillo {

/**
Omnidirectional car

@author Paolo Sacconier
*/
class Omnicar : public Entity, public IBallPicker {

	static const float maxJumpForce = 100;
	static const float corrIntensity = 100;
	static sgVec3 dirDim;
	static sgVec3 carDim;

	static void traslateBody(dBodyID b, dVector3 diff);

	int nWheels;
	
	SimpleBall& ball;
	dBodyID dirBid;
	dGeomID dirGid;
// 	dBodyID rejBid;
	dBodyID * carBid;
	dBodyID * wheelBid;
// 	dBodyID borBid[2];
	ssgTransform **wheelTrans;
	ssgTransform **carTrans;
// 	ssgTransform *borTrans[2];
	ssgTransform *dirTrans;
	ssgTransform *rejTrans;
// 	dGeomID pickerGid[4];
	dJointID *jam;
	dJointID diram;
	dJointGroupID jid;
// 	sgVec3 direction;
	sgVec3 bodyDir;
	float speed;
	float steering;
	bool backwards;
	bool jumping;
	float steerAngle;
	dJointID ballJoint;
	float jumpForce;
	bool fire;
	float fireTime;
	float savedCharge;
// 	dJointFeedback jf;
	
public:
	Omnicar(Context &c, SimpleBall& b, float pi = 0, int plid = 0, int nw = 3);
	
	~Omnicar();
	
	void update(float dt);
	void move(Entity::Move m);
	void getPos(sgVec3 out);
	void setPos(double x, double y, double z);
	void getMagnetDir(sgVec3 out);
	void getMagnetPos(sgVec3 out);
	void addForce(sgVec3 force);
	bool isPickerGeom(dGeomID o);
	void releaseBall();
	void powerShoot();
};

};

#endif
