2007-02-17 13:42:00 +00:00
|
|
|
#include "position_tracker.h"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void Position_Tracker::Update()
|
|
|
|
{
|
2007-02-20 21:01:02 +00:00
|
|
|
Mouse_Sensor* mouseLeft = parent->GetModule<Mouse_Sensor>(IO_SENSOR_MOUSE_LEFT);
|
|
|
|
Mouse_Sensor* mouseRight = parent->GetModule<Mouse_Sensor>(IO_SENSOR_MOUSE_RIGHT);
|
|
|
|
|
|
|
|
int8 leftX = mouseLeft->GetXMovement();
|
|
|
|
int8 leftY = mouseLeft->GetYMovement();
|
|
|
|
float distanceLeft = sqrt(leftX * leftX + leftY * leftY);
|
|
|
|
float angleLeft = easyAngle(atan2(leftY, leftX) + (225.0f * PI / 180.0f));
|
|
|
|
|
|
|
|
float movementLeftX = cos(angleLeft) * distanceLeft;
|
|
|
|
float movementLeftY = sin(angleLeft) * distanceLeft;
|
|
|
|
|
|
|
|
if(!leftX && !leftY)
|
|
|
|
{
|
|
|
|
movementLeftX = 0;
|
|
|
|
movementLeftY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8 rightX = mouseRight->GetXMovement();
|
|
|
|
int8 rightY = mouseRight->GetYMovement();
|
|
|
|
float distanceRight = sqrt(rightX * rightX + rightY * rightY);
|
|
|
|
float angleRight = easyAngle(atan2(rightY, rightX) - (45.0f * PI / 180.0f));
|
|
|
|
|
|
|
|
float movementRightX = cos(angleRight) * distanceRight;
|
|
|
|
float movementRightY = sin(angleRight) * distanceRight;
|
|
|
|
|
|
|
|
if(!rightX && !rightY)
|
|
|
|
{
|
|
|
|
movementRightX = 0;
|
|
|
|
movementRightY = 0;
|
|
|
|
}
|
|
|
|
|
2007-02-21 14:28:03 +00:00
|
|
|
float movementDifferenceX = (movementRightX + mouseRight->GetPositionX()) - (movementLeftX + mouseLeft->GetPositionX());
|
2007-02-20 21:01:02 +00:00
|
|
|
float movementDifferenceY = (movementRightY + mouseRight->GetPositionY()) - (movementLeftY + mouseLeft->GetPositionY());
|
|
|
|
|
2007-02-21 14:28:03 +00:00
|
|
|
float orientationDiff = atan2(movementDifferenceY, movementDifferenceX) - (PI / 2.0f);
|
|
|
|
|
2007-02-20 21:01:02 +00:00
|
|
|
float robotMovementX = movementDifferenceX / 2.0f;
|
|
|
|
float robotMovementY = movementDifferenceY / 2.0f;
|
2007-02-21 14:28:03 +00:00
|
|
|
robotMovementX += movementLeftX + mouseLeft->GetPositionX() + (-mouseLeft->GetPositionX() * cos(orientationDiff));
|
|
|
|
robotMovementY += movementLeftY + mouseLeft->GetPositionY() + (-mouseLeft->GetPositionX() * sin(orientationDiff));
|
2007-02-21 07:30:02 +00:00
|
|
|
//float robotDistance = sqrt(robotMovementX * robotMovementX + robotMovementY * robotMovementY);
|
2007-02-20 21:01:02 +00:00
|
|
|
|
2007-02-21 07:30:02 +00:00
|
|
|
float absoluteDiffX = cos(this->orientation + (orientationDiff / 2.0f)) * robotMovementX - sin(this->orientation + (orientationDiff / 2.0f)) * robotMovementY;
|
|
|
|
float absoluteDiffY = sin(this->orientation + (orientationDiff / 2.0f) + PI / 2.0f) * robotMovementY + cos(this->orientation + (orientationDiff / 2.0f) - PI / 2.0f) * robotMovementX;
|
|
|
|
|
|
|
|
//float absoluteDiffX = cos(this->orientation + (orientationDiff / 2.0f)) * robotDistance * sign(robotMovementX);
|
|
|
|
//float absoluteDiffY = sin(this->orientation + (orientationDiff / 2.0f)) * robotDistance * sign(robotMovementY);
|
2007-02-20 21:01:02 +00:00
|
|
|
|
|
|
|
if(!robotMovementX && !robotMovementY)
|
|
|
|
{
|
|
|
|
absoluteDiffX = 0;
|
|
|
|
absoluteDiffY = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print(" ", 5, 1);
|
|
|
|
//(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print(absoluteDiffX, 5, 1);
|
|
|
|
//(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print(absoluteDiffY, 12, 1);
|
|
|
|
|
|
|
|
this->positionX += absoluteDiffX;
|
|
|
|
this->positionY += absoluteDiffY;
|
|
|
|
|
|
|
|
this->orientation += orientationDiff;
|
|
|
|
|
|
|
|
this->orientation = easyAngle(this->orientation);
|
2007-02-17 13:42:00 +00:00
|
|
|
}
|