简体   繁体   English

XNA 2D世界在x轴上的反射

[英]XNA 2D World reflection on x-axis

I'm trying to reflect my game world on the x-axis. 我试图在x轴上反映我的游戏世界。 I have a camera, which calculate transform matrix: 我有一个摄像头,可以计算变换矩阵:

        _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));

It works fine, until I put a reflection part: 正常工作,直到我放入反射部分:

        _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));

With that "reflection" 有了这种“反思”

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

draw nothing. 什么也没画。 Please, help and sorry for my english :) 请帮忙,对不起我的英语:)


UPD : I have made some tests: UPD :我做了一些测试:

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

without .CreateReflection v2 = {X:450 Y:370} 没有.CreateReflection v2 = {X:450 Y:370}
with .CreateReflection v2 = {X:450 Y:350} //okay. 使用.CreateReflection v2 = {X:450 Y:350} //可以。 it's reflected. 它反映了。 but, why it dont drawing? 但是,为什么不绘图呢?

Using a scale with the X negated should do the job: 在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));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM