Corner.short_neighbours are now searched for based on the coordinates of the nodes.
This commit is contained in:
parent
2715d5aa6a
commit
40efeee436
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
// Delta-X data. Per direction of a triangle is a triple with Delta-X values for each direction.
|
// Delta-X data. Per direction of a triangle is a triple with Delta-X values for each direction.
|
||||||
static const int8_t dx[][3] = {{0, 1, -1}, {1, 0, -1}, {1, -1, 0}, {0, -1, 1}, {-1, 0, 1}, {-1, 1, 0}};
|
static const int8_t dx[][3] = {{0, 1, -1}, {1, 0, -1}, {1, -1, 0}, {0, -1, 1}, {-1, 0, 1}, {-1, 1, 0}};
|
||||||
static const int8_t dy[][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}, {1, 0, 0}, {0, -1, 0}, {0, 0, 1}};
|
static const int8_t dy[][3] = {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}, {1, 0, 0}, {0, -1, 0}, {0, 0, 1}};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t x;
|
int8_t x;
|
||||||
@ -15,10 +15,8 @@ typedef struct {
|
|||||||
} Coords;
|
} Coords;
|
||||||
|
|
||||||
class Node {
|
class Node {
|
||||||
private:
|
|
||||||
uint16_t _number;
|
|
||||||
Coords coords_at_direction(uint8_t edge);
|
|
||||||
public:
|
public:
|
||||||
|
uint16_t _number;
|
||||||
Coords coords;
|
Coords coords;
|
||||||
uint8_t direction;
|
uint8_t direction;
|
||||||
Node* neighbours[CORNERS_PER_PART];
|
Node* neighbours[CORNERS_PER_PART];
|
||||||
@ -26,6 +24,7 @@ class Node {
|
|||||||
Corner* _corners[CORNERS_PER_PART];
|
Corner* _corners[CORNERS_PER_PART];
|
||||||
Node(uint16_t number, Coords c, uint8_t direction);
|
Node(uint16_t number, Coords c, uint8_t direction);
|
||||||
Node* create_neighbour(uint8_t edge);
|
Node* create_neighbour(uint8_t edge);
|
||||||
|
Coords coords_at_direction(uint8_t edge);
|
||||||
|
|
||||||
void blend_to(CRGB color, uint16_t effect_id=0, uint8_t effect_speed=0);
|
void blend_to(CRGB color, uint16_t effect_id=0, uint8_t effect_speed=0);
|
||||||
void set_color(CRGB color);
|
void set_color(CRGB color);
|
||||||
|
39
src/main.cpp
39
src/main.cpp
@ -54,6 +54,45 @@ void setup_layout() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Node* n1 : nodes) {
|
||||||
|
LOGln("Looking for neighbours of node #%d @ %d,%d", n1->_number, n1->coords.x, n1->coords.y);
|
||||||
|
for(int edge=0; edge<CORNERS_PER_PART; edge++) {
|
||||||
|
Coords c = n1->coords_at_direction(edge);
|
||||||
|
LOGln(" Chcking edge %d @ %d,%d...", edge, c.x, c.y);
|
||||||
|
|
||||||
|
Node* found = nullptr;
|
||||||
|
for(Node* n2 : nodes) {
|
||||||
|
if (n2 == n1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (n2->coords.x == c.x && n2->coords.y == c.y) {
|
||||||
|
found = n2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found != nullptr) {
|
||||||
|
LOGln(" Found node #%d", found->_number);
|
||||||
|
uint8_t inverse_dir = (n1->direction + 2*edge + 3) % 6;
|
||||||
|
int8_t e = (inverse_dir - found->direction) % 6;
|
||||||
|
if (e < 0) e+=6;
|
||||||
|
e = e / 2;
|
||||||
|
//LOGln(" inverse_dir: %d, edge: %d", inverse_dir, edge);
|
||||||
|
int8_t e1 = (edge - 1) % CORNERS_PER_PART;
|
||||||
|
if (e1<0) e1+=CORNERS_PER_PART;
|
||||||
|
int8_t e2 = (e - 1) % CORNERS_PER_PART;
|
||||||
|
if (e2<0) e2+=CORNERS_PER_PART;
|
||||||
|
|
||||||
|
LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, edge, found->_number, e2);
|
||||||
|
n1->_corners[edge]->_short_neighbours.push_back(found->_corners[e]);
|
||||||
|
|
||||||
|
LOGln(" Mapping Corner #%d,%d with #%d,%d", n1->_number, e1, found->_number, e);
|
||||||
|
n1->_corners[e1]->_short_neighbours.push_back(found->_corners[e2]);
|
||||||
|
} else {
|
||||||
|
LOGln(" No match.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(Corner* corner: corners) {
|
for(Corner* corner: corners) {
|
||||||
LOGln("Corner %p:", corner);
|
LOGln("Corner %p:", corner);
|
||||||
for(auto c: corner->_long_neighbours) {
|
for(auto c: corner->_long_neighbours) {
|
||||||
|
@ -45,11 +45,6 @@ Node* Node::create_neighbour(uint8_t edge) {
|
|||||||
node->edges[0]->neighbour = this->edges[edge];
|
node->edges[0]->neighbour = this->edges[edge];
|
||||||
this->edges[edge]->neighbour = node->edges[0];
|
this->edges[edge]->neighbour = node->edges[0];
|
||||||
|
|
||||||
node->_corners[0]->_short_neighbours.push_back(_corners[(edge-1) % CORNERS_PER_PART]);
|
|
||||||
node->_corners[CORNERS_PER_PART - 1]->_short_neighbours.push_back(_corners[edge]);
|
|
||||||
_corners[(edge-1) % CORNERS_PER_PART]->_short_neighbours.push_back(node->_corners[0]);
|
|
||||||
_corners[edge]->_short_neighbours.push_back(node->_corners[CORNERS_PER_PART - 1]);
|
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user