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


C# Vector4.Dot方法代码示例

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


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

示例1: DotProduct_SameVector_ReturnsMSquared

        public void DotProduct_SameVector_ReturnsMSquared()
        {
            Vector4 test = new Vector4(2.0, 0.0, 0.0, 0.0);

            double result = test.Dot(test);

            Assert.AreEqual(4.0, result, Epsilon);
        }
开发者ID:patricknboyd,项目名称:VectorMath,代码行数:8,代码来源:Vector4_Test.cs

示例2: GetFrustumClipVolumes

		/// <summary>
		///		Internal method for calculating the clip volumes outside of the
		///		frustum which can be used to determine which objects are casting
		///		shadow on the frustum as a whole.
		/// </summary>
		/// <remarks>
		///		Each of the volumes is a pyramid for a point/spot light and
		///		a cuboid for a directional light.
		/// </remarks>
		/// <param name="camera"></param>
		/// <returns></returns>
		internal virtual PlaneBoundedVolumeList GetFrustumClipVolumes( Camera camera )
		{
			// Homogenous light position
			Vector4 lightPos = this.GetAs4DVector();

			// 3D version (not the same as DerivedPosition, is -direction for
			// directional lights)
			Vector3 lightPos3 = new Vector3( lightPos.x, lightPos.y, lightPos.z );
			Vector3 lightDir;

			Vector3[] clockwiseVerts = new Vector3[ 4 ];

			Matrix4 eyeToWorld = camera.ViewMatrix.Inverse();

			// Get worldspace frustum corners
			Vector3[] corners = camera.WorldSpaceCorners;

			bool infiniteViewDistance = ( camera.Far == 0 );

			this.frustumClipVolumes.Clear();

			for ( int n = 0; n < 6; n++ )
			{
				FrustumPlane frustumPlane = (FrustumPlane)n;

				// skip far plane if infinite view frustum
				if ( infiniteViewDistance && ( frustumPlane == FrustumPlane.Far ) )
				{
					continue;
				}

				Plane plane = camera[ frustumPlane ];

				Vector4 planeVec = new Vector4( plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D );

				// planes face inwards, we need to know if light is on negative side
				float d = planeVec.Dot( lightPos );

				if ( d < -1e-06f )
				{
					// Ok, this is a valid one
					// clockwise verts mean we can cross-product and always get normals
					// facing into the volume we create
					this.frustumClipVolumes.Add( new PlaneBoundedVolume() );
					PlaneBoundedVolume vol =
							(PlaneBoundedVolume)this.frustumClipVolumes[ this.frustumClipVolumes.Count - 1 ];

					switch ( frustumPlane )
					{
						case ( FrustumPlane.Near ):
							clockwiseVerts[ 0 ] = corners[ 3 ];
							clockwiseVerts[ 1 ] = corners[ 2 ];
							clockwiseVerts[ 2 ] = corners[ 1 ];
							clockwiseVerts[ 3 ] = corners[ 0 ];
							break;
						case ( FrustumPlane.Far ):
							clockwiseVerts[ 0 ] = corners[ 7 ];
							clockwiseVerts[ 1 ] = corners[ 6 ];
							clockwiseVerts[ 2 ] = corners[ 5 ];
							clockwiseVerts[ 3 ] = corners[ 4 ];
							break;
						case ( FrustumPlane.Left ):
							clockwiseVerts[ 0 ] = corners[ 2 ];
							clockwiseVerts[ 1 ] = corners[ 6 ];
							clockwiseVerts[ 2 ] = corners[ 5 ];
							clockwiseVerts[ 3 ] = corners[ 1 ];
							break;
						case ( FrustumPlane.Right ):
							clockwiseVerts[ 0 ] = corners[ 7 ];
							clockwiseVerts[ 1 ] = corners[ 3 ];
							clockwiseVerts[ 2 ] = corners[ 0 ];
							clockwiseVerts[ 3 ] = corners[ 4 ];
							break;
						case ( FrustumPlane.Top ):
							clockwiseVerts[ 0 ] = corners[ 0 ];
							clockwiseVerts[ 1 ] = corners[ 1 ];
							clockwiseVerts[ 2 ] = corners[ 5 ];
							clockwiseVerts[ 3 ] = corners[ 4 ];
							break;
						case ( FrustumPlane.Bottom ):
							clockwiseVerts[ 0 ] = corners[ 7 ];
							clockwiseVerts[ 1 ] = corners[ 6 ];
							clockwiseVerts[ 2 ] = corners[ 2 ];
							clockwiseVerts[ 3 ] = corners[ 3 ];
							break;
					}

					// Build a volume
					// Iterate over world points and form side planes
//.........这里部分代码省略.........
开发者ID:mono-soc-2011,项目名称:axiom,代码行数:101,代码来源:Light.cs

示例3: ApplyObliqueDepthProjection

		public override void ApplyObliqueDepthProjection( ref Matrix4 matrix, Plane plane, bool forGpuProgram )
		{
			// Thanks to Eric Lenyel for posting this calculation at www.terathon.com

			// Calculate the clip-space corner point opposite the clipping plane
			// as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
			// transform it into camera space by multiplying it
			// by the inverse of the projection matrix

			var q = new Vector4();
			q.x = ( Utility.Sign( plane.Normal.x ) + matrix[ 0, 2 ] ) / matrix[ 0, 0 ];
			q.y = ( Utility.Sign( plane.Normal.y ) + matrix[ 1, 2 ] ) / matrix[ 1, 1 ];
			q.z = -1.0f;
			q.w = ( 1.0f + matrix[ 2, 2 ] ) / matrix[ 2, 3 ];

			//Calculate the scaled plane vector
			var clipPlane4D = new Vector4( plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D );
			Vector4 c = clipPlane4D * ( 2.0f / ( clipPlane4D.Dot( q ) ) );

			//Replace the thrid row of the projection matrix
			matrix[ 2, 0 ] = c.x;
			matrix[ 2, 1 ] = c.y;
			matrix[ 2, 2 ] = c.z + 1.0f;
			matrix[ 2, 3 ] = c.w;
		}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:25,代码来源:GLES2RenderSystem.cs

示例4: ApplyObliqueDepthProjection

        public override void ApplyObliqueDepthProjection( ref Matrix4 projMatrix, Plane plane, bool forGpuProgram )
		{
			// Thanks to Eric Lenyel for posting this calculation at www.terathon.com

			// Calculate the clip-space corner point opposite the clipping plane
			// as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
			// transform it into camera space by multiplying it
			// by the inverse of the projection matrix

			var q = new Vector4();
			q.x = ( System.Math.Sign( plane.Normal.x ) + projMatrix.m02 ) / projMatrix.m00;
			q.y = ( System.Math.Sign( plane.Normal.y ) + projMatrix.m12 ) / projMatrix.m11;
			q.z = -1.0f;
			q.w = ( 1.0f + projMatrix.m22 ) / projMatrix.m23;

			// Calculate the scaled plane vector
			var clipPlane4D = new Vector4( plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D );
			var c = clipPlane4D * ( 2.0f / ( clipPlane4D.Dot( q ) ) );

			// Replace the third row of the projection matrix
			projMatrix.m20 = c.x;
			projMatrix.m21 = c.y;
			projMatrix.m22 = c.z + 1.0f;
			projMatrix.m23 = c.w;
		}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:25,代码来源:GLRenderSystem.cs

示例5: _updateFrustum

		protected virtual void _updateFrustum()
		{
			Real vpTop, vpRight, vpBottom, vpLeft;

			CalculateProjectionParameters( out vpLeft, out vpRight, out vpBottom, out vpTop );

			if ( !this._customProjectionMatrix )
			{
				// The code below will dealing with general projection
				// parameters, similar glFrustum and glOrtho.
				// Doesn't optimise manually except division operator, so the
				// code more self-explaining.

				Real inv_w = 1.0f/( vpRight - vpLeft );
				Real inv_h = 1.0f/( vpTop - vpBottom );
				Real inv_d = 1.0f/( this._farDistance - this._nearDistance );

				// Recalc if frustum params changed
				if ( this._projectionType == Projection.Perspective )
				{
					// Calc matrix elements
					Real A = 2.0f*this._nearDistance*inv_w;
					Real B = 2.0f*this._nearDistance*inv_h;
					Real C = ( vpRight + vpLeft )*inv_w;
					Real D = ( vpTop + vpBottom )*inv_h;
					Real q, qn;
					if ( this._farDistance == 0.0f )
					{
						// Infinite far plane
						q = Frustum.InfiniteFarPlaneAdjust - 1.0f;
						qn = this._nearDistance*( Frustum.InfiniteFarPlaneAdjust - 2.0f );
					}
					else
					{
						q = -( this._farDistance + this._nearDistance )*inv_d;
						qn = -2.0f*( this._farDistance*this._nearDistance )*inv_d;
					}

					// NB: This creates 'uniform' perspective projection matrix,
					// which depth range [-1,1], right-handed rules
					//
					// [ A   0   C   0  ]
					// [ 0   B   D   0  ]
					// [ 0   0   q   qn ]
					// [ 0   0   -1  0  ]
					//
					// A = 2 * near / (right - left)
					// B = 2 * near / (top - bottom)
					// C = (right + left) / (right - left)
					// D = (top + bottom) / (top - bottom)
					// q = - (far + near) / (far - near)
					// qn = - 2 * (far * near) / (far - near)

					this._projectionMatrix = Matrix4.Zero;
					this._projectionMatrix.m00 = A;
					this._projectionMatrix.m02 = C;
					this._projectionMatrix.m11 = B;
					this._projectionMatrix.m12 = D;
					this._projectionMatrix.m22 = q;
					this._projectionMatrix.m23 = qn;
					this._projectionMatrix.m32 = -1.0f;

					if ( this.useObliqueDepthProjection )
					{
						// Translate the plane into view space

						// Don't use getViewMatrix here, incase overrided by
						// camera and return a cull frustum view matrix
						UpdateView();

						var plane = this._viewMatrix*this.obliqueProjPlane;

						// Thanks to Eric Lenyel for posting this calculation
						// at www.terathon.com

						// Calculate the clip-space corner point opposite the
						// clipping plane
						// as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
						// transform it into camera space by multiplying it
						// by the inverse of the projection matrix

						/* generalised version
                        Vector4 q = matrix.inverse() *
                        Vector4(Math::Sign(plane.normal.x),
                        Math::Sign(plane.normal.y), 1.0f, 1.0f);
                         */
						var q1 = new Vector4();
						q1.x = ( System.Math.Sign( plane.Normal.x ) + this._projectionMatrix.m02 )/this._projectionMatrix.m00;
						q1.y = ( System.Math.Sign( plane.Normal.y ) + this._projectionMatrix.m12 )/this._projectionMatrix.m11;
						q1.z = -1.0f;
						q1.w = ( 1.0f + this._projectionMatrix.m22 )/this._projectionMatrix.m23;

						// Calculate the scaled plane vector
						var clipPlane4d = new Vector4( plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D );
						var c = clipPlane4d*( 2.0f/( clipPlane4d.Dot( q1 ) ) );

						// Replace the third row of the projection matrix
						this._projectionMatrix.m20 = c.x;
						this._projectionMatrix.m21 = c.y;
						this._projectionMatrix.m22 = c.z + 1.0f;
//.........这里部分代码省略.........
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:101,代码来源:Frustum.cs

示例6: Qform

 public double Qform(Vector4 u, Vector4 v)
 {
     return u.Dot(this.Mult(v));
 }
开发者ID:tcoats,项目名称:Voodoo,代码行数:4,代码来源:Matrix4.cs


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