Vector Interpolation (Camera Question)

Started by
5 comments, last by erissian 16 years, 9 months ago
Hey all. I'm currently working on a game and am in charge of the camera system. It's a third-person racing game and we're using a hard-attached camera. The problem: when the angle of the terrain changes, the camera re-orients itself to match the racer's orientation; this is sudden and painful to watch. So, I've been looking into ways to smooth this transition and think that vector interpolation would be the answer. Unfortunately, I can't seem to get it to work. What I'm doing is determining the camera's future position after the hard-attach when the angle of the terrain changes. To interpolate between the camera's current position and future position, I'm doing the following: vCamPos.x = vPrevCamPos.x * (1 - t) + vNextCamPos.x * t; vCamPos.y = vPrevCamPos.y * (1 - t) + vNextCamPos.y * t; vCamPos.z = vPrevCamPos.z * (1 - t) + vNextCamPos.z * t; where 0 < t < 1. As you can see, when t is 0 I get the camera's position before the change and when t is 1 I get the camera's position after the change. I'm sure that I'm missing a step or two and am wondering if anyone knows any good sites or tutorials that might help me. Also, if you've got a suggestion, I'd be glad to hear from you. Thank you for your time. EDIT: I'm also doing a look-at algorithm to keep the camera facing the racer during this transition. Not sure if this will affect anything.
Advertisement
Define "I can't seem to get it to work." Does it not compile? Does the camera end up looking upside down? Does it jerk around too much? Does it sneak into the pedestrians and try to look up a girl's skirt?
Quote:Does it sneak into the pedestrians and try to look up a girl's skirt?


That was happening, but a little time-out in the corner set it straight.


Quote:Define "I can't seem to get it to work."


My mistake, I should have been more clear. When I run the game, the camera repeatedly starts at the racer's position and translates back to the offset set in the hard-attach function. It looks as though I'm calculating the future position of the camera incorrectly. It appears to be interpolating from the racer's position to the correct camera offset.

I'm looking into it now.
Well I'm young and I don't have any official coding experience, but 5 years with DarkBasic and nearly 1 with C++, I still have a few tricks up my sleeve.

DarkBasic had a curvevalue function, if that's what you're interested in. You stick in the camera's current position (well, camera in this case), it's destination, and a smooth value, and it spits out a new position for the camera, a bit like this:

cam.x = curvevalue( cam.x, camera position x(), 20.0 )
Then you just reposition the camera.

Here's a simple define I made for it:

#define curvevalue( current, dest, smooth ) current + ((dest - current) / smooth )


Sorry if it's not what you need, I might not have read your post correctly, but if this was the problem, then this function would be the first I would think of :)
hey

Hmm, I think you might need to learn about linear interpolation, hehe. Anyhows I think you are trying todo alike this...

vCamPos.x = vPrevCamPos.x + ((vNextCamPos.x - vPrevCamPos.x) * t);

edit
I just tried your previous equation, and it seems to work... so maybe your prob is elsewhere?

another edit...
Hmm, I'm not completly sure if this will work for you... but I was thinking that maybe you should try this...

vCamPos.x += (vNextCamPos.x - vCamPos.x) * t;

Note that 't' here would refer to the interpolation speed... and you can keep it constant... I advise to set it at something like 0.05, but you can experiment, hehe.

cyas

[Edited by - yosh64 on July 17, 2007 9:20:02 AM]
Lol yosh, it seems we have just given him the same equations :P
Quote:Original post by yosh64
hey

Hmm, I think you might need to learn about linear interpolation, hehe. Anyhows I think you are trying todo alike this...

vCamPos.x = vPrevCamPos.x + ((vNextCamPos.x - vPrevCamPos.x) * t);


Don't laugh too hard, that's equivalent to what he has already.

vCamPos.x = vPrevCamPos.x * (1 - t) + vNextCamPos.x * t;          = vPrevCamPos.x - vPrevCamPos.x * t + vNextCamPos.x * t;          = vPrevCamPos.x + (vNextCamPos.x - vPrevCamPos.x) * t;


It seems like he's determined that his lerp is fine, but the position he's lerping to is incorrect.
We''re sorry, but you don''t have the clearance to read this post. Please exit your browser at this time. (Code 23)

This topic is closed to new replies.

Advertisement