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


C# Vector3.Normalize方法代码示例

本文整理汇总了C#中System.Vector3.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.Normalize方法的具体用法?C# Vector3.Normalize怎么用?C# Vector3.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Vector3的用法示例。


在下文中一共展示了Vector3.Normalize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LookAt

 public void LookAt(Vector3 lookDir, Vector3 up)
 {
     lookDir.Normalize();
     Matrix matView = Matrix.LookAtLH(Vector3.Zero, lookDir, up);
     Quaternion qtnView = Quaternion.RotationMatrix(matView);
     m_Orientation = Quaternion.Invert(qtnView);
 }
开发者ID:aik6980,项目名称:GameFramework,代码行数:7,代码来源:Camera.cs

示例2: GlobalSetUp

        public void GlobalSetUp()
        {
            randomTriangles = new Vector3[TRIANGLE_COUNT * 3];
            for (int i = 0; i < TRIANGLE_COUNT * 3; i++)
            {
                randomTriangles[i] = RNG.RandomVector3();
            }

            origin = RNG.RandomVector3();
            direction = RNG.RandomVector3();
            direction.Normalize();
            testRay = new Ray(origin, direction);

            randomRays = new Ray[RAY_COUNT];
            for (int i = 0; i < RAY_COUNT; i++)
            {
                Vector3 thisOrigin = RNG.RandomVector3();
                Vector3 thisDirection = RNG.RandomVector3();
                thisDirection.Normalize();
                randomRays[i] = new Ray(thisOrigin, thisDirection);
            }

            heightmap = new float[256 * 256];
            for (int y = 0; y < 256; y++)
            {
                for (int x = 0; x < 256; x++)
                {
                    heightmap[y * 256 + x] = (float)Math.Max(RNG.NextGaussian(25.0, 10.0), 0);
                }
            }
        }
开发者ID:thoys,项目名称:simian,代码行数:31,代码来源:RayTests.cs

示例3: Rotate

		public static Matrix4 Rotate (float angle, Vector3 r)
		{
			float a = RadiansOverPi (angle);
			float c = (float)Math.Cos (a);
			float s = (float)Math.Sin (a);

			float k = 1.0f - c;
			r.Normalize ();
			Vector3 u = r;
			Vector3 v = s * u;
			Vector3 w = k * u;

			Vector4 P = Vector4.Zero;
			Vector4 Q = Vector4.Zero;
			Vector4 R = Vector4.Zero;
			Vector4 S = Vector4.Zero;

			P.X = w.X * u.X + c;
			P.Y = w.X * u.Y + v.Z;
			P.Z = w.X * u.Z - v.Y;

			Q.X = w.X * u.Y - v.Z;
			Q.Y = w.Y * u.Y + c;
			Q.Z = w.Y * u.Z + v.X;

			R.X = w.X * u.Z + v.Y;
			R.Y = w.Y * u.Z - v.X;
			R.Z = w.Z * u.Z + c;

			S.W = 1.0f;

			return MakeResultMatrix (P, Q, R, S);
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:33,代码来源:MathUtils.cs

示例4: 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

示例5: PistonConstraint

		public PistonConstraint(
			int indexA,
			int indexB,
			SimulationObject[] simulationObject,
			Vector3 startAnchorPosition,
			Vector3 pistonAxis,
			double restoreCoefficient,
			double springCoefficient)
		{
			IndexA = indexA;
			IndexB = indexB;
			KeyIndex = GetHashCode();
			RestoreCoefficient = restoreCoefficient;
			SpringCoefficient = springCoefficient;
			StartAnchorPoint = startAnchorPosition;

			PistonAxis = -1.0 * pistonAxis.Normalize ();

			SimulationObject objectA = simulationObject[IndexA];
			SimulationObject objectB = simulationObject[IndexB];

			Vector3 relativePos = objectA.RotationMatrix *
				(startAnchorPosition - objectA.StartPosition);

			AnchorPoint = relativePos + objectA.Position;

			StartErrorAxis1 = objectA.RotationMatrix.Transpose() *
									 (AnchorPoint - objectA.Position);

			StartErrorAxis2 = objectB.RotationMatrix.Transpose() *
									 (AnchorPoint - objectB.Position);

			RelativeOrientation = objectB.RotationStatus.Inverse() *
										 objectA.RotationStatus;
		}
开发者ID:PieterMarius,项目名称:PhysicsEngine,代码行数:35,代码来源:PistonConstraint.cs

示例6: rotate

 public void rotate(Vector3 axis, float angle)
 {
     axis.Normalize();
     axis = axis * (float)Math.Sin(angle / 2.0f);
     float scalar = (float)Math.Cos(angle / 2.0f);
     rotate(new Quaternion(axis, scalar));
 }
开发者ID:r457r2,项目名称:bakaTest,代码行数:7,代码来源:SceneNode.cs

示例7: GetDistanceToCenter

        public override float GetDistanceToCenter(
                Vector3 particlePosition, Vector3 particleVelocity,
                out Vector3 alongAxis, out Vector3 aroundAxis, out Vector3 awayAxis)
        {
            // Along - following the main axis
            alongAxis = mainAxis;

            // Toward - tawards the main axis
            awayAxis = particlePosition - fieldPosition;
            awayAxis.Y = 0; // In case of cylinder the away vector should be flat (away from the axis rather than just a point)
            awayAxis.Normalize();

            // Around - around the main axis, following the right hand rule
            aroundAxis = Vector3.Cross(alongAxis, awayAxis);

            particlePosition -= fieldPosition;
            inverseRotation.Rotate(ref particlePosition);
            particlePosition /= fieldSize;

            // Start of code for Cylinder
            if (Math.Abs(particlePosition.Y) >= halfHeight)
                return 1;

            particlePosition.Y = 0;

            particlePosition.X /= radius;
            particlePosition.Z /= radius;

            var maxDist = particlePosition.Length();
            // End of code for Cylinder

            return maxDist;
        }
开发者ID:cg123,项目名称:xenko,代码行数:33,代码来源:Cylinder.cs

示例8: Render

        // レンダリング
        public void Render()
        {
            viewport.MakeCurrent();

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.FrontFace(FrontFaceDirection.Cw);
            GL.CullFace(CullFaceMode.Back);

            GL.Viewport(0, 0, viewport.Width, viewport.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.UseProgram(program);

            Vector3 eyePos = new Vector3(5.0f, 5.0f, 5.0f);
            Vector3 lookAt = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 eyeUp = new Vector3(0.0f, 1.0f, 0.0f);
            Matrix4 viewMatrix = Matrix4.LookAt(eyePos, lookAt, eyeUp);
            Matrix4 projectionMatrix = Matrix4.CreatePerspectiveFieldOfView((float)System.Math.PI / 4.0f, (float)viewport.Width / (float)viewport.Height, 0.1f, 10.0f);
            Matrix4 viewProjectionMatrix = viewMatrix * projectionMatrix;
            GL.UniformMatrix4(GL.GetUniformLocation(program, "viewProjection"), false, ref viewProjectionMatrix);

            Matrix4 worldMatrix = Matrix4.Identity;
            GL.UniformMatrix4(GL.GetUniformLocation(program, "world"), false, ref worldMatrix);

            Vector3 lightDir = new Vector3((float)Math.Cos((float)lightAngle), -1.0f, (float)Math.Sin((float)lightAngle));
            lightDir.Normalize();
            GL.Uniform3(GL.GetUniformLocation(program, "lightDir"), lightDir);
            lightAngle += 0.001f;

            cube.Render();

            viewport.SwapBuffers();
        }
开发者ID:aokomoriuta,项目名称:CubeView,代码行数:35,代码来源:MainForm.cs

示例9: LineBall

        /// <summary>
        /// Set of lines in 3D space.
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="xAxis"></param>
        /// <param name="yAxis"></param>
        /// <param name="scale">Scaling the field extent.</param>
        /// <param name="field"></param>
        public LineBall(Plane plane, LineSet lines, RenderEffect effect = RenderEffect.DEFAULT, Colormap colormap = Colormap.Parula, bool flatten = false)
        {
            _thickness = lines.Thickness * plane.PointSize;
            _color = lines.Color;
            this._vertexSizeBytes = Marshal.SizeOf(typeof(Vector4));
            this._numVertices = lines.NumPoints * 2 - lines.Lines.Length * 2; // Linelist means, all points are there twice, minus the endpoints.
            if (_numVertices == 0)
                return;
            this._topology = PrimitiveTopology.LineList;

            // Setting up the vertex buffer.
            if (!flatten)
                GenerateGeometry(plane, lines);
            else
                GenerateGeometryFlatXY(plane, lines);

            //this._technique = _lineEffect.GetTechniqueByName("Render");
            UsedMap = colormap;
            _planeNormal = plane.ZAxis;
            _planeNormal.Normalize();
            _effect = _lineEffect;
            SetRenderEffect(effect);

            this._vertexLayout = new InputLayout(_device, _technique.GetPassByIndex(0).Description.Signature, new[] {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0),
                new InputElement("SCALAR", 0, Format.R32_Float, 12, 0)
            });
        }
开发者ID:AnkeAnke,项目名称:FlowSharp,代码行数:36,代码来源:LineBall.cs

示例10: ComputeMatricies

			public void ComputeMatricies ( Matrix viewMatrix, Vector3 lightDir, int cascadeSize, float splitSize, float splitOffset, float splitFactor, float projDepth )
			{
				var	smSize		=	cascadeSize;
				var camMatrix	=	Matrix.Invert( viewMatrix );
				var viewPos		=	camMatrix.TranslationVector;

				lightDir.Normalize();


				for ( int i = 0; i<4; i++ ) {

					float	offset		=	splitOffset * (float)Math.Pow( splitFactor, i );
					float	radius		=	splitSize   * (float)Math.Pow( splitFactor, i );

					Vector3 viewDir		=	camMatrix.Forward.Normalized();
					Vector3	origin		=	viewPos + viewDir * offset;

					Matrix	lightRot	=	Matrix.LookAtRH( Vector3.Zero, Vector3.Zero + lightDir, Vector3.UnitY );
					Matrix	lightRotI	=	Matrix.Invert( lightRot );
					Vector3	lsOrigin	=	Vector3.TransformCoordinate( origin, lightRot );
					float	snapValue	=	4.0f * radius / smSize;
					lsOrigin.X			=	(float)Math.Round(lsOrigin.X / snapValue) * snapValue;
					lsOrigin.Y			=	(float)Math.Round(lsOrigin.Y / snapValue) * snapValue;
					lsOrigin.Z			=	(float)Math.Round(lsOrigin.Z / snapValue) * snapValue;
					origin				=	Vector3.TransformCoordinate( lsOrigin, lightRotI );//*/

					shadowViews[i]			=	Matrix.LookAtRH( origin, origin + lightDir, Vector3.UnitY );
					shadowProjections[i]	=	Matrix.OrthoRH( radius*2, radius*2, -projDepth/2, projDepth/2);
				}
			}
开发者ID:demiurghg,项目名称:FusionEngine,代码行数:30,代码来源:LightRenderer.CSMController.cs

示例11: checkIntegrity

        /// <summary> Checks if this vector has 'good' values, i.e. components are not very little values. </summary>
        /// <param name="vector"> Vector to check. Must be a normalized vector. </param>
        public static void checkIntegrity(ref Vector3 vector)
        {
            float threshold = 0.000001f;
            bool mustRenormalize = false;

            if (Math.Abs(vector.X) < threshold)
            {
                vector.X = 0;
                mustRenormalize = true;
            }
            if (Math.Abs(vector.Y) < threshold)
            {
                vector.Y = 0;
                mustRenormalize = true;
            }
            if (Math.Abs(vector.Z) < threshold)
            {
                vector.Z = 0;
                mustRenormalize = true;
            }

            if( mustRenormalize )
                vector.Normalize();

            if (Math.Abs(vector.X) > 0.999999)
                vector.X = Math.Sign(vector.X);

            if (Math.Abs(vector.Y) > 0.999999)
                vector.Y = Math.Sign(vector.Y);

            if (Math.Abs(vector.Z) > 0.999999)
                vector.Z = Math.Sign(vector.Z);
        }
开发者ID:rforsbach,项目名称:Treu-Structure,代码行数:35,代码来源:Extrusion.cs

示例12: AngleBetween

 private static float AngleBetween(Vector3 v1, Vector3 v2)
 {
     v1.Normalize();
     v2.Normalize();
     float dot = Vector3.Dot(v1, v2);
     return (float)Math.Acos(dot);
 }
开发者ID:SCUSIT,项目名称:PDAL,代码行数:7,代码来源:Trackball.cs

示例13: Quad

        public Quad(int startX,int endX, int startZ, int endZ, Base.Content.Terrain.Terrain terrain, RenderManager renderer)
        {
            _bounds = new QuadBounds
            {
                MinX = startX / terrain.PointsPerMeter,
                MaxX = endX / terrain.PointsPerMeter,
                MinZ = startZ / terrain.PointsPerMeter,
                MaxZ = endZ / terrain.PointsPerMeter,
                MinY = terrain.Height[0],
                MaxY = terrain.Height[0]
            };
            HorizontalCenter = new Vector2(Bounds.MinX + (Bounds.MaxX - Bounds.MinX) / 2, Bounds.MinZ + (Bounds.MaxZ - Bounds.MinZ) / 2);

            int verticesX = endX - startX + 1;
            int verticesZ = endZ - startZ + 1;

            var dataStream = new DataStream(32 * verticesX * verticesZ, true, true);

            for (int i = 0; i < verticesX; i++)
            {
                for (int j = 0; j < verticesZ; j++)
                {
                    //Position
                    int xindex = Math.Min(i + startX, terrain.PointsX - 1);//Clamp to arraybounds if neccessary
                    int zindex = Math.Min(j + startZ, terrain.PointsZ - 1);//(Quadsize needs to be consistent for sharing IndexBuffers)
                    float x = xindex / terrain.PointsPerMeter;
                    float z = zindex / terrain.PointsPerMeter;
                    float y = terrain.Height[xindex * terrain.PointsZ + zindex];
                    dataStream.Write(new Vector3(x, y, z));

                    //Normal
                    float deltax = (terrain.Height[(xindex < terrain.PointsX - 1 ? xindex + 1 : xindex) * terrain.PointsZ + zindex]
                        - terrain.Height[(xindex != 0 ? xindex - 1 : xindex) * terrain.PointsZ + zindex]);

                    float deltaz = (terrain.Height[xindex * terrain.PointsZ + (zindex < terrain.PointsZ - 1 ? zindex + 1 : zindex)]
                        - terrain.Height[xindex * terrain.PointsZ + (zindex != 0 ? zindex - 1 : zindex)]);
                    if (xindex == 0 || xindex == terrain.PointsX - 1)
                        deltax *= 2;
                    if (zindex == 0 || zindex == terrain.PointsZ - 1)
                        deltaz *= 2;
                    var normal = new Vector3(-deltax, 2 / terrain.PointsPerMeter, deltaz);
                    normal.Normalize();
                    dataStream.Write(normal);

                    //TextureCoordinates
                    dataStream.Write(new Vector2(x / terrain.PointsX, z / terrain.PointsZ));

                    //Boundingbox-Params
                    if (y < _bounds.MinY)
                        _bounds.MinY = y;
                    if (y > _bounds.MaxY)
                        _bounds.MaxY = y;
                }
            }

            dataStream.Position = 0;
            VBuffer = new Buffer(renderer.D3DDevice, dataStream, 32 * verticesX * verticesZ, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0);
            VertexBuffer = new VertexBufferBinding(VBuffer, 32, 0);
            dataStream.Dispose();
        }
开发者ID:hexd0t,项目名称:Garm_Net,代码行数:60,代码来源:TerrainQuad.cs

示例14: Camera

        /// <summary>
        /// Creates the instance of the camera at the given location.
        /// </summary>
        /// <param name="position">Position of the camera.</param>
        /// <param name="target">The target towards which the camera is pointing.</param>
        public Camera(Game game, Vector3 position, Vector3 target)
            : this(game)
        {
            m_position = position;
            m_direction = target - m_position;
            m_direction.Normalize();

            View = CreateLookAt();
        }
开发者ID:node-migrator-bot,项目名称:opentk-phantom,代码行数:14,代码来源:Camera.cs

示例15: SetDirection

        /// <summary>
        /// Modifies the orientation of the camera to get the camera to look in a particular direction.
        /// </summary>
        /// <param name="direction">The direction to have the camera look.</param>
        public void SetDirection(Vector3 direction)
        {
            if (direction == Vector3.Zero) return;

            Vector3 zvec = -direction.Normalize();
            Vector3 xvec = Vector3.Up.Cross(zvec).Normalize();
            Vector3 yvec = zvec.Cross(xvec).Normalize();
            Orientation = Quaternion.FromAxis(xvec, yvec, zvec);
        }
开发者ID:JeffSkynird,项目名称:opengl4tutorials,代码行数:13,代码来源:Camera.cs


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