|
|
|
|
@ -175,15 +175,40 @@ updateHexConeFill(int32 x, int32 y)
|
|
|
|
|
if (hxi && (hxi != g_game_state->current_hex) && g_game_state->start_hex) |
|
|
|
|
{ |
|
|
|
|
g_game_state->current_hex = hxi; |
|
|
|
|
vector<Hex> hexes = hex_conefill(g_game_state->start_hex->hex, hxi->hex); |
|
|
|
|
|
|
|
|
|
// TODO: Remove debug code here and from gooey.h
|
|
|
|
|
Point p1(g_game_state->start_hex->XPos, g_game_state->start_hex->YPos); |
|
|
|
|
Point p2(g_game_state->current_hex->XPos, g_game_state->current_hex->YPos); |
|
|
|
|
real64 angle = std::atan2(p2.y - p1.y, p2.x - p1.x); |
|
|
|
|
real64 len = std::hypot(p2.y - p1.y, p2.x - p1.x); |
|
|
|
|
real64 coneAngle = 30.f * M_PI / 180; // M_PI is non-standard and may not be portable
|
|
|
|
|
|
|
|
|
|
real64 x1 = len * std::cos(angle); |
|
|
|
|
real64 y1 = len * std::sin(angle); |
|
|
|
|
// top of cone
|
|
|
|
|
real64 topX = x1 * std::cos(coneAngle) - y1 * std::sin(coneAngle) + p1.x; |
|
|
|
|
real64 topY = x1 * std::sin(coneAngle) + y1 * std::cos(coneAngle) + p1.y; |
|
|
|
|
// bottom of cone
|
|
|
|
|
real64 botX = x1 * std::cos(coneAngle) + y1 * std::sin(coneAngle) + p1.x; |
|
|
|
|
real64 botY = x1 * std::sin(-1 * coneAngle) + y1 * std::cos(coneAngle) + p1.y; |
|
|
|
|
|
|
|
|
|
hex_info* topHex = getSingleHex(topX, topY); |
|
|
|
|
hex_info* botHex = getSingleHex(botX, botY); |
|
|
|
|
|
|
|
|
|
if (topHex && botHex) |
|
|
|
|
{ |
|
|
|
|
Point test_p; |
|
|
|
|
Point vert2 = Point(botHex->XPos, botHex->YPos); |
|
|
|
|
Point vert4 = Point(topHex->XPos, topHex->YPos); |
|
|
|
|
std::vector<Point> vertices = {p1, vert2, p2, vert4}; |
|
|
|
|
|
|
|
|
|
for (hex_info &h : *g_game_state->hex_array) |
|
|
|
|
{ |
|
|
|
|
// TODO: define a system of linear inequalities in hex-space to represent
|
|
|
|
|
// cones/arbitrary polygons
|
|
|
|
|
if (&h == g_game_state->start_hex) |
|
|
|
|
continue; |
|
|
|
|
test_p.x = h.XPos; |
|
|
|
|
test_p.y = h.YPos; |
|
|
|
|
|
|
|
|
|
if (hex_equal(h.hex, hxi->hex)) |
|
|
|
|
if (crossingTest(vertices, test_p)) |
|
|
|
|
{ |
|
|
|
|
h.selected = true; |
|
|
|
|
h.current_color = g_render_state->selected_fill_color; |
|
|
|
|
@ -195,6 +220,7 @@ updateHexConeFill(int32 x, int32 y)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
@ -385,7 +411,7 @@ int main(int argc, char* argv[])
|
|
|
|
|
g_game_state->is_selecting = false; |
|
|
|
|
g_game_state->start_hex = 0x0; |
|
|
|
|
g_game_state->current_hex = 0x0; |
|
|
|
|
g_game_state->draw_mode = LINE; |
|
|
|
|
g_game_state->draw_mode = CONE_FILL; |
|
|
|
|
|
|
|
|
|
// init global render state
|
|
|
|
|
g_render_state = new render_state(); |
|
|
|
|
|