aboutsummaryrefslogtreecommitdiff
path: root/BuddhaTest/include
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2018-03-15 22:34:52 +0100
committerAndreas Grois <andi@grois.info>2018-03-15 22:34:52 +0100
commitbb9b7d23a1ca8e2afa8c8636d7312adc700d9a34 (patch)
treeb30bc01efe728a8b7887061b02af8e4a5af9f770 /BuddhaTest/include
parentaf0d5f4988bf94c4bf918b306f72f8604395715b (diff)
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.
Diffstat (limited to 'BuddhaTest/include')
-rw-r--r--BuddhaTest/include/Helpers.h26
1 files changed, 25 insertions, 1 deletions
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<typename ValueType, typename TimeType>
+ 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{};
+ };
}