分形之二叉樹(Binary Tree)
核心代碼:
復制代碼
static void FractalBinaryTree(const Vector3& vStart, const Vector3& vEnd, Yreal angle, Yreal branch_c, Vector3* pVertices)
{
Vector3 vSub = vEnd - vStart;
Yreal len = D3DXVec3Length(&vSub);
Yreal alfa = atan2f(vSub.y, vSub.x);
Yreal branch = len*branch_c;
pVertices[0] = vEnd;
pVertices[1].x = pVertices[0].x + branch*cosf(alfa - angle);
pVertices[1].y = pVertices[0].y + branch*sinf(alfa - angle);
pVertices[1].z = 0.0f;
pVertices[2] = vEnd;
pVertices[3].x = pVertices[2].x + branch*cosf(alfa + angle);
pVertices[3].y = pVertices[2].y + branch*sinf(alfa + angle);
pVertices[3].z = 0.0f;
}