- void DrawP(LPDIRECT3DDEVICE9 Device, int baseX, int baseY, int baseW, int baseH, D3DCOLOR Cor)
- {
- D3DRECT BarRect = { baseX, baseY, baseX + baseW, baseY + baseH };
- Device->Clear(1, &BarRect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, Cor, 0, 0);
- }
- void DrawCornerBox(LPDIRECT3DDEVICE9 Device, int x, int y, int w, int h, int borderPx, DWORD borderColor)
- {
- DrawP(Device, x - (w / 2), (y - h + borderPx), w / 3, borderPx, borderColor); //BOTtom
- DrawP(Device, x - (w / 2) + w - w / 3, (y - h + borderPx), w / 3, borderPx, borderColor); //bottom
- DrawP(Device, x - (w / 2), (y - h + borderPx), borderPx, w / 3, borderColor); //left
- DrawP(Device, x - (w / 2), (y - h + borderPx) + h - w / 3, borderPx, w / 3, borderColor); //left
- DrawP(Device, x - (w / 2), y, w / 3, borderPx, borderColor); //top
- DrawP(Device, x - (w / 2) + w - w / 3, y, w / 3, borderPx, borderColor); //top
- DrawP(Device, (x + w - borderPx) - (w / 2), (y - h + borderPx), borderPx, w / 3, borderColor);//right
- DrawP(Device, (x + w - borderPx) - (w / 2), (y - h + borderPx) + h - w / 3, borderPx, w / 3, borderColor);//right
- }
- struct ModelInfo_t
- {
- D3DXVECTOR3 Position2D;
- D3DXVECTOR3 Position3D;
- float RealDistance;
- };
- std::vectorModelInfo;
- void Worldtoscreen(LPDIRECT3DDEVICE9 Device)
- {
- ModelInfo_t* pModel = new ModelInfo_t;
- D3DXMATRIX projMatrix;
- D3DXVECTOR4 position, input;
- Device->GetViewport(&Viewport);
- Device->GetVertexShaderConstantF(195, projMatrix, 4);
- input.y = 1; //height
- D3DXMatrixTranspose(&projMatrix, &projMatrix);
- D3DXVec4Transform(&position, &input, &projMatrix);
-
- position.x = input.x * projMatrix._11 + input.y * projMatrix._21 + input.z * projMatrix._31 + projMatrix._41;
- position.y = input.x * projMatrix._12 + input.y * projMatrix._22 + input.z * projMatrix._32 + projMatrix._42;
- position.z = input.x * projMatrix._13 + input.y * projMatrix._23 + input.z * projMatrix._33 + projMatrix._43;
- position.w = input.x * projMatrix._14 + input.y * projMatrix._24 + input.z * projMatrix._34 + projMatrix._44;
-
- if (projMatrix._44 > -0.1f)
- {
- pModel->Position2D.x = ((position.x / position.w) * (Viewport.Width / 2.0f)) + Viewport.X + (Viewport.Width / 2.0f);
- pModel->Position2D.y = Viewport.Y + (Viewport.Height / 2.0f) + ((position.y / position.w) * (Viewport.Height / 2.0f));
- pModel->RealDistance = position.w;
- }
- ModelInfo.push_back(pModel);
- //delete[] pModel;
- }
- //dip part:
- if(Stride == 20 && mVector4fCount == 213)
- {
- Worldtoscreen(Device);
- }
- //es part:
- if (ModelInfo.size() != NULL)
- {
- for (int i = 0; i < ModelInfo.size(); i += 1)
- {
- char dst[MAX_PATH];
- sprintf_s(dst, "|%.1f|", ModelInfo[i]->RealDistance);
- DrawText(Device, (int)ModelInfo[i]->Position2D.x-20, (int)ModelInfo[i]->Position2D.y, D3DCOLOR_ARGB(255, 255, 255, 255), dst);
- DrawCornerBox(Device, (int)ModelInfo[i]->Position2D.x, (int)ModelInfo[i]->Position2D.y + 20, 20, 30, 1, D3DCOLOR_ARGB(255, 255, 255, 0));
- }
- ModelInfo.clear();
- }
複製代碼 |
|