Mercurial > LightClone
changeset 5:88b5c4d51c68
Cleanup dialog code; Start work on grid centering
author | koryspansel |
---|---|
date | Thu, 08 Sep 2011 11:55:35 -0700 |
parents | d52a7042fa1a |
children | 817a7b518fbb |
files | LightClone/Source/Controller.cpp LightClone/Source/Core.cpp LightClone/Source/Core.h LightClone/Source/Dialog.cpp LightClone/Source/Dialog.h LightClone/Source/Interface.cpp LightClone/Source/Model.h LightClone/Source/RenderContext.cpp LightClone/Source/RenderContext.h LightClone/Source/View.cpp LightClone/ToDo.txt |
diffstat | 11 files changed, 271 insertions(+), 67 deletions(-) [+] |
line wrap: on
line diff
--- a/LightClone/Source/Controller.cpp Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/Controller.cpp Thu Sep 08 11:55:35 2011 -0700 @@ -61,9 +61,9 @@ Environment* pEnvironment = pModel->GetEnvironment(); if(pEnvironment->RequirementsMet()) { - //kDialog.Reset(); - //kDialog.SetMessage("Some message"); - //kDialog.SetButton(0, "Ok"); + pModel->kDialog.Reset("Some message"); + pModel->kDialog.AddButton(DialogButton_Ok, "Ok", 0.0f, 0.0f, 0.0f, 0.0f); + pModel->nGameState = GameState_Complete; } } @@ -242,6 +242,15 @@ } } } + + /* + int32 nSelection = kDialog.Pick(fMouseX, fMouseY); + + if(nSelection == DialogButton_A) + { + pModel->nGameState = GameState_LoadMap; + } + */ } } else @@ -262,6 +271,16 @@ } } } + + /* + int32 nSelection = kDialog.Pick(fMouseX, fMouseY); + + if(nSelection == DialogButton_A) + { + pModel->nCurrentLevel = 0; + pModel->nGameState = GameState_LoadMap; + } + */ } } else @@ -287,6 +306,21 @@ } } } + + /* + int32 nSelection = kDialog.Pick(fMouseX, fMouseY); + + if(nSelection == DialogButton_A) + { + pModel->nGameState = GameState_Exit; + } + else + + if(nSelection == DialogButton_B) + { + pModel->nGameState = GameState_Active; + } + */ } } }
--- a/LightClone/Source/Core.cpp Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/Core.cpp Thu Sep 08 11:55:35 2011 -0700 @@ -82,3 +82,53 @@ return 0.0f; } + +/* + * ComputePickRay + */ +void ComputePickRay(float fScreenX, float fScreenY, const D3DVIEWPORT9& kViewport, const D3DXMATRIX& kProjection, const D3DXMATRIX& kView, D3DXVECTOR3* pOrigin, D3DXVECTOR3* pDirection) +{ + const float fX = +(2.0f * (fScreenX / kViewport.Width) - 1.0f) / kProjection._11; + const float fY = -(2.0f * (fScreenY / kViewport.Height) - 1.0f) / kProjection._22; + const float fZ = 1.0f; + + D3DXMATRIX kInverseView; + D3DXMatrixInverse(&kInverseView, NULL, &kView); + + if(pOrigin) + { + pOrigin->x = kInverseView._41; + pOrigin->y = kInverseView._42; + pOrigin->z = kInverseView._43; + } + + if(pDirection) + { + pDirection->x = fX * kInverseView._11 + fY * kInverseView._21 + fZ * kInverseView._31; + pDirection->y = fX * kInverseView._12 + fY * kInverseView._22 + fZ * kInverseView._32; + pDirection->z = fX * kInverseView._13 + fY * kInverseView._23 + fZ * kInverseView._33; + } +} + +/* + * ComputeOrigin + */ +const D3DXVECTOR3 ComputeOrigin(float fScreenX, float fScreenY, const D3DVIEWPORT9& kViewport, const D3DXMATRIX& kProjection, const D3DXMATRIX& kView) +{ + const D3DXVECTOR3 kPlaneNormal(0.0f, 1.0f, 0.0f); + const D3DXVECTOR3 kPlaneOrigin(0.0f, 0.0f, 0.0f); + + D3DXVECTOR3 kCameraOrigin; + D3DXVECTOR3 kCameraDirection; + + ComputePickRay(fScreenX, fScreenY, kViewport, kProjection, kView, &kCameraOrigin, &kCameraDirection); + + D3DXVECTOR3 kDelta; + D3DXVec3Subtract(&kDelta, &kCameraOrigin, &kPlaneOrigin); + D3DXVec3Normalize(&kDelta, &kDelta); + + float fD = D3DXVec3Dot(&kPlaneNormal, &kCameraDirection); + float fT = fD != 0.0f ? D3DXVec3Dot(&kPlaneNormal, &kDelta) / fD : 0.0f; + + return kCameraOrigin + fT * kCameraDirection; +} \ No newline at end of file
--- a/LightClone/Source/Core.h Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/Core.h Thu Sep 08 11:55:35 2011 -0700 @@ -109,6 +109,16 @@ }; /* + * DialogButton + */ +enum +{ + DialogButton_Ok, + DialogButton_Yes = DialogButton_Ok, + DialogButton_No, +}; + +/* * ScreenSizeX */ const uint32 ScreenSizeX = 1280; @@ -277,4 +287,14 @@ */ float InterpolateDirection(uint32 nStart, uint32 nEnd, float fParameter); +/* + * ComputePickRay + */ +void ComputePickRay(float fScreenX, float fScreenY, const D3DVIEWPORT9& kViewport, const D3DXMATRIX& kProjection, const D3DXMATRIX& kView, D3DXVECTOR3* pOrigin, D3DXVECTOR3* pDirection); + +/* + * ComputeOrigin + */ +const D3DXVECTOR3 ComputeOrigin(float fScreenX, float fScreenY, const D3DVIEWPORT9& kViewport, const D3DXMATRIX& kProjection, const D3DXMATRIX& kView); + #endif //__CORE_H__
--- a/LightClone/Source/Dialog.cpp Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/Dialog.cpp Thu Sep 08 11:55:35 2011 -0700 @@ -5,17 +5,53 @@ #include "Dialog.h" /* - * kDialogBounds + * Dialog + */ +Dialog::Dialog() +{ + nButtonCount = 0; +} + +/* + * Reset */ -Rectangle2 kDialogBounds[][Dialog::MaximumButtonCount] = +void Dialog::Reset(const char* pText) { + if(strcpy_s(kMessage, pText) == 0) + { + nButtonCount = 0; + } +} + +/* + * AddButton + */ +void Dialog::AddButton(uint32 nButton, const char* pText, float fX, float fY, float fWidth, float fHeight) +{ + if(nButtonCount < MaximumButtonCount) { - Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f), - Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f), - }, + if(strcpy_s(kButtonLabel[nButtonCount], pText) == 0) + { + kButtonRectangle[nButtonCount] = Rectangle2(fX, fY, fWidth, fHeight); + nButtonIdentifier[nButtonCount] = nButton; + ++nButtonCount; + } + } +} + +/* + * Pick + */ +int32 Dialog::Pick(float fX, float fY) +{ + for(uint32 i = 0; i < nButtonCount; ++i) { - Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f), - Rectangle2(1023.0f + 2.5f * 54.0f, 638.0f + 0 * 00.0f, 48.0f, 48.0f), - }, -}; + if(kButtonRectangle[i].Contains(fX, fY)) + { + return (int32)nButtonIdentifier[i]; + } + } + + return -1; +}
--- a/LightClone/Source/Dialog.h Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/Dialog.h Thu Sep 08 11:55:35 2011 -0700 @@ -31,6 +31,26 @@ */ char kMessage[MaximumMessageLength]; + /* + * kButtonLabel + */ + char kButtonLabel[MaximumButtonCount][MaximumMessageLength]; + + /* + * kButtonRectangle + */ + Rectangle2 kButtonRectangle[MaximumButtonCount]; + + /* + * nButtonIdentifier + */ + uint32 nButtonIdentifier[MaximumButtonCount]; + + /* + * nButtonCount + */ + uint32 nButtonCount; + public: /* @@ -39,10 +59,19 @@ Dialog(); /* - * SetButton + * Reset + */ + void Reset(const char* pText); + + /* + * AddButton */ - void SetButton(uint32 nButton, const char* pMessage); + void AddButton(uint32 nButton, const char* pText, float fX, float fY, float fWidth, float fHeight); + /* + * Pick + */ + int32 Pick(float fX, float fY); }; #endif //__DIALOG_H__
--- a/LightClone/Source/Interface.cpp Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/Interface.cpp Thu Sep 08 11:55:35 2011 -0700 @@ -82,7 +82,7 @@ return Error_Fail; } - eCode = kContext.CreateTextureFromFile("Data\\Textures\\Background.tga", &pBackgroundTexture); + eCode = kContext.CreateTextureFromFile("Data\\Textures\\Background00.tga", &pBackgroundTexture); if(eCode != Error_Success) { Terminate(); @@ -307,13 +307,14 @@ { const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - const float fWidth = 304.0f;//10.0f * ScreenSizeX / 26.0f; - const float fHeight = ScreenSizeY; - const float fX = ScreenSizeX - fWidth; - const float fY = 0.0f; + D3DSURFACE_DESC kDescriptor; + pBackgroundTexture->GetLevelDesc(0, &kDescriptor); + + const float fX = ScreenSizeX - (float)kDescriptor.Width; + const float fY = 0.0f; D3DXMATRIX kScale; - D3DXMatrixScaling(&kScale, fWidth, fHeight, 1.0f); + D3DXMatrixScaling(&kScale, (float)kDescriptor.Width, (float)kDescriptor.Height, 1.0f); D3DXMATRIX kTranslate; D3DXMatrixTranslation(&kTranslate, -0.5f * ScreenSizeX + fX + 0.5f, 0.5f * ScreenSizeY - fY + 0.5f, 0.0f); @@ -341,7 +342,6 @@ const Rectangle2& kBounds = pModel->kToolbar.GetBounds(i); D3DXMATRIX kScale; - //D3DXMatrixScaling(&kScale, pModel->kActionBounds[i].Width, pModel->kActionBounds[i].Height, 1.0f); D3DXMatrixScaling(&kScale, kBounds.Width, kBounds.Height, 1.0f); D3DXMATRIX kTranslate; @@ -490,7 +490,6 @@ { const D3DXVECTOR4 kColorVector(1.0f, 1.0f, 1.0f, 1.0f); - //for(uint32 i = 0; i < sizeof(pModel->kControlBounds) / sizeof(pModel->kControlBounds[0]); ++i) for(uint32 i = 0; i < pModel->kControls.GetSize(); ++i) { const Rectangle2& kBounds = pModel->kControls.GetBounds(i); @@ -554,8 +553,6 @@ pFont->DrawTextA(NULL, kMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); pFont->DrawTextA(NULL, kMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); - - //RenderDialog(kContext, pModel, kMessage, "Ok"); } /* @@ -598,8 +595,6 @@ pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); - - //RenderDialog(kContext, pModel, pMessage, "Ok"); } /* @@ -642,8 +637,6 @@ pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER | DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0)); pFont->DrawTextA(NULL, pMessage, -1, &kRectangle, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(0, 0, 0)); - - //RenderDialog(kContext, pModel, pMessage, "Yes", "No"); } /*
--- a/LightClone/Source/Model.h Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/Model.h Thu Sep 08 11:55:35 2011 -0700 @@ -13,6 +13,7 @@ #include "InputManager.h" #include "DragController.h" #include "ButtonPane.h" +#include "Dialog.h" /* * GameState @@ -97,47 +98,31 @@ DragController kDragController; /* - * kActionBounds - */ - //Rectangle2 kActionBounds[8]; - - /* * kToolbar */ ButtonPane kToolbar; /* - * kMainBounds - */ - //Rectangle2 kMainBounds[16]; - - /* * kMain */ ButtonPane kMain; /* - * kFunctionBounds - */ - //Rectangle2 kFunctionBounds[8]; - - /* * kFunction */ ButtonPane kFunction; /* + * kControlBounds + */ + ButtonPane kControls; + + /* * kArrowBounds */ Rectangle2 kArrowBounds[2]; /* - * kControlBounds - */ - //Rectangle2 kControlBounds[3]; - ButtonPane kControls; - - /* * kDialog1Bounds */ Rectangle2 kDialog1Bounds[1]; @@ -147,6 +132,11 @@ */ Rectangle2 kDialog2Bounds[2]; + /* + * kDialog + */ + Dialog kDialog; + public: /*
--- a/LightClone/Source/RenderContext.cpp Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/RenderContext.cpp Thu Sep 08 11:55:35 2011 -0700 @@ -177,14 +177,15 @@ D3DXHANDLE kHandleProj = pEffect->GetParameterByName(NULL, "kProjection"); D3DXHANDLE kHandleView = pEffect->GetParameterByName(NULL, "kView"); + // setup projection matrix + D3DXMatrixPerspectiveFovLH(&kProjection, fViewAngle, (float)kViewport.Width / (float)kViewport.Height, 1.0f, 1024.0f); + + // setup view matrix + D3DXMatrixLookAtLH(&kView, &kLocation, &kTarget, &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); + if(kHandleProj && kHandleView) { - D3DXMATRIX kProjection; - D3DXMatrixPerspectiveFovLH(&kProjection, fViewAngle, (float)kViewport.Width / (float)kViewport.Height, 1.0f, 1024.0f); - - D3DXMATRIX kView; - D3DXMatrixLookAtLH(&kView, &kLocation, &kTarget, &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); - + // apply parameters to shader pEffect->SetMatrix(kHandleProj, &kProjection); pEffect->SetMatrix(kHandleView, &kView); } @@ -202,9 +203,12 @@ D3DXHANDLE kHandle = pEffect->GetParameterByName(NULL, "kProjection"); if(kHandle) { - D3DXMATRIX kProjection; + // setup projection matrix D3DXMatrixOrthoLH(&kProjection, (float)kViewport.Width, (float)kViewport.Height, 1.0f, 1024.0f); + // setup view matrix + D3DXMatrixIdentity(&kView); + pEffect->SetMatrix(kHandle, &kProjection); } } @@ -226,4 +230,20 @@ ErrorCode RenderContext::GetViewport(D3DVIEWPORT9* pViewport) { return SUCCEEDED(pDevice->GetViewport(pViewport)) ? Error_Success : Error_Fail; +} + +/* + * 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 Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/RenderContext.h Thu Sep 08 11:55:35 2011 -0700 @@ -29,6 +29,16 @@ */ D3DPRESENT_PARAMETERS kParameters; + /* + * kProjection + */ + D3DXMATRIX kProjection; + + /* + * kView + */ + D3DXMATRIX kView; + public: /* @@ -95,6 +105,16 @@ * GetViewport */ ErrorCode GetViewport(D3DVIEWPORT9* pViewport); + + /* + * GetProjection + */ + const D3DXMATRIX& GetProjection() const; + + /* + * GetView + */ + const D3DXMATRIX& GetView() const; }; #endif //__RENDERCONTEXT_H__
--- a/LightClone/Source/View.cpp Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/Source/View.cpp Thu Sep 08 11:55:35 2011 -0700 @@ -320,11 +320,17 @@ D3DXMATRIX kScaleMatrix; D3DXMatrixScaling(&kScaleMatrix, kScale.x, kScale.y, kScale.z); - const uint32 nSizeX = pEnvironment->GetWidth(); - const uint32 nSizeY = pEnvironment->GetHeight(); + const uint32 nSizeX = pEnvironment->GetWidth(); + const uint32 nSizeY = pEnvironment->GetHeight(); + + const D3DXMATRIX& kProjection = kContext.GetProjection(); + const D3DXMATRIX& kView = kContext.GetView(); - D3DXVECTOR3 kCenterWorld(-0.0f, 0.0f, -0.0f); - //D3DXVec3Unproject(&kCenterWorld, &kCenterScreen, &kViewport, &kProjectionMatrix, &kViewMatrix, &kWorldMatrix); + D3DVIEWPORT9 kViewport; + kContext.GetViewport(&kViewport); + + //D3DXVECTOR3 kCenterWorld(0.0f, 0.0f, 0.0f); + const D3DXVECTOR3& kCenterWorld = ComputeOrigin(0.5f * (ScreenSizeX - 304.0f), 0.5f * ScreenSizeY, kViewport, kProjection, kView); for(uint32 nZ = 0; nZ < nSizeY; ++nZ) {
--- a/LightClone/ToDo.txt Wed Sep 07 16:09:39 2011 -0700 +++ b/LightClone/ToDo.txt Thu Sep 08 11:55:35 2011 -0700 @@ -1,7 +1,13 @@ -1. Only draw slots that are being used -2. Center grid in viewport -3. Button tool tips -4. Main menu -5. Robot model & texture -6. Separate button images from dialog box -7. Refactor function handling in the VM \ No newline at end of file +1. Only draw slots that are being used +2. Center grid in viewport +3. Button tool tips +4. Main menu +5. Pause menu +6. Robot model & texture +7. Separate button images from dialog box +8. Finish level completion dialog +9. Implement game over dialog +10. Implement confirm exit dialog +11. Create textures for each button state +12. Help interface +13. Add button to clear code panes \ No newline at end of file