How to toggle addCameraSceneNodeFPS()-like camera rotation?

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
AlexAzazel
Posts: 31
Joined: Sun Jan 10, 2016 3:42 pm
Location: Tbilisi

How to toggle addCameraSceneNodeFPS()-like camera rotation?

Post by AlexAzazel »

I'm trying to make RTS/RTT camera, most of it is already done:

https://www.youtube.com/watch?v=PiPJfCxEOAA
https://github.com/insanewarlock/irrRTS-RTT

All I need now is to toggle addCameraSceneNodeFPS() like camera rotation when right mouse button is pressed. I payed attention without this line

Code: Select all

device->getCursorControl()->setVisible(false);
mouse stays fixed at the center when using FPS camera, I want something similar: when the right mouse button is clicked cursor should disappear (I managed to do only this part) and target of the camera should start rotating around the position of the camera according to how you move the mouse, when you release the right mouse button the cursor should reappear where ever it was when it disappeared. In the youtube video provided above you can see it doesn't do that, as it's expected since I haven't implemented that yet. Should I do the whole thing on my one with quaternion rotations or something like that, storing mouse location and moving it back when it reappears (by the way I have no idea how to do that last thing) or is there a smarter shortcut for doing it since addCameraSceneNodeFPS() has already implemented it all ?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to toggle addCameraSceneNodeFPS()-like camera rotati

Post by CuteAlien »

You can have 2 cameras and switch them when you press the right mouse button. Set the new camera first to the position (and target) of the old camera, maybe have to call updateAbsolutePosition() on it as well. Then then set the new camera active.

Not sure if it's a good solution. I tend to use Irrlicht cameras only for quick prototypes and testing things out. But for larger apps I always write my own camera. Just gives more flexibility and sooner or later you need that anyway.
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
AlexAzazel
Posts: 31
Joined: Sun Jan 10, 2016 3:42 pm
Location: Tbilisi

Re: How to toggle addCameraSceneNodeFPS()-like camera rotati

Post by AlexAzazel »

CuteAlien wrote:You can have 2 cameras and switch them when you press the right mouse button.

I had that though but that will have several unwanted consequences, so I'm now leaning towards making rotation algorithm myself. The only question I have right now is, how do I move cursor with code after it reappears back to the position I saved when it disappeared?

Oh and by the way, how do I write my own camera? By overriding ICameraSceneNode? I found this code but doesn't work for recent irrlicht versions

http://www.irrlicht3d.org/wiki/index.ph ... ByCmdKewin


besides I'm new to irrlicht and c++ do you know any good tutorial or forum threat about overriding ICameraSceneNode?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: How to toggle addCameraSceneNodeFPS()-like camera rotati

Post by CuteAlien »

You have several choices. Override ICameraSceneNode. In that case best look at the CCameraSceneNode.cpp./h files.
But probably easier/better to use an animator (derived from ISceneNodeAnimator). For an example look again at the sources. Irrlicht's CSceneNodeAnimatorCameraFPS does that for example.
And another solution is - just write your own code which updates a normal camera any way you want. Basically not so different from writing an animator.
You can also disable/enable animators. So you can disable the active one while the right mouse button is down for example.
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
Post Reply