Page 1 of 1

handmade camera wont follow handmade node

Posted: Mon Feb 09, 2004 3:44 am
by Tobey
i have a problem:
i wrote an event receiver so you can move/rotate a scene node with the cursor keys, and that the mouse rotates the camera around this scene node, always keeping the node at the center of the screen (Camera->setTarget(Node->getPosition())). basically, everything works, except for one thing: if i move the node (change its position and change the cameras target to this new position), the cameras focus and the nodes position go out of sync. the camera seems to still look where the node used to be one frame ago.

and now im confused... why would this happen? and how can i fix it?

Posted: Mon Feb 09, 2004 8:03 am
by NecromanX
the setTarget method will only make the camera look to the position of your node. So it wont make the camera move. To make the camera move you will still need to use the setPosition method on your camera node.

Posted: Mon Feb 09, 2004 12:49 pm
by Tobey
nah, im doing that. the camera keeps a constant distance to the node that can be rotated with the mouse... THAT works. the problem is, that the FASTER(!) i move the node (the bigger the delta position is), the more the cameras target stays behind. it seems to always look where the node used to be one frame ago. any ideas?

Posted: Mon Feb 09, 2004 11:59 pm
by Tobey
ok, looks like i need to elaborate a little since nobody replies and im just absolutely POSITIVE that this is NOT something no one has ever witnessed.

my code does this every frame, in this order:

1. change a nodes position by a variable value. (Node->setPosition(Node->getPosition() + vec3d))
2. change the cameras position by the same value. (Camera->setPosition(Camera->getPosition() + vec3d))
3. change the cameras target so it always focuses on the node (Camera->setTarget(Node->getPosition()))
4. render everything.

do you follow me? cool. now the error is this: the bigger vec3d is, the more does the node stay behind the camera focus. if vec3d is 0,0,0 the node is in the middle of the screen as it should be. but the bigger vec3d is - the bigger the movement is - the more does the node stay behind. it stays behind one frame exactly to be precise.

Posted: Tue Feb 10, 2004 12:40 am
by damocles
When you get the node position, couldn't you simply add the vector to that?

e.g:

Camera->setTarget(Node->getPosition()+vec3d)

It does sound like the value being retrieved is one frame behind. Perhaps the node positions don't get applied completely until the frame is completed? Either way, adding the vector as I mentioned should theoretically fix the problem.

Posted: Tue Feb 10, 2004 12:54 am
by Guest
damocles wrote:When you get the node position, couldn't you simply add the vector to that?
we're thinking the same thought, i managed to get around it that way, but i was kinda hoping there would be a more "professional" solution. doing it this way somehow feels like brushing dust under the carpet :wink:

Posted: Tue Feb 10, 2004 12:54 am
by Tobey
blah that was me replying :roll:

Posted: Tue Feb 10, 2004 1:34 pm
by Tobey
i am sure there is one *cough*

Posted: Tue Feb 10, 2004 1:52 pm
by Phunk
I don't think its a solution for you, but I have encountered the same problems, and my way to deal with them is just create a variable to transform on. Then I update everything according to the respective vars. I like this, because it gives me total control over the vector, and I dont have to worry about when or how the setTarget function is aplied. I also feel that the less calls to the engine functions, the faster, but I don't know if this is entirely true

Posted: Sat Feb 14, 2004 1:17 pm
by obi
I have a similar problem. In my app, the node and cam are only moved in the x and y directions (fixed z position). Any time I start or stop moving both, the node makes a small "jump". The camera target seems to be one frame behind. I could work around it by enlarging the target vector. Instead of setting it to the node position x,y,z (with a small fixed z), I set to x,y,1000 . The effect disappeared, but this is allmost as ugly as adding the motion vector to the target vector in advance.
I would appreciate a more general solution, too.

Posted: Sat Feb 14, 2004 8:29 pm
by 42
I had the same problems, this is what i made:
1) my game objects (camera and other scenenodes) have a task queue, the tasks change the position and rotation of the scenenode.
2) I update the taskqueues using an animator which implements kind of a callback mechanism to the gameobjects update function.

in the scenenode impl. after the animators are called the matrix of the node is recalculated by calling updateAbsolut.... so the matrixes are uptodate for the next frame and no jitter or what so ever will occure.

bye
42

Posted: Sun Feb 15, 2004 4:06 am
by Boogle
Yes, it was found quite a while ago that the setPosition() method of scene nodes updates the position vector inside the node, but the node's transformation matrix is not updated until after rendering (in onPostRender()). So any position, rotation, or scaling changes you make do not take affect until the frame after you set them. Not really noticable until you start trying to do things like setting cameras to look at nodes.