本文整理汇总了C#中Microsoft.Xna.Framework.Vector3.LengthSquared方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.LengthSquared方法的具体用法?C# Vector3.LengthSquared怎么用?C# Vector3.LengthSquared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Vector3
的用法示例。
在下文中一共展示了Vector3.LengthSquared方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetForce
public void SetForce(Vector3 force)
{
if (force.LengthSquared() > 1.0f)
force.Normalize();
mController.Force = GameOptions.MovementForce * force;
}
示例2: LocalGetSupportingVertexWithoutMargin
// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp
//public class Hull m_optionalHull;
public override Vector3 LocalGetSupportingVertexWithoutMargin(Vector3 vec)
{
Vector3 supVec = new Vector3();
float maxDot = -1e30f;
float lenSqr = vec.LengthSquared();
if (lenSqr < 0.0001f)
{
vec = new Vector3(1, 0, 0);
}
else
{
float rlen = 1f / (float)Math.Sqrt(lenSqr);
vec *= rlen;
}
Vector3 vtx;
float newDot;
for (int i = 0; i < VertexCount; i++)
{
GetVertex(i, out vtx);
newDot = Vector3.Dot(vec, vtx);
if (newDot > maxDot)
{
maxDot = newDot;
supVec = vtx;
}
}
return supVec;
}
示例3: Extend
public static Vector3 Extend(Vector3 value, float min)
{
float minSquared = min*min;
float vectorSquared = value.LengthSquared();
if (vectorSquared >= minSquared || vectorSquared == 0)
return value;
else
return value*(min/(float) Math.Sqrt(vectorSquared));
}
示例4: Truncate
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <param name="max"></param>
public static Vector3 Truncate(Vector3 value, float max)
{
float maxSquared = max * max;
float vectorSquared = value.LengthSquared();
if (vectorSquared <= maxSquared)
return value;
else
return value * (max / (float)Math.Sqrt(vectorSquared));
}
示例5: ProjectVector3D
public static void ProjectVector3D(ref Vector3 vec, ref Vector3 projectOn, out Vector3 result)
{
float dp;
Vector3.Dot(ref vec, ref projectOn, out dp);
float oneOnLenSqr = 1.0f / projectOn.LengthSquared();
result = new Vector3(
dp * oneOnLenSqr * projectOn.X,
dp * oneOnLenSqr * projectOn.Y,
dp * oneOnLenSqr * projectOn.Y);
}
示例6: update
public void update()
{
velocity += _acceleration;
position += velocity;
_acceleration = Vector3.Zero;
if( velocity.LengthSquared() < 0.001f * 0.001f )
velocity = Vector3.Zero;
velocity *= _damping;
_damping = 0.98f;
}
示例7: GetExtremePoint
///<summary>
/// Gets the extreme point of the shape in world space in a given direction with margin expansion.
///</summary>
///<param name="direction">Direction to find the extreme point in.</param>
/// <param name="shapeTransform">Transform to use for the shape.</param>
///<param name="extremePoint">Extreme point on the shape.</param>
public void GetExtremePoint(Vector3 direction, ref RigidTransform shapeTransform, out Vector3 extremePoint)
{
GetExtremePointWithoutMargin(direction, ref shapeTransform, out extremePoint);
float directionLength = direction.LengthSquared();
if (directionLength > Toolbox.Epsilon)
{
Vector3.Multiply(ref direction, collisionMargin / (float)Math.Sqrt(directionLength), out direction);
Vector3.Add(ref extremePoint, ref direction, out extremePoint);
}
}
示例8: MovingLevelPiece
public MovingLevelPiece(Game game, GameplayScreen host, String assetName, Vector3 pMovement, float pMoveSpeed)
: base(game, host, assetName)
{
m_movement = pMovement;
m_moveVelocity = m_movement;
if (m_moveVelocity.LengthSquared() != 0)
{
m_moveVelocity.Normalize();
}
//50 is a good number, fyi
m_moveVelocity *= pMoveSpeed;
m_currentMovement = Vector3.Zero;
}
示例9: NormalizeSafe
/// <summary>
/// 正規化された Vector3 を取得します。
/// もしも Vector3 がゼロ ベクトルである場合にはゼロ ベクトルを返します。
/// </summary>
/// <param name="vector">Vector3。</param>
/// <param name="result">正規化された Vector3。</param>
public static void NormalizeSafe(ref Vector3 vector, out Vector3 result)
{
var lengthSquared = vector.LengthSquared();
if (lengthSquared != 0.0f)
{
var coeff = 1.0f / (float) Math.Sqrt(lengthSquared);
result.X = vector.X * coeff;
result.Y = vector.Y * coeff;
result.Z = vector.Z * coeff;
}
else
{
result = vector;
}
}
示例10: contains
public override bool contains(Vector3 point)
{
Vector3 _p = new Vector3(point.X - Position.X, point.Y - Position.Y, point.Z - Position.Z);
//Vector3 _p2 = Vector3.Transform(_p, Matrix.CreateFromQuaternion(Orientation));
if (_p.Y >= 0 && _p.Y <= m_height)
{
if (_p.LengthSquared() < (m_radius * m_radius))
{
return true;
}
}
return false;
}
示例11: InertialMoveBehavior
public InertialMoveBehavior(Vector3 v, float a, float mv)
: base()
{
MaxSpeed = mv;
Accel = a;
if (v.LengthSquared() == 0)
{
Speed = 0;
Direction = new Vector3();
}
else
{
Speed = v.Length();
v.Normalize();
Direction = v;
}
}
示例12: GetLocalExtremePointWithoutMargin
///<summary>
/// Gets the extreme point of the shape in local space in a given direction.
///</summary>
///<param name="direction">Direction to find the extreme point in.</param>
///<param name="extremePoint">Extreme point on the shape.</param>
public override void GetLocalExtremePointWithoutMargin(ref Vector3 direction, out Vector3 extremePoint)
{
//Is it the tip of the cone?
float sinThetaSquared = radius * radius / (radius * radius + height * height);
//If d.Y * d.Y / d.LengthSquared >= sinthetaSquared
if (direction.Y > 0 && direction.Y * direction.Y >= direction.LengthSquared() * sinThetaSquared)
{
extremePoint = new Vector3(0, .75f * height, 0);
return;
}
//Is it a bottom edge of the cone?
float horizontalLengthSquared = direction.X * direction.X + direction.Z * direction.Z;
if (horizontalLengthSquared > Toolbox.Epsilon)
{
var radOverSigma = radius / Math.Sqrt(horizontalLengthSquared);
extremePoint = new Vector3((float)(radOverSigma * direction.X), -.25f * height, (float)(radOverSigma * direction.Z));
}
else // It's pointing almost straight down...
extremePoint = new Vector3(0, -.25f * height, 0);
}
示例13: VectorsDirectionEqual
public static bool VectorsDirectionEqual(Vector3 vec1, Vector3 vec2, float allowedError)
{
float len1 = vec1.LengthSquared();
float len2 = vec2.LengthSquared();
float dot = Vector3.Dot(vec1, vec2);
if(!(dot<0.0f))
dot *= dot / (len1 * len2);
return dot < 0.0f ? false : 1.0f - dot < allowedError;
}
示例14: Update
public void Update()
{
Velocity += acceleration;
Position += Velocity;
acceleration = Vector3.Zero;
if (Velocity.LengthSquared() < 0.001f * 0.001f)
Velocity = Vector3.Zero;
Velocity *= damping;
damping = 0.98f;
}
示例15: Project
public static Vector3 Project(this Vector3 v, Vector3 on)
{
return v.Dot(on) / on.LengthSquared() * on;
}