When are a camera's matrices & friends updated fully?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

When are a camera's matrices & friends updated fully?

Post by Nyxojaele »

So I've set up (successfully) an ortho camera using the following code:

Code: Select all

	ISceneManager *sceneMgr = mDevice->getSceneManager();
	ICameraSceneNode *cam = sceneMgr->addCameraSceneNode(NULL, irr::core::vector3df(0, 0, -100),
			irr::core::vector3df(0, 0, 0), 1);
	irr::core::matrix4 orthoMatrix;
	orthoMatrix.buildProjectionMatrixOrthoLH(1024, 768, -100, 200);
	cam->setProjectionMatrix(orthoMatrix);
	cam->setIsOrthogonal(true);
As you can see, I've set the width and height to match a standard screen resolution. So, after everything is properly updated in the camera, a call to the following code

Code: Select all

	ICameraSceneNode *cam = mDevice->getSceneManager()->getActiveCamera();
	const scene::SViewFrustum* f = cam->getViewFrustum();

	core::vector3df farLeftUp = f->getFarLeftUp();
	core::vector3df lefttoright = f->getFarRightUp() - farLeftUp;
	core::vector3df uptodown = f->getFarLeftDown() - farLeftUp;
should result in farLeftUp = (512, 384, 100), lefttoright = (1024, 0, 0), and uptodown = (0, 768, 0). And that is exactly what it is- but this is AFTER some time (after the first frame is rendered?) The problem is that if I call this code immediately after setting up the ortho camera above, it gives me incorrect values: farLeftUp = (-1, 1, 1), lefttoright = (2, 0, 0), uptodown = (0, -2, 0)

So my question is this: What is it that is done to this camera between my initializing code at the top, and after the first frame is rendered? Once I know that, in theory, I could come up with a way to force the camera to update that immediately after my initialization so I can get correct collision detection BEFORE the first frame is rendered.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You could always look at the source code for cameras yourself? It's probably updated in OnAnimate or something...

And i'm sure you know that you obviously can't just stick in 1024x768 right? You need to know the current screen resolution, which of course it handily provided by some function call which i can't actually recall :lol:
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

It's done by CCameraSceneNode::recalculateViewArea(), which is unfortunately protected.

You can force it by calling cam->OnRegisterSceneNode(). If you do this outside the scene loop then it should be harmless.

I don't see any particular harm in making recalculateViewArea() public though.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Post by Nyxojaele »

Yah, I tried looking at the source for it- and it wasn't making a boatload of sense. I got the basic understanding of it, and actually, I came to the conclusion that it was either the CCameraSceneNode::recalculateViewArea() or CCameraSceneNode::recalculateProjectionMatrix(), both of which are protected, as rogerborg pointed out.

I -thought- I had tested all combinations of those 2 functions already, but with no success- but if rogerborg says it should be in recalculateViewArea(), then I think I should give it another go- I'll keep you updated on that.

I was also wondering why that function was protected.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

I tested the OnRegisterSceneNode() workaround before suggesting it. Sorry, I know that's a shocking habit.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Nyxojaele
Posts: 98
Joined: Mon Sep 18, 2006 4:06 am

Post by Nyxojaele »

Yah, I just got that all working perfectly for me as well. Thanks for pointing that out for me rogerborg- it's such a strange way to go about it, I fear I'd have never thought of it myself!
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

No problem, but honestly, it didn't take any "thought".
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply