#include #include #include #include #include "circ.h" #include "Renderer.h" #include "VecField.h" using namespace std; #define NPARTS 1000 #define P_LEN 50 #define FSCALE 2 Renderer::Renderer(int wid, int ht) { int i; cursX = cursY = 0.0; circle = new Circ(1.0,36); VF = new vecField(wid/FSCALE,ht/FSCALE,FSCALE); initParticles(); Width = wid/FSCALE; Height = ht/FSCALE; cerr << "W H " << Width << " " << Height << "\n"; PathsX = new float*[NPARTS]; PathsY = new float*[NPARTS]; for(i=0;iupdateParms(); while( !AdvectionCrossing(cx, cy)); for(i=0;igetVec(300.0/2.0,300.0/2.0,dx,dy); //cerr << "Center Dx Dy " << dx << " " << dy << "\n"; } void Renderer::updateCursor(float rx,float ry, float &dx, float &dy)// for debugging { cursX = rx; cursY = ry; VF->getVec(rx/2.0,ry/2.0,dx,dy); } // YOUR CODE MAINLY GOES HERE void Renderer::Draw( int cond) // orthogonal mesh { int i,j; float *XV, *YV; float alpha; // cond it used to set up the rendering style if (cond < 2) glLineWidth(2.0); else glLineWidth(1.0); if(cond%2 == 0) alpha = 1.0; else alpha = 0.5; glPushMatrix(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glScalef(2.0,2.0,0.0); glColor4f(0.0,0.8,0.0,alpha); for(j=0;jFilled(0.6,XV[i-5],YV[i-5]); } glPopMatrix(); } bool Renderer::AdvectionCrossing(float &cx, float &cy) // used to determine where the advection path crosses the outer circle { float rad,xx,yy,dx,dy,rx,ry; int count = 0; xx = yy = 150.0; // start in the center rad = 0.0; while (rad < 50.0 && count < 300) { VF->getVec(xx,yy,dx,dy); xx +=dx; yy +=dy; rx = xx - 150.0; ry = yy - 150.0; rad = sqrt(rx*rx + ry*ry); ++count; } //cerr << "CROSSING " << " " << xx*2.0 << " " << yy*2.0 << "\n"; cx = (xx*2.0 - 300.0)/300.0; cy = (yy*2.0 - 300.0)/300.0; if (count == 300) return false; else return true; } void Renderer :: traceParticle(float *X, float *Y) { // Traces a particle int j; float xx,yy; float dx,dy; xx = Width*float(rand()%1000)/1000.0; // a random start yy = Height*float(rand()%1000)/1000.0; for (j=0;j< P_LEN;++j) { X[j] = xx; Y[j] = yy; dx = VF->dX[int(yy)][int(xx)]; dy = VF->dY[int(yy)][int(xx)]; xx += 0.5*dx; // how far does the particle move yy += 0.5*dy; if (xx > (Width-1.0)) xx = Width-1.0; // stop if (xx < 1.0) xx = 1.0; if (yy > (Height-1.0)) yy = Height-1.0; if (yy < 1.0) yy = 0.0; } } void Renderer::DrawOver() { int i; float y; glColor3f(0.6,0.6,0.6); glRectf(700.0,0.0,605.0,600.0); for(i=0;i<14;++i) { y = (i+1)*40.0 - 1.0; glRectf(700.0,y-2.0,840.0,y+2.0); } glColor3f(0.3,0.3,0.8); circle->Outline(10.0,300.0,300.0); circle->Outline(100.0,300.0,300.0); /*FOR Show and tell float rad,xx,yy,dx,dy,rx,ry; int count = 0; glColor3f(1.0,1.0,0.0); glBegin(GL_LINE_STRIP); xx = yy = 150.0; // start in the center rad = 0.0; while (rad < 50.0 && count < 300) { VF->getVec(xx,yy,dx,dy); xx +=dx; yy +=dy; rx = xx - 150.0; ry = yy - 150.0; rad = sqrt(rx*rx + ry*ry); glVertex3f(xx*2,yy*2,0.0); ++count; } glEnd(); */ } void Renderer::initParticles() { // Sets up a set of random start positions int i; for (i=0;i