/***************************************************************************
 *   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 GILLOCONTEXT_H
#define GILLOCONTEXT_H

#include "main.h"
#include "sound.h"
#include "iballpicker.h"

namespace gillo {

/**
World context needed by entities

@author ,,,
*/
class Context{
public:
	Context(Sound& s);

	~Context();

	inline dWorldID getWid(void) { return wid; }
	inline dSpaceID getSid(void) { return sid; }
	inline ssgRoot* getScenePtr(void) { return &scene; }
	inline ssgRoot* getAlphaScenePtr(void) { return &alphaScene; }
	inline const float* getGravity() { return gravity; }
	inline void setGravity(float x, float y, float z) { gravity[0]=x, gravity[1]=y, gravity[2]=z, dWorldSetGravity (wid, gravity[0], gravity[1], gravity[2]); }
	inline void setGravity(sgVec3 g) { sgCopyVec3(gravity, g), dWorldSetGravity (wid, gravity[0], gravity[1], gravity[2]); }
	inline void invertGravity() { gravity[0] = -gravity[0], gravity[1] = -gravity[1], gravity[2] = -gravity[2],  dWorldSetGravity (wid, gravity[0], gravity[1], gravity[2]); };
	inline void rotateGravity(float angle)
	{
		sgVec3 axis = {0, 1, 0};
		sgMat4 rot;
		sgMakeRotMat4(rot, angle, axis);
		sgXformVec3(gravity, rot);
		dWorldSetGravity (wid, gravity[0], gravity[1], gravity[2]);
	}
	
	ssgSimpleState* getState(int stateid);
	void       addToPool(ssgEntity* obj);
	ssgEntity* searchInPool(char* name);
	void releaseBall(IBallPicker* bPickPtr);
	inline IBallPicker* getBallPickerPtr() { return this->ballPickerPtr; }
	inline void toggleDebug() { debug = !debug; }
	inline bool isDebug() { return debug; }
	Sound& sound;

protected:
	ssgRoot scene;
	ssgRoot alphaScene;
	ssgInvisible* objPool;
	ssgStateSelector states;
	dWorldID wid;
	dSpaceID sid;
	sgVec3 gravity;
	IBallPicker* ballPickerPtr;
	bool debug;
	
};

};

#endif
