this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Updated circle angle coefficient and added a check to fix issues with small radius circles not having enough segments to complete the shape. Thanks GiovanniCmpaner for the report!

authored by

Jonathan Dearborn and committed by
Alice
b9ea2a13 107c122c

+108 -86
+33 -15
src/renderer_shapes_GL_common.inl
··· 76 76 77 77 78 78 79 + #define SDL_GPU_CIRCLE_SEGMENT_ANGLE_FACTOR 0.625f 80 + 81 + 82 + #define CALCULATE_CIRCLE_DT_AND_SEGMENTS(radius) \ 83 + dt = SDL_GPU_CIRCLE_SEGMENT_ANGLE_FACTOR/sqrtf(radius); /* s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good */ \ 84 + numSegments = (int)(2*PI/dt) + 1; \ 85 + \ 86 + if(numSegments < 16) \ 87 + { \ 88 + numSegments = 16; \ 89 + dt = 2*PI/(numSegments-1); \ 90 + } 79 91 80 92 81 93 static float SetLineThickness(GPU_Renderer* renderer, float thickness) ··· 178 190 } 179 191 180 192 181 - dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(outer_radius)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 193 + dt = ((end_angle - start_angle)/360)*(SDL_GPU_CIRCLE_SEGMENT_ANGLE_FACTOR/sqrtf(outer_radius)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 182 194 183 195 numSegments = (int)((fabs(end_angle - start_angle)*PI/180)/dt); 184 196 if(numSegments == 0) ··· 255 267 end_angle -= 360; 256 268 } 257 269 258 - dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(radius)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 270 + dt = ((end_angle - start_angle)/360)*(SDL_GPU_CIRCLE_SEGMENT_ANGLE_FACTOR/sqrtf(radius)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 259 271 260 272 numSegments = (int)((fabs(end_angle - start_angle)*RAD_PER_DEG)/dt); 261 273 if(numSegments == 0) ··· 314 326 float t = thickness/2; 315 327 float inner_radius = radius - t; 316 328 float outer_radius = radius + t; 317 - float dt = (1.25f/sqrtf(outer_radius)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 318 - int numSegments = (int)(2*PI/dt)+1; 329 + float dt; 330 + int numSegments; 331 + 332 + CALCULATE_CIRCLE_DT_AND_SEGMENTS(outer_radius); 319 333 320 334 float tempx; 321 335 float c = cosf(dt); ··· 345 359 346 360 static void CircleFilled(GPU_Renderer* renderer, GPU_Target* target, float x, float y, float radius, SDL_Color color) 347 361 { 348 - float dt = (1.25f/sqrtf(radius)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 362 + float dt; 349 363 float dx, dy; 350 - int numSegments = (int)(2*PI/dt)+1; 364 + int numSegments; 351 365 int i; 366 + 367 + CALCULATE_CIRCLE_DT_AND_SEGMENTS(radius); 352 368 353 369 float tempx; 354 370 float c = cosf(dt); ··· 395 411 float outer_radius_x = rx + t; 396 412 float inner_radius_y = ry - t; 397 413 float outer_radius_y = ry + t; 398 - float dt = (1.25f/sqrtf(outer_radius_x > outer_radius_y? outer_radius_x : outer_radius_y)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 399 - int numSegments = (int)(2*M_PI/dt)+1; 414 + float dt; 415 + int numSegments; 416 + 417 + CALCULATE_CIRCLE_DT_AND_SEGMENTS(outer_radius_x > outer_radius_y? outer_radius_x : outer_radius_y); 400 418 401 419 float tempx; 402 420 float c = cosf(dt); ··· 442 460 int i; 443 461 float rot_x = cosf(degrees*RAD_PER_DEG); 444 462 float rot_y = sinf(degrees*RAD_PER_DEG); 445 - float dt = (1.25f/sqrtf(rx > ry? rx : ry)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 446 - int numSegments = (int)(2*M_PI/dt)+1; 463 + float dt; 464 + int numSegments; 465 + CALCULATE_CIRCLE_DT_AND_SEGMENTS(rx > ry? rx : ry); 447 466 448 467 float tempx; 449 468 float c = cosf(dt); ··· 586 605 587 606 588 607 t = start_angle; 589 - dt = ((end_angle - start_angle)/360)*(1.25f/sqrtf(outer_radius)) * DEG_PER_RAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 608 + dt = ((end_angle - start_angle)/360)*(SDL_GPU_CIRCLE_SEGMENT_ANGLE_FACTOR/sqrtf(outer_radius)) * DEG_PER_RAD; // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 590 609 591 610 numSegments = (int)(fabs(end_angle - start_angle)/dt); 592 611 if(numSegments == 0) ··· 808 827 float t = thickness/2; 809 828 float inner_radius = radius - t; 810 829 float outer_radius = radius + t; 811 - float dt = (1.25f/sqrtf(outer_radius)); // s = rA, so dA = ds/r. ds of 1.25*sqrt(radius) is good, use A in degrees. 812 - int numSegments = (int)(2*PI/dt)+1; 813 - if(numSegments < 4) 814 - numSegments = 4; 830 + float dt; 831 + int numSegments; 832 + CALCULATE_CIRCLE_DT_AND_SEGMENTS(outer_radius); 815 833 816 834 // Make a multiple of 4 so we can have even corners 817 835 numSegments += numSegments % 4;
+75 -71
tests/shapes/main.c
··· 9 9 #define M_PI 3.14159f 10 10 #endif 11 11 12 + #define RANDOMIZE_SHAPE_DATA() \ 13 + for(i = 0; i < NUM_COLORS; i++) \ 14 + { \ 15 + colors[i].r = rand() % 256; \ 16 + colors[i].g = rand() % 256; \ 17 + colors[i].b = rand() % 256; \ 18 + GET_ALPHA(colors[i]) = rand() % 256; \ 19 + } \ 20 + \ 21 + for (i = 0; i < NUM_PIXELS; i++) \ 22 + { \ 23 + px[i] = rand() % screen->w; \ 24 + py[i] = rand() % screen->h; \ 25 + } \ 26 + \ 27 + for (i = 0; i < NUM_LINES; i++) \ 28 + { \ 29 + lx1[i] = rand() % screen->w; \ 30 + ly1[i] = rand() % screen->h; \ 31 + lx2[i] = rand() % screen->w; \ 32 + ly2[i] = rand() % screen->h; \ 33 + } \ 34 + \ 35 + for (i = 0; i < NUM_TRIS; i++) \ 36 + { \ 37 + tx1[i] = rand() % screen->w; \ 38 + ty1[i] = rand() % screen->h; \ 39 + tx2[i] = rand() % screen->w; \ 40 + ty2[i] = rand() % screen->h; \ 41 + tx3[i] = rand() % screen->w; \ 42 + ty3[i] = rand() % screen->h; \ 43 + } \ 44 + \ 45 + for (i = 0; i < NUM_RECTS; i++) \ 46 + { \ 47 + rx1[i] = rand() % screen->w; \ 48 + ry1[i] = rand() % screen->h; \ 49 + rx2[i] = rand() % screen->w; \ 50 + ry2[i] = rand() % screen->h; \ 51 + rr[i] = rand() % 10 + 2; \ 52 + } \ 53 + \ 54 + for (i = 0; i < NUM_ARCS; i++) \ 55 + { \ 56 + ax[i] = rand() % screen->w; \ 57 + ay[i] = rand() % screen->h; \ 58 + ar[i] = (rand() % screen->h) / 10.0f; \ 59 + ar2[i] = ((rand() % 101) / 100.0f) * ar[i]; \ 60 + aa1[i] = rand() % 360; \ 61 + aa2[i] = rand() % 360; \ 62 + } \ 63 + \ 64 + for (i = 0; i < NUM_POLYS; i++) \ 65 + { \ 66 + float cx = rand() % screen->w; \ 67 + float cy = rand() % screen->h; \ 68 + float radius = 20 + rand() % (screen->w / 8); \ 69 + \ 70 + int j; \ 71 + \ 72 + pn[i] = rand() % 8 + 3; \ 73 + pv[i] = (float*)malloc(2 * pn[i] * sizeof(float)); \ 74 + \ 75 + for (j = 0; j < pn[i] * 2; j += 2) \ 76 + { \ 77 + pv[i][j] = cx + radius * cos(2 * M_PI * (((float)j) / (pn[i] * 2))) + rand() % ((int)radius / 2); \ 78 + pv[i][j + 1] = cy + radius * sin(2 * M_PI * (((float)j) / (pn[i] * 2))) + rand() % ((int)radius / 2); \ 79 + } \ 80 + } 81 + 12 82 int main(int argc, char* argv[]) 13 83 { 14 84 GPU_Target* screen; ··· 79 149 shapeType = 0; 80 150 numShapeTypes = 18; 81 151 82 - for(i = 0; i < NUM_COLORS; i++) 83 - { 84 - colors[i].r = rand()%256; 85 - colors[i].g = rand()%256; 86 - colors[i].b = rand()%256; 87 - GET_ALPHA(colors[i]) = rand()%256; 88 - } 89 - 90 - 91 - 92 - for(i = 0; i < NUM_PIXELS; i++) 93 - { 94 - px[i] = rand()%screen->w; 95 - py[i] = rand()%screen->h; 96 - } 97 - 98 - for(i = 0; i < NUM_LINES; i++) 99 - { 100 - lx1[i] = rand()%screen->w; 101 - ly1[i] = rand()%screen->h; 102 - lx2[i] = rand()%screen->w; 103 - ly2[i] = rand()%screen->h; 104 - } 105 - 106 - for(i = 0; i < NUM_TRIS; i++) 107 - { 108 - tx1[i] = rand()%screen->w; 109 - ty1[i] = rand()%screen->h; 110 - tx2[i] = rand()%screen->w; 111 - ty2[i] = rand()%screen->h; 112 - tx3[i] = rand()%screen->w; 113 - ty3[i] = rand()%screen->h; 114 - } 115 - 116 - 117 - for(i = 0; i < NUM_RECTS; i++) 118 - { 119 - rx1[i] = rand()%screen->w; 120 - ry1[i] = rand()%screen->h; 121 - rx2[i] = rand()%screen->w; 122 - ry2[i] = rand()%screen->h; 123 - rr[i] = rand()%10 + 2; 124 - } 125 - 126 - for(i = 0; i < NUM_ARCS; i++) 127 - { 128 - ax[i] = rand()%screen->w; 129 - ay[i] = rand()%screen->h; 130 - ar[i] = (rand()%screen->h)/10.0f; 131 - ar2[i] = ((rand()%101)/100.0f)*ar[i]; 132 - aa1[i] = rand()%360; 133 - aa2[i] = rand()%360; 134 - } 135 - 136 - for(i = 0; i < NUM_POLYS; i++) 137 - { 138 - float cx = rand()%screen->w; 139 - float cy = rand()%screen->h; 140 - float radius = 20 + rand()%(screen->w/8); 141 - 142 - int j; 143 - 144 - pn[i] = rand()%8 + 3; 145 - pv[i] = (float*)malloc(2*pn[i]*sizeof(float)); 146 - 147 - for(j = 0; j < pn[i]*2; j+=2) 148 - { 149 - pv[i][j] = cx + radius*cos(2*M_PI*(((float)j)/(pn[i]*2))) + rand()%((int)radius/2); 150 - pv[i][j+1] = cy + radius*sin(2*M_PI*(((float)j)/(pn[i]*2))) + rand()%((int)radius/2); 151 - } 152 - } 152 + RANDOMIZE_SHAPE_DATA(); 153 153 154 154 blend = 0; 155 155 thickness = 1.0f; ··· 183 183 { 184 184 blend = !blend; 185 185 GPU_SetShapeBlending(blend); 186 + } 187 + else if(event.key.keysym.sym == SDLK_RETURN) 188 + { 189 + RANDOMIZE_SHAPE_DATA(); 186 190 } 187 191 else if(event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_EQUALS) 188 192 {