Game Development Reference
In-Depth Information
This sky node needs five textures: one each for the north, east, south, west, and top
sides of the box. The texture base name sent into the constructor lets a programmer
set a base name, like
and the textures that are actually
read append side name suffixes to the actual texture filename. You
Daytime
or
Nighttime,
ll see how this is
used in the VRender() method. VOnRestore() creates the vertex and index buffers
for the skybox. To do this, two triangles are created from four vertices, and then they
are transformed to make the four other sides. First, a 90-degree rotation around the
vertical makes the east, south, and west sides of the box. Then a 90-degree rotation
around the horizontal creates the top side.
'
HRESULT SkyNode::VOnRestore(Scene *pScene)
{
HRESULT hr;
V_RETURN (SceneNode::VOnRestore(pScene) );
SAFE_RELEASE(m_pVertexBuffer);
SAFE_RELEASE(m_pIndexBuffer);
V_RETURN (m_VertexShader.OnRestore(pScene) );
V_RETURN (m_PixelShader.OnRestore(pScene) );
m_numVerts = 20;
// Fill the vertex buffer. We are setting the tu and tv texture
// coordinates, which range from 0.0 to 1.0
D3D11Vertex_UnlitTextured *pVertices =
GCC_NEW D3D11Vertex_UnlitTextured[m_numVerts];
GCC_ASSERT(pVertices &&
Out of memory in D3DSkyNode11::VOnRestore()
);
if (!pVertices)
return E_FAIL;
D3D11Vertex_UnlitTextured skyVerts[4];
D3DCOLOR skyVertColor = 0xffffffff;
float dim = 50.0f;
skyVerts[0].Pos = Vec3( dim, dim, dim ); skyVerts[0].Uv = Vec2 (1.0f, 0.0f);
skyVerts[1].Pos = Vec3(-dim, dim, dim ); skyVerts[1].Uv = Vec2 (0.0f, 0.0f);
skyVerts[2].Pos = Vec3( dim,-dim, dim ); skyVerts[2].Uv = Vec2 (1.0f, 1.0f);
skyVerts[3].Pos = Vec3(-dim,-dim, dim ); skyVerts[3].Uv = Vec2(0.0f, 1.0f);
Vec3 triangle[3];
triangle[0] = Vec3(0.f,0.f,0.f);
triangle[1] = Vec3(5.f,0.f,0.f);
triangle[2] = Vec3(5.f,5.f,0.f);
Search WWH ::




Custom Search