libBeatsaber/src/beatlevelrenderhelper.cpp

71 lines
1.4 KiB
C++

#include "beatlevelrenderhelperimpl.h"
#include "beatmap.h"
#include <cmath>
static const float ROTLOOKUP[] {
0, // 0 (from top)
M_PI, // 1 (from bottom)
-M_PI_2, // 2 Left
M_PI_2, // 3 Right
-M_PI_4, // 4 Up Left
M_PI_4, // 5 Up Right
-M_PI_4 * 3, // 6 Down Left
M_PI_4 * 3, // 7 Down Right
0 // 8 Any (Dot Note)
};
namespace Beatsaber {
static const uint32_t LINECOUNT = 4;
static const uint32_t LAYERCOUNT = 3;
BeatLevelRenderHelperImpl::BeatLevelRenderHelperImpl(std::shared_ptr<const BeatLevel> level) : level(level) {
bps = level->getBeatMap()->getBPM() / 60.0;
}
BeatLevelRenderHelperImpl::~BeatLevelRenderHelperImpl() {}
//mat is a pointer to the matrix information in row first ordering
void BeatLevelRenderHelperImpl::setMat(float* mat, double time, uint32_t note) {
if(!mat) return;
double beat = bps * time;
const Note& n = level->getNotes().at(note);
//get matrix parameters
float offsetx = (n.line - (LINECOUNT / 2.0));
float offsety = n.layer;
float offsetz = n.time - beat;
float rotationz = ROTLOOKUP[n.cutdir];
float cosrotz = cos(rotationz);
float sinrotz = sin(rotationz);
//build matrix
mat[ 0] = cosrotz;
mat[ 1] = -sinrotz;
mat[ 2] = 0;
mat[ 3] = cosrotz*offsetx - sinrotz*offsety;
mat[ 4] = sinrotz;
mat[ 5] = cosrotz;
mat[ 6] = 0;
mat[ 7] = sinrotz*offsetx - cosrotz*offsety;
mat[ 8] = 0;
mat[ 9] = 0;
mat[10] = 1;
mat[11] = 0;
mat[12] = offsetx;
mat[13] = offsety;
mat[14] = offsetz;
mat[15] = 1;
}
}