I’m not really sure how to describe this effect that I want. I have played a little with dark basic and one of the tutorials it offers is on a smooth camera (It doesn’t give the actual math it’s doing though).
So if I move left or right in a first person 3d world, (as soon as I let off of the key) the scene will not immediatly stop rotating. There is a bit of “play” in the rotation.
When I let off the key to turn, the scene will still “glide” a little in the direction. I like tis effect a lot and I’m just not sure how to set the trig up for it…
I use this code for moving around…
if(GetAsyncKeyState(VK_UP)) {
x += sin(angle * (3.14 / 180)) * walkSpeed;
z += cos(angle * (3.14 / 180)) * walkSpeed;
}
if(GetAsyncKeyState(VK_DOWN)) {
x -= sin(angle * (3.14 / 180)) * walkSpeed;
z -= cos(angle * (3.14 / 180)) * walkSpeed;
}
//Increase angle of rotation
if(GetAsyncKeyState(VK_LEFT)) { angle += 0.5;}
//Decrease angle of rotation
if(GetAsyncKeyState(VK_RIGHT)) { angle -= 0.5;}
…bunch of code…
//Move the scene
glLoadIdentity(); //Reset the scene
rotate = 360 - angle; //Determine wrap around angle
glRotatef(360 - lookAround, 1,0,0); //Rotate up and down
glRotatef(rotate,0,1,0); //Rotate side to side
glTranslatef(x,y,z); //Move to correct position
then draw the scene…
Any suggestions as to how I could modify this to get this effect? I hope I was clear enough on what I’m looking for. Thanks
why not treat it as a physics problem? think about it: if the camera has rotational velocity, and it’s changing at a linear rate, then it’s due to a constant acceleration in the negative direction (in this case, the acceleration would be analogous to a drag force, such the the amount of acceleration would depend on the amount of velocity – greater velocity creates greater drag, which slows it down until it’s almost but not quite stopped.). you’ll probably want to have a lower threshold so that when the speed of the camera drops below a certain threshold (call this threshold “perceptible movement”), you just set the velocity to zero, and stop calculating this. otherwise, the camera will slow down for a long long time… until you reach the smallest float…
i just lerp my camera from where it was to where it wants to go it gives me a very smooth movement alter DOLLYSPEED to change the “smoothness”
VECTOR dd = gotoCAM - old_cameraPOS;
float fracF = (dd.length())/DOLLYSPEED;
// cap it otherwise the camera will be goingbackwards into infinity
if (fracF>1)
fracF=1.0;
float fracFdifference = 1.0 - fracF;
i found your response highly amusing michael! i just wanted to present an alternative solution… sure, a little math-heavy maybe, but you can’t argue with the accuracy… anyway.