Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

185 строки
4.5KB

  1. #include "include/path.h"
  2. #define STEPMULTI_X (4)
  3. #define CHAR_OFFSET_X (40)
  4. #define STEPMULTI_Y (5)
  5. #define CHAR_OFFSET_Y (20)
  6. void pp(point_t *point)
  7. {
  8. printf("%i, %i\n", point->x, point->y);
  9. }
  10. void path_add(path_t *path, path_node_t *point){
  11. list_add(&path->start, &point->list);
  12. pp(&point->point);
  13. }
  14. void path_add_vec(path_t *node, point_t *point, path_modus_t modus){
  15. path_node_t* new_point_ptr = (path_node_t*) malloc(sizeof(path_node_t));
  16. new_point_ptr->point = *point;
  17. new_point_ptr->modus = modus;
  18. path_add(node, new_point_ptr);
  19. }
  20. void path_add_interpolated(path_t *path, point_t *point, path_modus_t modus)
  21. {
  22. if(modus == PATH_MOVE){
  23. path_add_vec(path,point,modus);
  24. return;
  25. }
  26. path_node_t* current_node = (path_node_t*)path->start.next;
  27. //printf("Current node @ ");
  28. //pp(&current_node->point);
  29. point_t point_diff = point_sub(point, &current_node->point);
  30. while(point_mag2(&point_diff) > 64 )
  31. {
  32. point_t interval = point_interval(&current_node->point, point);
  33. path_add_interpolated(path, &(interval), modus);
  34. current_node = (path_node_t*)path->start.next;
  35. point_diff = point_sub(point, &current_node->point);
  36. }
  37. path_add_vec(path, point, modus);
  38. }
  39. /*
  40. void path_add_rect(path_t *node, gbRect2 *rect){
  41. gbVec2 corner = rect->pos;
  42. path_add_vec(node, &corner, PATH_MOVE);
  43. corner.x = corner.x + rect->dim.x;
  44. path_add_vec(node, &corner, PATH_DRAW);
  45. gb_vec2_add(&corner, rect->pos, rect->dim);
  46. path_add_vec(node, &corner, PATH_DRAW);
  47. corner.x = corner.x - rect->dim.x;
  48. path_add_vec(node, &corner, PATH_DRAW);
  49. corner = rect->pos;
  50. path_add_vec(node, &corner, PATH_DRAW);
  51. }
  52. */
  53. void path_add_char(path_t *path, char character)
  54. {
  55. path_modus_t modus = PATH_MOVE;
  56. asteroids_char_t char_path = asteroids_font[(uint8_t)character - 0x20];
  57. for(int i = 0; i<8; i++)
  58. {
  59. uint8_t char_point = char_path.points[i];
  60. if (char_point == FONT_LAST){
  61. path->char_count++;
  62. return;
  63. }
  64. if (char_point == FONT_UP){
  65. modus = PATH_MOVE;
  66. continue;
  67. }
  68. point_t point = {
  69. .x = ((char_point >> 4) & 0xF) * STEPMULTI_X + CHAR_OFFSET_X * path->char_count,
  70. .y = ((char_point >> 0) & 0xF) * STEPMULTI_Y + CHAR_OFFSET_Y
  71. };
  72. path_add_interpolated(path, &point, modus);
  73. modus = PATH_DRAW;
  74. }
  75. path->char_count++;
  76. }
  77. void path_init(path_t *path)
  78. {
  79. path->current = path->start;
  80. path->char_count = 0;
  81. point_t origin = {.x = 0, .y = 0};
  82. path_add_vec(path, &origin, PATH_MOVE);
  83. }
  84. void path_reset(path_t *path)
  85. {
  86. path->current = path->start;
  87. }
  88. /*void path_add_circle(path_t *node, gbVec2 *point, float radius, uint8_t division)
  89. {
  90. }
  91. void path_add_arc(path_t *node, gbVec2 *point, float radius, float angle_start, float angle_end, uint8_t division)
  92. {
  93. }
  94. */
  95. void path_reverse(path_t *node){
  96. if (node->start.next == 0x0)
  97. {
  98. return;
  99. }
  100. list_node_t* curr_node = node->start.next;
  101. list_node_t* next_node = NULL;
  102. list_node_t* prev_node = NULL;
  103. while(curr_node){
  104. next_node = curr_node->next;
  105. curr_node->next = prev_node;
  106. prev_node = curr_node;
  107. curr_node = next_node;
  108. }
  109. node->start.next = prev_node;
  110. }
  111. void path_increment(path_t *path)
  112. {
  113. if (path->current.next != NULL){
  114. path_node_t* point = path_next_point(path);
  115. path->current = point->list;
  116. }
  117. }
  118. path_node_t* path_next_point(path_t *path)
  119. {
  120. return (path_node_t*) path->current.next;
  121. }
  122. path_node_t* path_next(path_node_t *point){
  123. return (path_node_t*) point->list.next;
  124. }
  125. path_node_t* path_pop(path_node_t *point){
  126. return (path_node_t*) list_remove_head(&point->list);
  127. }
  128. /*gbVec2 path_next_setpoint(path_t *path, gbVec2 *current_position, float distance){
  129. gbVec2 position_error;
  130. gb_vec2_sub(&position_error, control->setpoint, current_position);
  131. float error_magnitude = gb_vec2_mag(&position_error);
  132. }*/
  133. point_t point_sub(point_t *a, point_t *b)
  134. {
  135. point_t point = {
  136. .x = a->x - b->x,
  137. .y = a->y - b->y
  138. };
  139. return point;
  140. }
  141. point_t point_add(point_t *a, point_t *b)
  142. {
  143. point_t point = {
  144. .x = a->x + b->x,
  145. .y = a->y + b->y
  146. };
  147. return point;
  148. }
  149. point_t point_interval(point_t *a, point_t*b)
  150. {
  151. point_t point = {
  152. .x = a->x + (b->x - a->x)/2,
  153. .y = a->y + (b->y - a->y)/2
  154. };
  155. return point;
  156. }
  157. int16_t point_mag2(point_t *a)
  158. {
  159. return a->x * a->x + a->y * a->y;
  160. }