/**
* Positional Data
* @version: 01-29-2005
* @author Joseph 'Pcjoe' Florencio
*/
#ifndef FXDATAPOINT_H
#define FXDATAPOINT_H

enum type_dp{DP_STATIC = 0,DP_BONE,DP_CAMERA};

class CFXDataPoint
{
public:
	// Constructors
	CFXDataPoint() { setType(DP_STATIC); setFXEvent(NULL); }
	CFXDataPoint( vec3_t v ) { CFXDataPoint(); setStaticPosition(v); }
	CFXDataPoint( std::string bone ) { CFXDataPoint(); setDynamicBone(bone); }
	CFXDataPoint( TiXmlElement *pElement ) { CFXDataPoint(); readXML(pElement); }

	//Get Position (dynamic or static)
	vec3_t getPosition( void );

	// Move point (add vector, add to offset if dynamic)
	void movePoint( vec3_t move )
	{	if(getType()==DP_STATIC)
		{	m_vecPosition = m_vecPosition + move;
		}
		else
		{	m_vecOffset = m_vecOffset + move;
		}
	}

	// Rotate point
	void rotatePoint( vec3_t angle )
	{	// Get rotation matrix
		float rmatrix[3][4];
		AngleMatrix(angle, rmatrix);
		if(getType()==DP_STATIC)
		{	// Rotate point
			VectorTransform(m_vecPosition, rmatrix, m_vecPosition);
		}
		// HACK HACK: Rotate position of dynamic position, then subtract by the dynamic position to get offset
		else
		{	vec3_t vecRotPos;
			vec3_t vecPos = getPosition();
			VectorTransform((vecPos + m_vecOffset), rmatrix, vecRotPos);
			m_vecOffset = vecRotPos - vecPos;
		}
	}

	// Write XML
	virtual TiXmlElement *writeXML( void );

	// read XML
	virtual void readXML( TiXmlElement *pElement );

	/*
	* Static
	*/
	// Accessors
	void setStaticPosition( vec3_t v ) { setType(DP_STATIC); m_vecPosition = v; }

	/*
	* Dynamic
	*/
	// Accessors
	void setDynamicBone( std::string strBone ) { setType(DP_BONE); m_strBone = strBone; }
	void setDynamicCamera( void ) { setType(DP_CAMERA); }
	void setDynamicOffset( vec3_t v ) { if(getType()!=DP_STATIC) { m_vecOffset = v; } }

	// Type accessors
	void setType( type_dp t ) { m_eType = t; }
	int getType( void ) { return (int)m_eType; }

	// FX Event
	void setFXEvent( CFXEvent *pEvent ) { m_pFXEvent = pEvent; }
	CFXEvent *getFXEvent( void ) { return m_pFXEvent; }

private:
	// Type
	type_dp m_eType;
	// Static Position Data
	vec3_t m_vecPosition;
	// Dynamic Position Data
	std::string m_strBone;
	vec3_t m_vecOffset;
	// FX Event, used to translate local positions to global space
	CFXEvent *m_pFXEvent;

};
#endif