All pastes #904384 Raw Edit

Mine

public text v1 · immutable
·published 2008-02-14 22:15 UTC
rendered paste body


class Drawer
{
private:
    float fMinX;
    float fMinY;
    float fHeight;
    float fWidth;
    float fDistX;
    float fDistY;

    int iScreenHeight;
    int iScreenWidth;

    int iOriginX;
    int iOriginY;

public:
    //Constructor
    Drawer(float fScreeMaxX,float fScreenMaxY,float fScreenMinX,float fScreenMinY,
            int iScreenX,int iScreenY,int iCenterX,int iCenterY);

    //Formulas
    inline float Wrangle(float distance,float fT);

    //Drawers
    void Draw(float iT);
};

Drawer::Drawer(float fScreenMaxX,float fScreenMaxY,float fScreenMinX,float fScreenMinY,int iScreenX,
                           int iScreenY,int iCenterX,int iCenterY)
{
    fMinX = fScreenMinX;
    fMinY = fScreenMinY;
    fHeight = fScreenMaxY - fScreenMinY;
    fWidth = fScreenMaxX - fScreenMinX;
    fDistX = fWidth/iScreenX;
    fDistY = fHeight/iScreenY;

    iScreenHeight = iScreenX;
    iScreenWidth = iScreenY;
    iOriginX = iCenterX;
    iOriginY = iCenterX;
}
 
static const float fRadian = 3.14159265f / 180.0f;

float Drawer::Wrangle(float fDistance, float fT)
{
    fT *= 5*fRadian;

    float fCircular = cos( fDistance-fT)*0.025;
    float fDamp = fDistance*0.025;
    if(fDamp < 0.5f)
        fDamp = 0.5f;

    //float fWave = cos(fX+fT)/40.0f;
    return fCircular/(fDamp);
}


void Drawer::Draw(float iT)
{
    int i = 0;
    glColor3f(0.0f,0.0f,1.0f);

    float iScale = 64./iScreenWidth;
    float jScale = 64./iScreenHeight;

    static std::vector<float> distances;
    if (distances.empty()) {
        distances.resize(iScreenHeight * iScreenWidth);

        for (int i = 0; i < iScreenHeight; ++i) {
            for (int j = 0; j < iScreenWidth; ++j) {
                float fX = (i*iScale - iOriginX) * 100 * fRadian;
                float fY = (j*jScale - iOriginY) * 100 * fRadian;

                distances[i * iScreenWidth + j] = sqrt(fX*fX + fY*fY);
            }
        }
    }

    static std::vector<float> grid(iScreenHeight * iScreenWidth);
    for (int i = 0; i < iScreenHeight; ++i)
        for (int j = 0; j < iScreenWidth; ++j)
            grid[i * iScreenWidth + j] = Wrangle(distances[i * iScreenWidth + j], iT);

    static std::vector<float> vertices((iScreenHeight - 1) * iScreenWidth * 6);
    static std::vector<float> colors((iScreenHeight - 1) * iScreenWidth * 6);

#if 1
    while(i < iScreenHeight - 1)
    {
        float fResult[2];
        int j = 0;
        while(j < iScreenWidth) {
            fResult[0] = grid[(i + 1) * iScreenWidth + j];
            fResult[1] = grid[i * iScreenWidth + j];

            int index = (i*iScreenWidth+j)*6;

            colors[index + 2] = 0.75 - fResult[0]*10;
            colors[index + 5] = 0.75 - fResult[1]*10;

            float fX = fMinX + i*fDistX;
            float fY = fMinY + j*fDistY;

            vertices[index] = fX + fDistX;
            vertices[index+1] = fY;
            vertices[index+2] = fResult[0];
            vertices[index+3] = fX;
            vertices[index+4] = fY;
            vertices[index+5] = fResult[1];

            j++;
        }

        i++;
    }
#endif

    glVertexPointer(3, GL_FLOAT, 0, &vertices[0]);
    glColorPointer(3, GL_FLOAT, 0, &colors[0]);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    for (int i = 0; i < iScreenHeight-1; ++i)
        glDrawArrays(GL_TRIANGLE_STRIP, iScreenWidth*i*2, iScreenWidth*2);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
}