#do raylib draw properly

16 messages · Page 1 of 1 (latest)

sour stone
#

Hello so I just started with raylib (and cpp) and wanted to do something ,,easy" at first. Ive done some little more advanced staff in pythons pygame but here I have that problem with drawing these rectangles, because the offset between them is so unequal, i believe the math is right, (but even with different math its just unequal so its harder to say) So I would be gratefull if someone can tell me how to do it. I post the code here https://pastebin.com/tsA4QX5k . I belive there must be a proper way of doing it right, because I dont want to just jump to another project or quit either...

hollow jewel
#

you use float numbers, it can cause sometimes less precision because of how the numbers are encoded in binary, maybe try using double (I didn't really dig that much into your code, but it is a frequent problem)

analog prism
#

No, do not use a double

#

The gpu works in floats

#

Your math is most likely off

#

I don’t have time to look at the full code, but I can say for certain that using floats are fine

sour stone
#

so the float for small rec width is (board1_width-11.0f)/10.0f as board1 is the blue rectangle, 11 is for the 11 spaces between the smaller recs, and divide by 10 for 10 rectangles...
pos x for small rectangle is (board1_posx+1)+small_rec_len * i+1 * i , starting from second pixel on x axis and adding small rectangles width and 1 px offsets,

analog prism
#

You math doesn’t look right

#

Why add one?

sour stone
#

1 * i so basically 1 px offset after the one before

analog prism
#
    for (unsigned int y = 0; y < HEIGHT; y += TILE_SIZE) {
        for (unsigned int x = 0; x < WIDTH; x += TILE_SIZE) {
            DrawRectangleLines(x, y, TILE_SIZE, TILE_SIZE, BLACK);
        }
    }

this is how i've drawn grids before

analog prism
sour stone
#

if i do just board1x + small_recs * i the next one will start where the one before ends

#

if i deleted the + i it looks kind like the one on the right (see pic)

sour stone
#

i tried similar aproach as you and: with for example this
int x = 0;
for(int n = 1; x < 10; n+= small_rec_len+1){
float posx = n+board1_posx;
float posy = board1_posy+1;
float width = small_rec_len;
float height = small_rec_height;
player1_rectangles.push_back(Rectangle{posx, posy, width, height});
x++;

i had some space after the last one so i used in the loop float n and n+= small_rec_len+(board1_width-small_rec_len*10)/10)
to calculate the even space but what it gaves was again that unequal offset between them

sour stone
#

do raylib draw properly