当前位置: 首页>>代码示例>>C#>>正文


C# Vector3.Length方法代码示例

本文整理汇总了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);
        }
开发者ID:kekdck,项目名称:RayTracer,代码行数:34,代码来源:Sphere.cs

示例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();
        }
开发者ID:danbystrom,项目名称:VisionQuest,代码行数:30,代码来源:FCameraMovement.cs

示例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)));
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:7,代码来源:Vector3Tests.cs

示例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);
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:7,代码来源:MeasureArrangeValidator.cs

示例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;
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:34,代码来源:Torus.cs

示例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);
 }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:7,代码来源:MyEffectAtmosphereBase.cs

示例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;
 }
开发者ID:3dcustom,项目名称:tsoview-dx,代码行数:33,代码来源:Helper.cs

示例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);
		}
开发者ID:Belxjander,项目名称:Asuna,代码行数:32,代码来源:TransformUtil.cs

示例9: MyVoxelMapImpostor

 public MyVoxelMapImpostor(Vector3 position, float radius, float angle)
 {
     Position = position;
     Radius = radius;
     Angle = angle;
     m_distance = position.Length();
 }
开发者ID:Bunni,项目名称:Miner-Wars-2081,代码行数:7,代码来源:MyVoxelMapImpostors.cs

示例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();
        }
开发者ID:KWMalik,项目名称:university-tasks,代码行数:30,代码来源:Cylinder.cs

示例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;
 }
开发者ID:seraph526,项目名称:Samples,代码行数:14,代码来源:ProjectileController.cs

示例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);
        }
开发者ID:Powerino73,项目名称:paradox,代码行数:8,代码来源:ArrangeValidator.cs

示例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;
		}
开发者ID:PieterMarius,项目名称:PhysicsEngine,代码行数:18,代码来源:JacobianCommon.cs

示例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 );
        }
开发者ID:stormont,项目名称:terraingine,代码行数:26,代码来源:VectorMath.cs

示例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;
        }
开发者ID:JakDaniels,项目名称:OpenSimBirds,代码行数:11,代码来源:BirdsUtil.cs


注:本文中的System.Vector3.Length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。