]> git.treefish.org Git - seamulator.git/blob - src/dot.cpp
trying
[seamulator.git] / src / dot.cpp
1 #include "dot.h"
2
3 Dot::Dot(const SurfacePoint& point, double frequency) :
4     m_point{point},
5     m_frequency{frequency}
6 {
7     m_noise.noteOn(frequency, 1.0);
8 //    m_noise.setFrequency(frequency);
9 }
10
11 void Dot::advance(double deltaT)
12 {
13 //    std::lock_guard<std::mutex> lock{m_mutex};
14
15     //deltaT *= 10;
16     
17     auto posBefore = m_pos;
18
19     m_vel += -std::pow(m_frequency/440.0, 2.0) * 1.0 * ( m_pos - m_point.getHeight() ) * deltaT;
20     m_vel -= m_vel * 0.01 * deltaT;
21     m_pos += m_vel * deltaT;
22
23     const auto absVel = std::fabs(m_vel);
24     m_maxAbsVel = std::max(absVel, m_maxAbsVel);
25
26     //std::cout << m_pos << std::endl;
27     
28     if (posBefore * m_pos < 0.0) {
29 // //        std::cout << m_vel / m_maxVel << std::endl;
30         m_noise.noteOn(m_pos >= 0 ? m_frequency : m_frequency, absVel / m_maxAbsVel);
31 //         //m_noise.pluck(absVel / m_maxAbsVel);
32 //         m_noise.controlChange(4, 1.0 * absVel / m_maxAbsVel);
33     }
34
35 //    m_noise.controlChange(128, 128.0 * absVel / m_maxAbsVel);
36 }
37
38 stk::StkFloat Dot::tick()
39 {
40 //    std::lock_guard<std::mutex> lock{m_mutex};
41
42     return m_noise.tick();
43 }