本文整理汇总了C#中System.Vector3.Length方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Length方法的具体用法?C# Vector3.Length怎么用?C# Vector3.Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Vector3
的用法示例。
在下文中一共展示了Vector3.Length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: intersect
public bool intersect(Vector3 source, Vector3 ray,
out float distance, out System.Drawing.Color color)
{
Vector3 s = m_center - source;
float rayDotS = Vector3.Dot(ray, s);
float discr = 4.0f * (float)(Math.Pow(rayDotS, 2) - Math.Pow(ray.Length(), 2)
* (Math.Pow(s.Length(), 2) - Math.Pow(m_radius, 2)));
if (discr >= 0)
{
float t1 = (float)(rayDotS + Math.Sqrt(discr)
/ (2.0f * Math.Pow(ray.Length(), 2)));
float t2 = (float)(rayDotS - Math.Sqrt(discr)
/ (2.0f * Math.Pow(ray.Length(), 2)));
if (t2 > 0)
{
distance = t2;
}
else
{
distance = t1;
}
}
else
{
distance = 0;
}
color = m_color;
return (discr >= 0);
}
示例2: OnMouseDown
protected override void OnMouseDown(MouseEventArgs e)
{
_time = DateTime.Now;
if (e.Button == MouseButtons.Left)
_pts[0] = e.Location;
if (e.Button == MouseButtons.Middle)
_pts[1] = e.Location;
if (e.Button == MouseButtons.Right)
_pts[2] = e.Location;
var v0 = new Vector3(_pts[1].X - _pts[0].X, 0, _pts[1].Y - _pts[0].Y);
var v1 = new Vector3(_pts[1].X - _pts[2].X, 0, _pts[1].Y - _pts[2].Y);
_out = Vector3.Cross(v0, v1);
var sinAngle = _out.Length()/(v0.Length()*v1.Length());
_angle = (float)Math.Asin(sinAngle);
System.Diagnostics.Debug.Print("{0:0.0}", MathUtil.RadiansToDegrees(_angle));
var v2 = Vector3.Cross(v1, _out);
v2.Normalize();
System.Diagnostics.Debug.Print("v2:{0} d:{1}", v2, v1.Length());
v2 *= v1.Length() / (float)Math.Tan(Math.PI - _angle) / 2;
_pts[3] = new PointF(v2.X + (_pts[2].X + _pts[1].X)/2, v2.Z + (_pts[2].Y + _pts[1].Y)/2);
copyToCamera();
System.Diagnostics.Debug.Print("MC {0:0.0}", MathUtil.RadiansToDegrees(_moveCameraArc._angle));
Invalidate();
}
示例3: Vector3_CalculatesLengthCorrectly
public void Vector3_CalculatesLengthCorrectly()
{
var vector = new Vector3(123.4f, 567.8f, 901.2f);
TheResultingValue(vector.Length()).WithinDelta(0.1f)
.ShouldBe((float)Math.Sqrt((123.4f * 123.4f) + (567.8f * 567.8f) + (901.2f * 901.2f)));
}
示例4: ArrangeOverride
protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
{
var maxLength = Math.Max(finalSizeWithoutMargins.Length(), ExpectedArrangeValue.Length());
Assert.IsTrue((finalSizeWithoutMargins - ExpectedArrangeValue).Length() <= maxLength * 0.001f);
return base.ArrangeOverride(finalSizeWithoutMargins);
}
示例5: GetDistanceToCenter
public override float GetDistanceToCenter(
Vector3 particlePosition, Vector3 particleVelocity,
out Vector3 alongAxis, out Vector3 aroundAxis, out Vector3 awayAxis)
{
alongAxis = new Vector3(0, 1, 0);
particlePosition -= fieldPosition;
inverseRotation.Rotate(ref particlePosition);
particlePosition /= fieldSize;
// Start by positioning hte particle on the torus' plane
var projectedPosition = new Vector3(particlePosition.X, 0, particlePosition.Z);
var distanceFromOrigin = projectedPosition.Length();
var distSquared = 1 + distanceFromOrigin * distanceFromOrigin - 2 * distanceFromOrigin + particlePosition.Y * particlePosition.Y;
var totalStrength = (distSquared >= smallRadiusSquared) ? 1 : ((float) Math.Sqrt(distSquared) / smallRadius);
// Fix the field's axis back to world space
var forceAxis = Vector3.Cross(alongAxis, projectedPosition);
fieldRotation.Rotate(ref forceAxis);
forceAxis.Normalize();
alongAxis = forceAxis;
projectedPosition = (distanceFromOrigin > 0) ? (projectedPosition/(float)distanceFromOrigin) : projectedPosition;
projectedPosition -= particlePosition;
projectedPosition *= fieldSize;
fieldRotation.Rotate(ref projectedPosition);
awayAxis = -projectedPosition;
awayAxis.Normalize();
aroundAxis = Vector3.Cross(alongAxis, awayAxis);
return totalStrength;
}
示例6: SetRelativeCameraPos
public void SetRelativeCameraPos(Vector3 cameraPos)
{
m_D3DEffect.SetValue(m_cameraPos, cameraPos);
float height = cameraPos.Length();
m_D3DEffect.SetValue(m_cameraHeight2, height * height);
m_D3DEffect.SetValue(m_cameraHeight, height);
}
示例7: DecomposeMatrix
/// <summary>
/// 拡大縮小ベクトルと回転行列と位置ベクトルに分割します。
/// </summary>
/// <param name="m">元の行列(戻り値は回転行列)</param>
/// <param name="scaling">拡大縮小ベクトル</param>
/// <returns>位置ベクトル</returns>
public static Vector3 DecomposeMatrix(ref Matrix m, out Vector3 scaling)
{
Vector3 vx = new Vector3(m.M11, m.M12, m.M13);
Vector3 vy = new Vector3(m.M21, m.M22, m.M23);
Vector3 vz = new Vector3(m.M31, m.M32, m.M33);
Vector3 vt = new Vector3(m.M41, m.M42, m.M43);
float scax = vx.Length();
float scay = vy.Length();
float scaz = vz.Length();
scaling = new Vector3(scax, scay, scaz);
vx.Normalize();
vy.Normalize();
vz.Normalize();
m.M11 = vx.X;
m.M12 = vx.Y;
m.M13 = vx.Z;
m.M21 = vy.X;
m.M22 = vy.Y;
m.M23 = vy.Z;
m.M31 = vz.X;
m.M32 = vz.Y;
m.M33 = vz.Z;
m.M41 = 0;
m.M42 = 0;
m.M43 = 0;
return vt;
}
示例8: IntegrateTransform
public static void IntegrateTransform(Matrix currentTransform, Vector3 linearVelocity, Vector3 angularVelocity, float timeStep, ref Matrix predictedTransform)
{
predictedTransform.Translation = currentTransform.Translation + linearVelocity * timeStep;
//exponential map
Vector3 axis;
float angle = angularVelocity.Length();
//limit the angular motion
if (angle * timeStep > AngularMotionTreshold)
{
angle = AngularMotionTreshold / timeStep;
}
if (angle < 0.001f)
{
// use Taylor's expansions of sync function
axis = angularVelocity * (0.5f * timeStep - (timeStep * timeStep * timeStep) * (0.020833333333f) * angle * angle);
}
else
{
// sync(fAngle) = sin(c*fAngle)/t
axis = angularVelocity * ((float)Math.Sin(0.5f * angle * timeStep) / angle);
}
Quaternion dorn = new Quaternion(axis.X, axis.Y, axis.Z, (float)Math.Cos(angle * timeStep * 0.5f));
Quaternion ornA = MatrixOperations.GetRotation(currentTransform);
Quaternion predictedOrn = dorn * ornA;
predictedOrn.Normalize();
MatrixOperations.SetRotation(ref predictedTransform, predictedOrn);
Matrix test = Matrix.CreateFromQuaternion(predictedOrn);
}
示例9: MyVoxelMapImpostor
public MyVoxelMapImpostor(Vector3 position, float radius, float angle)
{
Position = position;
Radius = radius;
Angle = angle;
m_distance = position.Length();
}
示例10: Cylinder
public Cylinder(float[] Begin, float[] End, float radius1, float radius2, int slices, int stacks, Device dev)
{
float_coordinates = new float[2][];
float_coordinates[0] = Begin;
float_coordinates[1] = End;
device = dev;
if ((Begin.Length != Basis.Length) || (End.Length != Basis.Length))
throw new Exception("Размерность базиса не совпадает с размерностью вектора позиции.");
Vector3 begin = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 end = new Vector3(0.0f, 0.0f, 0.0f);
for (int i = 0; i < Basis.Length; i++)
{
begin += Begin[i] * Basis[i];
end += End[i] * Basis[i];
}
MovingMatrix = Matrix.Translation(new Vector3(0, 0, (begin - end).Length() / 2));
Vector3 be = end - begin;
Vector3 curpos = new Vector3(0, 0, (begin - end).Length());
float angle = (float)Math.Acos(VectorActions.scalmul(be, curpos) / (be.Length() * curpos.Length()));
Vector3 axis = VectorActions.vectmul(be, curpos);
MovingMatrix *= Matrix.RotationAxis(axis, -angle);
MovingMatrix *= Matrix.Translation(begin);
meshes = new Mesh[1];
meshes[0] = Mesh.Cylinder(device, radius1, radius2, (begin - end).Length(), slices, stacks);
meshes[0].ComputeNormals();
material = new Material();
}
示例11: LaunchParticle
/// <summary>
/// Launch a particle
/// </summary>
/// <param name="position">Position the particle</param>
/// <param name="velocity">The velocity vector</param>
/// <param name="timeLife">The expiration time of the particle</param>
public void LaunchParticle(Vector3 position, Vector3 velocity, float timeLife)
{
this.Position = position;
this.Velocity = velocity;
this.VelocityLength = velocity.Length();
this.LifeTime = timeLife;
this.IsAlive = true;
}
示例12: ArrangeOverride
protected override Vector3 ArrangeOverride(Vector3 finalSizeWithoutMargins)
{
var maxLength = Math.Max(finalSizeWithoutMargins.Length(), ExpectedArrangeValue.Length());
Assert.IsTrue((finalSizeWithoutMargins - ExpectedArrangeValue).Length() <= maxLength * 0.001f,
"Arrange validator test failed: expected value=" + ExpectedArrangeValue + ", Received value=" + finalSizeWithoutMargins + " (Validator='" + Name + "'");
return base.ArrangeOverride(finalSizeWithoutMargins);
}
示例13: GetRotationAngle
public static double GetRotationAngle(
Vector3 rotationStatus,
double rotationValue,
Vector3 rotationAxis)
{
double angle = 0.0;
if (rotationStatus.Dot (rotationAxis) >= 0.0)
{
angle = 2.0 * Math.Atan2 (rotationStatus.Length (), rotationValue);
}
else
{
angle = 2.0 * Math.Atan2 (rotationStatus.Length (), -rotationValue);
}
return (angle > Math.PI) ? angle - 2.0 * Math.PI : angle;
}
示例14: Distance_PointToLine
/// <summary>
/// Gets the shortest distance between the given point and the given line.
/// </summary>
/// <param name="ray">Ray to build the line from.</param>
/// <param name="origin">Origin point to build the line from.</param>
/// <param name="point">Point to compare the distance from.</param>
/// <returns>The shortest distance from the point.</returns>
public static float Distance_PointToLine( Vector3 ray, Vector3 origin, Vector3 point )
{
if ( ray.Length() < 0.0f )
return -1.0f;
Vector3 pointVector = point - origin;
double theta;
float length = pointVector.Length();
if ( length < 0.0f )
return -1.0f;
if ( double.IsNaN( Math.Acos( Vector3.Dot( ray, pointVector ) / ( ray.Length() * length ) ) ) )
theta = 0;
else
theta = Math.Acos( Vector3.Dot( ray, pointVector ) / ( ray.Length() * length ) );
return length * ( float ) Math.Sin( theta );
}
示例15: Limit
public static Vector3 Limit(Vector3 initial, float maxLen)
{
float currLen = initial.Length ();
float ratio = 1.0f;
if (currLen > maxLen) {
ratio = currLen / maxLen;
}
return initial /= ratio;
}