【问题标题】:XNA 2D World reflection on x-axisXNA 2D 世界在 x 轴上的反射
【发布时间】:2013-08-29 16:18:29
【问题描述】:

我试图在 x 轴上反映我的游戏世界。 我有一个相机,它计算变换矩阵:

        _transform =
                    Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *                        
                    Matrix.CreateRotationZ(Rotation) *                        
                    Matrix.CreateScale(Zoom) *
                    Matrix.CreateTranslation(new Vector3(_graphicsDevice.Viewport.Width * 0.5f, _graphicsDevice.Viewport.Height * 0.5f, 0));

它工作正常,直到我放一个反射部分:

        _transform = //first try, place here
                    Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *                        
                    Matrix.CreateRotationZ(Rotation) *                        
                    Matrix.CreateScale(Zoom) *
                    Matrix.CreateReflection(new Plane(Vector3.UnitY, 0)) * //here
                    Matrix.CreateTranslation(new Vector3(_graphicsDevice.Viewport.Width * 0.5f, _graphicsDevice.Viewport.Height * 0.5f, 0));

有了那个“反思”

spriteBatch.Begin(SpriteSortMode.BackToFront,
                    BlendState.AlphaBlend,
                    null,
                    null,
                    null,
                    null,
                    Camera.Active.GetTransformation);

什么都不画。 请帮助并为我的英语感到抱歉:)


UPD:我做了一些测试:

var v = new Vector2(0, 10);
var v2 = Vector2.Transform(v, _transform);

没有 .CreateReflection v2 = {X:450 Y:370}
with .CreateReflection v2 = {X:450 Y:350} //好的。它反映了。但是,为什么不画呢?

【问题讨论】:

  • 你是在画图元还是精灵?
  • 你能复制你用来正常绘制精灵的代码并反射同一个精灵吗?
  • 查看 1 个回答下的评论

标签: c# xna 2d transform


【解决方案1】:

使用带有 X 否定的刻度应该可以完成这项工作:

    _transform = //first try, place here
                Matrix.CreateTranslation(new Vector3(-_pos.X, -_pos.Y, 0)) *                        
                Matrix.CreateRotationZ(Rotation) *                        
                Matrix.CreateScale(Zoom) *
                Matrix.CreateScale(-1,1,1) * //here
                Matrix.CreateTranslation(new Vector3(_graphicsDevice.Viewport.Width * 0.5f, _graphicsDevice.Viewport.Height * 0.5f, 0));

【讨论】:

  • 谢谢,好主意,但它没有解决我的问题。我做错了什么?在 Game.Update() 中我调用 Camera.Active.Update(gameTime); //(where _transform calculates) 在 Game.Draw() 中我调用 spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, Camera.Active.GetTransformation); foreach (var body in bodies) spriteBatch.DrawCircle(body.Position, Radius, 20, Color);
  • DrawCircle 扩展可能有问题?它使用:spriteBatch.Draw(pixel, point, null, color, angle, Vector2.Zero, new Vector2(length, thickness), SpriteEffects.None, 0);
  • 您必须确保每个 spritebatch.Begin 都以相机变换作为参数调用其完成...没有观看更多代码或屏幕截图与问题有关,我不知道要解决什么跨度>
  • aaahhh... 我已经编辑了答案以使 Scale = (-1,1,1) 不是 (-1,0,0) 这是非常错误的...
  • 您必须将 RasterizerState.CullNone 添加到 spritebatch.Begin
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-09-30
  • 1970-01-01
  • 1970-01-01
  • 2017-07-11
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
相关资源
最近更新 更多