3D objects key rendering steps
Key steps of Rendering objects:
1 Create objects’ meshes, which we can use C++’s vector container to hold them. They just some points structures, and indices(represented by int). Knowing exact what they are can demystify them.
2 Set up transformation matrixes: world matrix, view matrix, and projection matrix.
1) World matrix is identity matrix;
2) View matrix is caculated with three matrix, which can be done with one intrinsic function in DirectX:
// Build the view matrix. XMVECTOR pos = XMVectorSet(x, y, z, 1.0f); XMVECTOR target = XMVectorZero(); XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); XMMATRIX V = XMMatrixLookAtLH(pos, target, up);
3) Projection matrix, which is also called perspective projection matrix, can be calculated with one intrinsic function in DirectX, too:
XMMATRIX P = XMMatrixPerspectiveFovLH(0.25f*MathHelper::Pi, AspectRatio(), 1.0f, 1000.0f);
The math behind them can be very complicated. And sometime we may need to know them to perfrom some specific effects.
If we want to move our objects to some specific position and have specific orientation, we can use RST(rotation matrix, scaling matrix, and translation matrix) to transform our objects. And we can multiply RST with world matrix, like this: W = W*RST; and then use the new W as other non-transformed objects.
3 Create buffers to hold, majorly, vertice and indices, we call them vertics buffer and indices buffer, and then we must bind the buffers to our drawing context, so that our DirectX know what to draw.
4 Remember to set up our vertex layout, which mean we have to specify how to arrange our vertices, is it a vertex with color, normal, or even with texture coordinate? We have to make every thing crystal clear, otherwise computer just never know how to do it.
5 We have to watch out what variabl we have to set up in Shaders. We can achive it by dividing it into three steps:1) Create effect
2) Get techniques names and variables names
3) Set up these variables’ values with their names
The five step should be the key things tokeep in mind when we need to do rendering.
One more things to notices is:
The object(like a simple sphere) meshes we created by hand is essentially the same thing as modle meshes created by artisets. They record vertices’ position, normal, color and so on. One major different point between them would be molde meshes created by artisets with modle software, like 3DSMax, Maya and so forth, is more complicated than the simple shpere meshes we created, with more informations inside the modle files(like obj, x files).