예제 #1
0
파일: zoomcamera.cpp 프로젝트: 0-T-0/Gource
void ZoomCamera::adjust(const Bounds2D& bounds, bool adjust_distance) {

    //center camera on bounds

    vec2 centre  = bounds.centre();

    //adjust by screen ratio
    dest.x = centre.x;
    dest.y = centre.y;

    if(!adjust_distance) return;

    //scale by 10% so we dont have stuff right on the edge of the screen
    float width  = bounds.width() * padding;
    float height = bounds.height() * padding;

    float aspect_ratio = display.width / (float) display.height;

    if(aspect_ratio < 1.0) {
        height /= aspect_ratio;
    } else {
        width /= aspect_ratio;
    }

    //calc visible width of the opposite wall at a distance of 1 this fov
    float toa = tan( fov * 0.5f * DEGREES_TO_RADIANS ) * 2.0;

    float distance;

    //TOA = tan = opposite/adjacent (distance = adjacent)
    //use the larger side of the box

    //cropping: vertical, horizontal or none
    if(gGourceSettings.crop_vertical) {

        distance =  width / toa;

        
    } else if (gGourceSettings.crop_horizontal) {

        distance =  height / toa;
        
    } else {

        if(width >= height) {
            distance =  width / toa;
        } else {
            distance =  height / toa;
        }
    }

    //debugLog("toa %.2f, distance %.2f width %.2f height %.2f dratio %.2f\n", toa, distance, width, height, dratio);

    //check bounds are valid
    if(distance < min_distance) distance = min_distance;
    if(distance > max_distance) distance = max_distance;

    this->dest.z = -distance;
}
예제 #2
0
void ZoomCamera::adjust(Bounds2D& bounds) {

    //center camera on bounds

    //scale by 10% so we dont have stuff right on the edge of the screen
    float width  = bounds.width() * padding;
    float height = bounds.height() * padding;

    vec2f centre  = bounds.centre();

    //adjust by screen ratio
    float dratio = display.height / (float) display.width;

      if(dratio > 1.0) {
          height /= dratio;
      } else {
          width *= dratio;
      }

    //calc visible width of the opposite wall at a distance of 1 this fov
    float toa = tan( getFov() * 0.5f * DEGREES_TO_RADIANS ) * 2.0;

    float distance;

    //TOA = tan = opposite/adjacent (distance = adjacent)
    //use the larger side of the box

    //cropping: vertical, horizontal or none
    if(gGourceSettings.crop_vertical) {
        distance =  width / toa ;

    } else if (gGourceSettings.crop_horizontal) {
        distance =  height / toa ;

    } else {

        if(width > height) {
            distance =  width / toa ;
        } else {
            distance =  height / toa ;
        }
    }

    //debugLog("toa %.2f, distance %.2f width %.2f height %.2f dratio %.2f\n", toa, distance, width, height, dratio);

    //check bounds are valid
    if(distance < min_distance) distance = min_distance;
    if(distance > max_distance) distance = max_distance;

    this->dest = vec3f(centre.x, centre.y, -distance);
}