From ff9d900791810d4c9339a9c782da19316068263c Mon Sep 17 00:00:00 2001 From: Guillaume Bittoun Date: Wed, 5 Nov 2014 21:37:46 +0000 Subject: [PATCH] simplex_interpolator: adding interpolator skeleton --- src/lol/math/simplex_interpolator.h | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/lol/math/simplex_interpolator.h diff --git a/src/lol/math/simplex_interpolator.h b/src/lol/math/simplex_interpolator.h new file mode 100644 index 00000000..9de4a358 --- /dev/null +++ b/src/lol/math/simplex_interpolator.h @@ -0,0 +1,76 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2014 Sam Hocevar +// (c) 2013-2014 Benjamin "Touky" Huet +// (c) 2013-2014 Guillaume Bittoun +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://www.wtfpl.net/ for more details. +// + +#pragma once + +template +class simplex_interpolator +{ +public: + + simplex_interpolator() + { + this->InitBase(); + } + + inline arraynd & GetSamples() + { + return this->samples; + } + + // Single interpolation + inline T interp(vec_t position) + { + vec_t simplex_position = this->ToSimplexRef(position); + + // TODO + + return 0; + } + +protected: + + inline void InitBase() + { + base.SetSize(vec_t(N, N)); + base_inverse.SetSize(vec_t(N, N)); + + for (int i = 0 ; i < N ; ++i) + { + for (int j = i ; j < N ; ++j) + { + base[i][j] = sqrt((i+2)/(2*i + 2)) / (j > i ? i + 2 : 1); + base_inverse[i][j] = sqrt((2*j + 2)/(j+2)) * (j > i ? (1 / (float)j) : 1); + } + } + } + + inline vec_t ToSimplexRef(vec_t const & position) + { + vec_t result; + + for (int i = 0 ; i < N ; ++i) + { + for (int j = i ; j < N ; ++j) + { + result[i] += base_inverse[i][j] * position[j]; + } + } + + return result; + } + + arraynd<2, T> base; + arraynd<2, T> base_inverse; + + arraynd samples; +};