// This file is part of ThriceBall.
//
// Author: Kai Hillenbrand (AnTeevY)
// © Copyright, 2009 by Kai Hillenbrand, http://www.anteevy.de

// --------------------------------------------------

#include "info.h"

CInfo::CInfo(CRenderer *renderer, CLevel *level, NxOgre::Scene *scene, OGRE3DRenderSystem *rendersys)
	: m_pRenderer(renderer), m_pLevel(level), m_pScene(scene), m_pRenderSystem(rendersys), m_sText(""),
	m_fXPos(0), m_fYPos(0), m_fZPos(0), m_pSceneMgr(renderer->getSceneManager()), m_pPlayer(renderer->getPlayer())
{
}

void CInfo::create(float x, float y, float z, float size, String text)
{
	// apply the variables
	m_fSize = size;
	m_sText = text;
	m_fXPos = x;
	m_fYPos = y;
	m_fZPos = z;
	
	setupVolume();		// create the volume and trigger
}

void CInfo::setupVolume()
{
	m_pVolume = m_pScene->createVolume(new NxOgre::Box(m_fSize), 
		NxOgre::Matrix44(NxOgre::Real3(m_fXPos, m_fYPos, m_fZPos)),	this, NxOgre::Enums::VolumeCollisionType_EnterOrExit);
}

void CInfo::onVolumeEvent(NxOgre::Volume* volume, NxOgre::Shape* volumeShape, NxOgre::RigidBody* rigidBody, 
		NxOgre::Shape* rigidBodyShape, unsigned int collisionEvent)
{
	NxOgre::Actor* actor = static_cast<NxOgre::Actor*>(rigidBody);

	if ((volume == m_pVolume) && (actor == m_pPlayer->getCurBall()))
	{
		// if ball enters the volume, draw the info text, if it exits the volume, hide it
		if(collisionEvent == NxOgre::Enums::VolumeCollisionType_OnEnter)
		{
			m_pRenderer->getInterface()->drawInfo(m_sText);
		}
		else if(collisionEvent == NxOgre::Enums::VolumeCollisionType_OnExit)
		{
			m_pRenderer->getInterface()->hideInfo();
		}
	}
}