Remove window code from DLASystem{.h,.cpp}
This commit is contained in:
parent
ef89b285d1
commit
4e497b8438
@ -4,31 +4,18 @@
|
|||||||
|
|
||||||
#include "DLASystem.h"
|
#include "DLASystem.h"
|
||||||
|
|
||||||
// colors
|
|
||||||
namespace colours {
|
|
||||||
GLfloat blue[] = {0.1, 0.3, 0.9, 1.0}; // blue
|
|
||||||
GLfloat red[] = {1.0, 0.2, 0.1, 0.2}; // red
|
|
||||||
GLfloat green[] = {0.3, 0.6, 0.3, 1.0}; // green
|
|
||||||
GLfloat paleGrey[] = {0.7, 0.7, 0.7, 1.0}; // green
|
|
||||||
GLfloat darkGrey[] = {0.2, 0.2, 0.2, 1.0}; // green
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// this function gets called every step,
|
// this function gets called every step,
|
||||||
// if there is an active particle then it gets moved,
|
// if there is an active particle then it gets moved,
|
||||||
// if not then add a particle
|
// if not then add a particle
|
||||||
void DLASystem::Update() {
|
void DLASystem::Update() {
|
||||||
if (lastParticleIsActive == 1)
|
if (lastParticleIsActive == 1) {
|
||||||
moveLastParticle();
|
moveLastParticle();
|
||||||
else if (numParticles < endNum) {
|
} else if (numParticles < endNum) {
|
||||||
addParticleOnAddCircle();
|
addParticleOnAddCircle();
|
||||||
setParticleActive();
|
setParticleActive();
|
||||||
}
|
}
|
||||||
if (lastParticleIsActive == 0 || slowNotFast == 1)
|
|
||||||
glutPostRedisplay(); //Tell GLUT that the display has changed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DLASystem::clearParticles() {
|
void DLASystem::clearParticles() {
|
||||||
// delete particles and the particle list
|
// delete particles and the particle list
|
||||||
for (int i = 0; i < numParticles; i++) {
|
for (int i = 0; i < numParticles; i++) {
|
||||||
@ -88,7 +75,6 @@ int DLASystem::checkStop() {
|
|||||||
if (killCircle + 2 >= gridSize / 2) {
|
if (killCircle + 2 >= gridSize / 2) {
|
||||||
pauseRunning();
|
pauseRunning();
|
||||||
cout << "STOP" << endl;
|
cout << "STOP" << endl;
|
||||||
glutPostRedisplay(); // update display
|
|
||||||
return 1;
|
return 1;
|
||||||
} else return 0;
|
} else return 0;
|
||||||
}
|
}
|
||||||
@ -239,9 +225,8 @@ int DLASystem::checkStick() {
|
|||||||
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
DLASystem::DLASystem(Window *set_win) {
|
DLASystem::DLASystem() {
|
||||||
cout << "creating system, gridSize " << gridSize << endl;
|
cout << "creating system, gridSize " << gridSize << endl;
|
||||||
win = set_win;
|
|
||||||
numParticles = 0;
|
numParticles = 0;
|
||||||
endNum = 1000;
|
endNum = 1000;
|
||||||
|
|
||||||
@ -275,42 +260,3 @@ DLASystem::~DLASystem() {
|
|||||||
if (logfile.is_open())
|
if (logfile.is_open())
|
||||||
logfile.close();
|
logfile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// this draws the system
|
|
||||||
void DLASystem::DrawSquares() {
|
|
||||||
|
|
||||||
// draw the particles
|
|
||||||
double halfSize = 0.5;
|
|
||||||
for (int p = 0; p < numParticles; p++) {
|
|
||||||
double *vec = particleList[p]->pos;
|
|
||||||
glPushMatrix();
|
|
||||||
if (p == numParticles - 1 && lastParticleIsActive == 1)
|
|
||||||
glColor4fv(colours::red);
|
|
||||||
else if (p == 0)
|
|
||||||
glColor4fv(colours::green);
|
|
||||||
else
|
|
||||||
glColor4fv(colours::blue);
|
|
||||||
glRectd(drawScale * (vec[0] - halfSize),
|
|
||||||
drawScale * (vec[1] - halfSize),
|
|
||||||
drawScale * (vec[0] + halfSize),
|
|
||||||
drawScale * (vec[1] + halfSize));
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
// print some information (at top left)
|
|
||||||
// this ostringstream is a way to create a string with numbers and words (similar to cout << ... )
|
|
||||||
ostringstream str;
|
|
||||||
str << "num " << numParticles << " size " << clusterRadius;
|
|
||||||
|
|
||||||
// print the string
|
|
||||||
win->displayString(str, -0.9, 0.9, colours::red);
|
|
||||||
|
|
||||||
// if we are paused then print this (at bottom left)
|
|
||||||
if (running == 0) {
|
|
||||||
ostringstream pauseStr;
|
|
||||||
pauseStr << "paused";
|
|
||||||
win->displayString(pauseStr, -0.9, -0.9, colours::red);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
19
DLASystem.h
19
DLASystem.h
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <GLUT/glut.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -13,7 +12,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "Window.h"
|
|
||||||
#include "Particle.h"
|
#include "Particle.h"
|
||||||
#include "rnd.h"
|
#include "rnd.h"
|
||||||
|
|
||||||
@ -23,9 +21,6 @@ using namespace std;
|
|||||||
class DLASystem {
|
class DLASystem {
|
||||||
private:
|
private:
|
||||||
// these are private variables and functions that the user will not see
|
// these are private variables and functions that the user will not see
|
||||||
|
|
||||||
Window *win; // window in which the system is running
|
|
||||||
|
|
||||||
// list of particles
|
// list of particles
|
||||||
vector<Particle *> particleList;
|
vector<Particle *> particleList;
|
||||||
int numParticles;
|
int numParticles;
|
||||||
@ -69,9 +64,6 @@ public:
|
|||||||
// else create a new particle (on the adding circle)
|
// else create a new particle (on the adding circle)
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
// draw particles as squares
|
|
||||||
void DrawSquares();
|
|
||||||
|
|
||||||
// is the simulation running (1) or paused (0) ?
|
// is the simulation running (1) or paused (0) ?
|
||||||
int running;
|
int running;
|
||||||
|
|
||||||
@ -82,7 +74,7 @@ public:
|
|||||||
int lastParticleIsActive;
|
int lastParticleIsActive;
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
DLASystem(Window *set_win);
|
DLASystem();
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
~DLASystem();
|
~DLASystem();
|
||||||
@ -97,7 +89,7 @@ public:
|
|||||||
int checkStop();
|
int checkStop();
|
||||||
|
|
||||||
// stop/start the algorithm
|
// stop/start the algorithm
|
||||||
void setRunning() { if (checkStop() == 0) running = 1; }
|
void setRunning() { if (checkStop() == true) running = 1; }
|
||||||
|
|
||||||
void pauseRunning() { running = 0; }
|
void pauseRunning() { running = 0; }
|
||||||
|
|
||||||
@ -158,11 +150,4 @@ public:
|
|||||||
// check whether the last particle should stick
|
// check whether the last particle should stick
|
||||||
// currently it sticks whenever it touches another particle
|
// currently it sticks whenever it touches another particle
|
||||||
int checkStick();
|
int checkStick();
|
||||||
|
|
||||||
// set the background colour for the window
|
|
||||||
// it would be better for an OOP philosophy to make these member functions for the Window class
|
|
||||||
// but we are being a bit lazy here
|
|
||||||
void setWinBackgroundWhite() { glClearColor(1.0, 1.0, 1.0, 1.0); }
|
|
||||||
|
|
||||||
void setWinBackgroundBlack() { glClearColor(0.0, 0.0, 0.0, 0.0); }
|
|
||||||
};
|
};
|
||||||
|
|||||||
20
mainDLA.cpp
20
mainDLA.cpp
@ -6,19 +6,6 @@
|
|||||||
|
|
||||||
#include "DLASystem.h"
|
#include "DLASystem.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
// functions which are needed for openGL go into a namespace so that we can identify them
|
|
||||||
namespace drawFuncs {
|
|
||||||
void handleKeypress(unsigned char key, int x, int y);
|
|
||||||
|
|
||||||
void display(void);
|
|
||||||
|
|
||||||
void update(int val);
|
|
||||||
|
|
||||||
void introMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a global pointer, which is how we access the system itself
|
// this is a global pointer, which is how we access the system itself
|
||||||
DLASystem *sys;
|
DLASystem *sys;
|
||||||
|
|
||||||
@ -30,8 +17,13 @@ int main(int argc, char **argv) {
|
|||||||
int seed = 6;
|
int seed = 6;
|
||||||
cout << "setting seed " << seed << endl;
|
cout << "setting seed " << seed << endl;
|
||||||
sys->setSeed(seed);
|
sys->setSeed(seed);
|
||||||
|
sys->setRunning();
|
||||||
|
|
||||||
while (sys->Update()) {
|
/*
|
||||||
|
* NOTE: We run at max speed as rendering is handled by a different engine so we simply want to hjand
|
||||||
|
* */
|
||||||
|
while (sys->running) {
|
||||||
|
sys->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user