Home > other >  The use of relevant D3D template
The use of relevant D3D template

Time:09-18

Using the template, in d as in a mirror, but the book to explain don't quite understand, z coordinates the mirror itself is 3.0 f, and explain said the plane mirror in z=3.0 f,
Vertex are []=
{
//box vertex -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
.

//after wall
.

//the mirror
{XMFLOAT3 (3.0 2.0 f, f, 3.0 f), XMFLOAT2 (2.0 f to 0.0 f)},
{XMFLOAT3 (2.0 f, f, 3.0 3.0 f), XMFLOAT2 (0.0 f to 0.0 f)},
{XMFLOAT3 (2.0 f, 1.0 f to 3.0 f), XMFLOAT2 (2.0 f to 3.0 f)},

{XMFLOAT3 (2.0 f, 1.0 f to 3.0 f), XMFLOAT2 (2.0 f to 3.0 f)},
{XMFLOAT3 (2.0 f, f, 3.0 3.0 f), XMFLOAT2 (0.0 f to 0.0 f)},
{XMFLOAT3 (2.0 f to 1.0 f to 3.0 f), XMFLOAT2 (0.0 f to 3.0 f)},

};
.
.
Paint in the mirror like the following
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2, draw a mirror template, here only fill the template don't draw color -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
World=XMMatrixIdentity ();
Effect - & gt; GetVariableByName (" World ") - & gt; AsMatrix () - & gt; SetMatrix ((float *) & amp; World);//set the world coordinate system
//prohibited in color and set the template buffer state
ImmediateContext - & gt; OMSetBlendState (noColorWriteBS BlendFactor, 0 XFFFFFFFF);//using NoColorWrite state, prohibited to write color
ImmediateContext - & gt; OMSetDepthStencilState (markMirrorDSS, 0 x1);//set up the corresponding template buffer state

Technique - & gt; GetPassByIndex (0) - & gt; Apply (0, immediateContext);
ImmediateContext - & gt; The Draw (6, 54);//draw the mirror, but here only fill the template, do not draw a mirror

//restore original Settings
ImmediateContext - & gt; OMSetBlendState (NULL, NULL, 0 XFFFFFFFF);
ImmediateContext - & gt; OMSetDepthStencilState (NULL, 0 x1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2, draw a mirror template, here only fill the template don't draw color -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3, wooden cases and draw the mirror floor -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
XMVECTOR refPlane=XMVectorSet (0. F, 0. F, - 3 f, 0.0 f);//the plane mirror: [0, 0, 3, 0]
XMMATRIX Reflect=XMMatrixReflect (refPlane);//by the coordinates of the mirror

//draw the mirror box
//as a result of reflection before the clockwise order vertex after reflection becomes counterclockwise, so need to temporarily counterclockwise as positive to render
ImmediateContext - & gt; RSSetState (counterClockFrontRS);
//set up the corresponding template buffer state
ImmediateContext - & gt; OMSetDepthStencilState (drawReflectionDSS, 0 x1);
world=XMMatrixIdentity ();
World=XMMatrixTranslation (0.0 f, f, 0.0-6.0 f) * Reflect;
Effect - & gt; GetVariableByName (" World ") - & gt; AsMatrix () - & gt; SetMatrix ((float *) & amp; World);//set the world coordinate system

//set box texture
Effect - & gt; GetVariableByName (" Texture ") - & gt; AsShaderResource () - & gt; SetResource (textureBox);
Technique - & gt; GetPassByIndex (0) - & gt; Apply (0, immediateContext);
ImmediateContext - & gt; The Draw (36, 0);//draw the mirror box

//draw the mirror floor
//set the texture of the floor
Effect - & gt; GetVariableByName (" Texture ") - & gt; AsShaderResource () - & gt; SetResource (textureFloor);
Technique - & gt; GetPassByIndex (0) - & gt; Apply (0, immediateContext);
ImmediateContext - & gt; The Draw (6, 36);//draw the pool, the second parameter from the 36th vertex array (start from 0) vertex start drawing

//recovery state
ImmediateContext - & gt; RSSetState (NULL);
ImmediateContext - & gt; OMSetDepthStencilState (NULL, 0 x1);
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3, wooden cases and draw the mirror floor -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4, mixed mirror, wooden cases and the texture of the floor after drawing the mirror -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
ImmediateContext - & gt; OMSetBlendState (blendStateAlpha BlendFactor, 0 XFFFFFFFF);//open mixed
ImmediateContext - & gt; RSSetState (NoCullRS);//off on the back of the blanking
World=XMMatrixIdentity ();
Effect - & gt; GetVariableByName (" World ") - & gt; AsMatrix () - & gt; SetMatrix ((float *) & amp; World);//set the world coordinate system
Effect - & gt; GetVariableByName (" Texture ") - & gt; AsShaderResource () - & gt; SetResource (textureMirror);//set the texture of the mirror
Technique - & gt; GetPassByIndex (0) - & gt; Apply (0, immediateContext);
ImmediateContext - & gt; The Draw (6, 54);//draw the mirror, the second parameter from the 36th vertex array (start from 0) vertex start drawing
ImmediateContext - & gt; OMSetBlendState (0, 0 XFFFFFFFF);//close mixed, remember that the last must be closed mixed
ImmediateContext - & gt; RSSetState (0);//recovery on the back of the blanking
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4, mixed mirror, wooden cases and the texture of the floor after drawing the mirror -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Plus later translation matrix to get results, such as the code on the red font mark, I don't understand why this change, to solve the

CodePudding user response:

Because in your mirror (0,0,3,0), so if your mirror as the camera, the original origin will transform to (0, 0, 3, 0).
  • Related