Merge pull request #11 from Block-Party-VR/5-impliment-the-animator
Impliment the animator
This commit is contained in:
@@ -20,7 +20,7 @@ static constexpr uint32_t BOARD_WIDTH{3};
|
|||||||
static constexpr uint32_t BOARD_LENGTH{3};
|
static constexpr uint32_t BOARD_LENGTH{3};
|
||||||
static constexpr uint32_t BOARD_HEIGHT{3};
|
static constexpr uint32_t BOARD_HEIGHT{3};
|
||||||
|
|
||||||
static constexpr V3D BOARD_DIMENSIONS{BOARD_WIDTH, BOARD_LENGTH, BOARD_HEIGHT};
|
static constexpr V3D<uint32_t> BOARD_DIMENSIONS{BOARD_WIDTH, BOARD_LENGTH, BOARD_HEIGHT};
|
||||||
|
|
||||||
// define the number of stacks
|
// define the number of stacks
|
||||||
static constexpr uint32_t NUMBER_STACKS{BOARD_WIDTH * BOARD_LENGTH};
|
static constexpr uint32_t NUMBER_STACKS{BOARD_WIDTH * BOARD_LENGTH};
|
||||||
|
|||||||
@@ -3,17 +3,31 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
template <typename Type>
|
||||||
class V3D{
|
class V3D{
|
||||||
public:
|
public:
|
||||||
constexpr V3D(const V3D& other):
|
constexpr V3D(const V3D& other):
|
||||||
x(other.x),
|
x(other.x),
|
||||||
y(other.y),
|
y(other.y),
|
||||||
z(other.z){}
|
z(other.z){
|
||||||
|
static_assert(std::is_arithmetic<Type>::value, "Type must be a number");
|
||||||
|
}
|
||||||
|
|
||||||
constexpr V3D(uint32_t x=0, uint32_t y=0, uint32_t z=0):
|
constexpr V3D(Type x=0, Type y=0, Type z=0):
|
||||||
x(x),
|
x(x),
|
||||||
y(y),
|
y(y),
|
||||||
z(z){}
|
z(z){
|
||||||
|
static_assert(std::is_arithmetic<Type>::value, "Type must be a number");
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename OtherType>
|
||||||
|
constexpr V3D(const V3D<OtherType> other):
|
||||||
|
x(static_cast<Type>(other.x)),
|
||||||
|
y(static_cast<Type>(other.y)),
|
||||||
|
z(static_cast<Type>(other.z)){
|
||||||
|
static_assert(std::is_arithmetic<Type>::value, "Type must be a number");
|
||||||
|
static_assert(std::is_arithmetic<OtherType>::value, "OtherType must be a number");
|
||||||
|
}
|
||||||
|
|
||||||
V3D& operator=(const V3D &other){
|
V3D& operator=(const V3D &other){
|
||||||
this->x = other.x;
|
this->x = other.x;
|
||||||
@@ -36,7 +50,7 @@ class V3D{
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D& operator/=(const uint32_t scalar){
|
V3D& operator/=(const Type scalar){
|
||||||
if(scalar == 0){
|
if(scalar == 0){
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -46,7 +60,7 @@ class V3D{
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D& operator*=(const uint32_t scalar){
|
V3D& operator*=(const Type scalar){
|
||||||
this->x *= scalar;
|
this->x *= scalar;
|
||||||
this->y *= scalar;
|
this->y *= scalar;
|
||||||
this->z *= scalar;
|
this->z *= scalar;
|
||||||
@@ -58,9 +72,9 @@ class V3D{
|
|||||||
}
|
}
|
||||||
|
|
||||||
float magnitude(){
|
float magnitude(){
|
||||||
return std::sqrt(this->x * this->x + this->y * this->y + this->z * this-> z);
|
return std::sqrt(static_cast<float>(this->x * this->x + this->y * this->y + this->z * this->z));
|
||||||
}
|
}
|
||||||
uint32_t x;
|
Type x;
|
||||||
uint32_t y;
|
Type y;
|
||||||
uint32_t z;
|
Type z;
|
||||||
};
|
};
|
||||||
33
lib/Animator/AnimationTypes.h
Normal file
33
lib/Animator/AnimationTypes.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Vector3D.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
namespace ANIMATION_TYPES{
|
||||||
|
// for cube spots which aren't defined in a key frame,
|
||||||
|
// you can have the controller automatically interpolate a color
|
||||||
|
enum FillInterpolation{
|
||||||
|
NO_FILL, // if not specified, the cube color will be black
|
||||||
|
CLOSEST_COLOR, // The cube color will be the same color as the cube closest to it
|
||||||
|
LINEAR_WEIGHTED_DISTANCE, // the cube color will be an average of all specified cube colors weighted by the linear distance to this cube
|
||||||
|
SQUARE_WEIGHTED_DISTANCE // same as linear, but further colors have exponentially less impact on the color
|
||||||
|
};
|
||||||
|
|
||||||
|
enum FrameInterpolation{
|
||||||
|
SNAP, // After the delay, snap to the next key frame
|
||||||
|
FADE // over the course of the delay, fade to the next frame
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Cell{
|
||||||
|
V3D<uint32_t> position;
|
||||||
|
V3D<uint32_t> color;
|
||||||
|
};
|
||||||
|
|
||||||
|
// this contains all of the information to specify exactly how a single frame should look and fade to the next frame
|
||||||
|
struct AnimationFrame{
|
||||||
|
std::vector<Cell> frame;
|
||||||
|
FillInterpolation fillInterpolation;
|
||||||
|
FrameInterpolation frameInterpolation;
|
||||||
|
std::chrono::milliseconds delay;
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -2,68 +2,112 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
#include "Vector3D.h"
|
#include "Vector3D.h"
|
||||||
|
#include "AnimationTypes.h"
|
||||||
|
|
||||||
|
using namespace ANIMATION_TYPES;
|
||||||
|
|
||||||
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
|
class Animator{
|
||||||
|
|
||||||
class Animation{
|
|
||||||
public:
|
public:
|
||||||
// for cube spots which aren't defined in a key frame,
|
typedef std::array<std::array<std::array<V3D<uint32_t>, BOARD_DIMS.z>, BOARD_DIMS.y>, BOARD_DIMS.x> Frame;
|
||||||
// you can have the controller automatically interpolate a color
|
|
||||||
enum FillInterpolation{
|
|
||||||
NO_FILL, // if not specified, the cube color will be black
|
void StartAnimation(const std::vector<AnimationFrame> *animationSequence);
|
||||||
CLOSEST_COLOR, // The cube color will be the same color as the cube closest to it
|
|
||||||
LINEAR_WEIGHTED_DISTANCE, // the cube color will be an average of all specified cube colors weighted by the linear distance to this cube
|
void RunAnimation(const std::chrono::milliseconds& timePassed);
|
||||||
SQUARE_WEIGHTED_DISTANCE // same as linear, but further colors have exponentially less impact on the color
|
|
||||||
|
void SetLoop(bool isLooping);
|
||||||
|
|
||||||
|
Frame &GetInterpolatedFrame(){return this->interpolatedFrame;}
|
||||||
|
|
||||||
|
bool isEnabled{true};
|
||||||
|
bool interpolatedFrameHasChanged{false};
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isLooping{true};
|
||||||
|
// these are the uncompressed frames you get by following the key colors and interpolation instructions of an animation frame
|
||||||
|
Frame startFrame;
|
||||||
|
Frame interpolatedFrame;
|
||||||
|
Frame endFrame;
|
||||||
|
std::chrono::milliseconds timeElapsed;
|
||||||
|
|
||||||
|
const std::vector<AnimationFrame> *animationSequence;
|
||||||
|
uint32_t animationIndex{0};
|
||||||
|
|
||||||
|
void incrimentAnimationIndex();
|
||||||
|
|
||||||
|
void uncompressFrame(const AnimationFrame &keyFrame, Frame &frameBuffer);
|
||||||
|
|
||||||
|
void copyFrame(Frame ©From, Frame ©To){
|
||||||
|
std::memcpy(©To, ©From, sizeof(Frame));
|
||||||
|
}
|
||||||
|
|
||||||
|
V3D<uint32_t> getInterpolatedColor(const AnimationFrame &keyFrame, V3D<uint32_t> position);
|
||||||
|
|
||||||
|
V3D<uint32_t> keyFrame2BoardCoords(const V3D<uint32_t> &keyFramePosition);
|
||||||
|
|
||||||
|
V3D<uint32_t> noFillInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> position);
|
||||||
|
|
||||||
|
V3D<uint32_t> closestColorInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> position);
|
||||||
|
|
||||||
|
V3D<uint32_t> linearInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> position);
|
||||||
|
|
||||||
|
V3D<uint32_t> squareInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> position);
|
||||||
|
|
||||||
|
void PrintUncompressedFrame(){
|
||||||
|
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
||||||
|
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
||||||
|
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
|
||||||
|
auto color = this->startFrame[x][y][z];
|
||||||
|
Serial.print("Cube X:" + String(x) + ",Y:" + String(y) + ",Z:" + String(z));
|
||||||
|
Serial.println("\tColor R:" + String(color.x) + ",G:" + String(color.y) + ",B:" + String(color.z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum FrameInterpolation{
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
SNAP, // After the delay, snap to the next key frame
|
void Animator<BOARD_DIMS>::StartAnimation(const std::vector<AnimationFrame> *animationSequence){
|
||||||
FADE // over the course of the delay, fade to the next frame
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Cell{
|
|
||||||
V3D position;
|
|
||||||
V3D color;
|
|
||||||
};
|
|
||||||
|
|
||||||
// this contains all of the information to specify exactly how a single frame should look and fade to the next frame
|
|
||||||
struct AnimationFrame{
|
|
||||||
std::vector<Cell> frame;
|
|
||||||
FillInterpolation fillInterpolation;
|
|
||||||
FrameInterpolation frameInterpolation;
|
|
||||||
std::chrono::milliseconds delay;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::array<std::array<std::array<V3D, Z_SIZE>, Y_SIZE>, X_SIZE> Frame;
|
|
||||||
|
|
||||||
|
|
||||||
void StartAnimation(const std::vector<AnimationFrame> &animationSequence){
|
|
||||||
this->animationSequence = animationSequence;
|
this->animationSequence = animationSequence;
|
||||||
this->animationIndex = 0;
|
this->animationIndex = 0;
|
||||||
this->timeElapsed = std::chrono::milliseconds(0);
|
this->timeElapsed = std::chrono::milliseconds(0);
|
||||||
|
|
||||||
if(animationSequence.size() == 0){
|
if(animationSequence->size() == 0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if(animationSequence.size() == 1){
|
else if(animationSequence->size() == 1){
|
||||||
this->uncompressFrame(animationSequence[0], this->startFrame);
|
AnimationFrame frame{((*this->animationSequence)[0])};
|
||||||
this->uncompressFrame(animationSequence[0], this->endFrame);
|
this->uncompressFrame(frame, this->startFrame);
|
||||||
|
this->copyFrame(this->startFrame, this->interpolatedFrame);
|
||||||
|
this->copyFrame(this->startFrame, this->endFrame);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
this->uncompressFrame(animationSequence[0], this->startFrame);
|
this->uncompressFrame((*this->animationSequence)[0], this->startFrame);
|
||||||
this->uncompressFrame(animationSequence[1], this->endFrame);
|
this->copyFrame(this->startFrame, this->interpolatedFrame);
|
||||||
|
this->uncompressFrame((*this->animationSequence)[1], this->endFrame);
|
||||||
}
|
}
|
||||||
|
this->interpolatedFrameHasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame &RunAnimation(std::chrono::milliseconds timePassed){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
auto delayTime = this->animationSequence[this->animationIndex].delay;
|
void Animator<BOARD_DIMS>::RunAnimation(const std::chrono::milliseconds& timePassed){
|
||||||
|
if(!(this->isEnabled)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto delayTime = (*this->animationSequence)[this->animationIndex].delay;
|
||||||
this->timeElapsed += timePassed;
|
this->timeElapsed += timePassed;
|
||||||
Frame interpolatedFrame;
|
|
||||||
|
|
||||||
// load in the next frame if we're done with this transition
|
// load in the next frame if we're done with this transition
|
||||||
if(this->timeElapsed >= delayTime){
|
if(this->timeElapsed >= delayTime){
|
||||||
@@ -71,61 +115,66 @@ Frame &RunAnimation(std::chrono::milliseconds timePassed){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// don't do frame interpolations if we're doing snap fades
|
// don't do frame interpolations if we're doing snap fades
|
||||||
if(this->animationSequence[this->animationIndex].frameInterpolation == FrameInterpolation::SNAP){
|
if((*this->animationSequence)[this->animationIndex].frameInterpolation == FrameInterpolation::SNAP){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// linearly interpolate between the two uncompressed frames
|
// linearly interpolate between the two uncompressed frames
|
||||||
for(uint32_t x = 0; x < this->X_SIZE; x++){
|
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
||||||
for(uint32_t y = 0; y < this->Y_SIZE; y++){
|
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
||||||
for(uint32_t z = 0; z < this->Z_SIZE; z++){
|
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
|
||||||
V3D startColor{this->startFrame[x][y][z]};
|
V3D<float> startColor{this->startFrame[x][y][z]};
|
||||||
V3D endColor{this->endFrame[x][y][z]};
|
V3D<float> endColor{this->endFrame[x][y][z]};
|
||||||
V3D difference{endColor - startColor};
|
V3D<float> difference{endColor};
|
||||||
V3D interpolatedColor = this->timeElapsed.count() * difference / delayTime.count() + startColor;
|
difference -= startColor;
|
||||||
interpolatedFrame[x][y][z] = interpolatedColor;
|
|
||||||
|
V3D<float> interpolatedColor{difference};
|
||||||
|
interpolatedColor *= this->timeElapsed.count();
|
||||||
|
interpolatedColor /= delayTime.count();
|
||||||
|
interpolatedColor += startColor;
|
||||||
|
|
||||||
|
this->interpolatedFrame[x][y][z] = interpolatedColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->interpolatedFrameHasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetLoop(bool isLooping){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
|
void Animator<BOARD_DIMS>::SetLoop(bool isLooping){
|
||||||
this->isLooping = isLooping;
|
this->isLooping = isLooping;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
uint32_t X_SIZE{3};
|
void Animator<BOARD_DIMS>::incrimentAnimationIndex(){
|
||||||
uint32_t Y_SIZE{3};
|
if(this->animationIndex < this->animationSequence->size() - 2){
|
||||||
uint32_t Z_SIZE{3};
|
|
||||||
bool isLooping{true};
|
|
||||||
// these are the uncompressed frames you get by following the key colors and interpolation instructions of an animation frame
|
|
||||||
Frame startFrame;
|
|
||||||
Frame endFrame;
|
|
||||||
std::chrono::milliseconds timeElapsed;
|
|
||||||
|
|
||||||
const std::vector<AnimationFrame> & animationSequence;
|
|
||||||
uint32_t animationIndex{0};
|
|
||||||
|
|
||||||
void incrimentAnimationIndex(){
|
|
||||||
if(this->animationIndex < animationSequence.size() - 1){
|
|
||||||
this->animationIndex++;
|
this->animationIndex++;
|
||||||
this->timeElapsed = std::chrono::millis(0);
|
this->timeElapsed = std::chrono::milliseconds(0);
|
||||||
this->uncompressFrame(this->animationSequence[this->animationIndex], this->startFrame);
|
this->uncompressFrame((*this->animationSequence)[this->animationIndex], this->startFrame);
|
||||||
this->uncompressFrame(this->animationSequence[this->animationIndex + 1], this->endFrame);
|
this->copyFrame(this->startFrame, this->interpolatedFrame);
|
||||||
|
this->uncompressFrame((*this->animationSequence)[this->animationIndex + 1], this->endFrame);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
this->StartAnimation(this->animationSequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->interpolatedFrameHasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uncompressFrame(const AnimationFrame &keyFrame, Frame &frameBuffer){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
for(uint32_t x = 0; x < X_SIZE; x++){
|
void Animator<BOARD_DIMS>::uncompressFrame(const AnimationFrame &keyFrame, Frame &frameBuffer){
|
||||||
for(uint32_t y = 0; y < Y_SIZE; y++){
|
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
||||||
for(uint32_t z = 0; z < Z_SIZE; z++){
|
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
||||||
frameBuffer[x][y][z] = getInterpolatedColor(keyFrame, V3D(x, y, z));
|
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
|
||||||
|
frameBuffer[x][y][z] = getInterpolatedColor(keyFrame, V3D<uint32_t>(x, y, z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D &getInterpolatedColor(const AnimationFrame &keyFrame, V3D position){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
|
V3D<uint32_t> Animator<BOARD_DIMS>::getInterpolatedColor(const AnimationFrame &keyFrame, V3D<uint32_t> position){
|
||||||
switch(keyFrame.fillInterpolation){
|
switch(keyFrame.fillInterpolation){
|
||||||
case FillInterpolation::NO_FILL:
|
case FillInterpolation::NO_FILL:
|
||||||
return noFillInterpolate(keyFrame, position);
|
return noFillInterpolate(keyFrame, position);
|
||||||
@@ -136,17 +185,19 @@ V3D &getInterpolatedColor(const AnimationFrame &keyFrame, V3D position){
|
|||||||
case FillInterpolation::SQUARE_WEIGHTED_DISTANCE:
|
case FillInterpolation::SQUARE_WEIGHTED_DISTANCE:
|
||||||
return squareInterpolate(keyFrame, position);
|
return squareInterpolate(keyFrame, position);
|
||||||
default:
|
default:
|
||||||
return V3D{};
|
V3D<uint32_t> black{};
|
||||||
|
return black;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D &keyFrame2BoardCoords(V3D &keyFramePosition){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
V3D returnValue{};
|
V3D<uint32_t> Animator<BOARD_DIMS>::keyFrame2BoardCoords(const V3D<uint32_t> &keyFramePosition){
|
||||||
|
V3D<uint32_t> returnValue{};
|
||||||
float maxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
|
float maxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
|
||||||
// scale the key frame values down to be within board coordinates
|
// scale the key frame values down to be within board coordinates
|
||||||
float keyFrame_X = static_cast<float>(this->X_SIZE) * static_cast<float>(keyFramePosition.x) / maxValue;
|
float keyFrame_X = static_cast<float>(BOARD_DIMS.x - 1) * static_cast<float>(keyFramePosition.x) / maxValue;
|
||||||
float keyFrame_Y = static_cast<float>(this->Y_SIZE) * static_cast<float>(keyFramePosition.y) / maxValue;
|
float keyFrame_Y = static_cast<float>(BOARD_DIMS.y - 1) * static_cast<float>(keyFramePosition.y) / maxValue;
|
||||||
float keyFrame_Z = static_cast<float>(this->Z_SIZE) * static_cast<float>(keyFramePosition.z) / maxValue;
|
float keyFrame_Z = static_cast<float>(BOARD_DIMS.z - 1) * static_cast<float>(keyFramePosition.z) / maxValue;
|
||||||
|
|
||||||
// carefully quantize the float values back into ints with a precise rounding operation
|
// carefully quantize the float values back into ints with a precise rounding operation
|
||||||
if(keyFrame_X - std::floor(keyFrame_X) < 0.5f){
|
if(keyFrame_X - std::floor(keyFrame_X) < 0.5f){
|
||||||
@@ -173,8 +224,9 @@ V3D &keyFrame2BoardCoords(V3D &keyFramePosition){
|
|||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D &noFillInterpolate(const AnimationFrame &keyFrame, V3D position){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
V3D returnColor{};
|
V3D<uint32_t> Animator<BOARD_DIMS>::noFillInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> position){
|
||||||
|
V3D<uint32_t> returnColor{};
|
||||||
for(Cell cell : keyFrame.frame){
|
for(Cell cell : keyFrame.frame){
|
||||||
if(keyFrame2BoardCoords(cell.position) == position){
|
if(keyFrame2BoardCoords(cell.position) == position){
|
||||||
returnColor = cell.color;
|
returnColor = cell.color;
|
||||||
@@ -184,170 +236,58 @@ V3D &noFillInterpolate(const AnimationFrame &keyFrame, V3D position){
|
|||||||
return returnColor;
|
return returnColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D &closestColorInterpolate(const AnimationFrame &keyFrame, V3D position){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
V3D returnColor{};
|
V3D<uint32_t> Animator<BOARD_DIMS>::closestColorInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> cubePosition){
|
||||||
float closestDistance = (keyframe.frame[0].position - position).mag();
|
V3D<uint32_t> returnColor{keyFrame.frame[0].color};
|
||||||
|
V3D<uint32_t> distance{keyFrame.frame[0].position};
|
||||||
|
distance -= cubePosition;
|
||||||
|
float closestDistance = distance.magnitude();
|
||||||
|
|
||||||
for(Cell cell : keyFrame.frame){
|
for(Cell cell : keyFrame.frame){
|
||||||
float distance = (keyFrame2BoardCoords(cell.position) - position).mag();
|
distance = keyFrame2BoardCoords(cell.position);
|
||||||
if(distance < closestDistance){
|
distance -= cubePosition;
|
||||||
|
float euclidDistance = distance.magnitude();
|
||||||
|
if(euclidDistance < closestDistance){
|
||||||
returnColor = cell.color;
|
returnColor = cell.color;
|
||||||
closestDistance = distance;
|
closestDistance = euclidDistance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnColor;
|
return returnColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D &linearInterpolate(const AnimationFrame &keyFrame, V3D position){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
V3D returnColor{};
|
V3D<uint32_t> Animator<BOARD_DIMS>::linearInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> position){
|
||||||
|
V3D<uint32_t> returnColor{};
|
||||||
|
|
||||||
for(Cell cell : keyFrame.frame){
|
for(Cell cell : keyFrame.frame){
|
||||||
uint32_t distance = static_cast<uint32_t>((keyFrame2BoardCoords(cell.position) - position).mag());
|
V3D<uint32_t> vectorDistance{keyFrame2BoardCoords(cell.position)};
|
||||||
if(distance == 0) distance = 1;
|
vectorDistance -= position;
|
||||||
returnColor = returnColor + cell.color / distance;
|
float distance = vectorDistance.magnitude();
|
||||||
|
if(distance == 0) return cell.color;
|
||||||
|
returnColor += cell.color;
|
||||||
|
returnColor /= distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
returnColor = returnColor / keyFrame.frame.size();
|
returnColor /= keyFrame.frame.size();
|
||||||
|
|
||||||
return returnColor;
|
return returnColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
V3D &squareInterpolate(const AnimationFrame &keyFrame, V3D position){
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
V3D returnColor{};
|
V3D<uint32_t> Animator<BOARD_DIMS>::squareInterpolate(const AnimationFrame &keyFrame, V3D<uint32_t> position){
|
||||||
|
V3D<uint32_t> returnColor{};
|
||||||
|
|
||||||
for(Cell cell : keyFrame.frame){
|
for(Cell cell : keyFrame.frame){
|
||||||
uint32_t distance = static_cast<uint32_t>((keyFrame2BoardCoords(cell.position) - position).mag());
|
V3D<uint32_t> vectorDistance{keyFrame2BoardCoords(cell.position)};
|
||||||
|
vectorDistance -= position;
|
||||||
|
uint32_t distance = static_cast<uint32_t>(vectorDistance.magnitude());
|
||||||
distance *= distance;
|
distance *= distance;
|
||||||
if(distance == 0) distance = 1;
|
if(distance == 0) return cell.color;
|
||||||
returnColor = returnColor + cell.color / distance;
|
returnColor += cell.color;
|
||||||
|
returnColor /= distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
returnColor = returnColor / keyFrame.frame.size();
|
returnColor /= keyFrame.frame.size();
|
||||||
|
|
||||||
return returnColor;
|
return returnColor;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// let's make some test animation frames
|
|
||||||
|
|
||||||
namespace TestFrames{
|
|
||||||
V3D red{255,0,0};
|
|
||||||
V3D green{0,255,0};
|
|
||||||
V3D blue{0,0,255};
|
|
||||||
uint32_t maxValue{std::numeric_limits<uint32_t>::max()};
|
|
||||||
|
|
||||||
Animation::Cell &CreateCell(float x_percent, float y_percent, float z_percent, V3D &color){
|
|
||||||
float continuousMaxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
|
|
||||||
Animation::Cell cell{
|
|
||||||
.position = V3D{
|
|
||||||
static_cast<uint32_t>(continuousMaxValue*x_percent),
|
|
||||||
static_cast<uint32_t>(continuousMaxValue*y_percent),
|
|
||||||
static_cast<uint32_t>(continuousMaxValue*z_percent)
|
|
||||||
},
|
|
||||||
.color = color
|
|
||||||
};
|
|
||||||
|
|
||||||
return cell;
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame noFillFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::NO_FILL;
|
|
||||||
.frameInterpolation = FrameInterpolation::SNAP;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame closestColorFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR;
|
|
||||||
.frameInterpolation = FrameInterpolation::SNAP;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame linearFillFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE;
|
|
||||||
.frameInterpolation = FrameInterpolation::SNAP;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame squareFillFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::SQUARE_WEIGHTED_DISTANCE;
|
|
||||||
.frameInterpolation = FrameInterpolation::SNAP;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame noFillFadeFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::NO_FILL;
|
|
||||||
.frameInterpolation = FrameInterpolation::FADE;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame closestColorFadeFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR;
|
|
||||||
.frameInterpolation = FrameInterpolation::FADE;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame linearFillFadeFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE;
|
|
||||||
.frameInterpolation = FrameInterpolation::FADE;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
Animation::AnimationFrame squareFillFadeFrame{
|
|
||||||
.frame = {
|
|
||||||
CreateCell(0,0,0,red),
|
|
||||||
CreateCell(0.5,0.5,0.5,green),
|
|
||||||
CreateCell(1,1,1,blue)
|
|
||||||
};
|
|
||||||
.fillInterpolation = FillInterpolation::SQUARE_WEIGHTED_DISTANCE;
|
|
||||||
.frameInterpolation = FrameInterpolation::FADE;
|
|
||||||
.delay = std::chrono::millis(10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<AnimationFrame> testAnimationSequence{
|
|
||||||
noFillFrame,
|
|
||||||
closestColorFrame,
|
|
||||||
linearFillFrame,
|
|
||||||
squareFillFrame,
|
|
||||||
noFillFadeFrame,
|
|
||||||
closestFillFadeFrame,
|
|
||||||
linearFillFadeFrame,
|
|
||||||
squareFillFadeFrame
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
169
lib/Animator/TestFrames.h
Normal file
169
lib/Animator/TestFrames.h
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "AnimationTypes.h"
|
||||||
|
#include "Vector3D.h"
|
||||||
|
#include "Animator.h"
|
||||||
|
|
||||||
|
using namespace ANIMATION_TYPES;
|
||||||
|
|
||||||
|
namespace TestFrames{
|
||||||
|
|
||||||
|
V3D<uint32_t> red{255,0,0};
|
||||||
|
V3D<uint32_t> green{0,255,0};
|
||||||
|
V3D<uint32_t> blue{0,0,255};
|
||||||
|
uint32_t maxValue{std::numeric_limits<uint32_t>::max()};
|
||||||
|
|
||||||
|
Cell CreateCell(float x_percent, float y_percent, float z_percent, V3D<uint32_t> &color){
|
||||||
|
float continuousMaxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
|
||||||
|
Cell cell{
|
||||||
|
.position = V3D<uint32_t>{
|
||||||
|
static_cast<uint32_t>(continuousMaxValue*x_percent),
|
||||||
|
static_cast<uint32_t>(continuousMaxValue*y_percent),
|
||||||
|
static_cast<uint32_t>(continuousMaxValue*z_percent)
|
||||||
|
},
|
||||||
|
.color = color
|
||||||
|
};
|
||||||
|
|
||||||
|
return cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimationFrame noFillFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::NO_FILL,
|
||||||
|
.frameInterpolation = FrameInterpolation::SNAP,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame closestColorFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||||
|
.frameInterpolation = FrameInterpolation::SNAP,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame linearFillFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
|
||||||
|
.frameInterpolation = FrameInterpolation::SNAP,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame squareFillFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::SQUARE_WEIGHTED_DISTANCE,
|
||||||
|
.frameInterpolation = FrameInterpolation::SNAP,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame noFillFadeFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::NO_FILL,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame closestColorFadeFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame linearFillFadeFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame squareFillFadeFrame{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
CreateCell(0.5,0.5,0.5,green),
|
||||||
|
CreateCell(1,1,1,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::SQUARE_WEIGHTED_DISTANCE,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<AnimationFrame> testAnimationSequence2{
|
||||||
|
noFillFrame, // 0
|
||||||
|
closestColorFrame, // 1
|
||||||
|
linearFillFrame, // 2
|
||||||
|
squareFillFrame, // 3
|
||||||
|
noFillFadeFrame, // 4
|
||||||
|
closestColorFadeFrame, // 5
|
||||||
|
linearFillFadeFrame, // 6
|
||||||
|
squareFillFadeFrame, // 7
|
||||||
|
noFillFrame // 8
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame testFrame1{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,0,0,red),
|
||||||
|
// CreateCell(0.5,0.5,0,green),
|
||||||
|
CreateCell(1,1,0,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::NO_FILL,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame testFrame2{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0,1,0,red),
|
||||||
|
// CreateCell(0.5,0.5,0,green),
|
||||||
|
CreateCell(1,0,0,green)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::NO_FILL,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
AnimationFrame testFrame3{
|
||||||
|
.frame = {
|
||||||
|
CreateCell(0.5,0.5,0,red),
|
||||||
|
// CreateCell(0.5,0.5,0,green),
|
||||||
|
CreateCell(0,1,0,blue)
|
||||||
|
},
|
||||||
|
.fillInterpolation = FillInterpolation::NO_FILL,
|
||||||
|
.frameInterpolation = FrameInterpolation::FADE,
|
||||||
|
.delay = std::chrono::milliseconds(10000)
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<AnimationFrame> testAnimationSequence1{
|
||||||
|
testFrame1,
|
||||||
|
testFrame2,
|
||||||
|
testFrame3,
|
||||||
|
testFrame1
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -12,13 +12,13 @@
|
|||||||
#include "BoardTypes.h"
|
#include "BoardTypes.h"
|
||||||
#include "Vector3D.h"
|
#include "Vector3D.h"
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
class Board{
|
class Board{
|
||||||
public:
|
public:
|
||||||
Board() = default;
|
Board() = default;
|
||||||
~Board() = default;
|
~Board() = default;
|
||||||
|
|
||||||
constexpr const V3D &GetSize() const{return BOARD_DIMS;}
|
constexpr const V3D<uint32_t> &GetSize() const{return BOARD_DIMS;}
|
||||||
constexpr uint32_t GetNumberCubes() const{return BOARD_DIMS.x * BOARD_DIMS.y * BOARD_DIMS.z;}
|
constexpr uint32_t GetNumberCubes() const{return BOARD_DIMS.x * BOARD_DIMS.y * BOARD_DIMS.z;}
|
||||||
|
|
||||||
constexpr uint32_t GetMaxDimension(){return std::max(std::max(BOARD_DIMS.x, BOARD_DIMS.y), BOARD_DIMS.z);}
|
constexpr uint32_t GetMaxDimension(){return std::max(std::max(BOARD_DIMS.x, BOARD_DIMS.y), BOARD_DIMS.z);}
|
||||||
@@ -34,7 +34,7 @@ class Board{
|
|||||||
* @brief fill the entire board with the given color
|
* @brief fill the entire board with the given color
|
||||||
* @param color the color to fill the board with
|
* @param color the color to fill the board with
|
||||||
*/
|
*/
|
||||||
void FillColor(const V3D &color);
|
void FillColor(const V3D<uint32_t> &color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the color of the cube at the given position.
|
* @brief Set the color of the cube at the given position.
|
||||||
@@ -43,7 +43,7 @@ class Board{
|
|||||||
* @param position the position of the cube.
|
* @param position the position of the cube.
|
||||||
* @param color the color you want the cube to be
|
* @param color the color you want the cube to be
|
||||||
*/
|
*/
|
||||||
void SetCubeColor(const V3D &position, const V3D &color);
|
void SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the occupation status of the cube at a given position
|
* @brief Set the occupation status of the cube at a given position
|
||||||
@@ -52,7 +52,7 @@ class Board{
|
|||||||
* @post if the new occupation status of the cube is different than
|
* @post if the new occupation status of the cube is different than
|
||||||
* the old occupation status, this will enable boardStateHasChanged.
|
* the old occupation status, this will enable boardStateHasChanged.
|
||||||
*/
|
*/
|
||||||
void SetCubeOccupation(const V3D &position, bool occupation);
|
void SetCubeOccupation(const V3D<uint32_t> &position, bool occupation);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns true if the board state has changed since this flag was last set to false
|
* @returns true if the board state has changed since this flag was last set to false
|
||||||
@@ -69,16 +69,26 @@ class Board{
|
|||||||
* @brief Get a column along any axis read into the sliceBuffer
|
* @brief Get a column along any axis read into the sliceBuffer
|
||||||
* @param column .z specifies the normal direction of the plane (see PLANE_NORMAL), and
|
* @param column .z specifies the normal direction of the plane (see PLANE_NORMAL), and
|
||||||
* the x,y values specify the location of the column in that plane
|
* the x,y values specify the location of the column in that plane
|
||||||
* to fill. IE To fill one stack at 0,2 I would say give V3D(0,2,PLANE_NORMAL::Z)
|
* to fill. IE To fill one stack at 0,2 I would say give V3D<uint32_t>(0,2,PLANE_NORMAL::Z)
|
||||||
* @param sliceBuffer an array of pointers to the cubes along that column
|
* @param sliceBuffer an array of pointers to the cubes along that column
|
||||||
* @returns the number of elements written into the slice buffer
|
* @returns the number of elements written into the slice buffer
|
||||||
* @note That array is stored locally and will be overwritten everytime this function is called.
|
* @note That array is stored locally and will be overwritten everytime this function is called.
|
||||||
* Also, any unused spots at the end of the array will be nullptrs
|
* Also, any unused spots at the end of the array will be nullptrs
|
||||||
* @warning allocate the size of the slice buffer using GetMaxDimension if you don't know what you're doing!
|
* @warning allocate the size of the slice buffer using GetMaxDimension if you don't know what you're doing!
|
||||||
*/
|
*/
|
||||||
uint32_t SliceBoard(const V3D &column, BOARD_TYPES::Cube ** sliceBuffer);
|
uint32_t SliceBoard(const V3D<uint32_t> &column, BOARD_TYPES::Cube ** sliceBuffer);
|
||||||
|
|
||||||
void PrintEntireBoard() const;
|
void PrintEntireBoard() const;
|
||||||
|
|
||||||
|
void UpdateAllColors(const std::array<std::array<std::array<V3D<uint32_t>, BOARD_DIMS.z>, BOARD_DIMS.y>, BOARD_DIMS.x>& colorFrame){
|
||||||
|
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
||||||
|
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
||||||
|
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
|
||||||
|
this->cubes[x][y][z].color = colorFrame[x][y][z];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
// this is a 3d array of cubes to represent the board. Good luck visualizing it
|
// this is a 3d array of cubes to represent the board. Good luck visualizing it
|
||||||
/* _____________
|
/* _____________
|
||||||
@@ -96,7 +106,7 @@ class Board{
|
|||||||
bool boardStateHasChanged;
|
bool boardStateHasChanged;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
|
void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
|
||||||
std::array<uint32_t, BOARD_DIMS.x * BOARD_DIMS.y> linearizedBoard;
|
std::array<uint32_t, BOARD_DIMS.x * BOARD_DIMS.y> linearizedBoard;
|
||||||
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
|
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
|
||||||
@@ -116,8 +126,8 @@ void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void Board<BOARD_DIMS>::FillColor(const V3D &color){
|
void Board<BOARD_DIMS>::FillColor(const V3D<uint32_t> &color){
|
||||||
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
|
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
|
||||||
for(uint32_t y{0}; y < BOARD_DIMS.y; y++){
|
for(uint32_t y{0}; y < BOARD_DIMS.y; y++){
|
||||||
for(uint32_t z{0}; z < BOARD_DIMS.z; z++){
|
for(uint32_t z{0}; z < BOARD_DIMS.z; z++){
|
||||||
@@ -127,23 +137,23 @@ void Board<BOARD_DIMS>::FillColor(const V3D &color){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void Board<BOARD_DIMS>::SetCubeColor(const V3D &position, const V3D &color){
|
void Board<BOARD_DIMS>::SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color){
|
||||||
this->cubes[position.x][position.y][position.z].color = color;
|
this->cubes[position.x][position.y][position.z].color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void Board<BOARD_DIMS>::SetCubeOccupation(const V3D &position, bool occupation){
|
void Board<BOARD_DIMS>::SetCubeOccupation(const V3D<uint32_t> &position, bool occupation){
|
||||||
bool oldOccupation{this->cubes[position.x][position.y][position.z].isOccupied};
|
bool oldOccupation{this->cubes[position.x][position.y][position.z].isOccupied};
|
||||||
this->cubes[position.x][position.y][position.z].isOccupied = occupation;
|
this->cubes[position.x][position.y][position.z].isOccupied = occupation;
|
||||||
if(occupation != oldOccupation) this->boardStateHasChanged = true;
|
if(occupation != oldOccupation) this->boardStateHasChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
uint32_t Board<BOARD_DIMS>::SliceBoard(const V3D &column, BOARD_TYPES::Cube ** sliceBuffer){
|
uint32_t Board<BOARD_DIMS>::SliceBoard(const V3D<uint32_t> &column, BOARD_TYPES::Cube ** sliceBuffer){
|
||||||
uint32_t columnLength{0};
|
uint32_t columnLength{0};
|
||||||
V3D indexIncrimentVector{};
|
V3D<uint32_t> indexIncrimentVector{};
|
||||||
V3D indexVector{};
|
V3D<uint32_t> indexVector{};
|
||||||
|
|
||||||
switch(column.z){
|
switch(column.z){
|
||||||
case BOARD_TYPES::PLANE_NORMAL::X:
|
case BOARD_TYPES::PLANE_NORMAL::X:
|
||||||
@@ -179,7 +189,7 @@ uint32_t Board<BOARD_DIMS>::SliceBoard(const V3D &column, BOARD_TYPES::Cube ** s
|
|||||||
return columnLength;
|
return columnLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void Board<BOARD_DIMS>::PrintEntireBoard() const{
|
void Board<BOARD_DIMS>::PrintEntireBoard() const{
|
||||||
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
||||||
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ void BoardDriver<NUM_STACKS>::UpdateStackLEDs(
|
|||||||
){
|
){
|
||||||
this->pixelController.setPin(this->stacks[stackIndex].ledPin);
|
this->pixelController.setPin(this->stacks[stackIndex].ledPin);
|
||||||
for(int i = 0; i < numCubes; i++){
|
for(int i = 0; i < numCubes; i++){
|
||||||
V3D color{cubes[i]->color};
|
V3D<uint32_t> color{cubes[i]->color};
|
||||||
this->pixelController.setPixelColor(i*2, this->pixelController.Color(color.x, color.y, color.z));
|
this->pixelController.setPixelColor(i*2, this->pixelController.Color(color.x, color.y, color.z));
|
||||||
this->pixelController.setPixelColor((i*2 + 1), this->pixelController.Color(color.x, color.y, color.z));
|
this->pixelController.setPixelColor((i*2 + 1), this->pixelController.Color(color.x, color.y, color.z));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,12 @@
|
|||||||
#include "Board.h"
|
#include "Board.h"
|
||||||
#include "BoardDriver.h"
|
#include "BoardDriver.h"
|
||||||
#include "Vector3D.h"
|
#include "Vector3D.h"
|
||||||
|
#include "Animator.h"
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
class BoardManager{
|
class BoardManager{
|
||||||
public:
|
public:
|
||||||
BoardManager(BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &boardDriver);
|
BoardManager(BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &boardDriver, Animator<BOARD_DIMS> &animator);
|
||||||
|
|
||||||
~BoardManager() = default;
|
~BoardManager() = default;
|
||||||
|
|
||||||
@@ -30,7 +31,7 @@ class BoardManager{
|
|||||||
* @param position the position of the cube
|
* @param position the position of the cube
|
||||||
* @param color the oclor you want the cube to be
|
* @param color the oclor you want the cube to be
|
||||||
*/
|
*/
|
||||||
void SetCubeColor(const V3D &position, const V3D &color);
|
void SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the color of one column of cubes.
|
* @brief Set the color of one column of cubes.
|
||||||
@@ -39,17 +40,17 @@ class BoardManager{
|
|||||||
* @param column the column vector
|
* @param column the column vector
|
||||||
* @param color the color you want the column to be
|
* @param color the color you want the column to be
|
||||||
*/
|
*/
|
||||||
void SetColumnColors(const V3D &column, const V3D *color, uint32_t numColors);
|
void SetColumnColors(const V3D<uint32_t> &column, const V3D<uint32_t> *color, uint32_t numColors);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fill a column along any axis with a color
|
* @brief Fill a column along any axis with a color
|
||||||
* @param column .z specifies the normal direction of the plane (see PLANE_NORMAL), and
|
* @param column .z specifies the normal direction of the plane (see PLANE_NORMAL), and
|
||||||
* the x,y values specify the location of the column in that plane
|
* the x,y values specify the location of the column in that plane
|
||||||
* to fill. IE To fill one stack at 0,2 I would say give V3D(0,2,PLANE_NORMAL::Z)
|
* to fill. IE To fill one stack at 0,2 I would say give V3D<uint32_t>(0,2,PLANE_NORMAL::Z)
|
||||||
* @param color the color you want to fill the column with
|
* @param color the color you want to fill the column with
|
||||||
*/
|
*/
|
||||||
void FillColumnColor(const V3D &column, const V3D &color);
|
void FillColumnColor(const V3D<uint32_t> &column, const V3D<uint32_t> &color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns true if the board has changed state
|
* @returns true if the board has changed state
|
||||||
@@ -66,11 +67,14 @@ class BoardManager{
|
|||||||
*/
|
*/
|
||||||
void Board2StackString(String& messageBuffer);
|
void Board2StackString(String& messageBuffer);
|
||||||
|
|
||||||
|
void FillColor(const V3D<uint32_t> &color){this->board.FillColor(color);}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &driver;
|
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &driver;
|
||||||
Board<BOARD_DIMS> board{};
|
Board<BOARD_DIMS> board{};
|
||||||
|
Animator<BOARD_DIMS> &animator;
|
||||||
|
|
||||||
void updateStackColors(const V3D &column);
|
void updateStackColors(const V3D<uint32_t> &column);
|
||||||
|
|
||||||
uint32_t getColumnHeight(BOARD_TYPES::PLANE_NORMAL normal){
|
uint32_t getColumnHeight(BOARD_TYPES::PLANE_NORMAL normal){
|
||||||
switch(normal){
|
switch(normal){
|
||||||
@@ -88,32 +92,43 @@ class BoardManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateColorsFromAnimator();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
|
void BoardManager<BOARD_DIMS>::updateColorsFromAnimator(){
|
||||||
|
if(this->animator.interpolatedFrameHasChanged){
|
||||||
|
this->board.UpdateAllColors(this->animator.GetInterpolatedFrame());
|
||||||
|
this->animator.interpolatedFrameHasChanged = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
BoardManager<BOARD_DIMS>::BoardManager(BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &boardDriver):
|
BoardManager<BOARD_DIMS>::BoardManager(BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &boardDriver, Animator<BOARD_DIMS> &animator):
|
||||||
driver(boardDriver){}
|
driver(boardDriver),
|
||||||
|
animator(animator){}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::Init(){
|
void BoardManager<BOARD_DIMS>::Init(){
|
||||||
this->driver.Init();
|
this->driver.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::Update(){
|
void BoardManager<BOARD_DIMS>::Update(){
|
||||||
|
this->updateColorsFromAnimator();
|
||||||
// update the occupied cubes on the board and the cube colors
|
// update the occupied cubes on the board and the cube colors
|
||||||
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
|
||||||
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
|
||||||
uint32_t stackIndex{y * BOARD_DIMS.x + x};
|
uint32_t stackIndex{y * BOARD_DIMS.x + x};
|
||||||
uint32_t numCubes{this->driver.GetNumberCubes(stackIndex)};
|
uint32_t numCubes{this->driver.GetNumberCubes(stackIndex)};
|
||||||
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
|
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
|
||||||
V3D cubePosition{x, y, z};
|
V3D<uint32_t> cubePosition{x, y, z};
|
||||||
// update the cube's occupation
|
// update the cube's occupation
|
||||||
this->board.SetCubeOccupation(cubePosition, z < numCubes);
|
this->board.SetCubeOccupation(cubePosition, z < numCubes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the column vector for the slice direction
|
// create the column vector for the slice direction
|
||||||
V3D sliceVector{x,y,BOARD_TYPES::PLANE_NORMAL::Z};
|
V3D<uint32_t> sliceVector{x,y,BOARD_TYPES::PLANE_NORMAL::Z};
|
||||||
// create a cube slice array buffer
|
// create a cube slice array buffer
|
||||||
BOARD_TYPES::Cube* sliceBuffer[BOARD_DIMS.z];
|
BOARD_TYPES::Cube* sliceBuffer[BOARD_DIMS.z];
|
||||||
// have the board slice get read into our buffer
|
// have the board slice get read into our buffer
|
||||||
@@ -124,10 +139,10 @@ void BoardManager<BOARD_DIMS>::Update(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::updateStackColors(const V3D &column){
|
void BoardManager<BOARD_DIMS>::updateStackColors(const V3D<uint32_t> &column){
|
||||||
// the only column type allowed here is z.
|
// the only column type allowed here is z.
|
||||||
V3D sliceVector{column.x, column.y, BOARD_TYPES::Z};
|
V3D<uint32_t> sliceVector{column.x, column.y, BOARD_TYPES::Z};
|
||||||
// create a buffer for slice board to write the cube slice into
|
// create a buffer for slice board to write the cube slice into
|
||||||
BOARD_TYPES::Cube * cubeSlice[BOARD_DIMS.z];
|
BOARD_TYPES::Cube * cubeSlice[BOARD_DIMS.z];
|
||||||
this->board.SliceBoard(column, cubeSlice);
|
this->board.SliceBoard(column, cubeSlice);
|
||||||
@@ -136,15 +151,15 @@ void BoardManager<BOARD_DIMS>::updateStackColors(const V3D &column){
|
|||||||
this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes);
|
this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::SetCubeColor(const V3D &position, const V3D &color){
|
void BoardManager<BOARD_DIMS>::SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color){
|
||||||
this->board.SetCubeColor(position, color);
|
this->board.SetCubeColor(position, color);
|
||||||
V3D slice{position.x, position.y, BOARD_TYPES::PLANE_NORMAL::Z};
|
V3D<uint32_t> slice{position.x, position.y, BOARD_TYPES::PLANE_NORMAL::Z};
|
||||||
this->updateStackColors(slice);
|
this->updateStackColors(slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D &column, const V3D *color, uint32_t numColors){
|
void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D<uint32_t> &column, const V3D<uint32_t> *color, uint32_t numColors){
|
||||||
uint32_t columnHeight{this->getColumnHeight(static_cast<BOARD_TYPES::PLANE_NORMAL>(column.z))};
|
uint32_t columnHeight{this->getColumnHeight(static_cast<BOARD_TYPES::PLANE_NORMAL>(column.z))};
|
||||||
|
|
||||||
// create a cube pointer buffer and store a board slice into it
|
// create a cube pointer buffer and store a board slice into it
|
||||||
@@ -157,11 +172,11 @@ void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D &column, const V3D *col
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::FillColumnColor(const V3D &column, const V3D &color){
|
void BoardManager<BOARD_DIMS>::FillColumnColor(const V3D<uint32_t> &column, const V3D<uint32_t> &color){
|
||||||
uint32_t columnHeight{this->getColumnHeight(column.z)};
|
uint32_t columnHeight{this->getColumnHeight(column.z)};
|
||||||
|
|
||||||
V3D colors[columnHeight];
|
V3D<uint32_t> colors[columnHeight];
|
||||||
for(uint32_t i = 0; i < columnHeight; i++){
|
for(uint32_t i = 0; i < columnHeight; i++){
|
||||||
colors[i] = color;
|
colors[i] = color;
|
||||||
}
|
}
|
||||||
@@ -169,13 +184,13 @@ void BoardManager<BOARD_DIMS>::FillColumnColor(const V3D &column, const V3D &col
|
|||||||
this->SetColumnColors(column, colors);
|
this->SetColumnColors(column, colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
bool BoardManager<BOARD_DIMS>::HasBoardChanged(){return this->board.BoardStateChanged();}
|
bool BoardManager<BOARD_DIMS>::HasBoardChanged(){return this->board.BoardStateChanged();}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::ClearBoardChanged(){this->board.SetStateChanged(false);}
|
void BoardManager<BOARD_DIMS>::ClearBoardChanged(){this->board.SetStateChanged(false);}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D<uint32_t> &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::Board2StackString(String& messageBuffer){
|
void BoardManager<BOARD_DIMS>::Board2StackString(String& messageBuffer){
|
||||||
this->board.ToStackString(messageBuffer);
|
this->board.ToStackString(messageBuffer);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace BOARD_TYPES{
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Cube{
|
struct Cube{
|
||||||
V3D color;
|
V3D<uint32_t> color;
|
||||||
bool isOccupied{false};
|
bool isOccupied{false};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
41
src/main.cpp
41
src/main.cpp
@@ -19,6 +19,9 @@
|
|||||||
#include "BoardDriver.h"
|
#include "BoardDriver.h"
|
||||||
#include "BoardTypes.h"
|
#include "BoardTypes.h"
|
||||||
|
|
||||||
|
#include "Animator.h"
|
||||||
|
#include "TestFrames.h"
|
||||||
|
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
// ----------------- VARIABLES ----------------------
|
// ----------------- VARIABLES ----------------------
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
@@ -31,8 +34,9 @@ SerialMessage<SERIAL_CHAR_LENGTH, SERIAL_ARG_LENGTH> serialMessage(&Serial);
|
|||||||
|
|
||||||
Adafruit_NeoPixel pixelController{BOARD_HEIGHT*2, STACK1_LED_PIN, NEO_GRB + NEO_KHZ800};
|
Adafruit_NeoPixel pixelController{BOARD_HEIGHT*2, STACK1_LED_PIN, NEO_GRB + NEO_KHZ800};
|
||||||
|
|
||||||
|
Animator<BOARD_DIMENSIONS> animator{};
|
||||||
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> boardDriver{stacks, pixelController};
|
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> boardDriver{stacks, pixelController};
|
||||||
BoardManager<BOARD_DIMENSIONS> boardManager{boardDriver};
|
BoardManager<BOARD_DIMENSIONS> boardManager{boardDriver, animator};
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
// ----------------- FUNCTIONS ----------------------
|
// ----------------- FUNCTIONS ----------------------
|
||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
@@ -79,15 +83,15 @@ void SetStackColor(uint32_t * args, int argsLength){
|
|||||||
uint32_t Y_COORD{(stackNum - X_COORD) / BOARD_DIMENSIONS.y};
|
uint32_t Y_COORD{(stackNum - X_COORD) / BOARD_DIMENSIONS.y};
|
||||||
|
|
||||||
uint32_t numColors = (argsLength - 2) / 3;
|
uint32_t numColors = (argsLength - 2) / 3;
|
||||||
V3D colors[numColors];
|
V3D<uint32_t> colors[numColors];
|
||||||
|
|
||||||
for(int i = 0; i < numColors; i++){
|
for(int i = 0; i < numColors; i++){
|
||||||
uint32_t red = args[2 + (i * 3)];
|
uint32_t red = args[2 + (i * 3)];
|
||||||
uint32_t green = args[3 + (i * 3)];
|
uint32_t green = args[3 + (i * 3)];
|
||||||
uint32_t blue = args[4 + (i * 3)];
|
uint32_t blue = args[4 + (i * 3)];
|
||||||
colors[i] = V3D{red, green, blue};
|
colors[i] = V3D<uint32_t>{red, green, blue};
|
||||||
}
|
}
|
||||||
boardManager.SetColumnColors(V3D{X_COORD, Y_COORD, BOARD_TYPES::PLANE_NORMAL::Z}, colors, numColors);
|
boardManager.SetColumnColors(V3D<uint32_t>{X_COORD, Y_COORD, BOARD_TYPES::PLANE_NORMAL::Z}, colors, numColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseData(Message<SERIAL_CHAR_LENGTH, SERIAL_ARG_LENGTH> &message){
|
void parseData(Message<SERIAL_CHAR_LENGTH, SERIAL_ARG_LENGTH> &message){
|
||||||
@@ -95,26 +99,31 @@ void parseData(Message<SERIAL_CHAR_LENGTH, SERIAL_ARG_LENGTH> &message){
|
|||||||
uint32_t argsLength{message.GetPopulatedArgs()};
|
uint32_t argsLength{message.GetPopulatedArgs()};
|
||||||
uint32_t command = args[0];
|
uint32_t command = args[0];
|
||||||
switch(command){
|
switch(command){
|
||||||
case Commands::BoardState:
|
case Commands::BoardState:{
|
||||||
printBoardState();
|
printBoardState();
|
||||||
break;
|
break;
|
||||||
case Commands::PING:
|
}
|
||||||
|
case Commands::PING:{
|
||||||
GlobalPrint::Println("!" + String(Commands::PING) + ";");
|
GlobalPrint::Println("!" + String(Commands::PING) + ";");
|
||||||
break;
|
break;
|
||||||
case Commands::SetStackColors:
|
}
|
||||||
|
case Commands::SetStackColors:{
|
||||||
GlobalPrint::Println("!2;");
|
GlobalPrint::Println("!2;");
|
||||||
// TODO: replace this with the animator
|
animator.isEnabled = false;
|
||||||
// colorManager.Enable(false);
|
V3D<uint32_t> black{};
|
||||||
|
boardManager.FillColor(black);
|
||||||
SetStackColor(reinterpret_cast<uint32_t *>(args), argsLength);
|
SetStackColor(reinterpret_cast<uint32_t *>(args), argsLength);
|
||||||
break;
|
break;
|
||||||
case Commands::GoToIdle:
|
}
|
||||||
|
case Commands::GoToIdle:{
|
||||||
GlobalPrint::Println("!3;");
|
GlobalPrint::Println("!3;");
|
||||||
// TODO: replace this with the animator
|
animator.isEnabled = true;
|
||||||
// colorManager.Enable(true);
|
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
|
default:{
|
||||||
GlobalPrint::Println("INVALID COMMAND");
|
GlobalPrint::Println("INVALID COMMAND");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now that we have run the command we can clear the data for the next command.
|
// now that we have run the command we can clear the data for the next command.
|
||||||
@@ -148,13 +157,15 @@ void UpdateBoard(void * params){
|
|||||||
auto updateTickRate{std::chrono::milliseconds(8)};
|
auto updateTickRate{std::chrono::milliseconds(8)};
|
||||||
auto boardStateTimer{std::chrono::milliseconds(0)};
|
auto boardStateTimer{std::chrono::milliseconds(0)};
|
||||||
auto boardStateMaxUpdatePeriod{std::chrono::milliseconds(34)}; // this is a little slower than 30fps
|
auto boardStateMaxUpdatePeriod{std::chrono::milliseconds(34)}; // this is a little slower than 30fps
|
||||||
|
unsigned long accurateTimer{millis()};
|
||||||
for(;;){
|
for(;;){
|
||||||
if(boardStateTimer >= boardStateMaxUpdatePeriod && boardManager.HasBoardChanged()){
|
if(boardStateTimer >= boardStateMaxUpdatePeriod && boardManager.HasBoardChanged()){
|
||||||
printBoardState();
|
printBoardState();
|
||||||
boardManager.ClearBoardChanged();
|
boardManager.ClearBoardChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
animator.RunAnimation(std::chrono::milliseconds(millis() - accurateTimer));
|
||||||
|
accurateTimer = millis();
|
||||||
boardManager.Update();
|
boardManager.Update();
|
||||||
|
|
||||||
boardStateTimer += updateTickRate;
|
boardStateTimer += updateTickRate;
|
||||||
@@ -185,6 +196,8 @@ void setup() {
|
|||||||
|
|
||||||
Serial.println("Beginning Board Initializaiton");
|
Serial.println("Beginning Board Initializaiton");
|
||||||
boardManager.Init();
|
boardManager.Init();
|
||||||
|
animator.SetLoop(true);
|
||||||
|
animator.StartAnimation(&(TestFrames::testAnimationSequence2));
|
||||||
xTaskCreate(UpdateBoard, "UpdateBoard", 10000, NULL, 0, &updateBoardTask);
|
xTaskCreate(UpdateBoard, "UpdateBoard", 10000, NULL, 0, &updateBoardTask);
|
||||||
|
|
||||||
Serial.println("Setup Complete");
|
Serial.println("Setup Complete");
|
||||||
|
|||||||
Reference in New Issue
Block a user