Drawing wall splines
This commit is contained in:
parent
09cc69d38d
commit
b217a72e6d
4 changed files with 27 additions and 29 deletions
|
|
@ -40,11 +40,15 @@ bool kubo_context_add_wall(struct kubo_context *context,
|
||||||
|
|
||||||
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context) {
|
struct kubo_wall *kubo_context_get_pending_wall(struct kubo_context *context) {
|
||||||
|
|
||||||
if (context->num_walls > 0 &&
|
if (context->num_walls > 0) {
|
||||||
(context->walls[context->num_walls - 1]->wall_state == KUBO_WALL_INIT ||
|
switch (context->walls[context->num_walls - 1]->state) {
|
||||||
context->walls[context->num_walls - 1]->wall_state ==
|
case KUBO_WALL_INIT:
|
||||||
KUBO_WALL_STARTED)) {
|
case KUBO_WALL_DRAWING:
|
||||||
return context->walls[context->num_walls - 1];
|
return context->walls[context->num_walls - 1];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct kubo_wall *wall = kubo_wall_init();
|
struct kubo_wall *wall = kubo_wall_init();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ struct kubo_wall *kubo_wall_init() {
|
||||||
|
|
||||||
wall->num_vertices_alloc = KUBO_WALL_INIT_VERTICES;
|
wall->num_vertices_alloc = KUBO_WALL_INIT_VERTICES;
|
||||||
wall->vertices = malloc(sizeof(Vector2) * wall->num_vertices_alloc);
|
wall->vertices = malloc(sizeof(Vector2) * wall->num_vertices_alloc);
|
||||||
|
wall->num_vertices = 0;
|
||||||
|
wall->state = KUBO_WALL_INIT;
|
||||||
|
|
||||||
return wall;
|
return wall;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
enum kubo_wall_state {
|
enum kubo_wall_state {
|
||||||
KUBO_WALL_INIT,
|
KUBO_WALL_INIT,
|
||||||
KUBO_WALL_STARTED,
|
KUBO_WALL_DRAWING,
|
||||||
KUBO_WALL_DONE
|
KUBO_WALL_DONE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ struct kubo_wall {
|
||||||
unsigned int num_vertices;
|
unsigned int num_vertices;
|
||||||
unsigned int num_vertices_alloc;
|
unsigned int num_vertices_alloc;
|
||||||
|
|
||||||
enum kubo_wall_state wall_state;
|
enum kubo_wall_state state;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kubo_wall *kubo_wall_init();
|
struct kubo_wall *kubo_wall_init();
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,15 @@ void kubo_window_render(struct kubo_context *context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < context->num_walls; i++) {
|
for (int i = 0; i < context->num_walls; i++) {
|
||||||
if (context->walls[i]->wall_state == KUBO_WALL_STARTED) {
|
|
||||||
Vector2 mouse_pos = GetMousePosition();
|
|
||||||
Vector2 points[] = {context->walls[i]->vertices[0], mouse_pos};
|
|
||||||
DrawSplineLinear(points, 2, 10.f, BLACK);
|
|
||||||
} else if (context->walls[i]->wall_state == KUBO_WALL_DONE) {
|
|
||||||
DrawSplineLinear(context->walls[i]->vertices,
|
DrawSplineLinear(context->walls[i]->vertices,
|
||||||
context->walls[i]->num_vertices, 10.f, BLACK);
|
context->walls[i]->num_vertices, 10.f, BLACK);
|
||||||
|
if (context->walls[i]->state == KUBO_WALL_STARTED) {
|
||||||
|
Vector2 mouse_pos = GetMousePosition();
|
||||||
|
Vector2 points[] = {
|
||||||
|
context->walls[i]
|
||||||
|
->vertices[context->walls[i]->num_vertices - 1],
|
||||||
|
mouse_pos};
|
||||||
|
DrawSplineLinear(points, 2, 10.f, BLACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,26 +51,16 @@ void kubo_window_render(struct kubo_context *context) {
|
||||||
|
|
||||||
void kubo_window_input(struct kubo_context *context) {
|
void kubo_window_input(struct kubo_context *context) {
|
||||||
if (IsKeyPressed(KEY_Q)) {
|
if (IsKeyPressed(KEY_Q)) {
|
||||||
printf("q\n");
|
|
||||||
context->exit_pending = true;
|
context->exit_pending = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
|
||||||
|
|
||||||
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
struct kubo_wall *current_wall = kubo_context_get_pending_wall(context);
|
||||||
|
|
||||||
if (current_wall->wall_state == KUBO_WALL_INIT) {
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) {
|
||||||
printf("new wall\n");
|
Vector2 new_pos = GetMousePosition();
|
||||||
Vector2 start_pos = GetMousePosition();
|
kubo_wall_append(current_wall, new_pos);
|
||||||
kubo_wall_append(current_wall, start_pos);
|
current_wall->state = KUBO_WALL_STARTED;
|
||||||
current_wall->wall_state = KUBO_WALL_STARTED;
|
} else if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) {
|
||||||
} else if (current_wall->wall_state == KUBO_WALL_STARTED) {
|
current_wall->state = KUBO_WALL_DONE;
|
||||||
printf("started wall\n");
|
|
||||||
Vector2 end_pos = GetMousePosition();
|
|
||||||
kubo_wall_append(current_wall, end_pos);
|
|
||||||
current_wall->wall_state = KUBO_WALL_DONE;
|
|
||||||
} else {
|
|
||||||
printf("neither?\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue