Page 1 of 1

Camera Flickering when rotating alot?

Posted: Wed May 09, 2007 3:23 pm
by nomis
Hi guys,

I'm rotating the camera around my object but the screen keeps flickering a bit, it's hard to describe but it's like it is trying to refresh too often..
I have tried slowing it down aswell as limiting the number of positions on the rotation but it still happens.

here's the code:

Code: Select all

		// get vectors
		core::vector3df cp = camera->getPosition();
		core::vector3df cr = camera->getRotation();
		core::vector3df bp = bananaNode->getPosition();
		core::vector3df br = bananaNode->getRotation();

		// THEN ROTATE AROUND THE BANANA RISING UP.
		if (loopme <= 95)
		{
			time_now = (double)clock()/(double)CLOCKS_PER_SEC;

			if (time_now - time_last > 0.025)
			{
					cp.X = (bp.X + cos(loopme/10)*75);
					cp.Z = (bp.Z + sin(loopme/10)*75);
				
					camera->setPosition(cp);
					camera->setTarget(bp);

					printf("CAMSWIVEL: %d x %lf  z %lf\n", loopme, cp.X, cp.Z);
					
				time_last = (double)clock()/(double)CLOCKS_PER_SEC;	
				loopme++;
			}
		}
Any help would be greatly appreciated :D

Nomis.

Posted: Wed May 09, 2007 5:42 pm
by Luben
sin and cos take radians as parameters. 360 normal degrees is equal to 2*PI in radians.
loopme seems not to be a floating point variable, so while loopme is below 10, the parameter passed to cos and sin will be 0. Then, as fast as loopme goes above 10, 1 will be passed until you reach 20.
1 radian equals 57 degrees, so you've got a major jump there.

I'd make loopme a float, or at least divide with 10.f instead of 10, as that would produce a float insted of an integer(If i'm not mistaken). That way you make the steps smaller. I'd also multiply with (PI/180.f) to convert the degrees to radians. Irrlicht provides a const f32 called DEGTORAD which you can multiply with.

Posted: Fri May 11, 2007 10:38 am
by nomis
Alright I've narrowed it down to the setTarget which is causing the flickering, if i comment it out it runs smooth as a baby's bottom.

Code: Select all

camera->setTarget(bp);
Any ideas how to optimise it?

Posted: Fri May 11, 2007 12:49 pm
by kompromis
cos and sin often use radiance

Posted: Wed May 16, 2007 2:00 pm
by nano
nomis wrote:Alright I've narrowed it down to the setTarget which is causing the flickering, if i comment it out it runs smooth as a baby's bottom.

Code: Select all

camera->setTarget(bp);
Any ideas how to optimise it?
I'm also interested in this code as i'm trying to do something similar but it appears that the setTarget in the loop makes it flicker a lot.

I've tried setting the target at greater intervals but then the animation just looks choppy and the flicker still occurs.

Anyone have any idea how to fix this?