OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 double DistanceEffect::LinearGain(double distance) { | 61 double DistanceEffect::LinearGain(double distance) { |
62 // We want a gain that decreases linearly from m_refDistance to | 62 // We want a gain that decreases linearly from m_refDistance to |
63 // m_maxDistance. The gain is 1 at m_refDistance. | 63 // m_maxDistance. The gain is 1 at m_refDistance. |
64 return (1.0 - clampTo(rolloff_factor_, 0.0, 1.0) * | 64 return (1.0 - clampTo(rolloff_factor_, 0.0, 1.0) * |
65 (distance - ref_distance_) / | 65 (distance - ref_distance_) / |
66 (max_distance_ - ref_distance_)); | 66 (max_distance_ - ref_distance_)); |
67 } | 67 } |
68 | 68 |
69 double DistanceEffect::InverseGain(double distance) { | 69 double DistanceEffect::InverseGain(double distance) { |
| 70 if (ref_distance_ == 0) |
| 71 return 0; |
| 72 |
70 return ref_distance_ / (ref_distance_ + clampTo(rolloff_factor_, 0.0) * | 73 return ref_distance_ / (ref_distance_ + clampTo(rolloff_factor_, 0.0) * |
71 (distance - ref_distance_)); | 74 (distance - ref_distance_)); |
72 } | 75 } |
73 | 76 |
74 double DistanceEffect::ExponentialGain(double distance) { | 77 double DistanceEffect::ExponentialGain(double distance) { |
| 78 if (ref_distance_ == 0) |
| 79 return 0; |
| 80 |
75 return pow(distance / ref_distance_, -clampTo(rolloff_factor_, 0.0)); | 81 return pow(distance / ref_distance_, -clampTo(rolloff_factor_, 0.0)); |
76 } | 82 } |
77 | 83 |
78 } // namespace blink | 84 } // namespace blink |
OLD | NEW |