private void UpdatePoints() { // Debug.Log(visEvent.GetTotalDOMs()); // Initialize points if haven't done so if ((points == null || points.Length == 0) && visEvent.GetTotalDOMs() > 0) { InitializePoints(); } if (totalEventEnergy == 0f) { totalEventEnergy = visEvent.GetTotalEventEnergy(); } // Get current event index int idx = visEvent.GetCurrentDOM(); // Do not update graph if for some reason it tries to update the // same index more than once in sequence. if (visEvent.GetTotalDOMs() > 0 && idx != prevIdx) { // Get new energy level float energy = visEvent.GetCurrentEnergy(); if (displayMode == MODE.ACCUMULATE) { maxEnergy += energy; } else { if (energy > maxEnergy) { // Normalize graph again if new energy level exceeds the current maximum // Debug.Log("New max energy = " + energy); for (int i = 0; i < points.Length; i++) { // Get raw value float rawEnergy = points[i].y * maxEnergy; // Normalize it points[i].y = rawEnergy / energy; } maxEnergy = energy; // Update maximum energy level } } // Update graph base on displayMode switch (displayMode) { case MODE.INCREMENT: // Stacks energy levels at every index on new event points[idx].y = (points[idx].y * maxEnergy + graphHeight * energy) / maxEnergy; break; case MODE.OVERWRITE: // Starts new graph on new event if (idx == 0) { maxEnergy = (energy > START_ENERGY) ? energy : START_ENERGY; } points[idx].y = (graphHeight * energy) / maxEnergy; break; case MODE.ACCUMULATE: float numEventDOMs = visEvent.GetTotalDOMs(); float numMaxDOMs = visEvent.GetMaxDOMs(); float ratio = numMaxDOMs / numEventDOMs; if (idx == 0) { maxEnergy = (energy > START_ENERGY) ? energy : START_ENERGY; } int currIdx = Mathf.FloorToInt(prevIdx * ratio); int nextIdx = Mathf.FloorToInt(idx * ratio); //Debug.Log(currIdx); //Debug.Log(nextIdx); for (int p = currIdx; p < nextIdx; ++p) { points[p].y = ((Mathf.Log(maxEnergy) / totalEventEnergy) * graphHeight); } break; default: // Debug.Log("Something went wrong, displayMode is invalid: " + displayMode); points[idx].y = 0f; break; } prevIdx = idx; // For checking purposes } }