Hello everyone,
I am sorry for disturbation!
I really don’t understand why does my rect make half than it happens like crazy. How do I fix if I want make
But for me only vertices…
// EDIT:
My result:
This is Maths.cs
using Microsoft.Xna.Framework;
namespace MyTransformation
{
public class Maths
{
public static Matrix CreateTransformationMatrix(Vector3 position, float rotX, float rotY, float rotZ, float rescale)
{
Matrix translation = Matrix.CreateTranslation(position);
Matrix rotationX = Matrix.CreateRotationX(rotX);
Matrix rotationY = Matrix.CreateRotationY(rotY);
Matrix rotationZ = Matrix.CreateRotationZ(rotZ);
Matrix scale = Matrix.CreateScale(rescale);
Matrix transformation = translation * rotationX * rotationY * rotationZ * scale;
return transformation;
}
}
}
This is Entity.cs
using Microsoft.Xna.Framework;
namespace MyTransformation
{
public class Entity : GameComponent
{
private Game game;
private Vector3 position;
private float rotX;
private float rotY;
private float rotZ;
private float scale;
public Entity(Game game, Vector3 position, float rotX, float rotY, float rotZ, float scale) : base(game)
{
this.game = game;
this.position = position;
this.rotX = rotX;
this.rotY = rotY;
this.rotZ = rotZ;
this.scale = scale;
}
public void IncreasePosition(float distanceX, float distanceY, float distanceZ)
{
position.X += distanceX;
position.Y += distanceY;
position.Z += distanceZ;
}
public void IncreaseRotation(float distRotX, float distRotY, float distRotZ)
{
rotX += distRotX;
rotY += distRotY;
rotZ += distRotZ;
}
public void IncreaseScale(float distScale)
{
scale += distScale;
}
public virtual Game Instance
{
get
{
return game;
}
set
{
game = value;
}
}
public virtual Vector3 Position
{
get
{
return position;
}
set
{
position = value;
}
}
public virtual float RotX
{
get
{
return rotX;
}
set
{
rotX = value;
}
}
public virtual float RotY
{
get
{
return rotY;
}
set
{
rotY = value;
}
}
public virtual float RotZ
{
get
{
return rotZ;
}
set
{
rotZ = value;
}
}
public virtual float Scale
{
get
{
return scale;
}
set
{
scale = value;
}
}
}
}
Game1.cs
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace MyTransformation
{
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
VertexBuffer vertexBuffer;
IndexBuffer indexBuffer;
VertexPositionTexture[] vertices;
BasicEffect basicEffect;
Effect effect;
Texture2D exampleTex;
Entity entity;
Matrix transform;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
Window.Title = "Transformating triangles";
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
basicEffect = new BasicEffect(GraphicsDevice);
effect = Content.Load<Effect>("Shader");
VertexPositionTexture[] vertices = new VertexPositionTexture[4];
vertices[0] = new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0f), new Vector2(0, 0));
vertices[1] = new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0f), new Vector2(0, 1));
vertices[2] = new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0f), new Vector2(1, 1));
vertices[3] = new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0f), new Vector2(1, 0));
vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionTexture), 6, BufferUsage.WriteOnly);
vertexBuffer.SetData<VertexPositionTexture>(vertices);
exampleTex = Content.Load<Texture2D>("example");
entity = new Entity(this, new Vector3(0, 0, 0), 0, 0, 0, 1);
short[] indices = new short[6];
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 2; indices[4] = 3; indices[5] = 0;
indexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(short), indices.Length, BufferUsage.WriteOnly);
indexBuffer.SetData(indices);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
transform = Matrix.Identity;
transform = Maths.CreateTransformationMatrix(entity.Position, entity.RotX, entity.RotY, entity.RotZ, entity.Scale);
//entity.IncreasePosition(0.002f, 0, 0);
entity.IncreaseRotation(0, 0.01f, 0);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.Projection = Matrix.Identity;
basicEffect.View = Matrix.Identity;
GraphicsDevice.SetVertexBuffer(vertexBuffer);
GraphicsDevice.Indices = indexBuffer;
RasterizerState rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = rasterizerState;
effect.CurrentTechnique = effect.Techniques["ShaderTesxture"];
effect.Parameters["WorldViewProjection"].SetValue(Matrix.Identity * transform);
effect.Parameters["xTexture"].SetValue(exampleTex);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indexBuffer.IndexCount / 3);
}
base.Draw(gameTime);
}
}
}
result: it looks like crazy
Do you remember that original texture is 8 x 8 tiles black / white
like this
Since my monogame with transformation looks like 4 x 8 like it is wrong. and it happens “replying mode” why does matrix not work like limited matrix?
How do I fix if I have already made normal texture length of width and height ( just same in vertices ) But it happens half of rectangle. Why does it happen? What is it wrong?
Edit I have fixed add transformationMat in Shader.fx than it won’t move translate only rotate???
Why does it not work if I use add float4x4 transformationMat
in VS-Function
float4x4 together = worldviewprojection * transformationMat;
Is it correct or wrong?`What do I fix? I need add more for shader or do not need shader?
I try with
float4x4 worldviewprojection =
{
{ 1, 0, 0, 0},
{ 0, 1, 0, 0},
{ 0, 0, 1, 0},
{ 0, 0, 0, 1}
}
And it looks maniac
WHY IS RECTANGLE HALF???
Thank you for help and I appreciate that.