Looking in direction pointing line

This commit is contained in:
Niklas Ulf Anders Cullberg
2012-10-01 17:35:07 +02:00
parent f8d568371b
commit 62c633fecb
2 changed files with 32 additions and 4 deletions
@@ -97,6 +97,12 @@ namespace DepthsBelow.Component
}
public float Rotation;
public void Rotate(int directionX, int directionY)
{
Rotation = (float)Math.Atan(directionY/directionX);
}
public Vector2 Origin;
public static implicit operator Vector2(WorldTransform worldTransform)
+26 -4
View File
@@ -87,15 +87,17 @@ public MouseInput(Core core)
if (ms.RightButton == ButtonState.Released && lastMouseState.RightButton == ButtonState.Pressed)
{
foreach (var unit in core.Squad)
if (unit.Selected)
if (unit.Selected)
{
unit.GetComponent<Component.PathFinder>().Goal = Grid.WorldToGrid(mouseWorldPos);
}
}
if (ms.RightButton == ButtonState.Pressed)
{
foreach (var unit in core.Squad)
{
if (unit.Selected)
if (unit.Selected && gridRectangle.Intersects(unit.GetComponent<Component.Collision>().Rectangle))
{
checkingDirection = true;
directionStart = unit.Transform.World + unit.Transform.World.Origin;
@@ -104,8 +106,28 @@ public MouseInput(Core core)
}
if (checkingDirection == true && ms.RightButton == ButtonState.Pressed)
{
directionNow.X = ms.X;
directionNow.Y = ms.Y;
foreach (var unit in core.Squad)
if (unit.Selected)
{
directionNow.X = mouseWorldPos.X;
directionNow.Y = mouseWorldPos.Y;
float directionX = mouseWorldPos.X - unit.Transform.World.X;
float directionY = mouseWorldPos.Y - unit.Transform.World.Y;
var mouseDirection = mouseWorldPos;
mouseDirection.Normalize();
//float angle = (float)Math.Acos(Vector2.Dot(new Vector2(0, 1), mouseDirection)) * MathHelper.TwoPi;
/*if (directionX < 0)
{
directionX *= -1;
unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan(directionY / directionX);
}
else
{
*/unit.GetComponent<Component.Transform>().World.Rotation = (float)Math.Atan2(mouseWorldPos.Y - unit.Transform.World.Y, mouseWorldPos.X - unit.Transform.World.X);/*
}*/
//Console.WriteLine(angle);
//unit.GetComponent<Component.Transform>().World.Rotation = angle;
}
}
else
{