Game Development Reference
In-Depth Information
'
might be a good idea to get out the graph paper. To be honest, that
s how I created
this code in the first place!
The real trick to making the sky node special is the code inside VPreRender() :
HRESULT SkyNode::VPreRender(Scene *pScene)
{
Vec3 cameraPos = m_camera->VGet()->ToWorld().GetPosition();
Mat4x4 mat = m_Props.ToWorld();
mat.SetPosition(cameraPos);
VSetTransform(&mat);
return SceneNode::VPreRender(pScene);
}
This code grabs the camera position and moves the sky node exactly as the camera
moves. This gives a completely convincing illusion that the objects like sun, moon,
mountains, and other backgrounds rendered into the sky textures are extremely far
away, since they don
t appear to move as the player moves.
The code to render the sky should look a little familiar, since you saw snippets of it at
the end of the previous chapter:
'
HRESULT D3DSkyNode11::VRender(Scene *pScene)
{
HRESULT hr;
V_RETURN (m_VertexShader.SetupRender(pScene) );
V_RETURN (m_PixelShader.SetupRender(pScene, this) );
// Set vertex buffer
UINT stride = sizeof( D3D11Vertex_UnlitTextured );
UINT offset = 0;
DXUTGetD3D11DeviceContext()->
IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &stride, &offset );
// Set index buffer
DXUTGetD3D11DeviceContext()->
IASetIndexBuffer( m_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );
// Set primitive topology
DXUTGetD3D11DeviceContext()->
IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
for (DWORD side = 0; side < m_sides; side++)
{
const char *suffix[] =
{
_n.jpg
,
_e.jpg
,
_s.jpg
,
_w.jpg
,
_u.jpg
};
Search WWH ::




Custom Search