Having a problem with a rotation angle wrapping

So I need to get an angle to wrap around. I also need to have 4 directions so that my game updates the graphics displayed in a logical way. I have an angle of movement that is supposed to go from 0 to 90 and stop. I also notice when I try to do this in code I get a flash of some other frame.

I am working with some code that did work before I tried this.

This is the relevant code:

if (mosig == mleft || mosig == mright) {
			movement += deltaTime * 45;

			if (movement >= 90) {
				mosig = stopped;
				if (mosig == mleft) {
					direction = (direction + 3) % 4;
				}
				else {
					direction = (direction + 1) % 4;
				}
				movement = 0;
			}
			if (mosig == mleft) {
				iyaw -= movement;
			}
			else {
				iyaw += movement;
			}
		}
		iyaw = fmod(iyaw, 360);
		
		fpsCamera.mYaw = glm::radians(iyaw);
		fpsCamera.updateCameraVectors();

I solved it.

this is the code:

if (mosig == mleft || mosig == mright) {
			movement += deltaTime * 45;

			if (movement >= 90) {
				
				
				direction = int(iyaw / 90 + .5) % 4;
				iyaw = direction * 90;
				

				mosig = stopped;
				movement = 0;
			}
			else {
				if (mosig == mleft) {
					iyaw -= deltaTime * 45;
				}
				else {
					iyaw += deltaTime * 45;
				}
			}
		}
		if (iyaw < 0) iyaw = 360 - iyaw;
		if (iyaw > 360) iyaw = iyaw - 360;```

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.