Page 1 of 1

How to do camera zooming?

Posted: Sat Jan 22, 2011 8:48 am
by wsw1231

Code: Select all

case EMIE_MOUSE_WHEEL:
					{						
						if (event.MouseInput.Wheel == -1.0f)
							camFOV+=0.1f;
						else if (event.MouseInput.Wheel == 1.0f)
							camFOV-=0.1f;

						camera->setFOV(camFOV);
					} break;
I have used the above code to handle the camera zooming but something weird will happen.

If I wheel up/down too much, the nodes in the scene will be distorted and inverted.

How can I prevent this from happening?

Posted: Sat Jan 22, 2011 11:30 am
by kazymjir
I not programmer Irrlicht for long time,
but I can guess that can be something with 0.1 value.

Check this code:
http://ideone.com/d7APU

PC processor have troubles with computing values such as 0.1.
MATLAB can without problem compute those values without problem, but C++ can't without additional math libraries.

I am not sure, but this can be your problem.

Re: How to do camera zooming?

Posted: Sat Jan 22, 2011 12:30 pm
by Seven
wsw1231 wrote:

Code: Select all

case EMIE_MOUSE_WHEEL:
{						
      if (event.MouseInput.Wheel == -1.0f)  camFOV+=0.1f;
      else if (event.MouseInput.Wheel == 1.0f) camFOV-=0.1f;
 
      // clip the value
      #define maxFOV 10.0f
      #define minFOV 1.0f
      if (camFOV < minFOV) camFOV = minFOV;
      if (camFOV > maxFOV) camFOV = maxFOV;
     
      camera->setFOV(camFOV);
} break;
I have used the above code to handle the camera zooming but something weird will happen.

If I wheel up/down too much, the nodes in the scene will be distorted and inverted.

How can I prevent this from happening?
maybe just set up a min and a max value?

Posted: Sat Jan 22, 2011 12:48 pm
by polylux
I'll let that guy do the explanation -> :roll:
Oh, and then I'd go with Seven's reply.

Re: How to do camera zooming?

Posted: Sat Jan 22, 2011 1:05 pm
by wsw1231
Seven wrote:
wsw1231 wrote:

Code: Select all

case EMIE_MOUSE_WHEEL:
{						
      if (event.MouseInput.Wheel == -1.0f)  camFOV+=0.1f;
      else if (event.MouseInput.Wheel == 1.0f) camFOV-=0.1f;
 
      // clip the value
      #define maxFOV 10.0f
      #define minFOV 1.0f
      if (camFOV < minFOV) camFOV = minFOV;
      if (camFOV > maxFOV) camFOV = maxFOV;
     
      camera->setFOV(camFOV);
} break;
I have used the above code to handle the camera zooming but something weird will happen.

If I wheel up/down too much, the nodes in the scene will be distorted and inverted.

How can I prevent this from happening?
maybe just set up a min and a max value?
When the wheel is up, it is fine.
But when the wheel is down, the view will still turn upside down finally. :(

Posted: Sat Jan 22, 2011 1:27 pm
by elfuz
this code should do the trick. I've had a same problem in the past (although not with irrlicht).

Maybe try outputting the zoom variable camFOV to the screen and see at what value it disorts. Put that value as the minvalue and you're set.

Posted: Sat Jan 22, 2011 2:03 pm
by wsw1231
OK thank you everyone :D