All pastes #904855 Raw Edit

Stuff

public text v1 · immutable
·published 2008-02-15 10:25 UTC
rendered paste body
#ifndef drawer_hpp
#define drawer_hpp
 
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
 
class Drawer
{
private:
    float fMinX;
    float fMinY;
    float fHeight;
    float fWidth;
    float fDistX;
    float fDistY;

    float iScale;
    float jScale;
 
    std::vector<float> distances;
    std::vector<float> vertices;
    std::vector<float> colors;
 
 
public:
    int iScreenHeight;
    int iScreenWidth;
	std::vector<float> grid;

    //Constructor
    Drawer(float fScreeMaxX,float fScreenMaxY,float fScreenMinX,float fScreenMinY,
            int iScreenX,int iScreenY);

    //Drawers
    void Draw();
};
 
static const float fRadian = 3.14159265f / 180.0f;
 
Drawer::Drawer(float fScreenMaxX,float fScreenMaxY,float fScreenMinX,float fScreenMinY,int iScreenX,
                           int iScreenY)
    : distances(iScreenX * iScreenY)
    , grid(iScreenX * iScreenY)
    , vertices((iScreenX - 1) * iScreenY * 6)
    , colors((iScreenX - 1) * iScreenY * 6)
{
    fMinX = fScreenMinX;
    fMinY = fScreenMinY;
    fHeight = fScreenMaxY - fScreenMinY;
    fWidth = fScreenMaxX - fScreenMinX;
    fDistX = fWidth/iScreenX;
    fDistY = fHeight/iScreenY;
 
    iScreenHeight = iScreenX;
    iScreenWidth = iScreenY;
 
    iScale = 128./iScreenWidth;
    jScale = 128./iScreenHeight;
 
}
 
void Circular(float fT,int iHeight,int iWidth,float *fGrid)
{	
	for (int i = 0; i < iHeight; ++i)
	{
		for (int j = 0; j < iWidth; ++j)
		{

			float fX = i;
			float fY = j;
			float fDistance = sqrt(fX*fX+fY*fY);
			fT *= 5*fRadian;
			float fCircular = cos( -fT)*0.00625;
			float fDamp = fDistance*0.0125;
			float fWave = cos (fX+fT)*0.025;
			if(fDamp < 0.5f)
			fDamp = 0.5f;

			fGrid[i * iWidth + j] = fCircular/fDamp + fWave;
		}
	}
}


void Drawer::Draw()
{
    int i = 0;
    glColor3f(0.0f,0.0f,1.0f);
 
    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++;
    }
 
    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);
}
#endif