Driving a simulation through update of the frame time?

I am quite new to Openframeworks so Sorry if my question seems a bit off or trivial.
What I am trying to do is to drive a simulation by updating frame_rate ofxEasycam object. I have included


into the setup() method and I want to update this frame_rate to start simulation/animation. In update() method I have added followings:

FRAME_RATE = ofGetFrameRate();
if (FRAME_RATE < 50){
    FRAME_RATE ++;

to update the frame_rate and eventually start the simulation but it seems to be not working and I have no clue how else I could do that.
So any hint/tip would be appreciated.



What I am trying to do is to drive a simulation

Could you give more details about how do you want the program to behave? What do you mean with driving a simulation? Do you want the program to do A for a while, and later B?

If you only call ofSetFrameRate() inside setup it will never change, it will stay at whatever value FRAME_RATE had at that time (maybe 0?).

Of course! In core I want to simulate the motion of particles around a nuclei or a solar system where couple of sphere rotate another sphere. each planet/particle type has its own mass, position and velocity which are defined within particular class. The velocity and position update of planets/particles are already defined in planet.cpp and there is no need to update them in ofApp.cpp.
In short what I meant with drive is to initiate and carry out the simulation.
I hope this clear things up!?

It sounds very reasonable :slight_smile: But I don’t see the connection to FRAME_RATE from your initial example. Do you want the simulation to start as soon as the program starts? Or are you looking for a way to wait for user interaction?

In the first case you can declare the variables in the .h file, maybe initialize them inside setup, calculate motions etc inside update and finally draw everything inside draw.

In the second case, you could have either a boolean that you toggle as response to user interaction, or you could just wait until ofGetFrameNum() is high enough, and then start updating your particles.

Maybe you wanted to use ofGetFrameNum() instdead of ofGetFrameRate() ?

Well my intention is to start the simulation as soon as the app is triggered. And I have done all you have written there but it seems there is still something missing!
Anyway thanks for the suggestions.

it seems to be not working

Could you describe what is not working? What should happen that is not happening? Could you share a minimum runnable example that shows the issue?

Maybe it would be easier if I share the link to the ofApp.cpp and .h files. Basically the surrounding planets supposed to circle the Sun, and when the user changes the slide_bars on gui the program should react accordingly.

Seeing the code helps a lot :slight_smile: but what is the issue? Everthing black? Planets not moving? Something else?

Those 4 lines you shared in your first post above do nothing, as FRAME_RATE is not used anywhere.

Those four lines are used in update method, and the main issue is that the planets do not move!?

Hi! I see the program declares, initializes and changes FRAME_RATE, but its value is not used anywhere I can see, for example to set an angle or a position.

The update method is calling initSolarSystem() 60 times per second. Is that expected?

I don’t see any line of code changing the positions of planets. Is that happening maybe in the files you didn’t upload?