Page 1 of 1

Why setRotation/setPosition takes effect 1 loop late?

Posted: Wed Mar 15, 2006 7:03 pm
by Nextor
I've been using Irrlicht for a while and I've found something that I'm not sure whether it's a bug in the engine or it's done on purpose and I'm missing something. Sorry if that's an old issue.

Let's put this example of the engine loop:

Code: Select all

while(device->run()){

	driver->beginScene(...);
	<<drawing stuff>>
	driver->endScene();

	if(someCondition)
		node->setRotation();
	}
Let's suppose that <someCondition> it's true and the node gets a new rotation. Well, I've noticed that the node DOESN'T show it's new rotation the next time the program gets to the drawing block (beginScene & endScene) BUT the second time the node it's drawn on screen.

It happens with setPosition too: The new position isn't taken into account (at least, when drawing the node) until the second loop is executed. Even when using animators there's that problem (the animation starts and ends 1 loop late). This ¿bug? is better noticed in a slow computer, since fps are much lower.

Does anyone know anything about that?

Thanks a lot! :)

Posted: Wed Mar 15, 2006 8:02 pm
by vitek
The absolute position [world position] of every scene node is updated in ISceneNode::OnPostRender() when ISceneNode::updateAbsolutePosition() is called. If you make a change to the relative position or rotation, it isn't reflected until the next call to OnPostRender.

If it is important for the object to have the correct informatoin immediately, you can explicitly call updateAbsolutePosition() after changing the relative position.

Travis

Posted: Wed Mar 15, 2006 9:04 pm
by Nextor
THANKS A LOT TRAVIS :D :D :D
But I'm not quite sure about that because this problem affects the rotation too and I don't think there is some method to update the rotation. Anyway, I'll have a try and I'll tell you if the problem is solved. Thanx again.

Posted: Wed Mar 15, 2006 9:15 pm
by kburkhart84
I just wanted to confirm that this also happens if you initialize a node and then change it's position afterwards before you even draw yet. 1 frame, the node appears at the default position(0, 0, 0) then suddenly jumps. I fixed that by setting those parameters in the constructor, which avoids the need to call onpostrender() to get the positions to update.

Posted: Wed Mar 15, 2006 9:24 pm
by Nextor
Yes, kburkhart84, that's exactly what I mean! Even if you've changed the position/rotation before starting the while loop, it takes 2 frames to get the transformation correctly.

Posted: Wed Mar 15, 2006 10:46 pm
by vitek
I'm not quite sure about that because this problem affects the rotation too
The updateAbsolutePosition() call I mentioned above updates the absolute transformation matrix for the scene node [scale, translation and rotation].

The two problems mentioned above are actually the exact same problem. It has been discussed several times on this forum.

Travis

Posted: Fri Mar 17, 2006 1:03 pm
by Nextor
Thanks a lot again, Travis. Sorry if that was such an old known issue. :oops:
I haven't had the time to check it yet, but I guess you're right.