Skip to content

Commit

Permalink
Fix averaging function with wraparound angles
Browse files Browse the repository at this point in the history
  • Loading branch information
ckosmic committed Jan 29, 2022
1 parent 1bae4a7 commit 556efff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
8 changes: 6 additions & 2 deletions SliceDetails/Data/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ public void CalculateAverages() {
int noteCount = 0;
for (int i = 0; i < tileNoteInfos.Length; i++) {
if (tileNoteInfos[i].Count > 0) {
Vector2 angleXYAverages = Vector2.zero;
foreach (NoteInfo noteInfo in tileNoteInfos[i]) {
atLeastOneNote = true;
angleAverages[i] += noteInfo.cutAngle;
angleXYAverages.x += Mathf.Cos(noteInfo.cutAngle * Mathf.PI / 180f);
angleXYAverages.y += Mathf.Sin(noteInfo.cutAngle * Mathf.PI / 180f);
offsetAverages[i] += noteInfo.cutOffset;
scoreAverages[i] += noteInfo.score;
scoreAverage += noteInfo.score.TotalScore;
noteCount++;
}
angleAverages[i] /= tileNoteInfos[i].Count;
angleXYAverages.x /= tileNoteInfos[i].Count;
angleXYAverages.y /= tileNoteInfos[i].Count;
angleAverages[i] = Mathf.Atan2(angleXYAverages.y, angleXYAverages.x) * 180f / Mathf.PI;
offsetAverages[i] /= tileNoteInfos[i].Count;
scoreAverages[i] /= tileNoteInfos[i].Count;
}
Expand Down
10 changes: 7 additions & 3 deletions SliceDetails/SliceRecorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
using UnityEngine;
using Zenject;
using SliceDetails.Data;
using SiraUtil.Logging;

namespace SliceDetails
{
internal class SliceRecorder : IInitializable, IDisposable, ISaberSwingRatingCounterDidFinishReceiver
{
private readonly BeatmapObjectManager _beatmapObjectManager;
private readonly SliceProcessor _sliceProcessor;
private readonly SiraLog _siraLog;

private Dictionary<ISaberSwingRatingCounter, NoteInfo> _noteSwingInfos = new Dictionary<ISaberSwingRatingCounter, NoteInfo>();
private List<NoteInfo> _noteInfos = new List<NoteInfo>();

public SliceRecorder(BeatmapObjectManager beatmapObjectManager, SliceProcessor sliceProcessor) {
public SliceRecorder(SiraLog siraLog, BeatmapObjectManager beatmapObjectManager, SliceProcessor sliceProcessor) {
_siraLog = siraLog;
_beatmapObjectManager = beatmapObjectManager;
_sliceProcessor = sliceProcessor;
}
Expand Down Expand Up @@ -50,8 +53,9 @@ private void ProcessNote(NoteController noteController, NoteCutInfo noteCutInfo)
// No ME notes allowed >:(
if (noteGridPosition.x >= 4 || noteGridPosition.y >= 3 || noteGridPosition.x < 0 || noteGridPosition.y < 0) return;

Vector3 cutDirection = new Vector3(-noteCutInfo.cutNormal.y, noteCutInfo.cutNormal.x, 0f);
float cutAngle = Mathf.Atan2(cutDirection.y, cutDirection.x) * Mathf.Rad2Deg + 90.0f;
Vector2 cutDirection = new Vector3(-noteCutInfo.cutNormal.y, noteCutInfo.cutNormal.x);
float cutAngle = Mathf.Atan2(cutDirection.y, cutDirection.x) * Mathf.Rad2Deg + 180f;
_siraLog.Info(cutAngle);

float cutOffset = noteCutInfo.cutDistanceToCenter;
Vector3 noteCenter = noteController.noteTransform.position;
Expand Down
2 changes: 1 addition & 1 deletion SliceDetails/UI/NoteUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void SetNoteData(float angle, float offset, Score score) {
_backgroundImage.color = _noteColor;
_cutArrowImage.gameObject.SetActive(true);
_cutDistanceImage.gameObject.SetActive(true);
_cutGroup.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, angle - _noteRotation));
_cutGroup.transform.localRotation = Quaternion.Euler(new Vector3(0f, 0f, angle - _noteRotation - 90f));
if (Plugin.Settings.TrueCutOffsets) {
_cutArrowImage.transform.localPosition = new Vector3(offset * 20.0f, 0f, 0f);
_cutDistanceImage.transform.localScale = new Vector2(-offset * 1.33f, 1.0f);
Expand Down
2 changes: 1 addition & 1 deletion SliceDetails/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": "SliceDetails",
"name": "SliceDetails",
"author": "ckosmic",
"version": "1.1.2",
"version": "1.1.4",
"description": "View your average cuts per-angle per-grid position in the pause menu and completion screen.",
"gameVersion": "1.19.0",
"dependsOn": {
Expand Down

0 comments on commit 556efff

Please sign in to comment.