分形之花篮(Flower Basket)

这一篇展示的图形与上一篇文章分形之皇冠(Crown)很相似。

核心代码:

static void FractalFlowerBasket(const Vector3& vStart, const Vector3& vEnd, Yreal angle, Yreal top, Yreal bian, Vector3* pVertices)
{
    Vector3 vSub = vEnd - vStart;
    Yreal len = D3DXVec3Length(&vSub);

    pVertices[0] = vStart;
    pVertices[4] = vEnd;

    Yreal alfa = atan2f(vSub.y, vSub.x);

    Yreal a0 = alfa + angle;
    Yreal a1 = alfa - angle;
    alfa += atanf(top*2.0f);

    Yreal l = len * sqrtf(0.25f + top*top);
    pVertices[2].x = vStart.x + cosf(alfa)*l;
    pVertices[2].y = vStart.y + sinf(alfa)*l;
    pVertices[2].z = 0.0f;

    l = len * bian;
    pVertices[1].x = vStart.x + cosf(a0)*l;
    pVertices[1].y = vStart.y + sinf(a0)*l;
    pVertices[1].z = 0.0f;

    pVertices[3].x = vEnd.x - cosf(a1)*l;
    pVertices[3].y = vEnd.y - sinf(a1)*l;
    pVertices[3].z = 0.0f;
}

软件截图:

从图上看,我学得这东西不该叫花篮,应该叫花圈。

软件下载地址:https://files.cnblogs.com/WhyEngine/Fractal.7z

posted on 2014-10-17 16:43  叶飞影  阅读(1732)  评论(0编辑  收藏  举报