Panda3D
Loading...
Searching...
No Matches
physxLinearInterpolationValues.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file physxLinearInterpolationValues.cxx
10 * @author enn0x
11 * @date 2010-02-08
12 */
13
15
16/**
17 *
18 */
19void PhysxLinearInterpolationValues::
20clear() {
21
22 _map.clear();
23}
24
25/**
26 *
27 */
28void PhysxLinearInterpolationValues::
29insert(float index, float value) {
30
31 if (_map.empty()) {
32 _min = _max = index;
33 }
34 else {
35 _min = std::min(_min, index);
36 _max = std::max(_max, index);
37 }
38 _map[index] = value;
39}
40
41/**
42 *
43 */
44bool PhysxLinearInterpolationValues::
45is_valid(float number) const {
46
47 return (number >= _min) && (number <= _max);
48}
49
50/**
51 *
52 */
53unsigned int PhysxLinearInterpolationValues::
54get_size() const {
55
56 return _map.size();
57}
58
59/**
60 *
61 */
62float PhysxLinearInterpolationValues::
63get_value(float number) const {
64
65 MapType::const_iterator lower = _map.begin();
66 if (number < _min) {
67 return lower->second;
68 }
69
70 MapType::const_iterator upper = _map.end();
71 upper--;
72 if (number > _max) {
73 return upper->second;
74 }
75
76 upper = _map.lower_bound(number);
77 if (upper == lower) {
78 return upper->second;
79 }
80
81 lower = upper;
82 lower--;
83
84 float w1 = number - lower->first;
85 float w2 = upper->first - number;
86
87 return ((w2 * lower->second) + (w1 * upper->second)) / (w1 + w2);
88}
89
90/**
91 *
92 */
93float PhysxLinearInterpolationValues::
94get_value_at_index(int index) const {
95
96 MapType::const_iterator it = _map.begin();
97
98 for (int i=0; i<index; i++) {
99 ++it;
100 }
101
102 return it->second;
103}
104
105/**
106 *
107 */
108void PhysxLinearInterpolationValues::
109output(std::ostream &out) const {
110
111 MapType::const_iterator it = _map.begin();
112
113 for (; it != _map.end(); ++it) {
114 std::cout << it->first << " -> " << it->second << "\n";
115 }
116}
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.