handmade camera wont follow handmade node

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Tobey

handmade camera wont follow handmade node

Post 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?
NecromanX
Posts: 16
Joined: Sat Jan 24, 2004 6:01 pm

Post 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.
Tobey

Post 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?
Tobey

Post 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.
damocles
Posts: 5
Joined: Tue Feb 10, 2004 12:38 am

Post 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.
Guest

Post 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:
Tobey

Post by Tobey »

blah that was me replying :roll:
Tobey

Post by Tobey »

i am sure there is one *cough*
Phunk
Posts: 78
Joined: Sun Dec 14, 2003 8:18 pm
Location: The Netherlands

Post 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
obi
Posts: 2
Joined: Wed Oct 08, 2003 9:39 pm

Post 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.
42

Post 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
Boogle
Posts: 162
Joined: Fri Nov 21, 2003 3:16 pm
Location: Toronto, Canada

Post 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.
Post Reply