Skip to content

Commit 0cce1bd

Browse files
committed
testposition: SDL3 mouse coordinates are floats, not ints.
1 parent 6daf005 commit 0cce1bd

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tests/testposition.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ static ALenum get_openal_format(const SDL_AudioSpec *spec)
5959
typedef struct
6060
{
6161
ALuint sid;
62-
int x;
63-
int y;
62+
float x;
63+
float y;
6464
} obj;
6565

6666
/* !!! FIXME: eventually, add more sources and sounds. */
6767
static obj objects[2]; /* one listener, one source. */
6868
static int draggingobj = -1;
6969

70-
static int obj_under_mouse(const int x, const int y)
70+
static int obj_under_mouse(const float x, const float y)
7171
{
72-
const SDL_Point p = { x, y };
72+
const SDL_FPoint p = { x, y };
7373
const obj *o = objects;
7474
int i;
7575
for (i = 0; i < SDL_arraysize(objects); i++, o++) {
76-
const SDL_Rect r = { o->x - 25, o->y - 25, 50, 50 };
77-
if (SDL_PointInRect(&p, &r)) {
76+
const SDL_FRect r = { o->x - 25.0f, o->y - 25.0f, 50.0f, 50.0f };
77+
if (SDL_PointInRectFloat(&p, &r)) {
7878
return i;
7979
}
8080
}
@@ -113,8 +113,8 @@ static int mainloop(SDL_Renderer *renderer)
113113
case SDL_EVENT_MOUSE_MOTION:
114114
if (draggingobj != -1) {
115115
obj *o = &objects[draggingobj];
116-
o->x = SDL_min(800, SDL_max(0, e.motion.x));
117-
o->y = SDL_min(600, SDL_max(0, e.motion.y));
116+
o->x = SDL_min(800.0f, SDL_max(0.0f, e.motion.x));
117+
o->y = SDL_min(600.0f, SDL_max(0.0f, e.motion.y));
118118
/* we are treating the 2D view as the X and Z coordinate, as if we're looking at it from above.
119119
From this configuration, the Y coordinate would be depth, and we leave that at zero.
120120
the listener's default "at" orientation is towards the north in this configuration, with its
@@ -214,14 +214,14 @@ static void spatialize(SDL_Renderer *renderer, const char *fname)
214214

215215
/* the listener. */
216216
o->sid = 0;
217-
o->x = 400;
218-
o->y = 300;
217+
o->x = 400.0f;
218+
o->y = 300.0f;
219219
alListener3f(AL_POSITION, ((o->x / 400.0f) - 1.0f) * 10.0f, 0.0f, ((o->y / 300.0f) - 1.0f) * 10.0f);
220220
o++;
221221

222222
o->sid = sid;
223-
o->x = 400;
224-
o->y = 50;
223+
o->x = 400.0f;
224+
o->y = 50.0f;
225225
alSource3f(o->sid, AL_POSITION, ((o->x / 400.0f) - 1.0f) * 10.0f, 0.0f, ((o->y / 300.0f) - 1.0f) * 10.0f);
226226
o++;
227227

0 commit comments

Comments
 (0)