本文整理汇总了C#中Engine.Vector.Length方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Length方法的具体用法?C# Vector.Length怎么用?C# Vector.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Engine.Vector
的用法示例。
在下文中一共展示了Vector.Length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
public void Update(double elapsedTime)
{
// Get controls and apply to player character
double _x = _input.Controller.LeftControlStick.X;
double _y = _input.Controller.LeftControlStick.Y * -1;
Vector controlInput = new Vector(_x, _y, 0);
if (Math.Abs(controlInput.Length()) < 0.0001)
{
// If the input is very small, then the player may not be using
// a controller;, they might be using the keyboard.
if (_input.Keyboard.IsKeyHeld(Keys.Left))
{
controlInput.X = -1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Right))
{
controlInput.X = 1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Up))
{
controlInput.Y = 1;
}
if (_input.Keyboard.IsKeyHeld(Keys.Down))
{
controlInput.Y = -1;
}
}
_playerCharacter.Move(controlInput * elapsedTime);
}
示例2: Normalise
public Vector Normalise(Vector v)
{
double r = v.Length();
if (r != 0.0) // guard against divide by zero
{
return new Vector(v.X / r, v.Y / r, v.Z / r); // normalise and return
}
else
{
return new Vector(0, 0, 0);
}
}
示例3: Normalize
public Vector Normalize(Vector v)
{
double r = v.Length();
if (r != 0.0)
{
return new Vector(X / r, Y / r, Z / r);
}
else
{
return new Vector(0, 0, 0);
}
}
示例4: Normalise
public Vector Normalise(Vector v)
{
double r = v.Length();
if (r != 0.0)
{
return new Vector(v.X/r, v.Y/r, v.Z/r);
}
return new Vector(0, 0, 0);
}