From bb9b7d23a1ca8e2afa8c8636d7312adc700d9a34 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Thu, 15 Mar 2018 22:34:52 +0100 Subject: Fix endless loop in shader and make framerate adaptive It seems forcing points outside the cardioid and bulb with a bad random generator can take really long... Also, now framerate adjusts based on time it takes to render frames. --- BuddhaTest/include/Helpers.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'BuddhaTest/include') diff --git a/BuddhaTest/include/Helpers.h b/BuddhaTest/include/Helpers.h index fc63103..76f790b 100644 --- a/BuddhaTest/include/Helpers.h +++ b/BuddhaTest/include/Helpers.h @@ -46,7 +46,7 @@ namespace Helpers unsigned int globalWorkGroupSizeY = 1; unsigned int globalWorkGroupSizeZ = 1; - unsigned int iterationsPerFrame = 10; + unsigned int targetFrameRate = 60; std::string pngFilename = ""; double pngGamma = 1.0; @@ -57,4 +57,28 @@ namespace Helpers bool CheckValidity(); bool ParseCommandLine(int argc, char * argv[]); }; + + template + class PIDController + { + public: + PIDController(ValueType prop, ValueType diff, ValueType integral) : propFactor(prop), diffFactor(diff), intFactor(integral) {} + + ValueType Update(TimeType dT, ValueType Error) + { + errorSum += Error * dT; + const auto differential{(Error - lastError)/dT}; + lastError = Error; + return Error * propFactor + errorSum * intFactor + differential * diffFactor; + } + + protected: + ValueType propFactor{}; + ValueType diffFactor{}; + ValueType intFactor{}; + + private: + ValueType errorSum{}; + ValueType lastError{}; + }; } -- cgit v1.2.3