#include “ThumbStickRotate.h”
#include
ThumbStickRotate::ThumbStickRotate(XInputHandler *inputHandler, float startPos, float endPos)
{
this->inputHandler = inputHandler;
currentPosition = 0;
float stepSize = (endPos – startPos) / NUMBER_OF_SEGMENTS;
if (endPos < startPos) bRotateClockwise = false; else bRotateClockwise = true; for (int i = 0; i < NUMBER_OF_SEGMENTS; i++) angleSteps[i] = startPos + (stepSize * i); } bool ThumbStickRotate::Update() { Vector2 newVec = inputHandler->getLeftStickVector();
if (newVec.getMag() < 0.5f)
{
currentPosition = 0;
return false;
}
float fAngle = newVec.getAngle();
if (newVec.fX < 0.0f) fAngle = 360 - fAngle;
std::cout << "fangle: " << fAngle << " currentPos: " << angleSteps[currentPosition] << std::endl;
}
bool ThumbStickRotate::UpdateClockwise(float fAngle)
{
if (fAngle > angleSteps[currentPosition])
{
if (currentPosition == (NUMBER_OF_SEGMENTS – 1))
{
currentPosition = 0;
return true;
}
else if (fAngle < angleSteps[currentPosition + 1])
currentPosition++;
}
return false;
}
bool ThumbStickRotate::UpdateAntiClockwise(float fAngle)
{
if (fAngle < angleSteps[currentPosition])
{
if (currentPosition == (NUMBER_OF_SEGMENTS - 1))
{
currentPosition = 0;
return true;
}
else if (fAngle > angleSteps[currentPosition + 1])
currentPosition++;
}
return false;
}
ThumbStickRotate::~ThumbStickRotate()
{
this->inputHandler = nullptr;
}