I am not sure (because you did not provide enough information), but the first problem I see is that you are doing mElapsedTime = (float)frameProcessingTime / 1000.0f; regardless of Sleep(...) . In other words, you forgot to consider sleeping. To do this, you will need to re-select GetTickCount() after calling Sleep(...) . But even then, your code becomes too boilerplate and error prone.
Start approaching your problem by writing small, flexible, and reusable classes that perform simple tasks:
class Stopwatch { public: Stopwatch(): _start(0), _elapsed(0), _running(false) {} void start() { if (_running) return; _running = true; _start = GetTickCount(); } void stop() { if (!_running) return; _elapsed += GetTickCount() - _start; _running = false; } void reset() { _running = false; _elapsed = 0; } void restart() { _running = true; _elapsed = 0; _start = GetTickCount(); } bool isRunning() const { return _running; } DWORD elapsed() const { return _running ? _elapsed + (GetTickCount() - _start) : _elapsed); } bool hasExpired(DWORD interval) const { return elapsed() > interval; } private: DWORD _start; DWORD _elapsed; bool _running; };
Just how to use this class for your needs.
Secondly, I really donβt understand why you are using Sleep . The last time I saw an example of frame delay was around 5 years ago in some shitty toy-writing tutorials. This material was really popular in old games, but in modern games it makes no sense. Of course, if this is a requirement for your assignment, then I apologize, but this remark still applies.
Finally, I would like to give you additional tips on my own experience in real-time visualization. Never write time-dependent code with source features such as GetTickCount or other popular crap among Windows API programmers (or Linux APIs, it doesn't matter), because it smells like outdated tutorials on creating toy games again.
What to use, you ask? Well, these days we are lucky because there are well-designed, robust cross-platform libraries like Boost . You should probably be familiar with this, however, if you do not, you must do so. For your specific problem, there is a Boost.Chrono module that has been carefully designed to work properly over time. I have used it in several projects related to real-time rendering, and I must admit that it is very reliable and worth exploring.
Another library - Boost.Units - is a must for writing a stable and accurate physics engine. This library provides support for types for units (force, mass, speed, acceleration, etc.) and quantities for various models of unit systems (for example, SI or CGS). It is based on a metaprogramming pattern and, therefore, does not create unnecessary time consuming.
Once again, I understand that your assignment probably does not allow this. However, I believe that everything I mentioned here will be valuable to you in the future. By the way, this is a good example of how much more you should know than offering university assignments in order to be able to solve real-life problems.
If you still need more help on your issue, in particular, I need more information. For example, start by displaying the entire code for your game loop.