Guten Abend,
ich versuche einen eigenen SpriteBatch der stark optimiert wurde zu entwickeln.
Klappt _ alles gut, problematisch jedoch die Rotation.
Um eine zweidimensionale Projektion zu ermöglichen nutze ich Matrix.CreateOrthographic :
Es funktioniert zwar, es ist aber nicht möglich das damit projizierte Sprite zu rotieren.
Ein Sprite wird durch die Klasse
generiert.
rotiert nicht die Vertices, sondern verschiebt diese nur eben auf einer Kreisbahn.
Ferner wird keine Transformation durchgeführt wenn die Position (0,0) beträgt.
Wie ist es möglich den Sprite zu rotieren ( nicht auf einer Kreisbahn, sondern eben die ganze Figur), selbst dann, wenn die Position ein Nullvektor ist?
Lieben, lieben dank!
ich versuche einen eigenen SpriteBatch der stark optimiert wurde zu entwickeln.
Klappt _ alles gut, problematisch jedoch die Rotation.
Um eine zweidimensionale Projektion zu ermöglichen nutze ich Matrix.CreateOrthographic :
C#-Quellcode
- _effect.View = Matrix.CreateLookAt(new Vector3(__center, 0), new Vector3(__center, 1), new Vector3(0, 1, 0)); ;
- _effect.World =( Matrix.CreateScale(AbsoluteTextureSizeWidth, AbsoluteTextureSizeHeight, 1) * Matrix.CreateTranslation(GraphicsDevice.Viewport.Width - (AbsoluteTextureSizeWidth), GraphicsDevice.Viewport.Height - (AbsoluteTextureSizeHeight), 0)) * _manipulation;
- _effect.Projection = Matrix.CreateOrthographic(__center.X * 2, __center.Y * 2, -0.5f, 1000);
Es funktioniert zwar, es ist aber nicht möglich das damit projizierte Sprite zu rotieren.
Ein Sprite wird durch die Klasse
C#-Quellcode
- public class Sprite
- {
- public VertexPositionTexture[] Vertices = new VertexPositionTexture[4];
- public short[] Indices = new short[6];
- public Sprite(SpriteBatchOptimized batch, Vector2 position, Matrix manipulation, Vector2 origin, float rotation, Vector2 texCoord)
- {
- // return Vector2.Transform(point - origin, Matrix.CreateRotationZ(rotation)) + origin;
- position = Vector2.Transform(position, Matrix.CreateRotationX(rotation));
- texCoord = new Vector2(texCoord.X * batch.RatioX, texCoord.Y * batch.RatioY);
- Vertices[0] = new VertexPositionTexture(new Vector3(position.X, position.Y, 0), new Vector2(0 + texCoord.X, batch.RatioY + texCoord.Y));
- Vertices[1] = new VertexPositionTexture(new Vector3(position.X + 1, position.Y, 0), new Vector2(batch.RatioX + texCoord.X, batch.RatioY + texCoord.Y));
- Vertices[2] = new VertexPositionTexture(new Vector3(position.X + 1, position.Y + 1, 0), new Vector2(batch.RatioX + texCoord.X, 0 + texCoord.Y));
- Vertices[3] = new VertexPositionTexture(new Vector3(position.X, position.Y + 1, 0), new Vector2(0 + texCoord.X, 0 + texCoord.Y));
- Indices[0] = (int)(0);
- Indices[1] = (int)(1);
- Indices[2] = (int)(2);
- Indices[3] = (int)(2);
- Indices[4] = (int)(3);
- Indices[5] = (int)(0);
- }
- }
generiert.
rotiert nicht die Vertices, sondern verschiebt diese nur eben auf einer Kreisbahn.
Ferner wird keine Transformation durchgeführt wenn die Position (0,0) beträgt.
Wie ist es möglich den Sprite zu rotieren ( nicht auf einer Kreisbahn, sondern eben die ganze Figur), selbst dann, wenn die Position ein Nullvektor ist?
Lieben, lieben dank!
Und Gott alleine weiß alles am allerbesten und besser.