| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 distance = clampTo(distance, m_refDistance, m_maxDistance); | 46 distance = clampTo(distance, m_refDistance, m_maxDistance); |
| 47 | 47 |
| 48 switch (m_model) { | 48 switch (m_model) { |
| 49 case ModelLinear: | 49 case ModelLinear: |
| 50 return linearGain(distance); | 50 return linearGain(distance); |
| 51 case ModelInverse: | 51 case ModelInverse: |
| 52 return inverseGain(distance); | 52 return inverseGain(distance); |
| 53 case ModelExponential: | 53 case ModelExponential: |
| 54 return exponentialGain(distance); | 54 return exponentialGain(distance); |
| 55 } | 55 } |
| 56 ASSERT_NOT_REACHED(); | 56 NOTREACHED(); |
| 57 return 0.0; | 57 return 0.0; |
| 58 } | 58 } |
| 59 | 59 |
| 60 double DistanceEffect::linearGain(double distance) { | 60 double DistanceEffect::linearGain(double distance) { |
| 61 // We want a gain that decreases linearly from m_refDistance to | 61 // We want a gain that decreases linearly from m_refDistance to |
| 62 // m_maxDistance. The gain is 1 at m_refDistance. | 62 // m_maxDistance. The gain is 1 at m_refDistance. |
| 63 return (1.0 - | 63 return (1.0 - |
| 64 clampTo(m_rolloffFactor, 0.0, 1.0) * (distance - m_refDistance) / | 64 clampTo(m_rolloffFactor, 0.0, 1.0) * (distance - m_refDistance) / |
| 65 (m_maxDistance - m_refDistance)); | 65 (m_maxDistance - m_refDistance)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 double DistanceEffect::inverseGain(double distance) { | 68 double DistanceEffect::inverseGain(double distance) { |
| 69 return m_refDistance / | 69 return m_refDistance / |
| 70 (m_refDistance + | 70 (m_refDistance + |
| 71 clampTo(m_rolloffFactor, 0.0) * (distance - m_refDistance)); | 71 clampTo(m_rolloffFactor, 0.0) * (distance - m_refDistance)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 double DistanceEffect::exponentialGain(double distance) { | 74 double DistanceEffect::exponentialGain(double distance) { |
| 75 return pow(distance / m_refDistance, -clampTo(m_rolloffFactor, 0.0)); | 75 return pow(distance / m_refDistance, -clampTo(m_rolloffFactor, 0.0)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 } // namespace blink | 78 } // namespace blink |
| OLD | NEW |