Hi everyone…
I’ve just started using OF, and it looks pretty good.(I have successfully run the openframeworks examples, so everything is installed and working OK). I thought I’d start by converting one of my simple Processing programs to C++, to get me started (and I’m also curious to see whether it will run faster in C++). I’ve run into a bit of a problem, though…my main class is called “brownian”, and I am getting an error:
||=== brownian, release ===|
C:\Documents and Settings\Compaq_Administrator\Desktop\Open Frameworks\apps\Giles\brownian\src\main.cpp||In function int main()':| C:\Documents and Settings\Compaq\_Administrator\Desktop\Open Frameworks\apps\Giles\brownian\src\main.cpp|15|error: no matching function for call to
brownian::brownian()’
C:\Documents and Settings\Compaq_Administrator\Desktop\Open Frameworks\apps\Giles\brownian\src\brownian.h|12|note: candidates are: brownian::brownian(const brownian&)|
||=== Build finished: 1 errors, 0 warnings ===|
If anyone could help me get past this hurdle, that would be great (it’s not quite as straightforward as Processing).
And the code is here:
main.cpp:
#include "ofMain.h"
#include "brownian.h"
//#include "ofAppGlutWindow.h"
//========================================================================
int main()
{
//ofAppGlutWindow window;
ofSetupOpenGL(500,500, OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new brownian());
}
brownian.h:
#ifndef _BROWNIAN
#define _BROWNIAN
#include "ofMain.h"
#include "particle.h"
#define numparticles 100
class brownian : public ofBaseApp
{
public:
void setup();
void update();
void draw();
particle particles[numparticles];
};
#endif
brownian.cpp:
#include "ofMain.h"
#include "brownian.h"
//--------------------------------------------------------------
void brownian::setup()
{
ofBackground(255,255,255);
ofEnableSmoothing();
int i;
for(i=0; i<numparticles; i++)
{
particles[i] = particle(ofRandom(450, ofGetWidth()-20), ofRandom(450, ofGetHeight()-20), 10, 10, 5, 0.9);
}
}
//------------------------------------------------------------
void brownian::update()
{
int i;
for(i=0; i<numparticles; i++)
{
particles[i].collide();
particles[i].move();
particles[i].xspeed*=particles[i].dampfactor;
particles[i].yspeed*=particles[i].dampfactor;
}
}
//--------------------------------------------------------------
void brownian::draw()
{
int i;
for(i=0; i<numparticles; i++)
{
particles[i].render();
}
}
//--------------------------------------------------------------
particle.h:
#ifndef _PARTICLE
#define _PARTICLE
class particle
{
public:
float xpos, ypos;
float xspeed, yspeed;
float ewidth;
float eheight;
float speedfactor;
float dampfactor;
particle(float x, float y,int ew, int eh, float sf, float df);
void collide();
void move();
void render();
};
#endif
particle.cpp:
#include "particle.h"
particle::particle(float x, float y,int ew, int eh, float sf, float df)
{
xpos=x;
ypos=y;
xspeed=0;
yspeed=0;
ewidth=ew;
eheight=eh;
speedfactor=sf;
dampfactor=df;
}
void particle::collide()
{
float leftcols = ofRandom(0, eheight+1);
float rightcols= ofRandom(0, eheight+1);
float topcols= ofRandom(0, ewidth+1);
float botcols= ofRandom(0, ewidth+1);
xspeed+= (leftcols-rightcols)/speedfactor;
yspeed+= (topcols-botcols)/speedfactor;
}
void particle::move()
{
xpos+=xspeed;
ypos+=yspeed;
if (xpos+ewidth> ofGetWidth() || xpos-ewidth<0) xspeed*=-1;
if (ypos+eheight> ofGetHeight() || ypos-eheight<0) yspeed*=-1;
}
void particle::render()
{
ofFill();
ofSetColor(0,0,0);
ofEllipse(xpos, ypos, ewidth, eheight);
}