1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "Prerequisites/BsPrerequisitesUtil.h"
6
7namespace bs
8{
9 /** @addtogroup General
10 * @{
11 */
12
13 /**
14 * Contains a set of samples resulting from sampling some function at equal intervals. The table can then be used
15 * for sampling that function at arbitrary time intervals. The sampling is fast but precision is limited to the number
16 * of samples.
17 */
18 class BS_UTILITY_EXPORT LookupTable
19 {
20 public:
21 /**
22 * Constructs a lookup table from the provided set of values.
23 *
24 * @param[in] values Buffer containing information about all the samples. Total buffer size must be divisble
25 * by @p sampleSize.
26 * @param[in] startTime Time at which the first provided sample has been evaluated at.
27 * @param[in] endTime Time at which the last provided sample has been evaluate at. All samples in-between
28 * first and last are assumed to be evaluated to equal intervals in the
29 * [startTime, endTime] range.
30 * @param[in] sampleSize Number of 'float's each sample requires. This number must divide the number of elements
31 * in the @p values buffer.
32 */
33 LookupTable(Vector<float> values, float startTime = 0.0f, float endTime = 1.0f, uint32_t sampleSize = 1);
34
35 /**
36 * Evaluates the lookup table at the specified time.
37 *
38 * @param[in] t Time to evaluate the lookup table at.
39 * @param[out] left Pointer to the set of values contained in the sample left to the time value.
40 * @param[out] right Pointer to the set of values contained in the sample right to the time value.
41 * @param[out] fraction Fraction that determines how to interpolate between @p left and @p right values, where
42 * 0 corresponds to the @p left value, 1 to the @p right value and values in-between
43 * interpolate linearly between the two.
44 */
45 void evaluate(float t, const float*& left, const float*& right, float& fraction) const;
46
47 /** Returns a sample at the specified index. Returns last available sample if index is out of range. */
48 const float* getSample(uint32_t idx) const;
49
50 private:
51 Vector<float> mValues;
52 uint32_t mSampleSize;
53 uint32_t mNumSamples;
54 float mTimeStart;
55 float mTimeScale;
56 };
57
58 /** @} */
59}