
[ad_1]
Whenever I appear to create a rotation matrix or attempt to zoom, the meshes that I draw to the display screen get stretched and distorted.
I’ve tried to make a easy rotation matrix like this:
Matrix remodel = Matrix.CreateRotationZ(MathHelper.ToRadians(ang))
And then I do that once I make the vertices:
verts[i].Position = Vector3.Transform(verts[i].Position, remodel);
And it does rotate it, nevertheless it additionally will get stretched on the identical time.
Similarly, I made a easy Camera class:
utilizing Microsoft.Xna.Framework;
utilizing Microsoft.Xna.Framework.Graphics;
utilizing Microsoft.Xna.Framework.Input;
utilizing System;
utilizing System.Collections.Generic;
namespace _04_texturedquad
{
public class Camera
{
public Vector2 place {get; personal set;}
public Matrix ortho;
float zoom;
public float rotation;
Viewport viewport;
public Camera(Viewport v)
{
this.viewport = v;
ortho = Matrix.CreateOrthographicOffCenter(
0,
viewport.Width,
0,
viewport.Height,
0, 1);
}
public void Move(Vector2 vec)
{
this.place += vec;
Update();
}
public void Zoom(float quantity)
{
zoom += quantity;
Update();
}
public void SetPosition(Vector2 vec)
{
this.place = vec;
}
public void Update()
{
ortho = Matrix.CreateOrthographicOffCenter(
0 + place.X - zoom,
viewport.Width + place.X + zoom,
0 + place.Y - zoom,
viewport.Height + place.Y + zoom,
0, 1);
}
}
}
And shifting round works, however once I zoom, it does zoom, nevertheless it additionally will get stretched vertically once I accomplish that.
Here’s what I’m doing when I’m sending the buffers to the GPU:
public void Draw()
{
RasterizerState rs = new RasterizerState();
recreation.GraphicsSystem.RasterizerState = rs;
impact.Projection = c.ortho;
foreach (EffectPass cross in impact.CurrentTechnique.Passes)
{
cross.Apply();
recreation.GraphicsSystem.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _vertices, 0, _vertices.Length, _indices, 0, _indices.Length / 3, VertexPositionShade.VertexDeclaration);
}
}
I’ve additionally tried setting impact.View = Matrix.Identity, however that hasn’t labored both.
Why does every part get distorted once I zoom/rotate? I do not assume this can be a drawback with how I’m making the meshes, as a result of they appear superb in any other case.
[ad_2]