Proof reading some logic

Greetings. Having some trouble with a camera object when determining when to stop. Would you please proof read this snippet for any logical errors?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SDL_GetMouseState(&mosPos[0], &mosPos[1]);
			if (mosPos[0] >= 750 )
				motion[1] = true;
			if (mosPos[0] <= 50)
				motion[3] = true;
			if (mosPos[1] >= 750)
				motion[2] = true;
			if (mosPos[1] <= 50)
				motion[0] = true;
			// in between
			if (mosPos[0] < 750)
				motion[1] = false;
			if (mosPos[0] > 50)
				motion[3] = false;
			if (mosPos[1] < 750)
				motion[2] = false;
			if (mosPos[1] > 50)
				motion[0] = false;
Your code could be written a bit more concisely like this
1
2
3
4
5
SDL_GetMouseState(&mosPos[0], &mosPos[1]);
motion[1] = (mosPos[0] >= 750);
motion[3] = (mosPos[0] <= 50);
motion[2] = (mosPos[1] >= 750);
motion[0] = (mosPos[1] <= 50);

In either case no obvious logic error in that. Maybe the problem is in what you do with motion[0] to [3] ?


SDL_GetMouseState(&mosPos[0], &mosPos[1]);
motion[1] = (mosPos[0] >= 750);
motion[3] = (mosPos[0] <= 50);
motion[2] = (mosPos[1] >= 750);
motion[0] = (mosPos[1] <= 50);



That looks nice.
Genius! the problem was that the mosPos wasn't updating quick enough. Now each time it hits a true motion[] it updates its position and now works as intended. Thanks again
Topic archived. No new replies allowed.