本文整理汇总了C#中Microsoft.Xna.Framework.Matrix类的典型用法代码示例。如果您正苦于以下问题:C# Matrix类的具体用法?C# Matrix怎么用?C# Matrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Matrix类属于Microsoft.Xna.Framework命名空间,在下文中一共展示了Matrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reset
// Reset
public void Reset()
{
Offset = new Vector2();
Scale = new Vector2( 1.0f );
Rotation = new Vector3();
TransformMatrix = Matrix.Identity;
}
示例2: DrawWireframe
public static void DrawWireframe(PrimitiveDrawer primitiveDrawer,
Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection,
Vector3 center, float radius, Quaternion rotation, Color color)
{
// Draw three orthogonal discs.
Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Up, rotation)), radius, color, true);
Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Forward, rotation)), radius, color, true);
Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Left, rotation)), radius, color, true);
// Draw disc aligned with camera. To do this, first calculate the largest visible cross section using
// the technique described here: http://www.quantimegroup.com/solutions/pages/Article/Article.html
// Solve for dy.
Vector3 cameraToCenter = center - cameraPosition;
float distanceToCenter = cameraToCenter.Length();
float radius2 = radius * radius;
float dy = radius2 / distanceToCenter;
float r = MathUtility.Sqrt(radius2 - (dy * dy));
Vector3 directionToCenter = Vector3.Normalize(cameraToCenter);
Vector3 newCenter = cameraPosition + directionToCenter * (distanceToCenter - dy);
// Disc aligned with camera
Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection,
newCenter, directionToCenter, r, Color.White, false);
}
示例3: Draw
public override void Draw(GameTime gameTime)
{
Matrix worldMatrix = Matrix.Identity;
switch (Resources.Instance.GameSize)
{
case Resources.LevelSize.SMALL:
worldMatrix = Matrix.Identity * Matrix.CreateScale(85);
break;
case Resources.LevelSize.MEDIUM:
worldMatrix = Matrix.Identity * Matrix.CreateScale(100);
break;
case Resources.LevelSize.LARGE:
worldMatrix = Matrix.Identity * Matrix.CreateScale(115);
break;
}
Matrix[] transforms = new Matrix[_model.Bones.Count];
_model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in _model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.Projection = MathConverter.Convert(_manager.Camera.ProjectionMatrix);
effect.View = MathConverter.Convert(_manager.Camera.ViewMatrix);
effect.World = worldMatrix;
}
mesh.Draw();
}
base.Draw(gameTime);
}
示例4: Draw
/// <summary>
/// Draws the display object.
/// </summary>
/// <param name="viewMatrix">Current view matrix.</param>
/// <param name="projectionMatrix">Current projection matrix.</param>
public override void Draw(Matrix viewMatrix, Matrix projectionMatrix)
{
//This is not a particularly fast method of drawing.
//It's used very rarely in the demos.
model.CopyAbsoluteBoneTransformsTo(transforms);
for (int i = 0; i < Model.Meshes.Count; i++)
{
for (int j = 0; j < Model.Meshes[i].Effects.Count; j++)
{
var effect = Model.Meshes[i].Effects[j] as BasicEffect;
if (effect != null)
{
effect.World = transforms[Model.Meshes[i].ParentBone.Index] * WorldTransform;
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
if (Texture != null)
{
effect.TextureEnabled = true;
effect.Texture = Texture;
}
else
effect.TextureEnabled = false;
}
}
Model.Meshes[i].Draw();
}
}
示例5: ResetCamera
public void ResetCamera()
{
Position = Vector3.Zero;
Target = Vector3.Zero;
ViewMatrix = Matrix.Identity;
ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), Engine.Video.GraphicsDevice.Viewport.AspectRatio, 0.5f, 500f);
}
示例6: Draw
public static void Draw(this BoundingFrustum frustum, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color)
{
if (effect == null)
{
effect = new BasicEffect(graphicsDevice);
effect.VertexColorEnabled = true;
effect.LightingEnabled = false;
}
Vector3[] corners = frustum.GetCorners();
for (int i = 0; i < 8; i++)
{
verts[i].Position = corners[i];
verts[i].Color = color;
}
effect.View = view;
effect.Projection = projection;
foreach (var t in effect.Techniques)
foreach (var p in t.Passes)
{
p.Apply();
graphicsDevice.DrawUserIndexedPrimitives(
PrimitiveType.LineList, verts, 0, 8,
indices, 0, indices.Length / 2);
}
}
示例7: Draw
public void Draw(Matrix view, Matrix projection)
{
Effect.Projection = projection;
Effect.View = view;
Effect.CurrentTechnique.Passes[0].Apply();
Device.DrawUserPrimitives(PrimitiveType.LineList, Vertices, 0, 3);
}
示例8: EnvironmentBatch
public EnvironmentBatch(GraphicsDevice device, ContentManager content, Matrix projection)
{
_environmentEffect = content.Load<Effect>("AmbientEffect");
_environmentEffect.Parameters["BaseTexture"].SetValue(content.Load<Texture2D>("Drydock Floor"));
_environmentEffect.Parameters["Projection"].SetValue(projection);
_environmentEffect.Parameters["World"].SetValue(Matrix.CreateScale(_environmentScale));
}
示例9: Draw
public void Draw(Scattaring fx)
{
Matrix[] modelTansforms = new Matrix[Fbx.Bones.Count];
Fbx.CopyAbsoluteBoneTransformsTo(modelTansforms);
foreach (ModelMesh mesh in Fbx.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
Matrix world = modelTansforms[mesh.ParentBone.Index] * fx.WorldMatrix;
currentEffect.Parameters["WorldViewProj"].SetValue(world * fx.viewProjection);
currentEffect.Parameters["WorldInverseTranspose"].SetValue(fx.invertTransposeWorld);
currentEffect.Parameters["World"].SetValue(world);
currentEffect.Parameters["ViewInv"].SetValue(fx.invertView);
currentEffect.Parameters["LightDirection"].SetValue(fx.lightDirection);
currentEffect.Parameters["LightColor"].SetValue(fx.lightColor);
currentEffect.Parameters["LightColorAmbient"].SetValue(fx.lightColorAmbient);
currentEffect.Parameters["FogColor"].SetValue(fx.fogColor);
currentEffect.Parameters["fDensity"].SetValue(fx.fogDensity);
currentEffect.Parameters["SunLightness"].SetValue(fx.sunLightness);
currentEffect.Parameters["sunRadiusAttenuation"].SetValue(fx.sunRadiusAttenuation);
currentEffect.Parameters["largeSunLightness"].SetValue(fx.largeSunLightness);
currentEffect.Parameters["largeSunRadiusAttenuation"].SetValue(fx.largeSunRadiusAttenuation);
currentEffect.Parameters["dayToSunsetSharpness"].SetValue(fx.dayToSunsetSharpness);
currentEffect.Parameters["hazeTopAltitude"].SetValue(fx.hazeTopAltitude);
}
mesh.Draw();
}
}
示例10: Lamp
public Lamp(Game game, Matrix worldMatrix)
: base(game)
{
Name = "Lamp";
On = true;
WorldMatrix = worldMatrix;
}
示例11: Process
/// <summary>
/// Processes the particles.
/// </summary>
/// <param name="dt">Elapsed time in whole and fractional seconds.</param>
/// <param name="particleArray">A pointer to an array of particles.</param>
/// <param name="count">The number of particles which need to be processed.</param>
protected internal override unsafe void Process(float dt, Particle* particleArray, int count)
{
// Create the transformation matrix...
float h = ((this.HueShift * dt) * Calculator.Pi) / 180f;
float u = Calculator.Cos(h);
float w = Calculator.Sin(h);
Matrix hueTransform = new Matrix(1f, 0f, 0f, 0f,
0f, u, -w, 0f,
0f, w, u, 0f,
0f, 0f, 0f, 1f);
for (int i = 0; i < count; i++)
{
Particle* particle = (particleArray + i);
Vector4 colour;
// Convert the current colour of the particle to YIQ colour space...
Vector4.Transform(ref particle->Colour, ref HueShiftModifier.YIQTransformMatrix, out colour);
// Transform the colour in YIQ space...
Vector4.Transform(ref colour, ref hueTransform, out colour);
// Convert the colour back to RGB...
Vector4.Transform(ref colour, ref HueShiftModifier.RGBTransformMatrix, out colour);
// And apply back to the particle...
particle->Colour.X = colour.X;
particle->Colour.Y = colour.Y;
particle->Colour.Z = colour.Z;
}
}
示例12: Draw
/*
* Draw
*
* This function will draw the current menu
*
* SpriteBatch spriteBatch: The current sprite batch used to draw
*
* GraphicsDeviceManager graphics: The current graphics manager
*/
public void Draw(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Matrix scale)
{
spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend,
SamplerState.LinearClamp,
DepthStencilState.None,
RasterizerState.CullCounterClockwise,
null,
scale);
var mSize = new float[2] { _mScreenRect.Width / (float)graphics.GraphicsDevice.Viewport.Width, _mScreenRect.Height / (float)graphics.GraphicsDevice.Viewport.Height };
spriteBatch.Draw(_mTrans, graphics.GraphicsDevice.Viewport.Bounds, Color.White);
spriteBatch.Draw(_mTitle, new Rectangle(_mScreenRect.Center.X - (int)(_mTitle.Width * mSize[0]) / 2, _mScreenRect.Top, (int)(_mTitle.Width * mSize[0]), (int)(_mTitle.Height * mSize[1])), Color.White);
var currentLocation = new Vector2(_mScreenRect.Left, _mScreenRect.Top + (int)(_mTitle.Height * mSize[1]));
var height = _mScreenRect.Height - (int)(_mTitle.Height * mSize[1]);
height -= ((int)(_mItems[0].Height * mSize[1]) + (int)(_mItems[1].Height * mSize[1]) + (int)(_mItems[2].Height * mSize[1]));
height /= 2;
currentLocation.Y += height;
for (var i = 0; i < NumOptions; i++)
{
spriteBatch.Draw(_mItems[i], new Rectangle(_mScreenRect.Center.X - ((int)(_mItems[i].Width * mSize[0]) / 2), (int)currentLocation.Y, (int)(_mItems[i].Width * mSize[0]), (int)(_mItems[i].Height * mSize[1])), Color.White);
currentLocation.Y += (int)(_mItems[i].Height * mSize[1]);
}
spriteBatch.End();
}
示例13: RectangleProjection
public RectangleProjection(RectangleF rectangle, Matrix transform)
{
Vertices[0] = Vector2.Transform(rectangle.TopLeft, transform);
Vertices[1] = Vector2.Transform(rectangle.TopRight, transform);
Vertices[2] = Vector2.Transform(rectangle.BottomLeft, transform);
Vertices[3] = Vector2.Transform(rectangle.BottomRight, transform);
}
示例14: Transform
public void Transform()
{
// STANDART OVERLOADS TEST
var expectedResult1 = new Vector3(51, 58, 65);
var expectedResult2 = new Vector3(33, -14, -1);
var v1 = new Vector3(1, 2, 3);
var m1 = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
var v2 = new Vector3(1, 2, 3);
var q1 = new Quaternion(2, 3, 4, 5);
Vector3 result1;
Vector3 result2;
Assert.That(expectedResult1, Is.EqualTo(Vector3.Transform(v1, m1)).Using(Vector3Comparer.Epsilon));
Assert.That(expectedResult2, Is.EqualTo(Vector3.Transform(v2, q1)).Using(Vector3Comparer.Epsilon));
// OUTPUT OVERLOADS TEST
Vector3.Transform(ref v1, ref m1, out result1);
Vector3.Transform(ref v2, ref q1, out result2);
Assert.That(expectedResult1, Is.EqualTo(result1).Using(Vector3Comparer.Epsilon));
Assert.That(expectedResult2, Is.EqualTo(result2).Using(Vector3Comparer.Epsilon));
}
示例15: Draw
public override void Draw(GameTime gameTime)
{
Vector3 cameraPosition = MathConverter.Convert(_manager.Camera.Position);
Matrix[] transforms = new Matrix[_model.Bones.Count];
_model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in _model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
if (_texture != null)
{
effect.TextureEnabled = true;
effect.Texture = _texture;
}
effect.EnableDefaultLighting();
effect.Projection = MathConverter.Convert(_manager.Camera.ProjectionMatrix);
effect.View = MathConverter.Convert(_manager.Camera.ViewMatrix);
effect.World = Matrix.CreateScale(3000) * Matrix.CreateTranslation(cameraPosition.X, cameraPosition.Y, cameraPosition.Z);
}
mesh.Draw();
}
base.Draw(gameTime);
}