Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

163 wiersze
4.0KB

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