Skip to content

Commit

Permalink
Use note space for note cut vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
opl- committed Oct 17, 2021
1 parent 21749a2 commit 13a5f02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
29 changes: 17 additions & 12 deletions BeatSaberHTTPStatus/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public void OnNoteWasCut(NoteData noteData, in NoteCutInfo noteCutInfo, int mult
var gameStatus = statusManager.gameStatus;

SetNoteDataStatus(noteData);
SetNoteCutStatus(noteCutInfo, true);
SetNoteCutStatus(noteCutInfo, noteData, true);

int beforeCutScore = 0;
int afterCutScore = 0;
Expand Down Expand Up @@ -642,7 +642,7 @@ public void OnNoteWasFullyCut(CutScoreBuffer csb) {
NoteCutInfo noteCutInfo = noteFullyCutData.noteCutInfo;

SetNoteDataStatus(noteFullyCutData.noteData);
SetNoteCutStatus(noteCutInfo, false);
SetNoteCutStatus(noteCutInfo, noteFullyCutData.noteData, false);

// public static void ScoreModel.RawScoreWithoutMultiplier(ISaberSwingRatingCounter saberSwingRatingCounter, float cutDistanceToCenter, out int beforeCutRawScore, out int afterCutRawScore, out int cutDistanceRawScore)
ScoreModel.RawScoreWithoutMultiplier(noteCutInfo.swingRatingCounter, noteCutInfo.cutDistanceToCenter, out beforeCutScore, out afterCutScore, out cutDistanceScore);
Expand Down Expand Up @@ -696,27 +696,32 @@ private void SetNoteDataStatus(NoteData noteData) {
/// <summary>
/// Sets note cut related status data. Should be called after SetNoteDataStatus.
/// </summary>
private void SetNoteCutStatus(NoteCutInfo noteCutInfo, bool initialCut = true) {
private void SetNoteCutStatus(NoteCutInfo noteCutInfo, NoteData noteData, bool initialCut = true) {
GameStatus gameStatus = statusManager.gameStatus;

var transform = noteControllerMapping[noteData].noteTransform;

gameStatus.speedOK = noteCutInfo.speedOK;
gameStatus.directionOK = noteCutInfo.directionOK;
gameStatus.saberTypeOK = noteCutInfo.saberTypeOK;
gameStatus.wasCutTooSoon = noteCutInfo.wasCutTooSoon;
gameStatus.saberSpeed = noteCutInfo.saberSpeed;
gameStatus.saberDirX = noteCutInfo.saberDir[0];
gameStatus.saberDirY = noteCutInfo.saberDir[1];
gameStatus.saberDirZ = noteCutInfo.saberDir[2];
var saberDir = transform.InverseTransformDirection(noteCutInfo.saberDir);
gameStatus.saberDirX = saberDir[0];
gameStatus.saberDirY = saberDir[1];
gameStatus.saberDirZ = saberDir[2];
gameStatus.saberType = noteCutInfo.saberType.ToString();
gameStatus.swingRating = noteCutInfo.swingRatingCounter == null ? -1 : initialCut ? noteCutInfo.swingRatingCounter.beforeCutRating : noteCutInfo.swingRatingCounter.afterCutRating;
gameStatus.timeDeviation = noteCutInfo.timeDeviation;
gameStatus.cutDirectionDeviation = noteCutInfo.cutDirDeviation;
gameStatus.cutPointX = noteCutInfo.cutPoint[0];
gameStatus.cutPointY = noteCutInfo.cutPoint[1];
gameStatus.cutPointZ = noteCutInfo.cutPoint[2];
gameStatus.cutNormalX = noteCutInfo.cutNormal[0];
gameStatus.cutNormalY = noteCutInfo.cutNormal[1];
gameStatus.cutNormalZ = noteCutInfo.cutNormal[2];
var cutPoint = transform.InverseTransformPoint(noteCutInfo.cutPoint);
gameStatus.cutPointX = cutPoint[0];
gameStatus.cutPointY = cutPoint[1];
gameStatus.cutPointZ = cutPoint[2];
var cutNormal = transform.InverseTransformDirection(noteCutInfo.cutNormal);
gameStatus.cutNormalX = cutNormal[0];
gameStatus.cutNormalY = cutNormal[1];
gameStatus.cutNormalZ = cutNormal[2];
gameStatus.cutDistanceToCenter = noteCutInfo.cutDistanceToCenter;
}

Expand Down
14 changes: 11 additions & 3 deletions protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ StatusObject = {

### Note cut object

Each note cut has a **cut plane**, which is a plane defined by three points of the cutting saber:

- its top on the frame the collision happened,
- its bottom on the frame the collision happened,
- its center on the frame previous to the collision frame.

In **note space**, positive X, positive Y, and positive Z represent right, up, and forward respectively. The arrow of a directional note is always located at positive Y and pointing towards negative Y. The space origin is the center of the note.

```js
NoteCutObject = {
"noteID": Integer, // ID of the note
Expand All @@ -141,7 +149,7 @@ NoteCutObject = {
"cutDistanceScore": null | Integer, // Score for the hit itself. [0..15]
"multiplier": Integer, // Combo multiplier at the time of cut
"saberSpeed": Number, // Speed of the saber when the note was cut
"saberDir": [ // Direction the saber was moving in when the note was cut
"saberDir": [ // Direction in note space that the saber was moving in on the collision frame, calculated by subtracting the position of the saber's tip on the previous frame from its current position (current - previous).
Number, // X value
Number, // Y value
Number, // Z value
Expand All @@ -150,12 +158,12 @@ NoteCutObject = {
"swingRating": Number, // Game's swing rating. Uses the before cut rating in noteCut events and after cut rating for noteFullyCut events. -1 for bombs.
"timeDeviation": Number, // Time offset in seconds from the perfect time to cut a note
"cutDirectionDeviation": Number, // Offset from the perfect cut angle in degrees
"cutPoint": [ // Position of the point on the cut plane closests to the note center
"cutPoint": [ // Position in note space of the point on the cut plane closests to the note center
Number, // X value
Number, // Y value
Number, // Z value
],
"cutNormal": [ // Normal of the ideal plane to cut along
"cutNormal": [ // Normalized vector describing the normal of the cut plane in note space. Points towards negative X on a correct cut of a directional note.
Number, // X value
Number, // Y value
Number, // Z value
Expand Down

0 comments on commit 13a5f02

Please sign in to comment.