Rotating camera on X axis

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
n00bc0de
Posts: 55
Joined: Tue Oct 04, 2022 1:21 am

Rotating camera on X axis

Post by n00bc0de »

After rotating the camera on the X axis by more than 90 degrees, the camera seems to change orientation so its not upside down. Is there a way to disable this.

Here is the code (I just added this to example 18 to test camera rotation:

Code: Select all

irr::core::vector3df pt = Camera[0]->getAbsolutePosition();
pt += irr::core::vector3df(0,0,1);
Camera[0]->setTarget(pt);

irr::core::vector3df ct = Camera[0]->getTarget();
ct.rotateYZBy(cr, Camera[0]->getAbsolutePosition());

Camera[0]->setTarget(ct);
cr++;

if(cr >= 360)
   cr = 0;
Noiecity
Posts: 163
Joined: Wed Aug 23, 2023 7:22 pm
Contact:

Re: Rotating camera on X axis

Post by Noiecity »

I remember using fmod to work out the camera rotations based on angles in irrlicht

Code: Select all

fmod(+5.1, +3.0) = 2.1
fmod(-5.1, +3.0) = -2.1
fmod(+5.1, -3.0) = 2.1
fmod(-5.1, -3.0) = -2.1
https://en.cppreference.com/w/cpp/numeric/math/fmod

I also used core::clamp to limit the degrees, making it 360 degrees.
https://irrlicht.sourceforge.io/docu/na ... 81d3316969
Something like that, although I don't remember well:

Code: Select all

core::clamp(fmod(RotationAppliedVariable, totalDegrees), minLimit, maxLimit);
I also remember that it worked better using core::abs_ instead of fmod

https://irrlicht.sourceforge.io/docu/na ... 1ea7551c91

Edit: This solved it as the rotation could go from 400 degrees to 1 degree, instead of 400 to 401, it did not happen in these degrees but that was the problem lmao
**
If you are looking for people with whom to develop your game, even to try functionalities, I can help you, free. CC0 man.

Image
**
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Rotating camera on X axis

Post by CuteAlien »

It's because the up vector always looks to 0,1,0. Which works in most cases so you don't have to care about it, but not if you try to do this. If you need full 360° rotation you have to know all 3 axes of the camera, like:

Code: Select all

irr::core::vector3df pt = Camera[0]->getAbsolutePosition();
irr::core::vector3df view(0,0,1);
irr::core::vector3df right(1,0,0);
view.rotateYZBy(cr);
pt += view;
Camera[0]->setTarget(pt);
irr::core::vector3df up = view.crossProduct(right);
Camera[0]->setUpVector(up);
cr += 0.1f;
Note that "right" vector is fixed for this case - but for this to work in general you'll have to know the correct one always.
Also I rewrote your rotation a bit, yours likely also works, but it's a bit complicated.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
n00bc0de
Posts: 55
Joined: Tue Oct 04, 2022 1:21 am

Re: Rotating camera on X axis

Post by n00bc0de »

Thanks CuteAlien. That works perfectly.
Post Reply