c++ - DirectX 11 Vertices Coordinates -
i'm working on first c++ , directx 11 project current goal draw colored triangle on screen. has worked without problems. however, there's 1 part change, don't know how. i've tried searching solution havn't found yet, , guess reason because don't know should search for.
currently set triangles 3 vertices this:
vertexpos vertices[] = { { xmfloat3( 0.5f, 0.5f, 1.0f )}, { xmfloat3( 0.5f, -0.5f, 1.0f )}, { xmfloat3( -0.5f, -0.5f, 1.0f )}, }
where vertexpos defined this:
struct vertexpos { xmfloat3 pos; };
currenty, vertices position set range -1.0f 1.0f, 0.0f center. how can change can position vertices using "real" coordinates this:
vertexpos vertices[] = { { xmfloat3( 100.0f, 300.0f, 1.0f )}, { xmfloat3( 200.0f, 200.0f, 1.0f )}, { xmfloat3( 200.0f, 300.0f, 1.0f )}, }
usual way:
- create orthogonal projection matrix (
xmmatrixorthographiclh()
if using xmmath) - create constant buffer matrix on cpu side (c++ code) , on gpu size (vertex shader)
- multiply vertex positions orthogonal projection matrix in vertex shader
- create orthogonal projection matrix (
simpler way (from f.luna book):
xmfloat3 spritebatch::pointtondc(int x, int y, float z) { xmfloat3 p; p.x = 2.0f*(float)x/mscreenwidth - 1.0f; p.y = 1.0f - 2.0f*(float)y/mscreenheight; p.z = z; return p; }
almost same, on cpu side. of course, can move code shader too.
p.s. book/manual/tutorials learn little later. so, better trust , flow step-by step.
happy coding! =)
Comments
Post a Comment