- 4
- 6
Получаю координаты педа игрока и отрисовываю на нем бокс, но когда приближаюсь к игроку то бокс уменьшается, а когда отдаляюсь то становится больше, хотя все должно быть наоборот
C++:
void CRender::drawFilledBox(float x, float y, float width, float height, D3DCOLOR color)
{
vertex V[4];
V[0].color = V[1].color = V[2].color = V[3].color = color;
V[0].z = V[1].z = V[2].z = V[3].z = 0;
V[0].rhw = V[1].rhw = V[2].rhw = V[3].rhw = 0;
V[0].x = x;
V[0].y = y;
V[1].x = x + width;
V[1].y = y;
V[2].x = x + width;
V[2].y = y + height;
V[3].x = x;
V[3].y = y + height;
unsigned short indexes[] = { 0, 1, 3, 1, 2, 3 };
pRender->renderDevice->CreateVertexBuffer(4 * sizeof(vertex), D3DUSAGE_WRITEONLY, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &g_pVB, NULL);
pRender->renderDevice->CreateIndexBuffer(2 * sizeof(short), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIB, NULL);
VOID* pVertices;
g_pVB->Lock(0, sizeof(V), (void**)&pVertices, 0);
memcpy(pVertices, V, sizeof(V));
g_pVB->Unlock();
VOID* pIndex;
g_pIB->Lock(0, sizeof(indexes), (void**)&pIndex, 0);
memcpy(pIndex, indexes, sizeof(indexes));
g_pIB->Unlock();
pRender->renderDevice->SetTexture(0, NULL);
pRender->renderDevice->SetPixelShader(NULL);
pRender->renderDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
pRender->renderDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
pRender->renderDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
pRender->renderDevice->SetStreamSource(0, g_pVB, 0, sizeof(vertex));
pRender->renderDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);
pRender->renderDevice->SetIndices(g_pIB);
pRender->renderDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
g_pVB->Release();
g_pIB->Release();
}
void CalcScreenCoors(D3DXVECTOR3 *vecWorld, D3DXVECTOR3 *vecScreen)
{
//traceLastFunc("CalcScreenCoors()");
/** C++-ifyed function 0x71DA00, formerly called by CHudSA::CalcScreenCoors **/
// Get the static view matrix as D3DXMATRIX
D3DXMATRIX m((float *)(0xB6FA2C));
// Get the static virtual screen (x,y)-sizes
DWORD *dwLenX = (DWORD *)(0xC17044);
DWORD *dwLenY = (DWORD *)(0xC17048);
//DWORD *dwLenZ = (DWORD*)(0xC1704C);
//double aspectRatio = (*dwLenX) / (*dwLenY);
// Do a transformation
vecScreen->x = (vecWorld->z * m._31) + (vecWorld->y * m._21) + (vecWorld->x * m._11) + m._41;
vecScreen->y = (vecWorld->z * m._32) + (vecWorld->y * m._22) + (vecWorld->x * m._12) + m._42;
vecScreen->z = (vecWorld->z * m._33) + (vecWorld->y * m._23) + (vecWorld->x * m._13) + m._43;
// Get the correct screen coordinates
double fRecip = (double)1.0 / vecScreen->z; //(vecScreen->z - (*dwLenZ));
vecScreen->x *= (float)(fRecip * (*dwLenX));
vecScreen->y *= (float)(fRecip * (*dwLenY));
}
D3DXVECTOR3
player_pos,
player_screen_pos;
actor_info* actorTargetInfo = g_Players->pRemotePlayer[id]->pPlayerData->pSAMP_Actor->pGTA_Ped;
vect3_copy(actorTargetInfo->base.matrix + 12, player_pos);
CalcScreenCoors(&player_pos, &player_screen_pos);
if (player_screen_pos.z < 0.1f)
return;
pRender->drawFilledBox(player_screen_pos.x, player_screen_pos.y, 100, 100, D3DCOLOR_ARGB(255, 0, 255, 0));