Reputation: 445
What I am trying to do:
What I have already done:
Rendered the player on the minimap based upon it's in game x and y coordinates, rendered the enemies on the minimap based upon their x and y coordinates. When I move around in game the enemies in the minimap move relative to the player movements.
What I tried (but didn't work):
float radarX = 200;
float radarY = 200;
float zoom = 2;
// Function
float xOffset = radarX - LocalPlayer.Position.x;
float yOffset = radarY - LocalPlayer.Position.y;
draw(zoom *(LocalPlayer.Position.x + xOffset),
zoom * (LocalPlayer.Position.y + yOffset);
foreach(Player p in Game.OtherPlayers) // list of enemies
{
Vector2 rotatedLocation = VectorExt.Rotate(new Vector2(p.Position.x, p.Position.y), -LocalPlayer.Yaw - 90); // negate and -90 to convert to normal coordinate system (0 @ RHS, 90 @ Top, 180 @ LHS, 270 @ Bottom)
float tempX = zoom * (rotatedLocation.x + xOffset);
float tempY = zoom * (rotatedLocation.y + yOffset);
draw(myPen, zoom * (LocalPlayer.Position.x + xOffset), zoom * (LocalPlayer.Position.y + yOffset);
}
// End of function
// VectorExt.Rotate
var ca = Math.Cos(radians);
var sa = Math.Sin(radians);
return new Vector2(Convert.ToSingle(ca * v.x - sa * v.y), Convert.ToSingle(sa * v.x + ca * v.y));
// End of VectorExt.Rotate
Thanks in advance.
Upvotes: 0
Views: 324
Reputation: 66753
When you rotate your player in game the enemies rotate however they appear to be rotating around the 0,0 axis and not the player.
Yes, that's what your rotation code does. To rotate around another point, you must first subtract the coordinates of that rotation center, then do the rotation, then add the coordinates of the rotation center again.
See also this other C++ question.
Upvotes: 1