changeset 10:292e534f00c2

Moved rendering into Bot/Environment; Started work on Gui system
author koryspansel <koryspansel@bendbroadband.com>
date Sat, 10 Sep 2011 23:52:12 -0700
parents e494c4295dba
children d80d06d5ff53
files LightClone/LightClone.vcproj LightClone/Source/Bot.cpp LightClone/Source/Camera.h LightClone/Source/CameraController.cpp LightClone/Source/CameraController.h LightClone/Source/Environment.cpp LightClone/Source/Environment.h LightClone/Source/GuiContainer.cpp LightClone/Source/GuiContainer.h LightClone/Source/GuiElement.cpp LightClone/Source/GuiElement.h LightClone/Source/InputManager.h LightClone/Source/Interface.cpp LightClone/Source/Interface.h LightClone/Source/RenderContext.cpp LightClone/Source/RenderContext.h LightClone/Source/World.cpp LightClone/Source/World.h
diffstat 18 files changed, 1015 insertions(+), 366 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/LightClone.vcproj	Sat Sep 10 23:52:12 2011 -0700
@@ -221,6 +221,14 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Source\GuiContainer.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Source\GuiElement.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\Source\InputManager.cpp"
 				>
 			</File>
@@ -323,6 +331,14 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Source\GuiContainer.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Source\GuiElement.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Source\InputManager.h"
 				>
 			</File>
--- a/LightClone/Source/Bot.cpp	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/Bot.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -368,7 +368,7 @@
 
 	uint32 nPasses = 0;
 
-	kContext.Apply(kCamera, pEffect);
+	kContext.ApplyCameraToEffect(kCamera, pEffect);
 
 	pEffect->SetTechnique(pEffect->GetTechnique(0));
 	pEffect->Begin(&nPasses, 0);
--- a/LightClone/Source/Camera.h	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/Camera.h	Sat Sep 10 23:52:12 2011 -0700
@@ -20,24 +20,14 @@
 	virtual ~Camera();
 
 	/*
-	 * GetLocation
+	 * GetProjection
 	 */
-	virtual const D3DXVECTOR3 GetLocation() const = 0;
+	virtual const D3DXMATRIX GetProjection(const D3DVIEWPORT9& kViewport) const = 0;
 
 	/*
-	 * GetDirection
-	 */
-	virtual const D3DXVECTOR3 GetDirection() const = 0;
-
-	/*
-	 * GetRight
+	 * GetView
 	 */
-	virtual const D3DXVECTOR3 GetRight() const = 0;
-
-	/*
-	 * GetUp
-	 */
-	virtual const D3DXVECTOR3 GetUp() const = 0;
+	virtual const D3DXMATRIX GetView() const = 0;
 };
 
 #endif //__CAMERA_H__
--- a/LightClone/Source/CameraController.cpp	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/CameraController.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -9,9 +9,21 @@
  */
 CameraController::CameraController(float fInitialDistance, float fInitialYaw, float fInitialPitch)
 {
+	nMode			= CameraMode_3D;
 	fCameraDistance	= fInitialDistance;
 	fCameraYaw		= fInitialYaw;
 	fCameraPitch	= fInitialPitch;
+	fViewAngle		= D3DX_PI / 4.0f;
+	fMinimumZ		= 1.0f;
+	fMaximumZ		= 1024.0f;
+}
+
+/*
+ * SetMode
+ */
+void CameraController::SetMode(uint32 nCameraMode)
+{
+	nMode = nCameraMode;
 }
 
 /*
@@ -80,3 +92,48 @@
 {
 	return D3DXVECTOR3(0.0f, 1.0f, 0.0f);
 }
+
+/*
+ * GetProjection
+ */
+const D3DXMATRIX CameraController::GetProjection(const D3DVIEWPORT9& kViewport) const
+{
+	D3DXMATRIX kProjection;
+
+	if(nMode == CameraMode_2D)
+	{
+		D3DXMatrixOrthoLH(&kProjection, (float)kViewport.Width, (float)kViewport.Height, fMinimumZ, fMaximumZ);
+	}
+	else 
+	
+	if(nMode == CameraMode_3D)
+	{
+		D3DXMatrixPerspectiveFovLH(&kProjection, fViewAngle, (float)kViewport.Width / (float)kViewport.Height, fMinimumZ, fMaximumZ);
+	}
+
+	return kProjection;
+}
+
+/*
+ * GetView
+ */
+const D3DXMATRIX CameraController::GetView() const
+{
+	D3DXMATRIX kView;
+
+	if(nMode == CameraMode_2D)
+	{
+		D3DXMatrixIdentity(&kView);
+	}
+	else 
+	
+	if(nMode == CameraMode_3D)
+	{
+		const D3DXVECTOR3& kLocation = GetLocation();
+		const D3DXVECTOR3& kUp		= GetUp();
+
+		D3DXMatrixLookAtLH(&kView, &kLocation, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &kUp);
+	}
+
+	return kView;
+}
--- a/LightClone/Source/CameraController.h	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/CameraController.h	Sat Sep 10 23:52:12 2011 -0700
@@ -9,6 +9,15 @@
 #include "Camera.h"
 
 /*
+ * CameraMode
+ */
+enum
+{
+	CameraMode_2D,
+	CameraMode_3D,
+};
+
+/*
  * CameraController
  */
 class CameraController : public Camera
@@ -16,6 +25,11 @@
 public:
 
 	/*
+	 * nMode
+	 */
+	uint32 nMode;
+
+	/*
 	 * fCameraDistance
 	 */
 	float fCameraDistance;
@@ -30,6 +44,21 @@
 	 */
 	float fCameraPitch;
 
+	/*
+	 * fViewAngle
+	 */
+	float fViewAngle;
+
+	/*
+	 * fMinimumZ
+	 */
+	float fMinimumZ;
+
+	/*
+	 * fMaximumZ
+	 */
+	float fMaximumZ;
+
 public:
 
 	/*
@@ -38,6 +67,11 @@
 	CameraController(float fInitialDistance = 16.0f, float fInitialYaw = 0.306f, float fInitialPitch = 0.875f);
 
 	/*
+	 * SetMode
+	 */
+	void SetMode(uint32 nCameraMode);
+
+	/*
 	 * Update
 	 */
 	void Update(float fElapsed);
@@ -60,22 +94,32 @@
 	/*
 	 * GetLocation
 	 */
-	virtual const D3DXVECTOR3 GetLocation() const;
+	const D3DXVECTOR3 GetLocation() const;
 
 	/*
 	 * GetDirection
 	 */
-	virtual const D3DXVECTOR3 GetDirection() const;
+	const D3DXVECTOR3 GetDirection() const;
 
 	/*
 	 * GetRight
 	 */
-	virtual const D3DXVECTOR3 GetRight() const;
+	const D3DXVECTOR3 GetRight() const;
 
 	/*
 	 * GetUp
 	 */
-	virtual const D3DXVECTOR3 GetUp() const;
+	const D3DXVECTOR3 GetUp() const;
+
+	/*
+	 * GetProjection
+	 */
+	virtual const D3DXMATRIX GetProjection(const D3DVIEWPORT9& kViewport) const;
+
+	/*
+	 * GetView
+	 */
+	virtual const D3DXMATRIX GetView() const;
 };
 
 #endif //__CAMERACONTROLLER_H__
--- a/LightClone/Source/Environment.cpp	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/Environment.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -3,20 +3,22 @@
  */
 
 #include "Environment.h"
+#include "VertexTypes.h"
 #include "Util.h"
-#include <windows.h>
 
 /*
  * Environment
  */
 Environment::Environment() : pGrid(0)
 {
-	nWidth		= 0;
-	nHeight		= 0;
-
-	kScale.x	= 1.0f;
-	kScale.y	= 0.4f;
-	kScale.z	= 1.0f;
+	pBlockEffect		= NULL;
+	pBlockVertexBuffer	= NULL;
+	pBlockTexture		= NULL;
+	nWidth				= 0;
+	nHeight				= 0;
+	kScale.x			= 1.0f;
+	kScale.y			= 0.4f;
+	kScale.z			= 1.0f;
 }
 
 /*
@@ -30,7 +32,53 @@
 /*
  * Initialize
  */
-ErrorCode Environment::Initialize(uint32 nGridWidth, uint32 nGridHeight)
+ErrorCode Environment::Initialize(ResourceManager* pResourceManager)
+{
+	ErrorCode eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\Environment.fx", &pBlockEffect);
+	if(eCode == Error_Success)
+	{
+		eCode = pResourceManager->CreateTextureFromFile("Data\\Textures\\Block02.tga", &pBlockTexture);
+		if(eCode == Error_Success)
+		{
+			eCode = pResourceManager->CreateVertexBuffer(VerticesPerBlock * sizeof(Vertex::Block), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pBlockVertexBuffer);
+			if(eCode == Error_Success)
+			{
+				eCode = SetupVertexBuffer();
+			}
+		}
+	}
+
+	return eCode;
+}
+
+/*
+ * Terminate
+ */
+void Environment::Terminate()
+{
+	if(pBlockVertexBuffer)
+	{
+		pBlockVertexBuffer->Release();
+		pBlockVertexBuffer = NULL;
+	}
+
+	if(pBlockTexture)
+	{
+		pBlockTexture->Release();
+		pBlockTexture = NULL;
+	}
+
+	if(pBlockEffect)
+	{
+		pBlockEffect->Release();
+		pBlockEffect = 0;
+	}
+}
+
+/*
+ * Setup
+ */
+ErrorCode Environment::Setup(uint32 nGridWidth, uint32 nGridHeight)
 {
 	if(pGrid)
 	{
@@ -57,6 +105,112 @@
 }
 
 /*
+ * Render
+ */
+void Environment::Render(RenderContext& kContext, Camera& kCamera)
+{
+	uint32 nPasses = 0;
+
+	kContext.ApplyCameraToEffect(kCamera, pBlockEffect);
+
+	pBlockEffect->SetTechnique(pBlockEffect->GetTechnique(0));
+	pBlockEffect->Begin(&nPasses, 0);
+	pBlockEffect->BeginPass(0);
+
+	D3DXMATRIX kScaleMatrix;
+	D3DXMatrixScaling(&kScaleMatrix, kScale.x, kScale.y, kScale.z);
+
+	//const D3DXMATRIX& kProjection	= kContext.GetProjection();
+	//const D3DXMATRIX& kView			= kContext.GetView();
+
+	D3DVIEWPORT9 kViewport;
+	kContext.GetViewport(&kViewport);
+
+	D3DXVECTOR3 kCenterWorld(0.0f, 0.0f, 0.0f);
+	const float fMagicOffset = 400.0f;
+	//const D3DXVECTOR3& kCenterWorld = ComputeOrigin(0.5f * (ScreenSizeX - (304.0f + fMagicOffset)), 0.5f * ScreenSizeY, kViewport, kProjection, kView);
+
+	const float fOffsetX	= -0.5f * (nWidth * kScale.x);
+	const float fOffsetZ	= -0.5f * (nHeight * kScale.z);
+
+	for(uint32 nZ = 0; nZ < nHeight; ++nZ)
+	{
+		for(uint32 nX = 0; nX < nWidth; ++nX)
+		{
+			uint32 nType	= GetType(nX, nZ);
+			uint32 nHeight	= GetAltitude(nX, nZ);
+			uint32 nState	= GetState(nX, nZ);
+			uint32 nColor	= D3DCOLOR_XRGB(0x80, 0x80, 0x80);
+
+			if(nType == 1)
+			{
+				nColor = nState ? D3DCOLOR_XRGB(0, 0, 255) : D3DCOLOR_XRGB(255, 0, 0);
+			}
+
+			for(uint32 i = 0; i < GetAltitude(nX, nZ); ++i)
+			{
+				D3DXMATRIX kTranslateMatrix;
+				D3DXMatrixTranslation(&kTranslateMatrix, fOffsetX + (kCenterWorld.x + nX) * kScale.x, i * kScale.y, fOffsetZ + (kCenterWorld.z + nZ) * kScale.z);
+
+				D3DXMATRIX kWorldMatrix;
+				D3DXMatrixMultiply(&kWorldMatrix, &kScaleMatrix, &kTranslateMatrix);
+
+				const float fAlpha	= ((nColor >> 24) & 0xFF) / 255.0f;
+				const float fRed	= ((nColor >> 16) & 0xFF) / 255.0f;
+				const float fGreen	= ((nColor >> 8 ) & 0xFF) / 255.0f;
+				const float fBlue	= ((nColor >> 0 ) & 0xFF) / 255.0f;
+
+				const D3DXVECTOR4 kColorVector(fRed, fGreen, fBlue, fAlpha);
+
+				pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
+				pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
+				pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), pBlockTexture);
+				pBlockEffect->CommitChanges();
+
+				kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace);
+			}
+		}
+	}
+
+	pBlockEffect->EndPass();
+	pBlockEffect->End();
+
+	if(false) // wireframe
+	{
+		pBlockEffect->SetTechnique(pBlockEffect->GetTechniqueByName("Wire"));
+		pBlockEffect->Begin(&nPasses, 0);
+		pBlockEffect->BeginPass(0);
+
+		for(uint32 nZ = 0; nZ < nHeight; ++nZ)
+		{
+			for(uint32 nX = 0; nX < nWidth; ++nX)
+			{
+				for(uint32 i = 0; i < GetAltitude(nX, nZ); ++i)
+				{
+					D3DXMATRIX kTranslateMatrix;
+					D3DXMatrixTranslation(&kTranslateMatrix, nX * kScale.x, i * kScale.y, nZ * kScale.z);
+
+					D3DXMATRIX kWorldMatrix;
+					D3DXMatrixMultiply(&kWorldMatrix, &kScaleMatrix, &kTranslateMatrix);
+
+					const D3DXVECTOR4 kColorVector(0.0f, 0.0f, 0.0f, 1.0f);
+
+					pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
+					pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
+					pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), pBlockTexture);
+					pBlockEffect->CommitChanges();
+
+					kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace);
+				}
+			}
+		}
+
+		pBlockEffect->EndPass();
+		pBlockEffect->End();
+	}
+}
+
+/*
  * GetWidth
  */
 uint32 Environment::GetWidth() const
@@ -241,4 +395,68 @@
 	}
 
 	return true;
+}
+
+/*
+ * SetupVertexBuffer
+ */
+ErrorCode Environment::SetupVertexBuffer()
+{
+	Vertex::Block* pVertices = NULL;
+	
+	HRESULT hResult = pBlockVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
+	if(FAILED(hResult))
+	{
+		return Error_Fail;
+	}
+
+	const float fU1	= 0.66f;
+	const float fV1 = 0.66f;
+
+	// front
+	pVertices[0]	= Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f);
+	pVertices[1]	= Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 0.66f);
+	pVertices[2]	= Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f);
+	pVertices[3]	= Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f);
+	pVertices[4]	= Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f);
+	pVertices[5]	= Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 1.00f);
+	// back
+	pVertices[6]	= Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f);
+	pVertices[7]	= Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 0.66f);
+	pVertices[8]	= Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f);
+	pVertices[9]	= Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f);
+	pVertices[10]	= Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f);
+	pVertices[11]	= Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 1.00f);
+	// left
+	pVertices[12]	= Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
+	pVertices[13]	= Vertex::Block(-0.5f, 1.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 0.66f);
+	pVertices[14]	= Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
+	pVertices[15]	= Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
+	pVertices[16]	= Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
+	pVertices[17]	= Vertex::Block(-0.5f, 0.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 1.00f);
+	// right
+	pVertices[18]	= Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
+	pVertices[19]	= Vertex::Block(+0.5f, 1.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 0.66f);
+	pVertices[20]	= Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
+	pVertices[21]	= Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
+	pVertices[22]	= Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
+	pVertices[23]	= Vertex::Block(+0.5f, 0.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 1.00f);
+	// top
+	pVertices[24]	= Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f);
+	pVertices[25]	= Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.00f);
+	pVertices[26]	= Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f);
+	pVertices[27]	= Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f);
+	pVertices[28]	= Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f);
+	pVertices[29]	= Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.66f);
+	// bottom
+	pVertices[30]	= Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f);
+	pVertices[31]	= Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.00f);
+	pVertices[32]	= Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f);
+	pVertices[33]	= Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f);
+	pVertices[34]	= Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f);
+	pVertices[35]	= Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.66f);
+
+	pBlockVertexBuffer->Unlock();
+
+	return Error_Success;
 }
\ No newline at end of file
--- a/LightClone/Source/Environment.h	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/Environment.h	Sat Sep 10 23:52:12 2011 -0700
@@ -7,6 +7,8 @@
 
 #include "Core.h"
 #include "Tower.h"
+#include "RenderContext.h"
+#include "ResourceManager.h"
 
 /*
  * Environment
@@ -14,6 +16,21 @@
 class Environment
 {
 	/*
+	 * pBlockEffect
+	 */
+	ID3DXEffect* pBlockEffect;
+
+	/*
+	 * pBlockVertexBuffer
+	 */
+	IDirect3DVertexBuffer9* pBlockVertexBuffer;
+
+	/*
+	 * pBlockTexture
+	 */
+	IDirect3DTexture9* pBlockTexture;
+
+	/*
 	 * nWidth
 	 */
 	uint32 nWidth;
@@ -48,7 +65,17 @@
 	/*
 	 * Initialize
 	 */
-	ErrorCode Initialize(uint32 nGridWidth, uint32 nGridHeight);
+	ErrorCode Initialize(ResourceManager* pResourceManager);
+
+	/*
+	 * Terminate
+	 */
+	void Terminate();
+
+	/*
+	 * Setup
+	 */
+	ErrorCode Setup(uint32 nGridWidth, uint32 nGridHeight);
 
 	/*
 	 * Reset
@@ -56,6 +83,16 @@
 	void Reset();
 
 	/*
+	 * Update
+	 */
+	void Update(float fElapsed);
+
+	/*
+	 * Render
+	 */
+	void Render(RenderContext& kContext, Camera& kCamera);
+
+	/*
 	 * GetWidth
 	 */
 	uint32 GetWidth() const;
@@ -112,6 +149,13 @@
 	 *	Used by objects to notify the environment of changes
 	 */
 	void NotifyAction(uint32 nX, uint32 nY);
+
+private:
+
+	/*
+	 * SetupVertexBuffer
+	 */
+	ErrorCode SetupVertexBuffer();
 };
 
 #endif //__ENVIRONMENT_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiContainer.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -0,0 +1,36 @@
+/*
+ * GuiContainer
+ */
+
+#include "GuiContainer.h"
+
+/*
+ * GuiContainer
+ */
+GuiContainer::GuiContainer()
+{
+}
+
+/*
+ * Update
+ */
+void GuiContainer::Update(float fElapsed)
+{
+	for(uint32 i = 0; i < kChildren.GetSize(); ++i)
+	{
+		kChildren[i]->Update(fElapsed);
+	}
+
+	Layout(kChildren);
+}
+
+/*
+ * Render
+ */
+void GuiContainer::Render(RenderContext& kContext)
+{
+	for(uint32 i = 0; i < kChildren.GetSize(); ++i)
+	{
+		kChildren[i]->Render(kContext);
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiContainer.h	Sat Sep 10 23:52:12 2011 -0700
@@ -0,0 +1,46 @@
+/*
+ * GuiContainer
+ */
+
+#ifndef __GUICONTAINER_H__
+#define __GUICONTAINER_H__
+
+#include "Core.h"
+#include "GuiElement.h"
+
+/*
+ * GuiContainer
+ */
+class GuiContainer : public GuiElement
+{
+	/*
+	 * pChildren
+	 */
+	GuiElementList kChildren;
+
+public:
+
+	/*
+	 * GuiContainer
+	 */
+	GuiContainer();
+
+	/*
+	 * Update
+	 */
+	virtual void Update(float fElapsed);
+
+	/*
+	 * Render
+	 */
+	virtual void Render(RenderContext& kContext);
+
+protected:
+
+	/*
+	 * Layout
+	 */
+	virtual void Layout(GuiElementList& kElements) = 0;
+};
+
+#endif //__GUICONTAINER_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiElement.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -0,0 +1,217 @@
+/*
+ * GuiElement
+ */
+
+#include "GuiElement.h"
+
+/*
+ * GuiElement
+ */
+GuiElement::GuiElement()
+{
+}
+
+/*
+ * ~GuiElement
+ */
+GuiElement::~GuiElement()
+{
+}
+
+/*
+ * Attach
+ */
+void GuiElement::Attach(GuiElement* pInstance)
+{
+	pContainer = pInstance;
+}
+
+/* 
+ * Detach
+ */
+GuiElement* GuiElement::Detach()
+{
+	GuiElement* pInstance = pContainer;
+	pContainer = NULL;
+	return pInstance;
+}
+
+/*
+ * GetContainer
+ */
+GuiElement* GuiElement::GetContainer()
+{
+	return pContainer;
+}
+
+/*
+ * SetPosition
+ */
+void GuiElement::SetPosition(float fX, float fY)
+{
+	kPosition.x = fX;
+	kPosition.y = fY;
+}
+
+/*
+ * SetPosition
+ */
+void GuiElement::SetPosition(const D3DXVECTOR2& kValue)
+{
+	kPosition = kValue;
+}
+
+/*
+ * GetPosition
+ */
+const D3DXVECTOR2& GuiElement::GetPosition() const
+{
+	return kPosition;
+}
+
+/*
+ * SetDimensions
+ */
+void GuiElement::SetDimensions(float fWidth, float fHeight)
+{
+	kDimensions.x = fWidth;
+	kDimensions.y = fHeight;
+}
+
+/*
+ * SetDimensions
+ */
+void GuiElement::SetDimensions(const D3DXVECTOR2& kValue)
+{
+	kDimensions = kValue;
+}
+
+/*
+ * GetDimensions
+ */
+const D3DXVECTOR2& GuiElement::GetDimensions() const
+{
+	return kDimensions;
+}
+
+
+/*
+ * GuiElementList
+ */
+GuiElementList::GuiElementList() : pElement(NULL), nSize(0), nCount(0)
+{
+}
+
+/*
+ * ~GuiElementList
+ */
+GuiElementList::~GuiElementList()
+{
+	delete[] pElement;
+	pElement = NULL;
+}
+
+/*
+ * Add
+ */
+ErrorCode GuiElementList::Add(GuiElement* pInstance)
+{
+	ErrorCode eCode = Resize(nCount + 1);
+	if(eCode == Error_Success)
+	{
+		pElement[nCount++] = pInstance;
+	}
+
+	return eCode;
+}
+
+/*
+ * Remove
+ */
+ErrorCode GuiElementList::Remove(uint32 nIndex)
+{
+	if(nIndex < nCount)
+	{
+		--nCount;
+
+		for(uint32 i = nIndex; i < nCount; ++i)
+		{
+			pElement[i] = pElement[i + 1];
+		}
+
+		return Error_Success;
+	}
+
+	return Error_Fail;
+}
+
+/*
+ * Find
+ */
+int32 GuiElementList::Find(GuiElement* pInstance)
+{
+	for(uint32 i = 0; i < nCount; ++i)
+	{
+		if(pElement[i] == pInstance)
+		{
+			return (int32)i;
+		}
+	}
+
+	return -1;
+}
+
+/*
+ * GetSize
+ */
+uint32 GuiElementList::GetSize() const
+{
+	return nCount;
+}
+
+/*
+ * operator []
+ */
+GuiElement* GuiElementList::operator[](uint32 nIndex)
+{
+	//ASSERT(nIndex < nCount);
+	return pElement[nIndex];
+}
+
+/*
+ * operator []
+ */
+const GuiElement* GuiElementList::operator[](uint32 nIndex) const
+{
+	//ASSERT(nIndex < nCount);
+	return pElement[nIndex];
+}
+
+/*
+ * Resize
+ */
+ErrorCode GuiElementList::Resize(uint32 nLength)
+{
+	ErrorCode eCode = Error_Success;
+
+	if(nLength > nSize)
+	{
+		//TODO: Reallocate array and copy
+		GuiElement** pArray = new GuiElement*[2 * nSize + 1];
+
+		if(pElement)
+		{
+			for(uint32 i = 0; i < nCount; ++i)
+			{
+				pArray[i] = pElement[i];
+			}
+
+			delete[] pElement;
+		}
+
+		pElement = pArray;
+		nSize *= 2;
+	}
+
+	return eCode;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiElement.h	Sat Sep 10 23:52:12 2011 -0700
@@ -0,0 +1,181 @@
+/*
+ * GuiElement
+ */
+
+#ifndef __GUIELEMENT_H__
+#define __GUIELEMENT_H__
+
+#include "Core.h"
+#include "ResourceManager.h"
+#include "RenderContext.h"
+#include "Camera.h"
+
+/*
+ * GuiElement
+ */
+class GuiElement
+{
+	/*
+	 * pContainer
+	 */
+	GuiElement* pContainer;
+
+	/*
+	 * kPosition
+	 */
+	D3DXVECTOR2 kPosition;
+
+	/*
+	 * kDimensions
+	 */
+	D3DXVECTOR2 kDimensions;
+
+public:
+
+	/*
+	 * GuiElement
+	 */
+	GuiElement();
+
+	/*
+	 * ~GuiElement
+	 */
+	virtual ~GuiElement();
+
+	/*
+	 * Attach
+	 */
+	void Attach(GuiElement* pInstance);
+
+	/* 
+	 * Detach
+	 */
+	GuiElement* Detach();
+
+	/*
+	 * GetContainer
+	 */
+	GuiElement* GetContainer();
+
+	/*
+	 * SetPosition
+	 */
+	void SetPosition(float fX, float fY);
+
+	/*
+	 * SetPosition
+	 */
+	void SetPosition(const D3DXVECTOR2& kValue);
+
+	/*
+	 * GetPosition
+	 */
+	const D3DXVECTOR2& GetPosition() const;
+
+	/*
+	 * SetDimensions
+	 */
+	void SetDimensions(float fWidth, float fHeight);
+
+	/*
+	 * SetDimensions
+	 */
+	void SetDimensions(const D3DXVECTOR2& kValue);
+
+	/*
+	 * GetDimensions
+	 */
+	const D3DXVECTOR2& GetDimensions() const;
+
+	/*
+	 * Initialize
+	 */
+	virtual ErrorCode Initialize(ResourceManager* pResourceManager) = 0;
+
+	/*
+	 * Terminate
+	 */
+	virtual void Terminate() = 0;
+
+	/*
+	 * Update
+	 */
+	virtual void Update(float fElapsed) = 0;
+
+	/*
+	 * Render
+	 */
+	virtual void Render(RenderContext& kContext) = 0;
+};
+
+/*
+ * GuiElementList
+ */
+class GuiElementList
+{
+	/*
+	 * pElement
+	 */
+	GuiElement** pElement;
+
+	/*
+	 * nSize
+	 */
+	uint32 nSize;
+
+	/*
+	 * nCount;
+	 */
+	uint32 nCount;
+
+public:
+
+	/*
+	 * GuiElementList
+	 */
+	GuiElementList();
+
+	/*
+	 * ~GuiElementList
+	 */
+	~GuiElementList();
+
+	/*
+	 * Add
+	 */
+	ErrorCode Add(GuiElement* pInstance);
+
+	/*
+	 * Remove
+	 */
+	ErrorCode Remove(uint32 nIndex);
+
+	/*
+	 * Find
+	 */
+	int32 Find(GuiElement* pInstance);
+
+	/*
+	 * GetSize
+	 */
+	uint32 GetSize() const;
+
+	/*
+	 * operator []
+	 */
+	GuiElement* operator[](uint32 nIndex);
+
+	/*
+	 * operator []
+	 */
+	const GuiElement* operator[](uint32 nIndex) const;
+
+private:
+
+	/*
+	 * Resize
+	 */
+	ErrorCode Resize(uint32 nLength);
+};
+
+#endif //__GUIELEMENT_H__
--- a/LightClone/Source/InputManager.h	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/InputManager.h	Sat Sep 10 23:52:12 2011 -0700
@@ -9,6 +9,9 @@
 #include <dinput.h>
 #include "Core.h"
 
+//TODO: Remove the need to pass InputManager to world objects during
+//		initialization by sending input events instead
+
 /*
  * InputManager
  */
--- a/LightClone/Source/Interface.cpp	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/Interface.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -251,6 +251,12 @@
 			sprintf_s(kMessage, "Congratulations!\nYou have completed level %d", pModel->nCurrentLevel);
 
 			RenderDialog(kContext, pModel, kMessage, "Ok");
+
+			//TODO: This would occur before entering the complete state:
+			//pLevelDialog->SetMessage(kMessage);
+			//pLevelDialog->SetVisible(true);
+			//
+			//nGameState = GameState_Complete;
 		}
 		else
 
--- a/LightClone/Source/Interface.h	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/Interface.h	Sat Sep 10 23:52:12 2011 -0700
@@ -8,6 +8,7 @@
 #include "Core.h"
 #include "RenderContext.h"
 #include "ResourceManager.h"
+#include "GuiContainer.h"
 
 /*
  * Interface
--- a/LightClone/Source/RenderContext.cpp	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/RenderContext.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -118,16 +118,32 @@
 }
 
 /*
- * Apply
+ * ApplyCameraToEffect
  */
-void RenderContext::Apply(Camera& kCamera, ID3DXEffect* pEffect)
+void RenderContext::ApplyCameraToEffect(Camera& kCamera, ID3DXEffect* pEffect, const char* pProjection, const char* pView)
 {
-	//TODO:
+	D3DVIEWPORT9 kViewport;
+	if(SUCCEEDED(pGraphicsDevice->GetViewport(&kViewport)))
+	{
+		D3DXHANDLE kHandleProj	= pEffect->GetParameterByName(NULL, pProjection);
+		D3DXHANDLE kHandleView	= pEffect->GetParameterByName(NULL, pView);
+
+		if(kHandleProj && kHandleView)
+		{
+			const D3DXMATRIX& kProjectionMatrix	= kCamera.GetProjection(kViewport);
+			const D3DXMATRIX& kViewMatrix		= kCamera.GetView();
+
+			// apply parameters to shader
+			pEffect->SetMatrix(kHandleProj, &kProjectionMatrix);
+			pEffect->SetMatrix(kHandleView, &kViewMatrix);
+		}
+	}
 }
 
 /*
  * SetupCamera3D
  */
+/*
 void RenderContext::SetupCamera3D(ID3DXEffect* pEffect, const D3DXVECTOR3& kLocation, const D3DXVECTOR3& kTarget, float fViewAngle)
 {
 	D3DVIEWPORT9 kViewport;
@@ -150,10 +166,12 @@
 		}
 	}
 }
+*/
 
 /*
  * SetupCamera2D
  */
+/*
 void RenderContext::SetupCamera2D(ID3DXEffect* pEffect)
 {
 	D3DVIEWPORT9 kViewport;
@@ -172,6 +190,7 @@
 		}
 	}
 }
+*/
 
 /*
  * DrawTriangles
@@ -187,20 +206,4 @@
 ErrorCode RenderContext::GetViewport(D3DVIEWPORT9* pViewport)
 {
 	return pGraphicsDevice->GetViewport(pViewport);
-}
-
-/*
- * GetProjection
- */
-const D3DXMATRIX& RenderContext::GetProjection() const
-{
-	return kProjection;
-}
-
-/*
- * GetView
- */
-const D3DXMATRIX& RenderContext::GetView() const
-{
-	return kView;
 }
\ No newline at end of file
--- a/LightClone/Source/RenderContext.h	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/RenderContext.h	Sat Sep 10 23:52:12 2011 -0700
@@ -29,16 +29,6 @@
 	 */
 	//MatrixStack kWorldStack;
 
-	/*
-	 * kProjection
-	 */
-	D3DXMATRIX kProjection;
-
-	/*
-	 * kView
-	 */
-	D3DXMATRIX kView;
-
 public:
 
 	/*
@@ -87,19 +77,9 @@
 	void End();
 
 	/*
-	 * Apply
-	 */
-	void Apply(Camera& kCamera, ID3DXEffect* pEffect);
-
-	/*
-	 * SetupCamera3D
+	 * ApplyCameraToEffect
 	 */
-	void SetupCamera3D(ID3DXEffect* pEffect, const D3DXVECTOR3& kLocation, const D3DXVECTOR3& kTarget, float fViewAngle = D3DX_PI / 4.0f);
-
-	/*
-	 * SetupCamera2D
-	 */
-	void SetupCamera2D(ID3DXEffect* pEffect);
+	void ApplyCameraToEffect(Camera& kCamera, ID3DXEffect* pEffect, const char* pProjection = "kProjection", const char* pView = "kView");
 
 	/*
 	 * DrawTriangles
@@ -110,16 +90,6 @@
 	 * GetViewport
 	 */
 	ErrorCode GetViewport(D3DVIEWPORT9* pViewport);
-
-	/*
-	 * GetProjection
-	 */
-	const D3DXMATRIX& GetProjection() const;
-
-	/*
-	 * GetView
-	 */
-	const D3DXMATRIX& GetView() const;
 };
 
 #endif //__RENDERCONTEXT_H__
--- a/LightClone/Source/World.cpp	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/World.cpp	Sat Sep 10 23:52:12 2011 -0700
@@ -10,10 +10,6 @@
  */
 World::World() : kToolbar(8), kMain(16), kFunction(8), kControls(4)
 {
-	pBlockEffect			= NULL;
-	pBlockVertexBuffer		= NULL;
-	pBlockTexture			= NULL;
-
 	nGameState				= GameState_Active;
 	nSimulationState		= SimulationState_Idle;
 	pFunction				= 0;
@@ -79,28 +75,20 @@
 	{
 		pInputManager = pInput;
 
-		eCode = pResourceManager->CreateEffectFromFile("Data\\Shaders\\Environment.fx", &pBlockEffect);
+		eCode = kEnvironment.Initialize(pResourceManager);
 		if(eCode == Error_Success)
 		{
-			eCode = pResourceManager->CreateTextureFromFile("Data\\Textures\\Block02.tga", &pBlockTexture);
+			eCode = kBot.Initialize(pResourceManager);
 			if(eCode == Error_Success)
 			{
-				eCode = pResourceManager->CreateVertexBuffer(VerticesPerBlock * sizeof(Vertex::Block), D3DUSAGE_WRITEONLY, D3DPOOL_MANAGED, &pBlockVertexBuffer);
+				//eCode = kProgram.Initialize(pResourceManager);
 				if(eCode == Error_Success)
 				{
-					eCode = SetupVertexBuffer();
+					eCode = InitializeInterface(pResourceManager);				
 					if(eCode == Error_Success)
 					{
-						eCode = kInterface.Initialize(pResourceManager);
-						if(eCode == Error_Success)
-						{
-							eCode = kBot.Initialize(pResourceManager);
-							if(eCode == Error_Success)
-							{
-								nCurrentLevel	= 0;
-								nGameState		= GameState_LoadMap;
-							}
-						}
+						nCurrentLevel	= 0;
+						nGameState		= GameState_LoadMap;
 					}
 				}
 			}
@@ -116,30 +104,9 @@
 void World::Terminate()
 {
 	kInterface.Terminate();
+	//kProgram.Terminate();
 	kBot.Terminate();
-
-	if(pBlockVertexBuffer)
-	{
-		pBlockVertexBuffer->Release();
-		pBlockVertexBuffer = NULL;
-	}
-
-	if(pBlockTexture)
-	{
-		pBlockTexture->Release();
-		pBlockTexture = NULL;
-	}
-
-	if(pBlockEffect)
-	{
-		pBlockEffect->Release();
-		pBlockEffect = 0;
-	}
-
-	/*
-	kProgram.Terminate();
 	kEnvironment.Terminate();
-	*/
 }
 
 /*
@@ -182,7 +149,7 @@
 
 		const Size& kSize = kLoader.GetSize();
 
-		eCode = kEnvironment.Initialize(kSize.X, kSize.Y);
+		eCode = kEnvironment.Setup(kSize.X, kSize.Y);
 		if(eCode == Error_Success)
 		{
 			for(uint32 nY = 0; nY < kSize.Y; ++nY)
@@ -291,7 +258,10 @@
 
 	if(nGameState >= GameState_Active)
 	{
+		kCameraController.SetMode(CameraMode_3D);
 		Render3D(kContext);
+
+		kCameraController.SetMode(CameraMode_2D);
 		Render2D(kContext);
 	}
 
@@ -299,67 +269,101 @@
 }
 
 /*
- * SetupVertexBuffer
+ * InitializeInterface
  */
-ErrorCode World::SetupVertexBuffer()
+ErrorCode World::InitializeInterface(ResourceManager* pResourceManager)
 {
-	Vertex::Block* pVertices = NULL;
-	
-	HRESULT hResult = pBlockVertexBuffer->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD);
-	if(FAILED(hResult))
-	{
-		return Error_Fail;
-	}
+	return kInterface.Initialize(pResourceManager);
+
+	/*
+	GuiElement* pRoot = kInterface.GetRoot();
+
+	//CodePanel* 
+	pToolbar = new CodePanel(8);
+	pToolbar->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
+	pToolbar->SetSlotTexture("Data\\Textures\\Slot.tga");
+
+	//CodePanel* 
+	pMain = new CodePanel(16);
+	pMain->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
+	pMain->SetSlotTexture("Data\\Textures\\Slot.tga");
+
+	//CodePanel* 
+	pFunctionA = new CodePanel(16);
+	pFunctionA->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
+	pFunctionA->SetSlotTexture("Data\\Textures\\Slot.tga");
 
-	const float fU1	= 0.66f;
-	const float fV1 = 0.66f;
+	//CodePanel* 
+	pFunctionB = new CodePanel(16);
+	pFunctionB->SetBackgroundTexture("Data\\Textures\\CodePanel.tga");
+	pFunctionB->SetSlotTexture("Data\\Textures\\Slot.tga");
+
+	//SelectorPanel*
+	pSelectorPanel = new SelectorPanel();
+	pSelectorPanel->SetLeftTexture("Data\\Textures\\Left.tga");
+	pSelectorPanel->SetRightTexture("Data\\Textures\\Right.tga");
+	pSelectorPanel->Add(pFunctionA);
+	pSelectorPanel->Add(pFunctionB);
+
+	//GuiButton*
+	pButtonStart = new GuiButton();
+	pButtonStart->SetTexture("Data\\Textures\\Play.tga");
+	pButtonStart->SetDimensions(...);
+
+	//GuiButton*
+	pButtonStop = new GuiButton();
+	pButtonStop->SetTexture("Data\\Textures\\Stop.tga");
+	pButtonStop->SetDimensions(...);
 
-	// front
-	pVertices[0]	= Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f);
-	pVertices[1]	= Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 0.66f);
-	pVertices[2]	= Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f);
-	pVertices[3]	= Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 0.00f, 1.00f);
-	pVertices[4]	= Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 0.66f);
-	pVertices[5]	= Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, 0.0f, -1.0f, 1.00f, 1.00f);
-	// back
-	pVertices[6]	= Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f);
-	pVertices[7]	= Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 0.66f);
-	pVertices[8]	= Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f);
-	pVertices[9]	= Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 0.00f, 1.00f);
-	pVertices[10]	= Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 0.66f);
-	pVertices[11]	= Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, 0.0f, +1.0f, 1.00f, 1.00f);
-	// left
-	pVertices[12]	= Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
-	pVertices[13]	= Vertex::Block(-0.5f, 1.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 0.66f);
-	pVertices[14]	= Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
-	pVertices[15]	= Vertex::Block(-0.5f, 0.0f, +0.5f, -1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
-	pVertices[16]	= Vertex::Block(-0.5f, 1.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
-	pVertices[17]	= Vertex::Block(-0.5f, 0.0f, -0.5f, -1.0f, 0.0f, 0.0f, 1.00f, 1.00f);
-	// right
-	pVertices[18]	= Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
-	pVertices[19]	= Vertex::Block(+0.5f, 1.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 0.66f);
-	pVertices[20]	= Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
-	pVertices[21]	= Vertex::Block(+0.5f, 0.0f, -0.5f, +1.0f, 0.0f, 0.0f, 0.00f, 1.00f);
-	pVertices[22]	= Vertex::Block(+0.5f, 1.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 0.66f);
-	pVertices[23]	= Vertex::Block(+0.5f, 0.0f, +0.5f, +1.0f, 0.0f, 0.0f, 1.00f, 1.00f);
-	// top
-	pVertices[24]	= Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f);
-	pVertices[25]	= Vertex::Block(-0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.00f);
-	pVertices[26]	= Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f);
-	pVertices[27]	= Vertex::Block(-0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 0.00f, 0.66f);
-	pVertices[28]	= Vertex::Block(+0.5f, 1.0f, +0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.00f);
-	pVertices[29]	= Vertex::Block(+0.5f, 1.0f, -0.5f, 0.0f, +1.0f, 0.0f, 1.00f, 0.66f);
-	// bottom
-	pVertices[30]	= Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f);
-	pVertices[31]	= Vertex::Block(-0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.00f);
-	pVertices[32]	= Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f);
-	pVertices[33]	= Vertex::Block(-0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 0.00f, 0.66f);
-	pVertices[34]	= Vertex::Block(+0.5f, 0.0f, -0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.00f);
-	pVertices[35]	= Vertex::Block(+0.5f, 0.0f, +0.5f, 0.0f, -1.0f, 0.0f, 1.00f, 0.66f);
+	//GuiButton*
+	pButtonReset = new GuiButton();
+	pButtonReset->SetTexture("Data\\Textures\\Reset.tga");
+	pButtonReset->SetDimensions(...);
+
+	//GuiButton*
+	pButtonExit = new GuiButton();
+	pButtonExit->SetTexture("Data\\Textures\\Exit.tga");
+	pButtonExit->SetDimensions(...);
+
+	//GuiPanel*
+	pControlPanel = new GuiPanel();
+	pControlPanel->SetTexture("Data\\Textures\\ControlPanel.tga")
+	pControlPanel->SetDimensions(...);
+	pControlPanel->Add(pButtonStart);
+	pControlPanel->Add(pButtonStop);
+	pControlPanel->Add(pButtonReset);
+	pControlPanel->Add(pButtonExit);
+
+	//GuiDialog*
+	pLevelDialog = new GuiDialog();
+	pLevelDialog->AddButton(DialogButton_Ok, "Ok");
+	pLevelDialog->SetVisible(false);
 
-	pBlockVertexBuffer->Unlock();
+	//GuiDialog*
+	pGameDialog = new GuiDialog();
+	pGameDialog->AddButton(DialogButton_Ok, "Ok");
+	pGameDialog->SetVisible(false);
+
+	//GuiDialog*
+	pConfirmDialog = new GuiDialog();
+	pConfirmDialog->AddButton(DialogButton_Yes, "Yes");
+	pConfirmDialog->AddButton(DialogButton_No, "No");
+	pConfirmDialog->SetVisible(false);
 
-	return Error_Success;
+	//GuiPanel* 
+	pContainerPanel = new GuiPanel();
+	pContainerPanel->SetBackgroundTexture("Data\\Texturse\\ContainerPanel.tga");
+	pContainerPanel->Add(pToolbar);
+	pContainerPanel->Add(pMain);
+	pContainerPanel->Add(pSelectorPanel);
+	pContainerPanel->Add(pControlPanel);
+
+	pRoot->Add(pControlPanel);
+	pRoot->Add(pLevelDialog);
+	pRoot->Add(pGameDialog);
+	pRoot->Add(pConfirmDialog);
+
+	*/
 }
 
 /*
@@ -367,17 +371,8 @@
  */
 void World::Render3D(RenderContext& kContext)
 {
-	const D3DXVECTOR3& kScale	= kEnvironment.GetScale();
-	const uint32 nSizeX			= kEnvironment.GetWidth();
-	const uint32 nSizeY			= kEnvironment.GetHeight();
-
-	//const D3DXVECTOR3 kTarget(0.5f * (nSizeX - 1) * kScale.x, 0.0f, 0.5f * (nSizeY - 1) * kScale.z);
-	const D3DXVECTOR3 kTarget(0.0f, 0.0f, 0.0f);
-
-	kContext.SetupCamera3D(pBlockEffect, kTarget + kCameraController.GetLocation(), kTarget);
-
-	RenderEnvironment(kContext, &kEnvironment);
-	RenderBot(kContext, &kEnvironment, &kBot);
+	kEnvironment.Render(kContext, kCameraController);
+	kBot.Render(kContext, kCameraController);
 }
 
 /* 
@@ -389,166 +384,6 @@
 }
 
 /*
- * 	RenderEnvironment
- */
-void World::RenderEnvironment(RenderContext& kContext, Environment* pEnvironment)
-{
-	const D3DXVECTOR3& kScale = pEnvironment->GetScale();
-
-	uint32 nPasses = 0;
-
-	pBlockEffect->SetTechnique(pBlockEffect->GetTechnique(0));
-	pBlockEffect->Begin(&nPasses, 0);
-	pBlockEffect->BeginPass(0);
-
-	D3DXMATRIX kScaleMatrix;
-	D3DXMatrixScaling(&kScaleMatrix, kScale.x, kScale.y, kScale.z);
-
-	const uint32 nSizeX				= pEnvironment->GetWidth();
-	const uint32 nSizeY				= pEnvironment->GetHeight();
-	
-	const D3DXMATRIX& kProjection	= kContext.GetProjection();
-	const D3DXMATRIX& kView			= kContext.GetView();
-
-	D3DVIEWPORT9 kViewport;
-	kContext.GetViewport(&kViewport);
-
-	D3DXVECTOR3 kCenterWorld(0.0f, 0.0f, 0.0f);
-	const float fMagicOffset = 400.0f;
-	//const D3DXVECTOR3& kCenterWorld = ComputeOrigin(0.5f * (ScreenSizeX - (304.0f + fMagicOffset)), 0.5f * ScreenSizeY, kViewport, kProjection, kView);
-
-	const float fOffsetX	= -0.5f * (nSizeX * kScale.x);
-	const float fOffsetZ	= -0.5f * (nSizeY * kScale.z);
-
-	for(uint32 nZ = 0; nZ < nSizeY; ++nZ)
-	{
-		for(uint32 nX = 0; nX < nSizeX; ++nX)
-		{
-			uint32 nType	= pEnvironment->GetType(nX, nZ);
-			uint32 nHeight	= pEnvironment->GetAltitude(nX, nZ);
-			uint32 nState	= pEnvironment->GetState(nX, nZ);
-			uint32 nColor	= D3DCOLOR_XRGB(0x80, 0x80, 0x80);
-
-			if(nType == 1)
-			{
-				nColor = nState ? D3DCOLOR_XRGB(0, 0, 255) : D3DCOLOR_XRGB(255, 0, 0);
-			}
-
-			for(uint32 i = 0; i < pEnvironment->GetAltitude(nX, nZ); ++i)
-			{
-				D3DXMATRIX kTranslateMatrix;
-				D3DXMatrixTranslation(&kTranslateMatrix, fOffsetX + (kCenterWorld.x + nX) * kScale.x, i * kScale.y, fOffsetZ + (kCenterWorld.z + nZ) * kScale.z);
-
-				D3DXMATRIX kWorldMatrix;
-				D3DXMatrixMultiply(&kWorldMatrix, &kScaleMatrix, &kTranslateMatrix);
-
-				const float fAlpha	= ((nColor >> 24) & 0xFF) / 255.0f;
-				const float fRed	= ((nColor >> 16) & 0xFF) / 255.0f;
-				const float fGreen	= ((nColor >> 8 ) & 0xFF) / 255.0f;
-				const float fBlue	= ((nColor >> 0 ) & 0xFF) / 255.0f;
-
-				const D3DXVECTOR4 kColorVector(fRed, fGreen, fBlue, fAlpha);
-
-				pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-				pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-				pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), pBlockTexture);
-				pBlockEffect->CommitChanges();
-
-				kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace);
-			}
-		}
-	}
-
-	pBlockEffect->EndPass();
-	pBlockEffect->End();
-
-	if(false) // wireframe
-	{
-		pBlockEffect->SetTechnique(pBlockEffect->GetTechniqueByName("Wire"));
-		pBlockEffect->Begin(&nPasses, 0);
-		pBlockEffect->BeginPass(0);
-
-		for(uint32 nZ = 0; nZ < nSizeY; ++nZ)
-		{
-			for(uint32 nX = 0; nX < nSizeX; ++nX)
-			{
-				for(uint32 i = 0; i < pEnvironment->GetAltitude(nX, nZ); ++i)
-				{
-					D3DXMATRIX kTranslateMatrix;
-					D3DXMatrixTranslation(&kTranslateMatrix, nX * kScale.x, i * kScale.y, nZ * kScale.z);
-
-					D3DXMATRIX kWorldMatrix;
-					D3DXMatrixMultiply(&kWorldMatrix, &kScaleMatrix, &kTranslateMatrix);
-
-					const D3DXVECTOR4 kColorVector(0.0f, 0.0f, 0.0f, 1.0f);
-
-					pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-					pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-					pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), pBlockTexture);
-					pBlockEffect->CommitChanges();
-
-					kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace);
-				}
-			}
-		}
-
-		pBlockEffect->EndPass();
-		pBlockEffect->End();
-	}
-}
-
-/*
- * RenderBot
- */
-void World::RenderBot(RenderContext& kContext, Environment* pEnvironment, Bot* pBot)
-{
-	//*
-	const D3DXVECTOR3& kPosition	= pBot->GetWorldPosition();
-	const D3DXVECTOR3& kOrientation	= pBot->GetWorldOrientation();
-
-	const float fOffsetX	= -0.5f * (pEnvironment->GetWidth() * pEnvironment->GetScale().x);
-	const float fOffsetZ	= -0.5f * (pEnvironment->GetHeight() * pEnvironment->GetScale().z);
-
-	uint32 nPasses = 0;
-
-	pBlockEffect->SetTechnique(pBlockEffect->GetTechnique(0));
-	pBlockEffect->Begin(&nPasses, 0);
-	pBlockEffect->BeginPass(0);
-
-	D3DXMATRIX kScale;
-	D3DXMatrixScaling(&kScale, pBot->kSize.x, pBot->kSize.y, pBot->kSize.z);
-
-	D3DXMATRIX kTranslate;
-	D3DXMatrixTranslation(&kTranslate, fOffsetX + kPosition.x, kPosition.y, fOffsetZ + kPosition.z);
-
-	D3DXMATRIX kRotate;
-	D3DXMatrixRotationY(&kRotate, kOrientation.y);
-
-	D3DXMATRIX kTempMatrix;
-	D3DXMATRIX kWorldMatrix;
-	D3DXMatrixMultiply(&kWorldMatrix, D3DXMatrixMultiply(&kTempMatrix, &kScale, &kRotate), &kTranslate);
-
-	const float fAlpha	= ((pBot->nColor >> 24) & 0xFF) / 255.0f;
-	const float fRed	= ((pBot->nColor >> 16) & 0xFF) / 255.0f;
-	const float fGreen	= ((pBot->nColor >> 8 ) & 0xFF) / 255.0f;
-	const float fBlue	= ((pBot->nColor >> 0 ) & 0xFF) / 255.0f;
-
-	const D3DXVECTOR4 kColorVector(fRed, fGreen, fBlue, fAlpha);
-
-	pBlockEffect->SetMatrix(pBlockEffect->GetParameterByName(NULL, "kWorld"), &kWorldMatrix);
-	pBlockEffect->SetVector(pBlockEffect->GetParameterByName(NULL, "kColor"), &kColorVector);
-	pBlockEffect->SetTexture(pBlockEffect->GetParameterByName(NULL, "kTexture"), NULL);
-	pBlockEffect->CommitChanges();
-
-	kContext.DrawTriangles(Vertex::Block::Declaration, pBlockVertexBuffer, sizeof(Vertex::Block), FacesPerCube * TrianglesPerFace);
-
-	pBlockEffect->EndPass();
-	pBlockEffect->End();
-	//*/
-	//kBot.Render(kContext, kCameraController);
-}
-
-/*
  * ProcessInput
  */
 void World::ProcessInput(float fElapsed)
--- a/LightClone/Source/World.h	Fri Sep 09 18:36:18 2011 -0700
+++ b/LightClone/Source/World.h	Sat Sep 10 23:52:12 2011 -0700
@@ -115,24 +115,6 @@
 	Rectangle2 kDialog2Bounds[2];
 
 	/*
-	 * pBlockEffect
-	 *	Move to World
-	 */
-	ID3DXEffect* pBlockEffect;
-
-	/*
-	 * pBlockVertexBuffer
-	 *	Move to World
-	 */
-	IDirect3DVertexBuffer9* pBlockVertexBuffer;
-
-	/*
-	 * pBlockTexture
-	 *	Move to World
-	 */
-	IDirect3DTexture9* pBlockTexture;
-
-	/*
 	 * kInterface
 	 *	Move to World
 	 */
@@ -208,9 +190,9 @@
 private:
 
 	/*
-	 * SetupVertexBuffer
+	 * InitializeInterface
 	 */
-	ErrorCode SetupVertexBuffer();
+	ErrorCode InitializeInterface(ResourceManager* pResourceManager);
 
 	/*
 	 * Render3D