Well, I have a third-person camera working. It's "ok" I guess. It just doesn't quite work the way I want it to. It rotates around the target perfectly. Exactly how I want it to. It zooms in and out on the target perfectly too. What I am having troubles with is having it rotate over the target. The reason this is difficult is because it depends on the direction I am facing. These are my functions so far:
void ViewManager::rotateOver(float amt){
y_theta += amt;
position.y = target.y + radius * cos(y_theta * M_PI / 180.0f);
v_matrix = glm::lookAt(position, target, glm::vec3(0.0f,1.0f,0.0f));
return;
}
void ViewManager::rotateAround(float amt){
x_theta += amt;
z_theta += amt;
position.x = target.x + radius * sin(x_theta * M_PI / 180.0f);
position.z = target.z + radius * cos(z_theta * M_PI / 180.0f);
v_matrix = glm::lookAt(position, target, glm::vec3(0.0f,1.0f,0.0f));
return;
}
void ViewManager::zoomIn(float amt){
radius += amt;
position.x = target.x + radius * sin(x_theta * M_PI / 180.0f);
position.y = target.y + radius * cos(y_theta * M_PI / 180.0f);
position.z = target.z + radius * cos(z_theta * M_PI / 180.0f);
v_matrix = glm::lookAt(position, target, glm::vec3(0.0f,1.0f,0.0f));
return;
}
I've tried a lot of different things. I've had it rotating over one axis, both axes, but never the correct axes. I don't think I need 3 angles... I just did that recently trying different ideas... there are angles created between the x-y axes and x-z axes. This is based on polar coordinates.
I hope I gave enough information...