void VectorHistogram::AddVectorInterpolated(float x, float y) { // ensure angle \in (0, 1) float bin = NormAngle(x, y) * num_bins_; float magn = hypot(x, y); float int_bin = floor(bin); const float bin_center[3] = { int_bin - 1.0f + 0.5f, int_bin + 0.5f, int_bin + 1.0f + 0.5f }; const int bin_idx[3] = { ((int)int_bin - 1 + num_bins_) % num_bins_, (int)int_bin, ((int)int_bin + 1) % num_bins_ }; // Loop over. for (int i = 0; i < 3; ++i) { const float da = fabs(bin_center[i] - bin); if (da < 1) { bins_[bin_idx[i]] += (1 - da) * magn; } } ++num_vectors_; }
float GetAngle(float x, float y) { if (fabs(x) < 1e-6f) { return y > 0 ? D3DX_PI / 2 : -D3DX_PI / 2; } float a = atanf(y / abs(x)); if (x < 0) a = D3DX_PI - a; return NormAngle(a); }
bool CObjectRotateCamera::Update() { CMouseManager* mouse = GetMouse(); bool down[2] = {mouse->IsPressed(0), mouse->IsPressed(1)}; int x = mouse->GetX(); int y = mouse->GetY(); int dx = x - m_lastx; int dy = y - m_lasty; bool needUpdate = false; if (!GetKeyboard()->IsPressed(VK_SHIFT) && m_lastDown[0] && down[0] && (abs(dx) + abs(dy) > 0)) { m_anglex += dx * 0.01f; // * elapsedTime; m_anglez += dy * 0.01f;// * elapsedTime; m_anglex = NormAngle(m_anglex); m_anglez = NormAngle(m_anglez); Point3 eye = Angle2Pos(m_anglex, m_anglez); SetEye(eye.x, eye.y, eye.z); needUpdate = true; } if (GetMouse()->GetWheel() != 0) { m_radius *= max(0.01f, 1 - GetMouse()->GetWheel() * 0.0003f); Point3 eye = Angle2Pos(m_anglex, m_anglez); SetEye(eye.x, eye.y, eye.z); needUpdate = true; } m_lastDown[0] = down[0]; m_lastDown[1] = down[1]; m_lastx = x; m_lasty = y; return needUpdate; }
void VectorHistogram::AddVector(float x, float y) { bins_[NormAngle(x, y) * num_bins_] += hypot(x, y); ++num_vectors_; }