本文整理汇总了C#中Balder.Core.Math.Vector类的典型用法代码示例。如果您正苦于以下问题:C# Vector类的具体用法?C# Vector怎么用?C# Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Vector类属于Balder.Core.Math命名空间,在下文中一共展示了Vector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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++;
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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));
}
示例7: Vector
public Vector(Vector v1)
: this()
{
X = v1.X;
Y = v1.Y;
Z = v1.Z;
W = v1.W;
}
示例8: DirectionalLight
public DirectionalLight()
{
Strength = 1f;
Specular = true;
Diffuse = true;
Ambient = true;
Direction = new Vector(0, 0, 1, 0);
}
示例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);
}
示例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));
}
示例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;
}
示例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));
}
示例13: Node
protected Node()
{
World = Matrix.Identity;
PositionMatrix = Matrix.Identity;
ScaleMatrix = Matrix.Identity;
Scale = new Vector(1f,1f,1f);
Position = Vector.Zero;
}
示例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));
}
示例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);
}