Ejemplo n.º 1
0
  mat4 Camera::getProjectionMatrix(float windowRatio) const {
    if (projectionMode_ == ORTHOGRAPHIC) {
      if (windowRatio > 1.0f)
        return glm::ortho(frust_.getLeft() * windowRatio, frust_.getRight() * windowRatio,
        frust_.getTop(), frust_.getBottom(),
        -frust_.getNearDist(), frust_.getFarDist());
      else
        return glm::ortho(frust_.getLeft(), frust_.getRight(),
        frust_.getTop() * (1.0f / windowRatio), frust_.getBottom() * (1.0f / windowRatio),
        -frust_.getNearDist(), frust_.getFarDist());
    }
    else if (projectionMode_ == PERSPECTIVE) {
      float fovy = frust_.getFovy();
      if (fovy < 6.f)
        fovy = 6.f;
      if (fovy > 175.f)
        fovy = 175.f;

      if (windowRatio >= 1.0f)
        return glm::perspective(glm::deg2rad(fovy), frust_.getRatio() * windowRatio, frust_.getNearDist(), frust_.getFarDist());
      else
        return glm::perspective(atan(tan(glm::deg2rad(fovy / 2.f)) / (windowRatio* frust_.getRatio())) * 2, frust_.getRatio() * windowRatio, frust_.getNearDist(), frust_.getFarDist());
    }
    else
      return getFrustumMatrix(windowRatio);
  }
Ejemplo n.º 2
0
 // This is called to set up the Camera-View
 void Camera::look(float windowRatio) {
   MatStack.matrixMode(MatrixStack::PROJECTION);
   MatStack.loadIdentity();
   updateFrustum();
   MatStack.loadMatrix(getFrustumMatrix(windowRatio));
   MatStack.matrixMode(MatrixStack::MODELVIEW);
   MatStack.loadIdentity();
   updateVM();
   MatStack.loadMatrix(viewMatrix_);
 }
Ejemplo n.º 3
0
/*
 * SPECIAL VERSION TAKING IN COUNT PAN AND ZOOM
 */
const Matrix44f getPerspectiveMatrix(float fovy, float zNear, float zFar, float width, float height, float panX, float panY, float zoom)
{
    float halfHeight = zNear * ci::math<float>::tan(fovy * PI / 360) / zoom;
    float halfWidth = halfHeight * width / height;

    float offsetX = -panX * (halfWidth * 2 / width);
    float offsetY = -panY * (halfHeight * 2 / height);

    return getFrustumMatrix(-halfWidth + offsetX, halfWidth + offsetX, -halfHeight + offsetY, halfHeight + offsetY, zNear, zFar);
}
Ejemplo n.º 4
0
const Matrix44f getPerspectiveMatrix(float fovy, float aspect, float zNear, float zFar)
{
    float ymax = zNear * ci::math<float>::tan(fovy * PI / 360);
    float ymin = -ymax;

    float xmin = ymin * aspect;
    float xmax = ymax * aspect;

    return getFrustumMatrix(xmin, xmax, ymin, ymax, zNear, zFar);
}
Ejemplo n.º 5
0
// This is called to set up the Camera-View
void Camera::look() {
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    updateFrustum();
    loadMatrix(getFrustumMatrix());
    //getProjectionMatrix();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    updateVM();
    loadMatrix(viewMatrix_);
}
Ejemplo n.º 6
0
mat4 Camera::getProjectionMatrix() const {
    if(projectionMode_ == ORTHOGRAPHIC) {
        if(windowRatio_ > 1.0f)
            return mat4::createOrtho(frust_.getLeft() * windowRatio_, frust_.getRight() * windowRatio_,
                                     frust_.getTop(), frust_.getBottom(),
                                    -frust_.getNearDist(), frust_.getFarDist());
        else
            return mat4::createOrtho(frust_.getLeft(), frust_.getRight(),
                                     frust_.getTop() * (1.0f/windowRatio_), frust_.getBottom() * (1.0f/windowRatio_),
                                    -frust_.getNearDist(), frust_.getFarDist());
    } else if(projectionMode_ == PERSPECTIVE) {
        float fovy = frust_.getFovy();
        if(fovy < 6.f)
            fovy = 6.f;
        if(fovy > 175.f)
            fovy = 175.f;

        return mat4::createPerspective(deg2rad(fovy), frust_.getRatio() * windowRatio_, frust_.getNearDist(), frust_.getFarDist());
    }
    else
        return getFrustumMatrix();
}
Ejemplo n.º 7
0
 mat4 Camera::getFrustumMatrix(ivec2 windowSize) const {
   return getFrustumMatrix(static_cast<float>(windowSize.x) / windowSize.y);
 }