Hello All,
When I draw multiple spheres the quality of the remaining spheres drops, significantly. As seen in this gif (I know the UI isn’t the prettiest, just working on basic functionality for now):
Does anyone know why this occurs? Visual Studio says the program takes up around 72 mb of RAM and 4% CPU. Is my code inefficient?
Here are the relevant pieces of code. I’ll only upload the code for the ‘Oxygen’ sphere as the other spheres/ relevant code are near identical copies with different colors and radii.
The class declaration for Oxygen:
class Oxygen {
public:
void setup();
void draw();
void update();
bool isActive;
ofPoint location;
ofSpherePrimitive oxygen;
ofLight light;
};
The oxygen class functions:
void Oxygen::setup() {
location = ofPoint(895, 100, 0);
oxygen.setRadius(55);
}
void Oxygen::draw() {
ofSetColor(204, 0, 0);
oxygen.setPosition(location);
ofEnableDepthTest();
light.enable();
oxygen.draw();
light.disable();
ofDisableDepthTest();
}
void Oxygen::update() {
}
ofApp.h:
Oxygen oxygen[3];
Hydrogen hydrogen[3];
Sodium sodium[3];
Nitrogen nitrogen[3];
Chlorine chlorine[3];
ofApp: setup():
for (int i = 0; i < 3; i++) {
oxygen[i].setup();
hydrogen[i].setup();
sodium[i].setup();
nitrogen[i].setup();
chlorine[i].setup();
}
ofApp: draw():
ofRectangle viewport(0, 0, 768, 900);
//Oxygen
int countO = 0;
oxygen[0].draw();
oxygen[0].isActive = true;
while (viewport.inside(oxygen[countO].location) && countO < 2) {
countO++;
oxygen[countO].draw();
oxygen[countO].isActive = true;
}
The loop for the other spheres (atoms) is exactly the same, I just initialized a different variable.
and lastly: ofApp: mouseDragged:
for (int i = 0; i < 3; i++) {
if (oxygen[i].isActive == true) {
if (x >= oxygen[i].location.x - 55 && x <= oxygen[i].location.x + 55) {
if (y >= oxygen[i].location.y - 55 && y <= oxygen[i].location.y + 55) {
if (button == 0) {
oxygen[i].location.x = ofGetMouseX();
oxygen[i].location.y = ofGetMouseY();
}
}
}
}
}
I’m a beginner so any tips and advice would be greatly appreciated. Also, i do apologize if I formatted this post in an unorthodox way. Thanks for reading!!!