// Platform skeleton for EterLib/GrpScreen.h (40250 EterLib/GrpScreen.cpp), generated by platform_stub.py. // Every MT_PLATFORM_STUB() body is unimplemented: replace it with the platform implementation. #include "EterLib/StdAfx.h" #include "EterLib/GrpScreen.h" #include "EterLib/StateManager.h" #include "EterLib/Camera.h" #include "../PlatformStub.h" #include "UIRenderCommands.h" #include // 40250 GrpScreen.cpp:838 CScreen::CScreen() { } CScreen::~CScreen() { } auto CScreen::ClearDepthBuffer() -> void { if (ms_lpd3dDevice) ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_ZBUFFER, ms_clearColor, ms_clearDepth, ms_clearStencil); } auto CScreen::Clear() -> void { if (ms_lpd3dDevice) ms_lpd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, ms_clearColor, ms_clearDepth, ms_clearStencil); } // 40250 GrpScreen.cpp:691. CPythonApplication::Process brackets the frame's render with Begin/End; only // inside the scene does CStateManager hand transforms to the recording device. bool CScreen::Begin() { assert(ms_lpd3dDevice != NULL); ResetFaceCount(); if (!STATEMANAGER.BeginScene()) { Tracenf("BeginScene FAILED\n"); return false; } return true; } // 40250 GrpScreen.cpp:705 void CScreen::End() { STATEMANAGER.EndScene(); } auto CScreen::Show(HWND) -> void { MT_PLATFORM_STUB(); } auto CScreen::Show(RECT *) -> void { MT_PLATFORM_STUB(); } auto CScreen::Show(RECT *, HWND) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderLine2d(float sx, float sy, float ex, float ey, float) -> void { UIRenderAdd({UIRenderCommand::Line, sx, sy, ex, ey, ms_diffuseColor}); } auto CScreen::RenderBox2d(float sx, float sy, float ex, float ey, float) -> void { // 40250's four line pairs, including its one-pixel extension of the bottom edge. UIRenderAdd({UIRenderCommand::Line, sx, sy, ex, sy, ms_diffuseColor}); UIRenderAdd({UIRenderCommand::Line, sx, sy, sx, ey, ms_diffuseColor}); UIRenderAdd({UIRenderCommand::Line, ex, sy, ex, ey, ms_diffuseColor}); UIRenderAdd({UIRenderCommand::Line, sx, ey, ex + 1.0f, ey, ms_diffuseColor}); } auto CScreen::RenderBar2d(float sx, float sy, float ex, float ey, float) -> void { UIRenderAdd({UIRenderCommand::Bar, sx, sy, ex, ey, ms_diffuseColor}); } auto CScreen::RenderGradationBar2d(float sx, float sy, float ex, float ey, DWORD start, DWORD end, float) -> void { if (sx == ex || sy == ey) return; UIRenderCommand command{UIRenderCommand::GradientBar, sx, sy, ex, ey, start}; command.end_argb = end; UIRenderAdd(std::move(command)); } auto CScreen::RenderCircle2d(float, float, float, float, int) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderCircle3d(float, float, float, float, int) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderLine3d(float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderBox3d(float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderBar3d(float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderBar3d(const D3DXVECTOR3 *) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderGradationBar3d(float, float, float, float, float, float, DWORD, DWORD) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderLineCube(float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderCube(float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderCube(float, float, float, float, float, float, D3DXMATRIX) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderTextureBox(float, float, float, float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderBillboard(D3DXVECTOR3 *, D3DXCOLOR &) -> void { MT_PLATFORM_STUB(); } auto CScreen::DrawMinorGrid(float, float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::DrawGrid(float, float, float, float, float, float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderD3DXMesh(LPD3DXMESH, const D3DXMATRIX *, float, float, float, float, D3DFILLMODE) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderSphere(const D3DXMATRIX *, float, float, float, float, D3DFILLMODE) -> void { MT_PLATFORM_STUB(); } auto CScreen::RenderCylinder(const D3DXMATRIX *, float, float, float, float, float, D3DFILLMODE) -> void { MT_PLATFORM_STUB(); } // 40250 GrpScreen.cpp void CScreen::SetColorOperation() { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); } // 40250 GrpScreen.cpp void CScreen::SetDiffuseOperation() { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); } // 40250 GrpScreen.cpp void CScreen::SetBlendOperation() { STATEMANAGER.SetTexture(0, NULL); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_CURRENT); STATEMANAGER.SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); STATEMANAGER.SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); } auto CScreen::SetOneColorOperation(D3DXCOLOR &) -> void { MT_PLATFORM_STUB(); } auto CScreen::SetAddColorOperation(D3DXCOLOR &) -> void { MT_PLATFORM_STUB(); } auto CScreen::SetDiffuseColor(DWORD color) -> void { ms_diffuseColor = color; } auto CScreen::SetDiffuseColor(float r, float g, float b, float a) -> void { auto channel = [](float value) -> DWORD { return static_cast(std::clamp(value, 0.0f, 1.0f) * 255.0f + 0.5f); }; ms_diffuseColor = (channel(a) << 24) | (channel(r) << 16) | (channel(g) << 8) | channel(b); } auto CScreen::SetClearColor(float, float, float, float) -> void { MT_PLATFORM_STUB(); } auto CScreen::SetClearDepth(float) -> void { MT_PLATFORM_STUB(); } auto CScreen::SetClearStencil(DWORD) -> void { MT_PLATFORM_STUB(); } // 40250 GrpScreen.cpp:487, verbatim: the pick ray through the cursor. void CScreen::SetCursorPosition(int x, int y, int hres, int vres) { D3DXVECTOR3 v; v.x = -(((2.0f * x) / hres) - 1) / ms_matProj._11; v.y = (((2.0f * y) / vres) - 1) / ms_matProj._22; v.z = 1.0f; D3DXMATRIX matViewInverse=ms_matInverseView; //D3DXMatrixInverse(&matViewInverse, NULL, &ms_matView); ms_vtPickRayDir.x = v.x * matViewInverse._11 + v.y * matViewInverse._21 + v.z * matViewInverse._31; ms_vtPickRayDir.y = v.x * matViewInverse._12 + v.y * matViewInverse._22 + v.z * matViewInverse._32; ms_vtPickRayDir.z = v.x * matViewInverse._13 + v.y * matViewInverse._23 + v.z * matViewInverse._33; ms_vtPickRayOrig.x = matViewInverse._41; ms_vtPickRayOrig.y = matViewInverse._42; ms_vtPickRayOrig.z = matViewInverse._43; ms_Ray.SetStartPoint(ms_vtPickRayOrig); ms_Ray.SetDirection(-ms_vtPickRayDir, 51200.0f); } auto CScreen::GetCursorPosition(float * px, float * py, float * pz) -> bool { if (!GetCursorXYPosition(px, py)) return false; if (!GetCursorZPosition(pz)) return false; return true; } auto CScreen::GetCursorXYPosition(float * px, float * py) -> bool { D3DXVECTOR3 v3Eye = CCameraManager::Instance().GetCurrentCamera()->GetEye(); TPosition posVertices[4]; posVertices[0] = TPosition(v3Eye.x - 90000000.0f, v3Eye.y + 90000000.0f, 0.0f); posVertices[1] = TPosition(v3Eye.x - 90000000.0f, v3Eye.y - 90000000.0f, 0.0f); posVertices[2] = TPosition(v3Eye.x + 90000000.0f, v3Eye.y + 90000000.0f, 0.0f); posVertices[3] = TPosition(v3Eye.x + 90000000.0f, v3Eye.y - 90000000.0f, 0.0f); static const WORD sc_awFillRectIndices[6] = { 0, 2, 1, 2, 3, 1, }; float u, v, t; for (int i = 0; i < 2; ++i) { if (IntersectTriangle(ms_vtPickRayOrig, ms_vtPickRayDir, posVertices[sc_awFillRectIndices[i * 3]], posVertices[sc_awFillRectIndices[i * 3 + 1]], posVertices[sc_awFillRectIndices[i * 3 + 2]], &u, &v, &t)) { *px = u; *py = v; return true; } } return false; } auto CScreen::GetCursorZPosition(float * pz) -> bool { D3DXVECTOR3 v3Eye = CCameraManager::Instance().GetCurrentCamera()->GetEye(); TPosition posVertices[4]; posVertices[0] = TPosition(v3Eye.x - 90000000.0f, 0.0f, v3Eye.z + 90000000.0f); posVertices[1] = TPosition(v3Eye.x - 90000000.0f, 0.0f, v3Eye.z - 90000000.0f); posVertices[2] = TPosition(v3Eye.x + 90000000.0f, 0.0f, v3Eye.z + 90000000.0f); posVertices[3] = TPosition(v3Eye.x + 90000000.0f, 0.0f, v3Eye.z - 90000000.0f); static const WORD sc_awFillRectIndices[6] = { 0, 2, 1, 2, 3, 1, }; float u, v, t; for (int i = 0; i < 2; ++i) { if (IntersectTriangle(ms_vtPickRayOrig, ms_vtPickRayDir, posVertices[sc_awFillRectIndices[i * 3]], posVertices[sc_awFillRectIndices[i * 3 + 1]], posVertices[sc_awFillRectIndices[i * 3 + 2]], &u, &v, &t)) { *pz = t; return true; } } return false; } auto CScreen::GetPickingPosition(float t, float * x, float * y, float * z) -> void { *x = ms_vtPickRayOrig.x + ms_vtPickRayDir.x * t; *y = ms_vtPickRayOrig.y + ms_vtPickRayDir.y * t; *z = ms_vtPickRayOrig.z + ms_vtPickRayDir.z * t; } // 40250 GrpScreen.cpp:749-779. void CScreen::ProjectPosition(float x, float y, float z, float * pfX, float * pfY) { D3DXVECTOR3 Input(x, y, z); D3DXVECTOR3 Output; D3DXVec3Project(&Output, &Input, &ms_Viewport, &ms_matProj, &ms_matView, &ms_matIdentity); *pfX = Output.x; *pfY = Output.y; } void CScreen::ProjectPosition(float x, float y, float z, float * pfX, float * pfY, float * pfZ) { D3DXVECTOR3 Input(x, y, z); D3DXVECTOR3 Output; D3DXVec3Project(&Output, &Input, &ms_Viewport, &ms_matProj, &ms_matView, &ms_matIdentity); *pfX = Output.x; *pfY = Output.y; *pfZ = Output.z; } void CScreen::UnprojectPosition(float x, float y, float z, float * pfX, float * pfY, float * pfZ) { D3DXVECTOR3 Input(x, y, z); D3DXVECTOR3 Output; D3DXVec3Unproject(&Output, &Input, &ms_Viewport, &ms_matProj, &ms_matView, &ms_matIdentity); *pfX = Output.x; *pfY = Output.y; *pfZ = Output.z; } auto CScreen::IsLostDevice() -> BOOL { MT_PLATFORM_STUB(); return mt_platform_stub_return(); } auto CScreen::RestoreDevice() -> BOOL { MT_PLATFORM_STUB(); return mt_platform_stub_return(); } auto CScreen::BuildViewFrustum() -> void { CCamera* pkCamera = CCameraManager::Instance().GetCurrentCamera(); if (!pkCamera) return; const D3DXVECTOR3& c_rv3Eye = pkCamera->GetEye(); const D3DXVECTOR3& c_rv3View = pkCamera->GetView(); auto vv = ms_matView * ms_matProj; ms_frustum.BuildViewFrustum2( vv, ms_fNearY, ms_fFarY, ms_fFieldOfView, ms_fAspect, c_rv3Eye, c_rv3View); } auto CScreen::Identity() -> void { STATEMANAGER.SetTransform(D3DTS_WORLD, &ms_matIdentity); } decltype(CScreen::ms_diffuseColor) CScreen::ms_diffuseColor{}; decltype(CScreen::ms_clearColor) CScreen::ms_clearColor{}; decltype(CScreen::ms_clearStencil) CScreen::ms_clearStencil{}; decltype(CScreen::ms_clearDepth) CScreen::ms_clearDepth{}; decltype(CScreen::ms_frustum) CScreen::ms_frustum{};