在DirectX中创建粒子吸引器

时间:2009-07-29 14:28:59

标签: c++ directx

编辑:我自己解决了这个问题,其中一个很难在其他部分注意到的小错字,现在效果很好。

我有一个C ++的粒子生成器,我从互联网上下载。它基本上是你可以做的一些事情的样本,所以我研究了它,知道发生了什么以及我需要做些什么来添加我想要的功能。我正在研究这个。我有另一种方法,我用来创建GravPoint然后这个方法涉及数学。评论描述了发生了什么以及我的错误在哪里。

// Update velocity with respect to any GravPoints in range
// Start at the head of the list
ppGravPoint = &m_pGravPoints;

// Temporary D3DXVECTOR3
D3DXVECTOR3 vTemp;

// While there is still a node on the list
while ( *ppGravPoint )
{
    pGravPoint = *ppGravPoint;
    // vTemp becomes a vector pointing from m_vCurPos to m_vPoint
    // I'm getting an error at this line, it opens up d3dx9math.inl
    // and points at this piece of code:
    // D3DXINLINE D3DXVECTOR3
    // D3DXVECTOR3::operator - ( CONST D3DXVECTOR3& v ) const
    // {
    //     return D3DXVECTOR3(x - v.x, y - v.y, z - v.z);
    // }
    vTemp = pGravPoint->m_vPoint - pParticle->m_vCurPos;
    // if ||vTemp|| (length of vTemp) < m_fMaxDist (FLOAT m_fMaxDist)
    if((sqrt((vTemp.x * vTemp.x) + (vTemp.y * vTemp.y) + (vTemp.z * vTemp.z)) < pGravPoint->m_fMaxDist))
    {
        // Then the velocity of the current particle being rendered is adjusted
        // to be attracted towards the gravpoint. Pretty sure this is right
        pParticle->m_vCurVel += (vTemp * (pGravPoint->m_fStrength * fElpasedTime));
    }
    // Go to next point if there is one.
    ppGravPoint = &pGravPoint->m_gpNext;
}

1 个答案:

答案 0 :(得分:0)

错误消息是什么?您的示例会建议pParticle->m_vCurPosNULL