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


C# Vector3d.Normalize方法代码示例

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


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

示例1: Ray

 public Ray(Vector3d origin, Vector3d direction)
 {
     Origin = origin;
     if (direction == Vector3d.Zero)
     {
         throw new Exception("Direction cannot be a zero vector");
     }
     Direction = direction;
     Direction.Normalize();
 }
开发者ID:Azzi777,项目名称:Umbra-Voxel-Engine,代码行数:10,代码来源:Ray.cs

示例2: ProjectToSphere

        private Vector3d ProjectToSphere(Vector2d point)
        {
            var x = point.X;
            var y = point.Y;
            var z = CalculateZCoordinate(point);

            var projectedPoint = new Vector3d(x, y, z);
            projectedPoint.Normalize();

            return projectedPoint;
        }
开发者ID:ChrisJansson,项目名称:ObjLoader,代码行数:11,代码来源:TrackballCameraRotationCalculator.cs

示例3: beamTimer_Elapsed

        void beamTimer_Elapsed(object sender, EventArgs e)
        {
            if (beamID == null) return;

            try
            {
                client.Self.SphereEffect(GlobalPosition(targetPrim), beamColors[beamRandom.Next(0, 3)], 0.85f, sphereID);
                int i = 0;
                for (i = 0; i < numBeans; i++)
                {
                    UUID newBeam = UUID.Random();
                    Vector3d scatter;

                    if (i == 0)
                    {
                        scatter = GlobalPosition(targetPrim);
                    }
                    else
                    {
                        Vector3d direction = client.Self.GlobalPosition - GlobalPosition(targetPrim);
                        Vector3d cross = direction % new Vector3d(0, 0, 1);
                        cross.Normalize();
                        scatter = GlobalPosition(targetPrim) + cross * (i * 0.2d) * (i % 2 == 0 ? 1 : -1);
                    }
                    client.Self.BeamEffect(effectSource, UUID.Zero, scatter, beamColors[beamRandom.Next(0, 3)], 1.0f, beamID[i]);
                }

                for (int j = 1; j < numBeans; j++)
                {
                    UUID newBeam = UUID.Random();
                    Vector3d scatter;
                    Vector3d cross = new Vector3d(0, 0, 1);
                    cross.Normalize();
                    scatter = GlobalPosition(targetPrim) + cross * (j * 0.2d) * (j % 2 == 0 ? 1 : -1);

                    client.Self.BeamEffect(effectSource, UUID.Zero, scatter, beamColors[beamRandom.Next(0, 3)], 1.0f, beamID[j + i - 1]);
                }
            }
            catch (Exception) { };

        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:41,代码来源:EffectBeamInfo.cs

示例4: TransformPickPointToWorldSpace

        public void TransformPickPointToWorldSpace(Vector2d ptCursor, int backBufferWidth, int backBufferHeight, out Vector3d vPickRayOrig, out Vector3d vPickRayDir)
        {
            // Credit due to the DirectX 9 C++ Pick sample and MVP Robert Dunlop
            // Get the pick ray from the mouse position

            // Compute the vector of the pick ray in screen space
            Vector3d v;
            v.X = (((2.0f * ptCursor.X) / backBufferWidth) - 1) / ProjMatrix.M11;
            v.Y = -(((2.0f * ptCursor.Y) / backBufferHeight) - 1) / ProjMatrix.M22;
            v.Z = 1.0f;
            var mInit = TranMatrix;

            var m = Matrix3d.Invert(mInit);

            // Transform the screen space pick ray into 3D space
            vPickRayDir.X = v.X * m.M11 + v.Y * m.M21 + v.Z * m.M31;
            vPickRayDir.Y = v.X * m.M12 + v.Y * m.M22 + v.Z * m.M32;
            vPickRayDir.Z = v.X * m.M13 + v.Y * m.M23 + v.Z * m.M33;

            vPickRayDir.Normalize();

            vPickRayOrig.X = m.M41;
            vPickRayOrig.Y = m.M42;
            vPickRayOrig.Z = m.M43;

            // Calculate the origin as intersection with nearValue frustum

            vPickRayOrig.X += vPickRayDir.X * near;
            vPickRayOrig.Y += vPickRayDir.Y * near;
            vPickRayOrig.Z += vPickRayDir.Z * near;
        }
开发者ID:bluephoton,项目名称:wwt-windows-client,代码行数:31,代码来源:SolveAlignment.cs

示例5: SceneObj

        /// <summary>
        /// Generic OBJ-loading scene definition routine.
        /// </summary>
        /// <param name="dir">Viewing direction of a camera.</param>
        /// <param name="FoVy">Field of View in degrees.</param>
        /// <param name="correction">Value less than 1.0 brings camera nearer.</param>
        /// <param name="name">OBJ file-name.</param>
        /// <param name="names">Substitute file-name[s].</param>
        /// <returns>Number of triangles.</returns>
        protected static long SceneObj( IRayScene sc, Vector3d dir, double FoVy, double correction, string name, string[] names, double[] surfaceColor )
        {
            Debug.Assert( sc != null );

              Vector3 center = Vector3.Zero;   // center of the mesh
              dir.Normalize();                 // normalized viewing vector of the camera
              float diameter = 2.0f;           // default scene diameter
              int faces = 0;

              // CSG scene:
              CSGInnerNode root = new CSGInnerNode( SetOperation.Union );

              // OBJ file to read:
              if ( names.Length == 0 ||
               names[ 0 ].Length == 0 )
            names = new string[] { name };

              string[] paths = Scenes.SmartFindFiles( names );
              if ( paths[ 0 ] == null || paths[ 0 ].Length == 0 )
              {
            for ( int i = 0; i < names.Length; i++ )
              if ( names[ i ].Length > 0 )
            names[ i ] += ".gz";
            paths = Scenes.SmartFindFiles( names );
              }
              if ( paths[ 0 ] == null || paths[ 0 ].Length == 0 )
            root.InsertChild( new Sphere(), Matrix4d.Identity );
              else
              {
            // B-rep scene construction:
            WavefrontObj objReader = new WavefrontObj();
            objReader.MirrorConversion = false;
            SceneBrep brep = new SceneBrep();
            faces = objReader.ReadBrep( paths[ 0 ], brep );
            brep.BuildCornerTable();
            diameter = brep.GetDiameter( out center );
            TriangleMesh m = new TriangleMesh( brep );
            root.InsertChild( m, Matrix4d.Identity );
              }

              root.SetAttribute( PropertyName.REFLECTANCE_MODEL, new PhongModel() );
              root.SetAttribute( PropertyName.MATERIAL, new PhongMaterial( surfaceColor, 0.2, 0.5, 0.4, 32 ) );
              root.SetAttribute( PropertyName.COLOR, surfaceColor );
              sc.Intersectable = root;

              // Background color:
              sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 };

              // Camera:
              double dist = (0.5 * diameter * correction) / Math.Tan( MathHelper.DegreesToRadians( (float)(0.5 * FoVy) ) );
              Vector3d cam = (Vector3d)center - dist * dir;
              sc.Camera = new StaticCamera( cam, dir, FoVy );

              // Light sources:
              sc.Sources = new LinkedList<ILightSource>();
              sc.Sources.Add( new AmbientLightSource( 0.8 ) );
              Vector3d lightDir = Vector3d.TransformVector( dir, Matrix4d.CreateRotationY( -2.0 ) );
              lightDir = Vector3d.TransformVector( lightDir, Matrix4d.CreateRotationZ( -0.8 ) );
              sc.Sources.Add( new PointLightSource( (Vector3d)center + diameter * lightDir, 1.0 ) );

              return faces;
        }
开发者ID:pepouch,项目名称:PG1Grcis,代码行数:71,代码来源:RayCastingScenes.cs

示例6: IsLeftOfHalfSpace

        private bool IsLeftOfHalfSpace(Vector3d pntA, Vector3d pntB, Vector3d pntTest)
        {
            pntA.Normalize();
            pntB.Normalize();
            var cross = Vector3d.Cross(pntA, pntB);

            var dot = Vector3d.Dot(cross, pntTest);

            return dot > 0;
        }
开发者ID:bluephoton,项目名称:wwt-windows-client,代码行数:10,代码来源:ToastTools.cs

示例7: FindNormal

 internal static void FindNormal( ref Vector3d A, ref Vector3d B, ref Vector3d C, out Vector3d result )
 {
     Vector3d temp1, temp2;
     Vector3d.Subtract( ref A, ref B, out temp1 );
     temp1.Normalize();
     Vector3d.Subtract(ref C, ref B, out temp2);
     temp2.Normalize();
     Vector3d.Cross( ref temp1, ref temp2, out result );
     result *=  -1.0;
     result.Normalize();
 }
开发者ID:RetroAchievements,项目名称:opentk,代码行数:11,代码来源:SierpinskiTetrahedron.cs

示例8: ApplyVorticity

        private void ApplyVorticity(double dt)
        {
            for (int i = 1; i < max_x - 1; i++)
            {
                for (int j = 1; j < max_y - 1; j++)
                {
                    //(dv/dx - du/dy)k = curl
                    cells[i, j].Vorticity = (u_x[i, j + 1] - u_x[i, j - 1]) / 2 - (u_y[i + 1, j] - u_y[i - 1, j]) / 2;
                }
            }

            for (int i = 2; i < max_x - 2; i++)
            {
                for (int j = 2; j < max_y - 2; j++)
                {
                    Vector3d curl = new Vector3d(0, 0, cells[i, j].Vorticity);
                    Vector3d N = new Vector3d((Math.Abs(cells[i + 1, j].Vorticity) - Math.Abs(cells[i - 1, j].Vorticity)) / 2,
                                           (Math.Abs(cells[i, j + 1].Vorticity) - Math.Abs(cells[i, j - 1].Vorticity)) / 2,
                                           0);
                    N.Normalize();
                    Vector3d f_vorticity = Vector3d.Cross(N, curl);
                    Vector3d.Mult(f_vorticity, FluidConstants.VORTICITY);

                    u_x[i, j] += (dt * f_vorticity.X) / 2;
                    u_x[i + 1, j] += (dt * f_vorticity.X) / 2;
                    u_y[i, j] += (dt * f_vorticity.Y) / 2;
                    u_y[i, j + 1] += (dt * f_vorticity.Y) / 2;


                }
            }
        }
开发者ID:kjin,项目名称:cs5643_a4,代码行数:32,代码来源:BasicFluid2D.cs

示例9: Smooth

		protected Point3D Smooth(Point3D p, IList<Point3D> nearPts)
		{
			if(nearPts.Count<1)
				return p;
			Vector3d pos = new Vector3d(0, 0, 0);
			Vector3d norm = new Vector3d(0, 0, 0);

			int count =nearPts.Count;
			for (int i = 0; i < count; i++)
			{
				pos = pos + (nearPts[i].Position - p.Position);
				norm = norm + (nearPts[i].Normal - p.Normal);
			}

			pos = p.Position + pos / count;
			norm = p.Normal + norm / count;
			norm.Normalize();

			return new Point3D(pos,norm,p.Color);
		}
开发者ID:robotsrulz,项目名称:Sardauscan,代码行数:20,代码来源:SurfaceSmoothing.cs

示例10: GetRay

 /// <summary>
 /// Ray-generator. Simple variant, w/o an integration support.
 /// </summary>
 /// <param name="x">Origin position within a viewport (horizontal coordinate).</param>
 /// <param name="y">Origin position within a viewport (vertical coordinate).</param>
 /// <param name="p0">Ray origin.</param>
 /// <param name="p1">Ray direction vector.</param>
 /// <returns>True if the ray (viewport position) is valid.</returns>
 public bool GetRay( double x, double y, out Vector3d p0, out Vector3d p1 )
 {
     p0 = center;
       p1 = origin + x * dx + y * dy;
       p1 = p1 - center;
       p1.Normalize();
       return true;
 }
开发者ID:pepouch,项目名称:PG1Grcis,代码行数:16,代码来源:RayCastingBasic.cs

示例11: StaticCamera

 /// <summary>
 /// Initializing constructor, able to set all camera parameters.
 /// </summary>
 /// <param name="cen">Center of the projection.</param>
 /// <param name="dir">View direction (must not be zero).</param>
 /// <param name="ang">Horizontal viewing angle in degrees.</param>
 public StaticCamera( Vector3d cen, Vector3d dir, double ang )
 {
     center    = cen;
       direction = dir;
       direction.Normalize();
       hAngle = MathHelper.DegreesToRadians( (float)ang );
       Width  = 300;
       Height = 400;
 }
开发者ID:pepouch,项目名称:PG1Grcis,代码行数:15,代码来源:RayCastingBasic.cs

示例12: ColorReflection

        public double[] ColorReflection( IMaterial material, Vector3d normal, Vector3d input, Vector3d output, ReflectionComponent comp )
        {
            if ( !(material is PhongMaterial) ) return null;

              PhongMaterial mat = (PhongMaterial)material;
              int bands = mat.Color.Length;
              double[] result = new double[ bands ];
              bool viewOut = Vector3d.Dot( output, normal ) > 0.0;
              double coef;

              if ( input.Equals( Vector3d.Zero ) )    // ambient term only..
              {
            // dim ambient light if viewer is inside
            coef = viewOut ? mat.Ka : (mat.Ka * mat.Kt);
            for ( int i = 0; i < bands; i++ )
              result[ i ] = coef * mat.Color[ i ];

            return result;
              }

              // directional light source:
              input.Normalize();
              double cosAlpha = Vector3d.Dot( input, normal );
              bool   lightOut = cosAlpha > 0.0;
              double ks = mat.Ks;
              double kd = mat.Kd;
              double kt = mat.Kt;

              Vector3d r = Vector3d.Zero;
              coef       = 1.0;
              if ( viewOut == lightOut )            // viewer and source are on the same side..
              {
            if ( (comp & ReflectionComponent.SPECULAR_REFLECTION) != 0 )
            {
              double cos2 = cosAlpha + cosAlpha;
              r = normal * cos2 - input;

              if ( !lightOut &&                   // total reflection check
               -cosAlpha <= mat.cosTotal )
            if ( (ks += kt) + kd > 1.0 )
              ks = 1.0 - kd;
            }
              }
              else                                  // opposite sides => use specular refraction
              {
            if ( (comp & ReflectionComponent.SPECULAR_REFRACTION) != 0 )
              r = Geometry.SpecularRefraction( normal, mat.n, input );
            coef = kt;
              }

              double diffuse = (comp & ReflectionComponent.DIFFUSE) == 0 ? 0.0 : coef * kd * Math.Abs( cosAlpha );
              double specular = 0.0;

              if ( r != Vector3d.Zero )
              {
            double cosBeta = Vector3d.Dot( r, output );
            if ( cosBeta > 0.0 )
              specular = coef * ks * Arith.Pow( cosBeta, mat.H );
              }

              for ( int i = 0; i < bands; i++ )
            result[i] = diffuse * mat.Color[i] + specular;

              return result;
        }
开发者ID:pepouch,项目名称:PG1Grcis,代码行数:65,代码来源:RayCastingBasic.cs

示例13: Plane

		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="point"></param>
		/// <param name="normal"></param>
		public Plane(Vector3d point, Vector3d normal)
		{
			Point = point;
			Normal = normal;
			Normal.Normalize();
		}
开发者ID:robotsrulz,项目名称:Sardauscan,代码行数:11,代码来源:Plane.cs

示例14: TransformPickPointToWorldSpaceFishEye

        public void TransformPickPointToWorldSpaceFishEye(Vector2d ptCursor, int backBufferWidth, int backBufferHeight, out Vector3d vPickRayOrig, out Vector3d vPickRayDir)
        {
            var point = new Vector2d((((ptCursor.X / backBufferWidth) - .5) - OffsetX) / (Fov/Aspect),
                                (((ptCursor.Y / backBufferHeight) - .5) - OffsetY) / Fov);

            var altAz = GetAltAzFromPoint(point);

            var pnt3d = Coordinates.GeoTo3dDouble(altAz.Y, altAz.X);

            var matInv = TranMatrix;
            matInv.Invert();

            pnt3d = Vector3d.TransformCoordinate(pnt3d, TranMatrix);

            // Transform the screen space pick ray into 3D space
            vPickRayDir = pnt3d;
            vPickRayDir.Normalize();

            vPickRayOrig.X = X;
            vPickRayOrig.Y = Y;
            vPickRayOrig.Z = Z;
        }
开发者ID:bluephoton,项目名称:wwt-windows-client,代码行数:22,代码来源:SolveAlignment.cs

示例15: shade

        /// <summary>
        /// Recursive shading function - computes color contribution of the given ray (shot from the
        /// origin 'p0' into direction vector 'p1''). Recursion is stopped
        /// by a hybrid method: 'importance' and 'level' are checked.
        /// Internal integration support.
        /// </summary>
        /// <param name="level">Current recursion depth.</param>
        /// <param name="importance">Importance of the current ray.</param>
        /// <param name="p0">Ray origin.</param>
        /// <param name="p1">Ray direction vector.</param>
        /// <param name="rank">Rank of this sample, 0 <= rank < total (for integration).</param>
        /// <param name="total">Total number of samples (for integration).</param>
        /// <param name="rnd">Global (per-thread) instance of the random generator.</param>
        /// <param name="color">Result color.</param>
        /// <returns>Hash-value (ray sub-signature) used for adaptive subsampling.</returns>
        protected virtual long shade( int level, double importance, ref Vector3d p0, ref Vector3d p1,
                                   int rank, int total, RandomJames rnd, double[] color )
        {
            int bands = color.Length;
              LinkedList<Intersection> intersections = scene.Intersectable.Intersect( p0, p1 );
              Intersection.countRays++;
              Intersection i = Intersection.FirstIntersection( intersections, ref p1 );
              int b;

              if ( i == null )          // no intersection -> background color
              {
            Array.Copy( scene.BackgroundColor, color, bands );
            return 1L;
              }

              // there was at least one intersection
              i.Complete();

              // hash code for adaptive supersampling:
              long hash = i.Solid.GetHashCode();

              // apply all the textures fist..
              if ( i.Textures != null )
            foreach ( ITexture tex in i.Textures )
              hash = hash * HASH_TEXTURE + tex.Apply( i, rank, total, rnd );

              p1 = -p1;   // viewing vector
              p1.Normalize();

              if ( scene.Sources == null || scene.Sources.Count < 1 )
            // no light sources at all
            Array.Copy( i.SurfaceColor, color, bands );
              else
              {
            // apply the reflectance model for each source
            i.Material = (IMaterial)i.Material.Clone();
            i.Material.Color = i.SurfaceColor;
            Array.Clear( color, 0, bands );

            foreach ( ILightSource source in scene.Sources )
            {
              Vector3d dir;
              double[] intensity = source.GetIntensity( i, rank, total, rnd, out dir );
              if ( intensity != null )
              {
            if ( DoShadows && !dir.Equals( Vector3d.Zero ) )
            {
              intersections = scene.Intersectable.Intersect( i.CoordWorld, dir );
              Intersection.countRays++;
              Intersection si = Intersection.FirstIntersection( intersections, ref dir );
              // Better shadow testing: intersection between 0.0 and 1.0 kills the lighting
              if ( si != null && !si.Far( 1.0, ref dir ) ) continue;
            }

            double[] reflection = i.ReflectanceModel.ColorReflection( i, dir, p1, ReflectionComponent.ALL );
            if ( reflection != null )
            {
              for ( b = 0; b < bands; b++ )
                color[ b ] += intensity[ b ] * reflection[ b ];
              hash = hash * HASH_LIGHT + source.GetHashCode();
            }
              }
            }
              }

              // check the recursion depth:
              if ( level++ >= MaxLevel ||
               !DoReflections && !DoRefractions )
            return hash;                        // no further recursion

              Vector3d r;
              double maxK;
              double[] comp = new double[ bands ];
              double newImportance;

              if ( DoReflections )                  // trying to shoot a reflected ray..
              {
            Geometry.SpecularReflection( ref i.Normal, ref p1, out r );
            double[] ks = i.ReflectanceModel.ColorReflection( i, p1, r, ReflectionComponent.SPECULAR_REFLECTION );
            if ( ks != null )
            {
              maxK = ks[ 0 ];
              for ( b = 1; b < bands; b++ )
            if ( ks[ b ] > maxK )
              maxK = ks[ b ];
//.........这里部分代码省略.........
开发者ID:pepouch,项目名称:PG1Grcis,代码行数:101,代码来源:RayTracingRender.cs


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