/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/src/sgx/input/rumble_profile.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/input/input.hpp"

//
// The base implementation
//
tREAL32 CSGXRumbleProfile::getInnerCone() const {
	return SGX_FLOAT_MAX_VALUE;
}

tREAL32 CSGXRumbleProfile::getOuterCone() const {
	return SGX_FLOAT_MAX_VALUE;
}

//
// Example profiles
//
tREAL32 CSGXRumbleProfileConstant::getRumbleOutput(const tREAL32 t) const {
SGX_UNUSED(t);
	return 1.0f;
}

//
// Pulse :  |^|________
//
CSGXRumbleProfilePulse::CSGXRumbleProfilePulse(const tREAL32 t) {
	m_fPulseDuration = t;
}

tREAL32 
CSGXRumbleProfilePulse::getRumbleOutput(const tREAL32 t) const {
	return t < m_fPulseDuration ? 1.0f : 0;
}


//
// Spike :  |\________
//
CSGXRumbleProfileSpike::CSGXRumbleProfileSpike(const tREAL32 tailDuration) {
	m_fTailDuration = tailDuration;
}

tREAL32 
CSGXRumbleProfileSpike::getRumbleOutput(const tREAL32 t) const {
	return t < m_fTailDuration ? (m_fTailDuration-t)/m_fTailDuration : 0;
}

//
// Sawtooth :  /\/\/\/\/\
//
CSGXRumbleProfileSawtooth::CSGXRumbleProfileSawtooth(const tREAL32 period) {
	m_fPeriod = period;
}

tREAL32 
CSGXRumbleProfileSawtooth::getRumbleOutput(const tREAL32 tm) const {
	tREAL32 t = tm;
	while(t>m_fPeriod) {
		t -= m_fPeriod;
	}
	tREAL32 p2 = m_fPeriod/2.0f;
	return  t < p2 ? (p2-t)/p2 : 1.0f-(t-p2)/p2;
}

//
// Square :  |^|_|^|_|^|_
//
CSGXRumbleProfileSquare::CSGXRumbleProfileSquare(const tREAL32 mark, const tREAL32 space) {
	m_fMarkDuration = mark;
	m_fSpaceDuration = space;
	m_fTotalDuration = m_fMarkDuration + m_fSpaceDuration;
}

tREAL32 
CSGXRumbleProfileSquare::getRumbleOutput(const tREAL32 tm) const {
	tREAL32 t = tm;
	while(t>m_fTotalDuration) {
		t -= m_fTotalDuration;
	}
	return  t < m_fMarkDuration ? 1.0f : 0;
}
