本文整理汇总了C#中Microsoft.Xna.Framework.Vector2.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector2.Normalize方法的具体用法?C# Vector2.Normalize怎么用?C# Vector2.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Vector2
的用法示例。
在下文中一共展示了Vector2.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Shoot
public override bool Shoot(Player player, ref Microsoft.Xna.Framework.Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
{
Vector2 direction = new Vector2(speedX, speedY);
direction.Normalize();
position += direction * item.width;
return true;
}
示例2: AngleBetween
public static float AngleBetween(Vector2 v1, Vector2 v2)
{
v1.Normalize();
v2.Normalize();
float Angle = (float)Math.Acos(Vector2.Dot(v1, v2));
return Angle;
}
示例3: DrawLightningStreak
/// <summary>
/// A streak of lightning is drawn simply by piecing together a long string of small line segments,
/// each of which is slightly rotated.
/// </summary>
private void DrawLightningStreak(LineBatch lineBatch, Color color, Vector2 start, Vector2 end, int numSegments,
float deviation)
{
Random randomGen = new Random();
Vector2 disp = end - start;
Vector2 unitDisp = Vector2.Normalize(disp);
Vector2 stepVector = unitDisp * disp.Length() / (float)numSegments;
Vector2 perpVec = new Vector2(-stepVector.Y, stepVector.X);
perpVec.Normalize();
Vector2 startPoint = start;
Vector2 endPoint = new Vector2();
for (int i = 0; i < numSegments; ++i)
{
endPoint = start + stepVector * (i + 1);
// If this is an intermediate segment, apply an offset perpendicular to the line connecting start to end.
if (i < numSegments - 1)
{
float random = (float)randomGen.NextDouble();
float offset = (random >= 0.5f ? 1 : -1) * random * deviation;
endPoint += perpVec * offset;
}
lineBatch.DrawLine(startPoint, endPoint, color);
startPoint = endPoint;
}
}
示例4: DirectionFrom
public static Vector2 DirectionFrom(Vector2 point1, Vector2 point2, out float angle)
{
angle = AngleFrom(point1, point2);
Vector2 direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
direction.Normalize();
return direction;
}
示例5: Calculate
public override void Calculate()
{
if (EnemyList.Count > 0)
{
Target = FindClosestEnemy();// EnemyList[0]; //TODO beregn den fysisk nermeste fiendem
Vector2 t = new Vector2(Target.X + Target.Width/2, Target.Y + Target.Height/2);
dir = t - Position;
dir.Normalize();
Angle = (float)Math.Atan2(
(double)dir.Y,
(double)dir.X);
Position += dir * Speed;
X = (int)Position.X;
Y = (int)Position.Y;
}
else
{
X = (int)Position.X;
Y = (int)Position.Y;
Position += dir * Speed;
}
}
示例6: Act
public override void Act(GameTime gameTime)
{
base.Act(gameTime);
hitTime -= 1.0f;
if (hitTime <= 0)
{
Vector2 temp = new Vector2(Owner.FaceVector.X, Owner.FaceVector.Y);
temp.Normalize();
ArrayList targetList = new ArrayList();
Owner.EntitiesInRadius(50, Owner.CenterPosition + Owner.Bounds, targetList);
for (int i = 0; i < targetList.Count; i++)
{
if (targetList[i] is Player)
{
if (Owner is BigZombie)
{
((Being)targetList[i]).Health -= 8;
}
((Being)targetList[i]).Health -= 2;
}
}
hitTime = 5;
//Zombie.CurrentState = new ZombieWalkState();
}
}
示例7: MoveDown
public void MoveDown(float delta)
{
dir = new Vector2(0,1);
pos = pos + dir * speed * delta;
dir.Normalize();
}
示例8: FindTargets
public override Vector2[] FindTargets(ZazumoActor zazumoActor, IEnumerable<EnemyActor> enemies)
{
var moveDiretion = new Vector2(zazumoActor.Location.X, zazumoActor.Location.Y) - _lastPosition;
moveDiretion.Normalize();
_lastPosition = new Vector2(zazumoActor.Location.X, zazumoActor.Location.Y);
var requestedTarget = new Vector2(moveDiretion.X * -10f, moveDiretion.Y * -6f);
if (Single.IsNaN(requestedTarget.X) || Single.IsNaN(requestedTarget.Y))
return new Vector2[]{};
if (_lastTarget == Vector2.Zero)
{
_lastTarget = requestedTarget;
return new Vector2[] { requestedTarget };
}
else
{
_lastTarget.Normalize();
var lastAngle = (Single)(Math.Acos(_lastTarget.X) * (_lastTarget.Y > 0 ? -1.0 : 1.0));
requestedTarget.Normalize();
var requestedAngle = (Single)(Math.Acos(requestedTarget.X) * (requestedTarget.Y > 0 ? -1.0 : 1.0));
Single angle = (0.7f * lastAngle) + (0.3f * requestedAngle);
var direction = new Vector2((Single)Math.Cos(angle), (Single)Math.Sin(angle) * -1.0f);
direction.Normalize();
var newtarget = new Vector2(direction.X * 10f, direction.Y * 6f);
_lastTarget = newtarget;
return new Vector2[] { newtarget };
}
}
示例9: Goalie
public Goalie(World world, GoalieData spawn)
{
var body = new Body(world);
var angle = spawn.End - spawn.Begin;
body.Rotation = FMath.Atan2(angle.Y, angle.X);
segment.A = spawn.Begin;
segment.B = spawn.End;
var normal = new Vector2(-angle.Y, angle.X);
normal.Normalize();
delta = normal * .5f;
segmentOut.A = spawn.Begin + delta;
segmentOut.B = spawn.End + delta;
segmentIn.A = spawn.Begin - delta;
segmentIn.B = spawn.End - delta;
body.Position = spawn.Begin;
var verts = new Vertices();
verts.Add(new Vector2(left, bottom));
verts.Add(new Vector2(right, bottom));
verts.Add(new Vector2(right, top));
verts.Add(new Vector2(left, top));
var shape = new PolygonShape(verts, 1f);
body.FixedRotation = true;
body.BodyType = BodyType.Dynamic;
Fixture = body.CreateFixture(shape);
}
示例10: Line
public Line(int x1, int y1, int x2, int y2)
{
direction = new Vector2(x2-x1,y2-y1);
worldPosition = new Vector2(x1,y1);
normal = new Vector2(-direction.Y,direction.X);
normal.Normalize();
}
示例11: Draw
public void Draw(SpriteBatch spriteBatch, TrackPoint tp)
{
if (tp == this)
{
if (!drawn)
{
drawn = true;
}
else
{
drawn = false;
return;
}
}
next.Draw(spriteBatch, tp);
foreach (Particle p in occupying)
{
Vector2 shift = new Vector2(0, 1);
shift.Normalize();
shift *= -10 * occupying.IndexOf(p);
Color colour = maxThroughput < 3 ? Color.Red : Color.IndianRed;
p.Draw(spriteBatch, rotate(loc + shift, 1), colour);
}
}
示例12: WheelJointTest
private WheelJointTest()
{
Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
{
PolygonShape shape = new PolygonShape(1);
shape.Vertices = PolygonTools.CreateRectangle(0.5f, 2.0f);
Body body = new Body(World);
body.BodyType = BodyType.Dynamic;
body.Position = new Vector2(0.0f, 7.0f);
body.CreateFixture(shape);
Vector2 axis = new Vector2(-1000.0f, -2.0f);
axis.Normalize();
WheelJoint jd = new WheelJoint(ground, body, new Vector2(0, 8.5f), axis);
jd.MotorSpeed = 1.0f;
jd.MaxMotorTorque = 1000.0f;
jd.MotorEnabled = true;
jd.SpringFrequencyHz = 1.0f;
jd.SpringDampingRatio = 0.2f;
World.AddJoint(jd);
PolygonShape shape2 = new PolygonShape(1);
shape2.Vertices = PolygonTools.CreateRectangle(0.5f, 2.0f);
Body body2 = BodyFactory.CreatePolygon(World, shape2.Vertices, 0.5f);
body2.BodyType = BodyType.Dynamic;
body2.Position = new Vector2(10.0f, 7.0f);
}
}
示例13: GetInletDirection
public static Vector2 GetInletDirection(Vector2 Position)
{
Vector2 inletDirection = new Vector2();
inletDirection = inletPosition - Position;
inletDirection.Normalize();
return inletDirection;
}
示例14: Update
public override void Update(GameTime gameTime)
{
Vector2 direction = new Vector2(0, 0);
mFixture.Body.ResetDynamics();
mFixture.Body.LinearVelocity = new Vector2(0, 0);
mFixture.Body.Rotation = 0;
UpdateInput();
//base.Update(gameTime);
if (mControllable)
{
direction = DetermineDesiredDirection();
if (direction.Length() > .065f)
{
mFixture.Body.LinearVelocity = (direction * mMaxSpeed);
}
if (direction.Length() > 0)
{
direction.Normalize();
mDirection = direction;
}
}
mPosition = new Vector2(mFixture.Body.Position.X, mFixture.Body.Position.Y); // converts Body.Position (meters) into pixels
UpdateAnimation(gameTime, direction);
}
示例15: update
override public void update(float dt)
{
//Console.WriteLine(path.Count);
double distance = Math.Sqrt(Math.Pow(target.hitBox.Center.X - owner.hitBox.Center.X, 2) + Math.Pow(target.hitBox.Center.Y - owner.hitBox.Center.Y, 2));
if (distance > 50)
{
Vector2 attackVector = new Vector2(owner.hitBox.Center.X - target.hitBox.Center.X, owner.hitBox.Center.Y - target.hitBox.Center.Y);
attackVector.Normalize();
attackVector *= 50;
attackVector.X += target.hitBox.Center.X;
attackVector.Y += target.hitBox.Center.Y;
Point attackPos = new Point((int)attackVector.X, (int)attackVector.Y);
Vector2 movement = new Vector2(attackPos.X - owner.hitBox.Center.X, attackPos.Y - owner.hitBox.Center.Y);
movement.Normalize();
movement *= 5;
//owner.movementIntent /= 3f;
owner.velocity.X = movement.X;
owner.velocity.Y = movement.Y;
owner.isWalking = true;
owner.setGaze(attackPos);
}
else
{
owner.setGaze(target.hitBox.Center);
Punch punch = new Punch(owner.animationList, owner);
if (!owner.animationList.has(punch))
{
owner.animationList.pushFront(punch);
}
}
}