Jump to content
  • Advertisement
Sign in to follow this  
meiryousa

third-person camera

This topic is 2048 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!