two cameras, permitted?

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
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

two cameras, permitted?

Post by ulao »

I set up a camera and made it active, I do a lot of transformations on it, and its pointer reference is passed around a lot. I just tried adding a new cam for debug reasons. I put it way up above the scene and set it to look down. I added an event so I could switch active cams, and when I do this I get access violations. It seems the data from the active cam is erased when I switch to another. Does this sound normal?

The idea here is to watch the cam from above. Of course there is a mesh that shows where the cam is, as it follows it around. Is this not the way to achieve this?
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

You can switch cameras, but you have to be a little careful.

First if you just add a new camera with addCameraSceneNode then the old active camera will be removed unless you keep an own pointer to it which has grab()'ed it once more. So maybe you forgot that. If you have pointers to cameras they need to grab() it.

addCameraSceneNode always replaces the active camera (which isn't really nice by Irrlicht and should probably be changed...). Because of that it sometimes is also necessary to getActiveCamera first, grab that pointer and setActiveCamera back afterwards (and droping the pointer again).
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
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

Post by ulao »

Yeah that is my problem alright... Dont understand it, but I'll have a look at grab in the doc and see what its about, thx
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

CuteAlien wrote:if you just add a new camera with addCameraSceneNode then the old active camera will be removed unless you keep an own pointer to it which has grab()'ed it once more. So maybe you forgot that. If you have pointers to cameras they need to grab() it.
I'm fairly certain that this is not right. The active camera should have a reference count of 2, and any other camera in the scene would have a reference count of 1. Unless, of course, the user has grab()'d them.

Travis
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

vitek wrote:
CuteAlien wrote:if you just add a new camera with addCameraSceneNode then the old active camera will be removed unless you keep an own pointer to it which has grab()'ed it once more. So maybe you forgot that. If you have pointers to cameras they need to grab() it.
I'm fairly certain that this is not right. The active camera should have a reference count of 2, and any other camera in the scene would have a reference count of 1. Unless, of course, the user has grab()'d them.

Travis
*sigh* complete fail from me. It's certainly as you say and I have no idea what I was thinking when I wrote that.

About the only correct thing I wrote above was that addCameraSceneNode does indeed replace the active camera, but as vitek wrote it's certainly also referenced additionally by the scenegraph.

Sorry.
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
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

Post by ulao »

So I do not need to drop and grab when switch, but need to grab if I play to create a second?

Like so?

create cam 1
grab it
create cam 2


Later in code when switching just set active cam to the cam I wish?

UPDATE:: yes that did in fact work like a charm thx to you both.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

CuteAlien wrote:About the only correct thing I wrote above was that addCameraSceneNode does indeed replace the active camera
not correct, it doesn't replace the camera, but it creates a new one and makes it active, the 1st one is still there, but inactive, so no replacement... ;)

also I don't think you need to grab the 1st camera (or any other) !?!?! :shock:
I never grabed a camera and always could switch between several cameras I created in the same scene... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
CuteAlien
Admin
Posts: 9933
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Acki wrote:
CuteAlien wrote:About the only correct thing I wrote above was that addCameraSceneNode does indeed replace the active camera
not correct, it doesn't replace the camera, but it creates a new one and makes it active, the 1st one is still there, but inactive, so no replacement... ;)

also I don't think you need to grab the 1st camera (or any other) !?!?! :shock:
I never grabed a camera and always could switch between several cameras I created in the same scene... ;)
Yes that's what I mean. Only thing it does is change (not replace) the active camera.

So forget about my original message - it was just wrong. You shouldn't need that grab() & drop() stuff here at all (though it's certainly always clean doing that if you keep pointers around).
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
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

Post by ulao »

out of curiosity. What exactly is grab and drop? I read the docs but I dont clearly understand them. Are they irrLicht terms or standard terms I should be acquainted with?
wITTus
Posts: 167
Joined: Tue Jun 24, 2008 7:41 pm
Location: Germany

Post by wITTus »

grab() raises the counter and drop() decreases the counter. when drop() has been called and the counter is (then) zero, the object gets deleted.
Generated Documentation for BlindSide's irrNetLite.
"When I heard birds chirping, I knew I didn't have much time left before my mind would go." - clinko
rooly
Posts: 224
Joined: Tue Oct 25, 2005 4:32 pm
Location: Louisiana, USA, backwater country
Contact:

Post by rooly »

ulao, grab() and drop() are a simple form of automatic memory management. It saves the user from needing to call 'new' and 'delete' on Irrlicht objects (not that you can anyway since they are all virtual)
When banks compete, you win.
When ISPs compete, you win.
When electronics retailers compete, you win.
When governments compete...you get drafted.
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

Post by ulao »

rooly wrote:ulao, grab() and drop() are a simple form of automatic memory management. It saves the user from needing to call 'new' and 'delete' on Irrlicht objects (not that you can anyway since they are all virtual)
Hey Rooly. Would it be safe to say its not necessary, but rather "proper" to use grab for every irr object? For example most of the time when you see a newly created device, you dont see the device grab'd. Same goes with most of the other examples.
Brkopac
Posts: 88
Joined: Fri Sep 19, 2008 2:36 am

Post by Brkopac »

ulao wrote:
rooly wrote:ulao, grab() and drop() are a simple form of automatic memory management. It saves the user from needing to call 'new' and 'delete' on Irrlicht objects (not that you can anyway since they are all virtual)
Hey Rooly. Would it be safe to say its not necessary, but rather "proper" to use grab for every irr object? For example most of the time when you see a newly created device, you dont see the device grab'd. Same goes with most of the other examples.
If you don't need another reference to the object, there is really no point in using grab(). You should only use it when you need it.
Image - The glory days.
ulao
Posts: 274
Joined: Fri Mar 28, 2008 2:13 am

Post by ulao »

If you don't need another reference to the object, there is really no point in using grab(). You should only use it when you need it.
- Ok fair enough. Thx all.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

and remember that functions starting with create (e.g. createDevice) need to be droped when not needed any longer... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply