/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double val = 100 * ((EMA(Fast)[0] - EMA(Slow)[0]) / EMA(Slow)[0]); Default.Set(val); Smoothed.Set(EMA(Value, smooth)[0]); }
// Use this for initialization void Start() { //Screen.sleepTimeout = SleepTimeout.NeverSleep ; DeviceInput.Init(); // setup smoothing class Smoothed.SetSmoothingStrength(Smooth); // sensor fusion needs gyroscope m_UseSensorFusion = DeviceInput.HasGyro; m_ToggleFlash.isOn = m_FlashingFocus; m_ToggleSnap.isOn = m_SnapIfAccurate; m_ToggleSensorFusion.isOn = m_UseSensorFusion; if (!DeviceInput.HasGyro) { m_ToggleSensorFusion.interactable = false; } // find parent m_PhotoTask = transform.parent.gameObject.GetComponent <PhotoTask> (); // setup label objects for (int i = 0; i < 4; i++) { // TaskPanel Panels[i] = transform.Find(PanelTitles[i]).gameObject.GetComponent <TaskPanel> (); Panels[i].Heading = 90.0f * i; Panels[i].Pitch = TaskPitch; Panels[i].Name = PanelNames [i]; } // setup frame // Panel_Frame Transform TrFrame = transform.Find("Panel_Frame"); KompassFrame = TrFrame.gameObject; TrFrame.SetParent(transform.parent, false); m_StringTakePhoto = LocalizationSupport.GetString("TakePhotoPoint"); m_StringHoldStill = LocalizationSupport.GetString("TakePhotoHoldStill"); m_StringLandscape = LocalizationSupport.GetString("TakePhotoLandscape"); m_StringFocus = LocalizationSupport.GetString("TakePhotoFocus"); }
// Update is called once per frame public void UpdateTask() { float DeltaTime = Time.deltaTime; //m_Timer.Update(DeltaTime); DeviceInput.Update(); Smoothed.SetTimeStep(DeltaTime); //ClearString(); SOrientation AccMagOrientation = DeviceInput.AccMagOrientation; Quaternion RotationChange = DeviceInput.GetRotationChange(DeltaTime); SOrientation Orientation; if (DeviceInput.HasGyro) { m_SensorFusion.Update(AccMagOrientation, RotationChange, 0.9f); } m_SmoothedOrientation.Update(AccMagOrientation); if (m_UseSensorFusion) { Orientation = m_SensorFusion.Orientation; } else { Orientation = m_SmoothedOrientation.Orientation; } m_DebugText.PrintText(Orientation); m_DebugText.NewLine(); float heading = Orientation.Yaw; float pitch = Orientation.Pitch; float tilt = Orientation.Roll; int iFocus = -1; for (int i = 0; i < 4; i++) { // TaskPanel float Dist = Panels[i].UpdateAngles(heading, pitch); if (!Panels[i].IsFinished()) { if (m_Distance >= Dist && m_Distance >= Mathf.Abs(tilt)) { iFocus = i; if (0.6f < Panels[i].GetFocusTime()) { TakePicture(i); } else { Panels[i].SetStatus(TaskPanel.ETaskStatus.TS_Focus, m_FlashingFocus); } } else { Panels[i].SetStatus(TaskPanel.ETaskStatus.TS_Pending); } } } bool bAllFinished = IsAllFinished(); if (bAllFinished) { m_bTakingPointPhoto = true; } if (m_bTakingPointPhoto) { m_CompassStrip.SetActive(false); m_ButtonTakePicture.SetActive(true); } else { m_CompassStrip.SetActive(true); m_ButtonTakePicture.SetActive(false); } if (bAllFinished || m_bTakingPointPhoto) { StatusText.text = m_StringTakePhoto; } else if (iFocus >= 0) { StatusText.text = m_StringHoldStill;//"Halten Sie das Handy kurz ruhig" ; if (iFocus >= 0 && m_SnapIfAccurate) { tilt = 0.0f; float SnappedHeading = Panels[iFocus].Heading; float SnappedPitch = Panels[iFocus].Pitch; for (int i = 0; i < 4; i++) { Panels[i].UpdateAngles(SnappedHeading, SnappedPitch); } } } else if (Mathf.Abs(tilt) > 20.0f) { StatusText.text = m_StringLandscape;//"Halte das Handy im Landschaftsmodus" ; } else { StatusText.text = m_StringFocus;//"Bringe die roten Quadrate in den Rahmen um Fotos nach Norden, Osten, Süden und Westen zu machen"; } m_DebugText.PrintText("iFocus", iFocus); float RotZ = Div.getClamped(-2.0f * tilt, -35.0f, 35.0f); transform.localRotation = Quaternion.Euler(0.0f, 0.0f, RotZ); }