Hello!
I am a super mega beginner with basically no programming worth noting under my belt.
I am trying to do the very informative Ooops! tutorial (from t he wiki) from here: http://wiki.openframeworks.cc/index.php-…-2B-Classes
So, I am walking through this step by step, and got to the end. For some reason, my little circles/balls are all the same size, even though I declared their dimensions to be different in my array (according to the tutorial). I can’t figure out what I am doing incorrectly. I tried to see if things are being drawn/updated somewhere else (it’s my first time working with C++ or CodeBlocks or any of this stuff)…
Here are my files in the project -
main.cpp
#include "ofMain.h"
#include "testApp.h"
#include "ofAppGlutWindow.h"
//========================================================================
int main( ){
ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, 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 testApp());
}
testApp.h
#ifndef _TEST_APP
#define _TEST_APP
#include "ofMain.h"
#include "ofBall.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
ofBall**myBall;
int nBalls;
};
#endif
testApp.cpp
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
nBalls = 95;
myBall = new ofBall*[nBalls];
for (int i = 0; i < nBalls; i++){
float x = 20+(100*i);
float y = 20+(100*i);
int dim = 10+(i*100);
myBall[i] = new ofBall(x,y,dim);
}
}
//--------------------------------------------------------------
void testApp::update(){
for (int i = 0; i < nBalls; i++){
myBall[i]->update();
}
}
//--------------------------------------------------------------
void testApp::draw(){
for (int i = 0; i < nBalls; i++){
myBall[i]->draw();
}
}
//--------------------------------------------------------------
void testApp::keyPressed(int key){
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h){
}
ofBall.h
#ifndef _OF_BALL
#define _OF_BALL
#include "ofMain.h"
class ofBall{
public:
//method
void update();
void draw();
//constructor
ofBall(float x, float y, int dim);
float x; // position
float y;
float speedY; // speed and direction
float speedX;
int dim; // size
};
#endif
and ofBall.cpp
#include "ofBall.h"
ofBall::ofBall(float _x, float _y, int _dim)
{
x = ofRandom(0, ofGetWidth());
y = ofRandom(0, ofGetHeight());
speedX = ofRandom(-1,1);
speedY = ofRandom(-1,1);
dim = 20;
}
void ofBall::update(){
if (x < 0){
x = 0;
speedX *= -1;
} else if (x > ofGetWidth()) {
x = ofGetWidth();
speedX *=-1;
}
if (y < 0){
y = 0;
speedY *= -1;
} else if (y > ofGetHeight()) {
y = ofGetHeight();
speedY *= -1;
}
x+=speedX;
y+=speedY;
}
void ofBall::draw(){
// values for R, G, B
ofSetColor(120,120,120);
ofCircle(x, y, dim);
}
Thanks in advance for helping me out.
Also thanks for making the wiki/tutorials/examples, etc
—b