Camera Flickering when rotating alot?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
nomis
Posts: 14
Joined: Wed May 09, 2007 5:54 am

Camera Flickering when rotating alot?

Post 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.
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post 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.
If you don't have anything nice to say, don't say anything at all.
nomis
Posts: 14
Joined: Wed May 09, 2007 5:54 am

Post 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?
kompromis
Posts: 98
Joined: Mon Sep 11, 2006 2:36 pm
Location: sweden/stockholm

Post by kompromis »

cos and sin often use radiance
nano
Posts: 25
Joined: Mon May 07, 2007 1:12 pm

Post 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?
Post Reply