handmade camera wont follow handmade node
handmade camera wont follow handmade node
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?
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?
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?
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.
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.
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.
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.
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
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.
I would appreciate a more general solution, too.
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
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
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.