I have a Picturebox
that is created dynamically, and I'm moving it randomly on a panel. It works perfectly when I increment your location.X / Y with integers.
In certain cases, however, I need Picturebox to move at a certain angle, that is, I calculate the angle between picturebox and target and decompose into sin / cos to increase its position by drawing a straight line between origin and destination. But this increment is float / double, not integer.
The picturebox moves perfectly in several angles, however in certain scenarios it is locked, immobile, I believe it is due to the rounding occurring from incrementing to ZERO, making it still on the panel.
Is there any way I can transform Picturebox's coordinates (int by nature) into Picturebox's float?
//
void Vant::vectorStep(Point ^ target)
{
float angle, ix, iy, distX, distY;
distX = target->X - getCenterLocation().X;
distY = target->Y - getCenterLocation().Y;
angle = Math::Atan2(distY, distX);
if (angle < 0)
angle += 2 * Math::PI;
ix = (float) Math::Cos(angle);
iy = (float) Math::Sin(angle);
if (Math::Abs(distX) >= 0)
incrementX(ix);
if (Math::Abs(distY) >= 0)
incrementY(iy);
}
void Vant::incrementX(float x)
{
myX = myPic->Location.X;
myY = myPic->Location.Y;
myPic->Location = System::Drawing::Point((myX + (x * mySpeed)), (myY));
if (myLabel->Visible)
{
myLabel->Location = System::Drawing::Point((float) (myX + myPic->Size.Width), myY);
myLabel->Text = "ID:" + myID + "\r\nSp:" + mySpeed + "\r\nConn(" + isUAVConnected() + "/" + isSensorConnected() + ")";
}
}
void Vant::incrementY(float y)
{
myX = myPic->Location.X;
myY = myPic->Location.Y;
myPic->Location = System::Drawing::Point((myX), (float) (myY + (y * mySpeed)));
if (myLabel->Visible)
{
myLabel->Location = System::Drawing::Point(myX + myPic->Size.Width, myY);
myLabel->Text = "ID:" + myID + "\r\nSp:" + mySpeed + "\r\nConn(" + isUAVConnected() + "/" + isSensorConnected() + ")";
}
}