Пример #1
0
void PlatformDemo::updateAdditionalMass()
{
    for (unsigned i = 2; i < 6; i++)
    {
        particleArray[i].setMass(BASE_MASS);
    }

    // Find the coordinates of the mass as an index and proportion
    cyclone::real xp = massPos.x;
    if (xp < 0) xp = 0;
    if (xp > 1) xp = 1;

    cyclone::real zp = massPos.z;
    if (zp < 0) zp = 0;
    if (zp > 1) zp = 1;

    // Calculate where to draw the mass
    massDisplayPos.clear();

    // Add the proportion to the correct masses
    particleArray[2].setMass(BASE_MASS + EXTRA_MASS*(1-xp)*(1-zp));
    massDisplayPos.addScaledVector(
        particleArray[2].getPosition(), (1-xp)*(1-zp)
        );

    if (xp > 0)
    {
        particleArray[4].setMass(BASE_MASS + EXTRA_MASS*xp*(1-zp));
        massDisplayPos.addScaledVector(
            particleArray[4].getPosition(), xp*(1-zp)
            );

        if (zp > 0)
        {
            particleArray[5].setMass(BASE_MASS + EXTRA_MASS*xp*zp);
            massDisplayPos.addScaledVector(
                particleArray[5].getPosition(), xp*zp
                );
        }
    }
    if (zp > 0)
    {
        particleArray[3].setMass(BASE_MASS + EXTRA_MASS*(1-xp)*zp);
        massDisplayPos.addScaledVector(
            particleArray[3].getPosition(), (1-xp)*zp
            );
    }
}
Пример #2
0
void BridgeDemo::updateAdditionalMass()
{
    for (unsigned i = 0; i < 12; i++)
    {
        particleArray[i].setMass(BASE_MASS);
    }

    // Find the coordinates of the mass as an index and proportion
    int x = int(massPos.x);
    cyclone::real xp = real_fmod(massPos.x, cyclone::real(1.0f));
    if (x < 0)
    {
        x = 0;
        xp = 0;
    }
    if (x >= 5)
    {
        x = 5;
        xp = 0;
    }

    int z = int(massPos.z);
    cyclone::real zp = real_fmod(massPos.z, cyclone::real(1.0f));
    if (z < 0)
    {
        z = 0;
        zp = 0;
    }
    if (z >= 1)
    {
        z = 1;
        zp = 0;
    }

    // Calculate where to draw the mass
    massDisplayPos.clear();

    // Add the proportion to the correct masses
    particleArray[x*2+z].setMass(BASE_MASS + EXTRA_MASS*(1-xp)*(1-zp));
    massDisplayPos.addScaledVector(
        particleArray[x*2+z].getPosition(), (1-xp)*(1-zp)
        );

    if (xp > 0)
    {
        particleArray[x*2+z+2].setMass(BASE_MASS + EXTRA_MASS*xp*(1-zp));
        massDisplayPos.addScaledVector(
            particleArray[x*2+z+2].getPosition(), xp*(1-zp)
            );

        if (zp > 0)
        {
            particleArray[x*2+z+3].setMass(BASE_MASS + EXTRA_MASS*xp*zp);
            massDisplayPos.addScaledVector(
                particleArray[x*2+z+3].getPosition(), xp*zp
                );
        }
    }
    if (zp > 0)
    {
        particleArray[x*2+z+1].setMass(BASE_MASS + EXTRA_MASS*(1-xp)*zp);
        massDisplayPos.addScaledVector(
            particleArray[x*2+z+1].getPosition(), (1-xp)*zp
            );
    }
}