1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
void Render()
{
//Update our time
static float t = 0.0f;
if ( g_driverType == D3D_DRIVER_TYPE_REFERENCE )
{
t += ( float )XM_PI * 0.0125f;
}
else
{
static ULONGLONG timeStart = 0;
ULONGLONG timeCur = GetTickCount64();
if (timeStart == 0)
timeStart = timeCur;
t = (timeCur - timeStart) / 1000.0f;
}
//
// Animate the cube
//
//g_World = XMMatrixRotationY( t );
//
// Clear the back buffer
//
g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, Colors::MidnightBlue );
//g_pImmediateContext->ClearDepthStencilView( g_depthView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0 );
//
// Update variables
//
ConstantBuffer cb;
//cb.mWorld = cube1;
cb.mWorld = XMMatrixTranspose( cube1 );
cb.mView = XMMatrixTranspose( g_View );
cb.mProjection = XMMatrixTranspose( g_Projection );
g_pImmediateContext->UpdateSubresource( g_pConstantBuffer, 0, nullptr, &cb, 0, 0 );
//
// Draws first square
//
g_pImmediateContext->VSSetShader(g_pVertexShader, nullptr, 0);
g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_pConstantBuffer);
g_pImmediateContext->PSSetShader(g_pPixelShader, nullptr, 0);
g_pImmediateContext->DrawIndexed(36, 0, 0); //36 vertices needed for 12 triangles in a triangle list
ConstantBuffer cb2;
//cb2.mWorld = cube2;
cb2.mWorld = XMMatrixTranspose(cube2);
cb2.mView = XMMatrixTranspose(g_View);
cb2.mProjection = XMMatrixTranspose(g_Projection);
g_pImmediateContext->UpdateSubresource(g_pConstantBuffer, 0, nullptr, &cb2, 0, 0);
// g_pImmediateContext->VSSetShader(g_pVertexShader, nullptr, 0);
// g_pImmediateContext->VSSetConstantBuffers(0, 1, &g_pConstantBuffer);
// g_pImmediateContext->PSSetShader(g_pPixelShader, nullptr, 0);
g_pImmediateContext->DrawIndexed(36, 0, 0);
//cube1 = XMMatrixIdentity();
//
// Present our back buffer to our front buffer
//
g_pSwapChain->Present( 0, 0 );
}
void Update()
{
rot += 0.0005f;
if (rot > 6.26f)
rot = 0.0f;
cube1 = XMMatrixIdentity();
XMVECTOR rotaxis = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
Rotation = XMMatrixRotationAxis(rotaxis, rot);
Translation = XMMatrixTranslation(1.0f, 1.0f, 0.0f);
cube1 = Translation * Rotation;
cube2 = XMMatrixIdentity();
Rotation = XMMatrixRotationAxis(rotaxis, -rot);
Scale = XMMatrixScaling(0.5f, 0.5f, 0.5f);
cube2 = Scale;
}
|