Page 1 of 1

New camera class trouble.

Posted: Mon Jun 09, 2008 12:59 am
by malahaas
Hi, I've been trying to write my own camera class but have run into an issue that I am unsure how to resolve.

The real problem I'm having is that OnAnimate isn't being called. I used the FPSCamera as a model since what I'd like to create is similar (Hence referencing OnAnimate).

In order to narrow the list of what could cause the problem in my camera, I decided to copy the source code for CCameraSceneNode and CCameraFPSSceneNode into my own files and try to add an FPS camera like so:

(FPSCamera is my class name for the CCameraFPSSceneNode code)

FPSCamera camera = new FPSCamera(0, smgr, device->getTimer(),
device->getCursorControl(), -1,
100.0f, 300.0f, 0.f,
0, 0, true );

smgr->setActiveCamera(camera)

You'll notice that I pass device->getTimer() into the constructor. I added this because the source for CCameraFPSSceneNode uses os::Timer::getTime(), which I do not have access to. I therefore simply added a member variable pointer to ITimer and set it to device->getTImer(). (this doesn't matter since OnAnimate() isn't getting called anyway).

I've come to the conclusion that the difference between my code and just using the built-in addCameraSceneNodeFPS() is that CSceneManager passes 'this' into parent if none is set. My problem is, I can't pass my pointer to the SceneManager, since it is of type ISceneManager, which does not inherit from ISceneNode, whereas CSceneManager does. Perhaps I am missing something here, but that's the only cause I could come up with for why my camera renders everything fine, but won't move.

Any help would be greatly appreciated. I'd also like to know if ISceneManager not inheriting from ISceneNode was intentional, and if so, was curious as to what the reason was.

Thanks in advance.

Posted: Mon Jun 09, 2008 4:35 am
by malahaas
Hi,

I've found that passing smgr->getRootSceneNode() as parent fixes my issues. Strange since that doesnt seem to be the way that the addCamera...() methods work in the CSceneManager class... However, can't complain if it works. I definately love what I've used so far of Irrlicht.

Thanks

Posted: Mon Jun 09, 2008 7:20 am
by arras
I've found that passing smgr->getRootSceneNode() as parent fixes my issues. Strange since that doesnt seem to be the way that the addCamera...() methods work in the CSceneManager class
It is exactly the way scene manager works. It adds node to child list of root scene node. Irrlicht than goes through that list once scenemanager->drawAll() is called and calls certain functions in nodes it finds (like OnAnimate()). Thats the way manager keeps track of nodes. If you just create wild node, how can scene manager knows it even exist? Samegoes for GUI environment by the way.

Posted: Tue Jun 10, 2008 12:55 am
by malahaas
arras wrote:
I've found that passing smgr->getRootSceneNode() as parent fixes my issues. Strange since that doesnt seem to be the way that the addCamera...() methods work in the CSceneManager class
It is exactly the way scene manager works. It adds node to child list of root scene node. Irrlicht than goes through that list once scenemanager->drawAll() is called and calls certain functions in nodes it finds (like OnAnimate()). Thats the way manager keeps track of nodes. If you just create wild node, how can scene manager knows it even exist? Samegoes for GUI environment by the way.
Thanks for the response. It makes sense, but when I was looking at SceneManager's source code, it passes "this" (itself) which I can't do since ISceneManager doesn't inherit from ISceneNode the way that CSceneManager does. I find that strange is all, and wondered if there was a reason the matching interface didn't inherit the same way.

Posted: Tue Jun 10, 2008 7:47 am
by hybrid
The scene manager inherits from scene node as well, and that'S the part that is passed via 'this'. So you're supposed to pass getRootSceneNode().