-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsf_utilities.c
More file actions
46 lines (41 loc) · 1.31 KB
/
sf_utilities.c
File metadata and controls
46 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
** EPITECH PROJECT, 2024
** B-MUL-100-LYN-1-1-myradar-aurelien.demeusy
** File description:
** sf_utilities.c
*/
#include <SFML/Graphics.h>
#include <SFML/Window.h>
#include <SFML/Audio.h>
#include "include/structs.h"
#include "include/my.h"
#include <math.h>
sfBool my_intersect(sfFloatRect *rec1, sfFloatRect *rec2)
{
float left = fmax(rec1->left, rec2->left);
float top = fmax(rec1->top, rec2->top);
float right = fmin(rec1->left + rec1->width, rec2->left + rec2->width);
float bottom = fmin(rec1->top + rec1->height, rec2->top + rec2->height);
if (!rec1 || !rec2)
return sfFalse;
if (left < right && top < bottom)
return sfTrue;
return sfFalse;
}
sfFloatRect my_sfsprite_getglobalbounds(const sfRectangleShape *sprite)
{
const sfTexture *texture = sfRectangleShape_getTexture(sprite);
sfVector2u texture_size = sfTexture_getSize(texture);
sfVector2f scale = sfRectangleShape_getScale(sprite);
sfVector2f position = sfRectangleShape_getPosition(sprite);
sfFloatRect bounds;
if (!sprite)
return (sfFloatRect){0, 0, 0, 0};
if (!texture)
return (sfFloatRect){0, 0, 0, 0};
bounds.left = position.x;
bounds.top = position.y;
bounds.width = texture_size.x * scale.x;
bounds.height = texture_size.y * scale.y;
return bounds;
}