我对函数atan2
有疑问。
实际上,我正在尝试将这些线连接起来看起来是对称的。
目前它看起来像这样:
计算:
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:
struct S_fRect
{
FLOAT fLeft;
FLOAT fTop;
FLOAT fRight;
FLOAT fBottom;
};
我做错了什么?