• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Math.Vector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Balder.Core.Math.Vector的典型用法代码示例。如果您正苦于以下问题:C# Vector类的具体用法?C# Vector怎么用?C# Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Vector类属于Balder.Core.Math命名空间,在下文中一共展示了Vector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Calculate

		public override Color Calculate(Vector point, Vector normal)
		{
            // Use dotproduct for diffuse lighting. Add point functionality as this now is a directional light.
            // Ambient light
            var ambient = ColorAmbient.ToVector() * Strength;

            // Diffuse light
            var lightDir = Direction;
            lightDir.Normalize();
            normal.Normalize();
            var dfDot = lightDir.Dot(normal);
            MathHelper.Saturate(ref dfDot);
            var diffuse = ColorDiffuse.ToVector() * dfDot * Strength;

            // Specular highlight
            var Reflection = 2 * dfDot * normal - lightDir;
            Reflection.Normalize();
            var view = Camera.Position - point;
            view.Normalize();
            var spDot = Reflection.Dot(view);
            MathHelper.Saturate(ref spDot);
            var specular = ColorSpecular.ToVector() * spDot * Strength;

            // Compute self shadowing
            var shadow = 4.0f * lightDir.Dot(normal);
            MathHelper.Saturate(ref shadow);


            // Final result
            var colorVector = ambient + shadow * (diffuse + specular);
            //var colorVector = ambient + diffuse;

			return colorVector.ToColorWithClamp();
		}
开发者ID:baldercollaborator,项目名称:Balder,代码行数:34,代码来源:DirectionalLight.cs


示例2: RenderUnscaled

		private static void RenderUnscaled(IBuffers buffer, int positionOffset, Image image, Vector translatedPosition, int bufferSize, UInt32 bufferZ)
		{
			var rOffset = buffer.FrameBuffer.RedPosition;
			var gOffset = buffer.FrameBuffer.GreenPosition;
			var bOffset = buffer.FrameBuffer.BluePosition;
			var aOffset = buffer.FrameBuffer.AlphaPosition;
			var imageContext = image.ImageContext as ImageContext;
			var spriteOffset = 0;

			for (var y = 0; y < image.Height; y++)
			{
				var offset = y * buffer.FrameBuffer.Stride;
				var depthBufferOffset = (buffer.Width * ((int)translatedPosition.Y + y)) + (int)translatedPosition.X;
				for (var x = 0; x < image.Width; x++)
				{
					var actualOffset = offset + positionOffset;

					if (actualOffset >= 0 && actualOffset < bufferSize &&
						bufferZ < buffer.DepthBuffer[depthBufferOffset])
					{
						buffer.FrameBuffer.Pixels[actualOffset] = imageContext.Pixels[spriteOffset];
						buffer.DepthBuffer[depthBufferOffset] = bufferZ;
					}
					offset ++;
					spriteOffset ++;
					depthBufferOffset++;
				}
			}
		}
开发者ID:baldercollaborator,项目名称:Balder,代码行数:29,代码来源:SpriteContext.cs


示例3: Render

        public void Render(Viewport viewport, Sprite sprite, Matrix view, Matrix projection, Matrix world, float xScale, float yScale, float rotation)
        {
            var image = sprite.CurrentFrame;

            var position = new Vector(0, 0, 0);
            var transformedPosition = Vector.Transform(position, world, view);
            var translatedPosition = Vector.Translate(transformedPosition, projection, viewport.Width, viewport.Height);

            var z = ((transformedPosition.Z / viewport.View.DepthDivisor) + viewport.View.DepthZero);
            var depthBufferAdjustedZ = z;

            var bufferSize = BufferContainer.Stride * BufferContainer.Height;
            var bufferZ = (UInt32)((1.0f - depthBufferAdjustedZ) * (float)UInt32.MaxValue);
            if (depthBufferAdjustedZ < 0f || depthBufferAdjustedZ >= 1f)
            {
                return;
            }

            var xOriginOffset = (int)-((sprite.CurrentFrame.Width / 2f) * xScale);
            var yOriginOffset = (int)-((sprite.CurrentFrame.Height / 2f) * yScale);

            var actualX = ((int) translatedPosition.X) + xOriginOffset;
            var actualY = ((int) translatedPosition.Y) + yOriginOffset;

            var positionOffset = actualX + (actualY * BufferContainer.Stride);

            if (xScale != 1f || yScale != 1f)
            {
                RenderScaled(viewport, positionOffset, actualX, actualY, sprite.CurrentFrame, translatedPosition, bufferSize, bufferZ, xScale, yScale);
            }
            else
            {
                RenderUnscaled(viewport, positionOffset, actualX, actualY, sprite.CurrentFrame, translatedPosition, bufferSize, bufferZ);
            }
        }
开发者ID:petriw,项目名称:Balder,代码行数:35,代码来源:SpriteContext.cs


示例4: Transform

		public void Transform(Matrix world, Matrix view)
		{
			TransformedVector = Vector.Transform(Vector, world);
			TransformedVector = Vector.Transform(TransformedVector, view);
			TransformedNormal = Vector.TransformNormal(Normal, world);
			TransformedNormal = Vector.TransformNormal(TransformedNormal, view);
		}
开发者ID:tekbob27,项目名称:Balder,代码行数:7,代码来源:Vertex.cs


示例5: Render

		public void Render(IViewport viewport, Sprite sprite, Matrix view, Matrix projection, Matrix world, float xScale, float yScale, float rotation)
		{
			var buffer = BufferManager.Instance.Current;

			var image = sprite.CurrentFrame;

			
			var position = new Vector(0, 0, 0);
			var transformedPosition = Vector.Transform(position, world, view);
			var translatedPosition = Vector.Translate(transformedPosition, projection, viewport.Width, viewport.Height);
			var depthBufferAdjustedZ = -transformedPosition.Z / viewport.Camera.DepthDivisor;
			var positionOffset = (((int)translatedPosition.X)) + (((int)translatedPosition.Y) * buffer.FrameBuffer.Stride);

			var bufferSize = buffer.FrameBuffer.Stride*buffer.Height;
			var bufferZ = (UInt32)(depthBufferAdjustedZ * (float)UInt32.MaxValue);
			if( depthBufferAdjustedZ < 0f || depthBufferAdjustedZ >= 1f)
			{
				return;
			}
			
			if( xScale != 1f || yScale != 1f )
			{
				RenderScaled(buffer, positionOffset, sprite.CurrentFrame, translatedPosition, bufferSize, bufferZ, xScale, yScale);
				
			} else
			{
				RenderUnscaled(buffer,positionOffset,sprite.CurrentFrame,translatedPosition,bufferSize,bufferZ);
			}
		}
开发者ID:baldercollaborator,项目名称:Balder,代码行数:29,代码来源:SpriteContext.cs


示例6: ImplicitlySettingAVectorAsCoordinateShouldReturnSameValuesAsInVector

 public void ImplicitlySettingAVectorAsCoordinateShouldReturnSameValuesAsInVector()
 {
     var vector = new Vector(5f, 6f, 7f);
     Coordinate coordinate = vector;
     Assert.That(coordinate.X, Is.EqualTo(vector.X));
     Assert.That(coordinate.Y, Is.EqualTo(vector.Y));
     Assert.That(coordinate.Z, Is.EqualTo(vector.Z));
 }
开发者ID:petriw,项目名称:Balder,代码行数:8,代码来源:CoordinateTests.cs


示例7: Vector

        public Vector(Vector v1)
			: this()
        {
            X = v1.X;
            Y = v1.Y;
            Z = v1.Z;
            W = v1.W;
        }
开发者ID:baldercollaborator,项目名称:Balder,代码行数:8,代码来源:Vector.cs


示例8: DirectionalLight

        public DirectionalLight()
		{
			Strength = 1f;
            Specular = true;
            Diffuse = true;
            Ambient = true;
            Direction = new Vector(0, 0, 1, 0);
		}
开发者ID:baldercollaborator,项目名称:Balder,代码行数:8,代码来源:DirectionalLight.cs


示例9: Transform

		public void Transform(Matrix world, Matrix view)
		{
			TransformedNormal = Vector.TransformNormal(Normal, world);
			TransformedNormal = Vector.TransformNormal(TransformedNormal, view);
			TransformedPosition = Vector.Transform(Position, world, view);

			TransformedDebugNormal = TransformedPosition +(TransformedNormal); //*DebugNormalLength);
		}
开发者ID:baldercollaborator,项目名称:Balder,代码行数:8,代码来源:Face.cs


示例10: TransformingWithOnlyTranslationShouldPositionSphereCorrectly

 public void TransformingWithOnlyTranslationShouldPositionSphereCorrectly()
 {
     var boundingSphere = new BoundingSphere(Vector.Zero, 1);
     var position = new Vector(10, 5, 3);
     var matrix = Matrix.CreateTranslation(position);
     var transformedBoundingSphere = boundingSphere.Transform(matrix);
     Assert.That(transformedBoundingSphere.Center, Is.EqualTo(position));
 }
开发者ID:Conn,项目名称:Balder,代码行数:8,代码来源:BoundingSphereTests.cs


示例11: Vertex

 public Vertex(float x, float y, float z)
     : this()
 {
     Vector = new Vector(x, y, z);
     TransformedVector = new Math.Vector(x, y, z);
     TranslatedVector = new Math.Vector(x, y, z);
     Normal = Vector.Zero;
     TranslatedScreenCoordinates = Vector.Zero;
 }
开发者ID:Conn,项目名称:Balder,代码行数:9,代码来源:Vertex.cs


示例12: AddingACoordinateToAVectorShouldReturnAVectorWithCorrectResult

 public void AddingACoordinateToAVectorShouldReturnAVectorWithCorrectResult()
 {
     var v1 = new Vector(2f, 4f, 6f);
     var c2 = new Coordinate { X = 1f, Y = 2f, Z = 3f };
     var vector = v1 + c2;
     Assert.That(vector.X, Is.EqualTo(3f));
     Assert.That(vector.Y, Is.EqualTo(6f));
     Assert.That(vector.Z, Is.EqualTo(9f));
 }
开发者ID:petriw,项目名称:Balder,代码行数:9,代码来源:CoordinateTests.cs


示例13: Node

		protected Node()
		{
			World = Matrix.Identity;

			PositionMatrix = Matrix.Identity;
			ScaleMatrix = Matrix.Identity;
			Scale = new Vector(1f,1f,1f);
			Position = Vector.Zero;
		}
开发者ID:Conn,项目名称:Balder,代码行数:9,代码来源:Node.cs


示例14: AddingAVectorToACoordinateShouldReturnAVectorWithCorrectResult

 public void AddingAVectorToACoordinateShouldReturnAVectorWithCorrectResult()
 {
     var c1 = new Coordinate { X = 2f, Y = 4f, Z = 6f };
     var v2 = new Vector(1f, 2f, 3f);
     var vector = c1 + v2;
     Assert.That(vector.X, Is.EqualTo(3f));
     Assert.That(vector.Y, Is.EqualTo(6f));
     Assert.That(vector.Z, Is.EqualTo(9f));
 }
开发者ID:petriw,项目名称:Balder,代码行数:9,代码来源:CoordinateTests.cs


示例15: Transform

 public void Transform(Matrix world, Matrix view)
 {
     //var matrix = world*view;
     var matrix = view;
     TransformedVector = Vector.Transform(Vector, matrix);
     //TransformedVector = Vector.Transform(TransformedVector, view);
     TransformedNormal = Vector.TransformNormal(Normal, matrix);
     //TransformedNormal = Vector.TransformNormal(TransformedNormal, view);
 }
开发者ID:Conn,项目名称:Balder,代码行数:9,代码来源:Vertex.cs


示例16: Transform

 public static Vector Transform(Vector position, Matrix matrix)
 {
     Vector vector = Vector.Zero;
     float num3 = (((position.X * matrix[0, 0]) + (position.Y * matrix[1, 0])) + (position.Z * matrix[2, 0])) + matrix[3, 0];
     float num2 = (((position.X * matrix[0, 1]) + (position.Y * matrix[1, 1])) + (position.Z * matrix[2, 1])) + matrix[3, 1];
     float num = (((position.X * matrix[0, 2]) + (position.Y * matrix[1, 2])) + (position.Z * matrix[2, 2])) + matrix[3, 2];
     vector.X = num3;
     vector.Y = num2;
     vector.Z = num;
     return vector;
 }
开发者ID:petriw,项目名称:Balder,代码行数:11,代码来源:ViewportExtensions.cs


示例17: TransormingWith90DegreesRotationAroundYAndTranslationShouldPositionSphereCorrectly

 public void TransormingWith90DegreesRotationAroundYAndTranslationShouldPositionSphereCorrectly()
 {
     var boundingSphere = new BoundingSphere(Vector.Zero, 1);
     var position = new Vector(10, 5, 3);
     var translationMatrix = Matrix.CreateTranslation(position);
     var rotationMatrix = Matrix.CreateRotationY(90f);
     var matrix = translationMatrix * rotationMatrix;
     var transformedBoundingSphere = boundingSphere.Transform(matrix);
     var expectedPosition = position*rotationMatrix;
     Assert.That(transformedBoundingSphere.Center, Is.EqualTo(expectedPosition));
 }
开发者ID:Conn,项目名称:Balder,代码行数:11,代码来源:BoundingSphereTests.cs


示例18: Calculate

        public Color Calculate(Viewport viewport, Vector vector, Vector normal)
        {
            var color = viewport.Scene.AmbientColor;

            foreach( ILight light in viewport.Scene.Lights )
            {
                var lightColor = light.Calculate(viewport, vector, normal);
                color = color.Additive(lightColor);
            }

            return color;
        }
开发者ID:petriw,项目名称:Balder,代码行数:12,代码来源:ColorCalculator.cs


示例19: UnprojectingCenterOfViewportWithIdentityViewShouldGenerateAVectorAtCenter

        public void UnprojectingCenterOfViewportWithIdentityViewShouldGenerateAVectorAtCenter()
        {
            var viewport = new Viewport { Width = 640, Height = 480 };

            var aspect = (float) viewport.Height/(float) viewport.Width;
            var projection = Matrix.CreatePerspectiveFieldOfView(40f, aspect, 1, 4000f);
            var view = Matrix.Identity;
            var world = Matrix.Identity;
            var position = new Vector((float)viewport.Width/2, (float)viewport.Height/2,0);
            var result = viewport.Unproject(position, projection, view, world);
            Assert.That(result,Is.EqualTo(new Vector(0,0,-1)));
        }
开发者ID:petriw,项目名称:Balder,代码行数:12,代码来源:ViewportExtensionsTests.cs


示例20: GettingDistanceFromPlaneShouldReturnCorrectDistance

		public void GettingDistanceFromPlaneShouldReturnCorrectDistance()
		{
			var plane = new Plane();
			var vector1 = new Vector(-100, -100, 100);
			var vector2 = new Vector(100, -100, 100);
			var vector3 = new Vector(0, -100, 0);
			plane.SetVectors(vector1,vector2,vector3);

			var vectorToTest = new Vector(0, -200, 0);

			var length = plane.GetDistanceFromVector(vectorToTest);
			Assert.That(length,Is.EqualTo(-100f));
		}
开发者ID:tekbob27,项目名称:Balder,代码行数:13,代码来源:PlaneTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DAL.QUANLYXEKHACHEntities类代码示例发布时间:2022-05-24
下一篇:
C# Pagination.PaginationQueryCondition类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap