3

SpriteBatch とカスタム描画頂点を並行して XNA を使用しています。目標は、両方の手法で同じ座標系を使用することです。つまり、画面座標にマップする射影行列が必要です。(0, 0) は画面の左上隅にあり、幅と高さは画面の解像度によって決まります。

Matrix.CreateOrthographicOffCenter(0, width, 0, height, -1, 1);

うまく機能しますが、中央が左下隅にあります。

Matrix.CreateOrthographicOffCenter(0, width, height, 0, -1, 1);

何も表示されません。

最初の射影行列を平行移動と組み合わせて y を -1 でスケーリングしようとしても、何も表示されません。正の値によるスケーリングはうまく機能し、変換も同様です。しかし、負の値でスケーリングするとすぐに、出力がまったく得られません。

何か案は?

PS: テスト目的で、画面座標をはるかに超えて頂点を描画しているため、翻訳にエラーがある場合は少なくとも何かが表示されます。

4

1 に答える 1

4

このコードを使用して、線を描画するために 2D カメラを初期化し、基本的なカスタム効果を使用して描画します。

    Vector2 center;
    center.X = Game.GraphicsDevice.Viewport.Width * 0.5f;
    center.Y = Game.GraphicsDevice.Viewport.Height * 0.5f;

    Matrix View = Matrix.CreateLookAt( new Vector3( center, 0 ), new Vector3( center, 1 ), new Vector3( 0, -1, 0 ) );
    Matrix Projection = Matrix.CreateOrthographic( center.X * 2, center.Y * 2, -0.5f, 1 );

効果

uniform float4x4 xWorld;
uniform float4x4 xViewProjection;

void VS_Basico(in float4 inPos : POSITION,  in float4 inColor: COLOR0,  out float4      outPos: POSITION,    out float4 outColor:COLOR0 )
{
    float4 tmp = mul (inPos, xWorld);
    outPos = mul (tmp, xViewProjection);
    outColor = inColor; 
}

technique Lines
{
    pass Pass0
    {   
        VertexShader = compile vs_2_0 VS_Basico();
        FILLMODE = SOLID;
        CULLMODE = NONE;        
    }  
}
于 2011-08-31T09:30:12.050 に答える