0

I am experimenting with different matrices, studying their effect on a textured quad. So far I have implemented Scaling, Rotation, and Translation matrices fairly easily - by using the following method against my position vectors:

enter code here
        for(int a=0;a<noOfVertices;a++)
        {
            myVectorPositions[a] = SlimDX.Vector3.TransformCoordinate(myVectorPositions[a],myPerspectiveMatrix);
        }

However, I what I want to do is be able to position my vectors using world-space coordinates, not object-space.

At the moment my position vectors are declared thusly:

enter code here
        myVectorPositions[0] = new Vector3(-0.1f, 0.1f, 0.5f);
        myVectorPositions[1] = new Vector3(0.1f, 0.1f, 0.5f);
        myVectorPositions[2] = new Vector3(-0.1f, -0.1f, 0.5f);
        myVectorPositions[3] = new Vector3(0.1f, -0.1f, 0.5f);

On the other hand (and as part of learning about matrices) I have read that I need to apply a matrix to get to screen coordinates. I've been looking through the SlimDX API docs and can't seem to pin down the one I should be using.

In any case, hopefully the above makes sense and what I am trying to achieve is clear. I'm aiming for a simple 1024 x 768 window as my application area, and want to position a my textured quad at 10,10. How do I go about this? Most confused right now.

4

2 に答える 2

1

私は Slimdx には詳しくありませんが、ネイティブ DirectX では、画面座標でクワッドを描画する場合は、頂点形式を Translated として定義する必要があります。つまり、D3D 変換エンジンを使用して頂点を変換する代わりに、画面座標を直接指定します。 . 以下の頂点定義

#define SCREEN_SPACE_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

そして、このように頂点を定義できます

ScreenVertex Vertices[] =
{
    // Triangle 1
    { 150.0f, 150.0f, 0, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
    { 350.0f, 150.0f, 0, 1.0f, 0xff00ff00, },
    { 350.0f, 350.0f, 0, 1.0f, 0xff00ffff, },

    // Triangle 2
    { 150.0f, 150.0f, 0, 1.0f, 0xffff0000, }, 
    { 350.0f, 350.0f, 0, 1.0f, 0xff00ffff, },
    { 150.0f, 350.0f, 0, 1.0f, 0xff00ffff, },
};
于 2012-09-08T02:41:37.797 に答える
1

3D システムのデフォルトの画面スペースは -1 から 1 です (-1,-1 は左下隅、1,1 は右上隅です)。

これらの単位をピクセル値に変換するには、ピクセル値をこの空間に変換する必要があります。たとえば、1024*768 の画面上のピクセル 10,30 は次のようになります。

 position.x = 10.0f * (1.0f / 1024.0f); // maps to 0/1
 position.x *= 2.0f; //maps to 0/2
 position.x -= 1.0f; // Maps to -1/1

今、あなたはそうします

 position.y = 30.0f * (1.0f / 768.0f); // maps to 0/1
 position.y = 1.0f - position.y; //Inverts y
 position.y *= 2.0f; //maps to 0/2
 position.y -= 1.0f; // Maps to -1/1

また、クワッドに変換を適用する場合は、頂点で乗算を行うよりも、シェーダーに変換を送信する (頂点シェーダーでベクトル変換を行う) 方が良いでしょう。これは、頂点を更新する必要がないためです。毎回頂点バッファ。

于 2012-09-21T13:34:27.313 に答える