third-person camera

Started by
0 comments, last by _WeirdCat_ 10 years, 1 month ago

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

Advertisement

try the formula that you add x minus y and z

(in this case glop is a true heading angle, and heading angle is i dont know what (upside-down roattion angle ;])

SUPERPOINT.x = 100000*(sin(glop*imopi)*cos(heading*imopi));
SUPERPOINT.z = 100000*(cos(glop*imopi)*cos(heading*imopi));
SUPERPOINT.y = 100000*(sin(heading*imopi));

gluLookAt(old.x,old.y,old.z,old.x+SUPERPOINT.x,old.y-SUPERPOINT.y,old.z-SUPERPOINT.z,0,1,0);

This topic is closed to new replies.

Advertisement