XNA Rotate Texture 2D

时光怂恿深爱的人放手 提交于 2019-12-19 18:38:01

问题


I'd like to rotate a Texture in XNA. I know I can rotate it when it is drawn, but I would like the Texture2D variable to be the rotated texture. Is there any way to do this?


回答1:


Use RenderTarget, draw your texture rotated into the RenderTarget, take the texture and save it.




回答2:


You should provide a new shader that manage texture coords rotation. As the HLSL code of the basiceffect is public, it should be pretty easy to add this behaviour.

Basic Effect HLSL code

Passing an angle parameter to the shader, the transform should be:

 newU = U*cos(alfa) - V*sin(alfa);
 newV = U*sin(alfa) + V*cos(alfa);



回答3:


One way would be to pass a rotation matrix to your shader and multiply your texcoords by that before calling the texture sampler.

I'm not sure if XNA/DirectX has the same concept as OpenGL's texture matrix.



来源:https://stackoverflow.com/questions/7466418/xna-rotate-texture-2d

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!