2011-10-06 3 views
1

모두 좋은 하루. 제 질문에 당신을 도울 수 있기를 바랍니다.XNA 4.0 회전/왜곡 된 텍스처 그리기

스프라이트를 변환하거나 직접 렌더링하는 방법이 있습니까?

example 3d를 사용하지 않고. 3d에서 쉽게 할 수 있다는 것을 알고 있지만, 제가 작업하고있는 프로젝트는 3d를 전혀 사용하지 않습니다. 그래서 작은 것 때문에 3d를 포함하고 싶지 않습니다.

(예제 이미지는 임의의 게임에서 가져온 것임)

기본적으로 내가 필요한 것 : 스프라이트를 사각형으로 만든 다음 자유롭게 변형하여 해당 스프라이트의 점을 임의의 좌표로 설정할 수 있습니다. 직사각형처럼.

미리 감사드립니다.

+0

[this] (http://forums.create.msdn.com/forums/t/37143.aspx) – dowhilefor

+0

dowhilefor을 살펴 보았습니다. 그 내용을 살펴 봤지만, 정확히 내가 필요한 것은 아닙니다 ... 또한 일반적인 해결책을 제시하지 못합니다. 그러나 어쨌든 고마워. – NewProger

답변

1

해당 이미지에 사용 된 기술은 레이 캐스팅 2d입니다. 그것은 wolfenstein 3d에서 처음 사용되었으며 2D에서 가짜 3D를 구현합니다. 이 당신이 원하는 것은 아니지만

여기 당신은 tutotial http://lodev.org/cgtutor/

을 찾을 수 있습니다.

원하는 것을 얻기위한 가장 좋은 방법은 두 개의 삼각형을 정의하고 그 기본 도형과 함께 GraphicsDevice.DrawUserPrimitives를 사용하는 것입니다.

// Init Triangles with four points A,B,C and D 

    VertexPOsitionTexture[] Vertex = new VertexPositionTexture[6]; 
    Vertex[0].Position = (A.X,A.Y,0); 
    Vertex[1].Position = (B.X,B.Y,0); 
    Vertex[2].Position = (C.X,C.Y,0); 
    Vertex[3].Position = (C.X,C.Y,0); 
    Vertex[4].Position = (B.X,B.Y,0); 
    Vertex[5].Position = (D.X,D.Y,0); 

    Vertex[0].Texture= (0,0); 
    Vertex[1].Texture= (1,0); 
    Vertex[2].Texture= (0,1); 
    Vertex[3].Texture= (0,1); 
    Vertex[4].Texture= (1,0); 
    Vertex[5].Texture= (1,1); 

    // Init Effect from http://blogs.msdn.com/b/shawnhar/archive/2010/04/05/spritebatch-and-custom-shaders-in-xna-game-studio-4-0.aspx 

    Matrix projection = Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1); 
    Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0); 


    BasicEffect effect = new BasicEffect(); 

    effect.Texture = your texture; 
    effect.TextureEnabled = true; 
    effect.World = Matrix.Identity; 
    effect.View = Matrix.Identity; 
    effect.Projection = halfPixelOffset * projection; 

    // Draw Triangles 
    effect.Apply(): 
    GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(vertex, TriangleList, ...,...); 

이 코드는 의사 코드로 이해해야하며 테스트되지는 않았지만 수행 할 관련 작업을 보여줍니다.

관련 문제