beatlevel renderhelper added
This commit is contained in:
parent
54a555640f
commit
90f36901fd
|
@ -47,6 +47,8 @@ public:
|
|||
|
||||
virtual std::shared_ptr<BeatSet> getBeatSet() const override;
|
||||
virtual std::shared_ptr<BeatMap> getBeatMap() const override;
|
||||
|
||||
virtual std::shared_ptr<BeatLevelRenderHelper> getRenderHelper() const override;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include "beatlevelrenderhelper.h"
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
class BeatLevelRenderHelperImpl : public BeatLevelRenderHelper {
|
||||
public:
|
||||
BeatLevelRenderHelperImpl(std::shared_ptr<const BeatLevel> level);
|
||||
virtual ~BeatLevelRenderHelperImpl();
|
||||
|
||||
//mat is a pointer to the matrix information in row first ordering
|
||||
virtual void setMat(float* mat, double time, uint32_t note) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<const BeatLevel> level;
|
||||
double bps; //beats per second
|
||||
};
|
||||
|
||||
}
|
|
@ -12,6 +12,7 @@ namespace Beatsaber {
|
|||
//fwd
|
||||
class BeatSet;
|
||||
class BeatMap;
|
||||
class BeatLevelRenderHelper;
|
||||
|
||||
class BeatLevel {
|
||||
public:
|
||||
|
@ -34,6 +35,8 @@ public:
|
|||
virtual std::shared_ptr<BeatSet> getBeatSet() const = 0; // parent
|
||||
virtual std::shared_ptr<BeatMap> getBeatMap() const = 0; // grandparent
|
||||
|
||||
virtual std::shared_ptr<BeatLevelRenderHelper> getRenderHelper() const = 0;
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "beatlevel.h"
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
// helps rendering a level
|
||||
class BeatLevelRenderHelper {
|
||||
public:
|
||||
BeatLevelRenderHelper() {}
|
||||
virtual ~BeatLevelRenderHelper() {}
|
||||
|
||||
//mat is a pointer to the matrix information in row first ordering
|
||||
virtual void setMat(float* mat, double time, uint32_t note) = 0;
|
||||
};
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
#include "beatset.h"
|
||||
#include "beatnoteimpl.h"
|
||||
#include "beatmap.h" // for debug print
|
||||
#include "beatlevelrenderhelperimpl.h"
|
||||
|
||||
namespace Beatsaber {
|
||||
|
||||
|
@ -121,4 +122,9 @@ std::shared_ptr<BeatMap> BeatLevelImpl::getBeatMap() const {
|
|||
return parent.lock()->getBeatMap();
|
||||
}
|
||||
|
||||
std::shared_ptr<BeatLevelRenderHelper> BeatLevelImpl::getRenderHelper() const {
|
||||
auto ptr = std::make_shared<BeatLevelRenderHelperImpl>(shared_from_this());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
#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;
|
||||
static const double LINESPACING = 0.6;
|
||||
static const double LAYERSPACING = 0.6;
|
||||
static const double LAYEROFFSET = 0.6;
|
||||
static const double LINEOFFSET = LINESPACING/2;
|
||||
|
||||
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)) * LINESPACING) + LINEOFFSET;
|
||||
float offsety = (n.layer * LAYERSPACING) + LAYEROFFSET;
|
||||
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] = offsetx;
|
||||
|
||||
mat[ 4] = sinrotz;
|
||||
mat[ 5] = cosrotz;
|
||||
mat[ 6] = 0;
|
||||
mat[ 7] = offsety;
|
||||
|
||||
mat[ 8] = 0;
|
||||
mat[ 9] = 0;
|
||||
mat[10] = 1;
|
||||
mat[11] = offsetz;
|
||||
|
||||
mat[12] = 0;
|
||||
mat[13] = 0;
|
||||
mat[14] = 0;
|
||||
mat[15] = 1;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue