#include "curvedpathparticle.h"

CurvedPathParticle::CurvedPathParticle(HSPRITE sprite):VelocityParticle(sprite)
{	VelocityParticle::VelocityParticle(sprite);
	sideVelocity = vec3_t(0,0,0);
	duration = 1000;
	acceleration = vec3_t(0,0,0);
	forwardVelocity = vec3_t(0,0,0);;
	sideVelocity = vec3_t(0,0,0);
	SetThink(&CurvedPathParticle::curveThink);		
}

CurvedPathParticle::CurvedPathParticle(float flStartAngle, float flSpeed, float flRadius, vec3_t _position,vec3_t vecForward,vec3_t vecRight,vec3_t vecUp, double flDuration, HSPRITE sprite):VelocityParticle(sprite)
{
	//Particle::Particle(_position,sprite);

	//calculate start speed		
	float flSideSpeed = sin(flStartAngle)*flSpeed;	
	float flForwardSpeed = cos(flStartAngle)*flSpeed;	
	sideVelocity = vecRight*gEngfuncs.pfnRandomFloat(-1,1)+vecUp*gEngfuncs.pfnRandomFloat(-1,1);
	sideVelocity = sideVelocity.Normalize() * flSideSpeed;

	//calculate acceleration
	float flHalfDuration = flRadius*0.5/flSpeed;
	acceleration = (1.0/flHalfDuration) * sideVelocity;

	forwardVelocity = vecForward*flForwardSpeed;
	velocity = forwardVelocity + sideVelocity;	
	
	startPosition = _position;
	duration = flDuration;
	SetThink(&CurvedPathParticle::curveThink);	
}
//-------------------------------------------------------------------------
CurvedPathParticle::~CurvedPathParticle()
{	
}
//-------------------------------------------------------------------------
void CurvedPathParticle::curveThink(float time)
{
	//velocity = forwardVelocity + sideVelocity - acceleration * time;
	position = startPosition + forwardVelocity*time+sideVelocity*time-0.5*acceleration*time*time;
	//VelocityParticle::velocityThink(time);	
}

