I'm writing a program in
GLM; I'm trying to get my camera to follow my car. So far it successfully follows it around the screen, but I'm having trouble adjusting the Camera's origin (position) to make it stay directly behind the car when it turns. (when the car turns, I want the camera to turn as well to stay inline with it).
After doing a little googling and S/Oing, I think the way forward is by using Geometric Slerp, who's equation is seen here.
It involves the following equation and relates to this diagram:
Below is what I'm trying to achieve; in a program, I have a camera following a car and when the car turns, the cameras position needs to update to stay behind it. Below are two doodles to help you understand my description above. The first image shows the car and camera; the second shows the details:
I have tried writing a function for the equation as seen below:
vec2 slerp = (((sin((1-t)*Omega))/(sin(Omega)))*p0)+(((sin(t*Omega))/(sin(Omega)))*p1)
But I'm unsure how to calculate P1... I'm assuming P0 is the current position and Omega is the rotation of the car. (so by turning left, the camera rotates from P0 to P1.
This is how my car position is updated and how I've got my camera following my object:
camOrigin.x = (0 +globalPos.x+velocity.x); //Cam Position camOrigin.y = (0 +globalPos.y+velocity.y); //Assuming I need to *slerp to X and Z?? camOrigin.z = (100 +globalPos.z+velocity.z); //stays 100 behind car on Z plane camLookingAt.x = (0 +globalPos.x+velocity.x); //Cam Looking at Object camLookingAt.y = (0 +globalPos.y+velocity.y); camLookingAt.z = (0 +globalPos.z+velocity.z); camNormalXYZ.x = (0); //Cam Normal = Y camNormalXYZ.y = (1); camNormalXYZ.z = (0);
Or maybe I'm looking at this wrong and there's an easier way to do this?