directx — соединяет линии, чтобы они выглядели симметрично в d3d9 Stack Overflow

У меня проблема с функцией atan2,

На самом деле, я пытаюсь соединить линии, чтобы они выглядели симметрично.

В настоящее время это выглядит так:

pic1
pic2

Расчет:

    CRect rectCurrent = pCurrent->GetRect();
CRect rectNext = pNext>GetRect();

CPoint ptLineStart = rectCurrent.CenterPoint();
CPoint ptLineEnd = rectNext.CenterPoint();

FLOAT fRadian = ((atan2(ptLineEnd.y - ptLineStart.y, ptLineEnd.x - ptLineStart.x)));
{
FLOAT fScaleX = sqrt(pow(ptLineStart.x - ptLineEnd.x, 2) + pow(ptLineStart.y - ptLineEnd.y, 2));
RenderTextureRotate(ptLineStart, pTexture, 255, fScaleX / pTexture->GetSize().cx, 1.0f, fRadian);
}

Функция RenderTextureRotate:

void RenderTextureRotate(_In_ CPoint pt, _Inout_ CMTexture* pTexture, _In_ CONST DWORD dwBlendFactor, _In_ FLOAT fScaleX, _In_ FLOAT fScaleY, _In_ FLOAT fRadian)
{
if (!pTexture)
return;

// scalling
fScaleX = (pTexture->GetSize().cx * fScaleX);
fScaleY = (pTexture->GetSize().cy * fScaleY);
// set the texture FLOAT rect
S_fRect rct = { pt.x, pt.y, pt.x + fScaleX, pt.y + fScaleY };

D3DXVECTOR2 v1, v2, v3, v4;
D3DXMATRIX  mRot;

// set up 2d vectors for rotation
v1.x = 0;
v1.y = 0;
v2.x = fScaleX;
v2.y = 0;
v3.x = 0;
v3.y = fScaleY;
v4.x = fScaleX;
v4.y = fScaleY;

// rotation in radians
D3DXMatrixRotationZ(&mRot, fRadian);
D3DXVec2TransformCoord(&v1, &v1, &mRot);
D3DXVec2TransformCoord(&v2, &v2, &mRot);
D3DXVec2TransformCoord(&v3, &v3, &mRot);
D3DXVec2TransformCoord(&v4, &v4, &mRot);

// set texture vertex
sTEXTUREVERTEX vertex[4];
SetTextureVertex((&vertex[0]), rct.fLeft + v1.x, rct.fTop + v1.y, pTexture->GetCoordinates().fuLT, pTexture->GetCoordinates().fvLT);
SetTextureVertex((&vertex[1]), rct.fLeft + v2.x, rct.fTop + v2.y, pTexture->GetCoordinates().fuRT, pTexture->GetCoordinates().fvRT);
SetTextureVertex((&vertex[2]), rct.fLeft + v3.x, rct.fTop + v3.y, pTexture->GetCoordinates().fuLB, pTexture->GetCoordinates().fvLB);
SetTextureVertex((&vertex[3]), rct.fLeft + v4.x, rct.fTop + v4.y, pTexture->GetCoordinates().fuRB, pTexture->GetCoordinates().fvRB);

// prepare device for texture rendering just small things like blendfactor.
PREPARE_DEVICE_TEXTURRENDER(m_pD3DDevice);

// set texture
m_pD3DDevice->SetTexture(0, pTexture->GetDXTexture());
// set FVF
m_pD3DDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
// draw
m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertex, sizeof(sTEXTUREVERTEX));
// reset texture.
m_pD3DDevice->SetTexture(0, NULL);
}

S_fRect структура:

struct S_fRect
{
FLOAT fLeft;
FLOAT fTop;
FLOAT fRight;
FLOAT fBottom;
};

Что я делаю неправильно?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector