static void rna_Camera_angle_y_set(PointerRNA *ptr, float value) { Camera *cam = ptr->id.data; cam->lens = fov_to_focallength(value, cam->sensor_y); }
/** When this method is called, the writer must write the camera. * \return The writer should return true, if writing succeeded, false otherwise.*/ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) { if (mImportStage != General) return true; Camera *cam = NULL; std::string cam_id, cam_name; ExtraTags *et=getExtraTags(camera->getUniqueId()); cam_id = camera->getOriginalId(); cam_name = camera->getName(); if (cam_name.size()) cam = (Camera *)BKE_camera_add(G.main, (char *)cam_name.c_str()); else cam = (Camera *)BKE_camera_add(G.main, (char *)cam_id.c_str()); if (!cam) { fprintf(stderr, "Cannot create camera.\n"); return true; } if (et && et->isProfile("blender")) { et->setData("shiftx",&(cam->shiftx)); et->setData("shifty",&(cam->shifty)); et->setData("YF_dofdist",&(cam->YF_dofdist)); } cam->clipsta = camera->getNearClippingPlane().getValue(); cam->clipend = camera->getFarClippingPlane().getValue(); COLLADAFW::Camera::CameraType type = camera->getCameraType(); switch (type) { case COLLADAFW::Camera::ORTHOGRAPHIC: { cam->type = CAM_ORTHO; } break; case COLLADAFW::Camera::PERSPECTIVE: { cam->type = CAM_PERSP; } break; case COLLADAFW::Camera::UNDEFINED_CAMERATYPE: { fprintf(stderr, "Current camera type is not supported.\n"); cam->type = CAM_PERSP; } break; } switch (camera->getDescriptionType()) { case COLLADAFW::Camera::ASPECTRATIO_AND_Y: { switch (cam->type) { case CAM_ORTHO: { double ymag = 2 * camera->getYMag().getValue(); double aspect = camera->getAspectRatio().getValue(); double xmag = aspect * ymag; cam->ortho_scale = (float)xmag; } break; case CAM_PERSP: default: { double yfov = camera->getYFov().getValue(); double aspect = camera->getAspectRatio().getValue(); // NOTE: Needs more testing (As we curretnly have no official test data for this) double xfov = 2.0f * atanf(aspect * tanf(DEG2RADF(yfov) * 0.5f)); cam->lens = fov_to_focallength(xfov, cam->sensor_x); } break; } } break; /* XXX correct way to do following four is probably to get also render * size and determine proper settings from that somehow */ case COLLADAFW::Camera::ASPECTRATIO_AND_X: case COLLADAFW::Camera::SINGLE_X: case COLLADAFW::Camera::X_AND_Y: { switch (cam->type) { case CAM_ORTHO: cam->ortho_scale = (float)camera->getXMag().getValue() * 2; break; case CAM_PERSP: default: { double x = camera->getXFov().getValue(); // x is in degrees, cam->lens is in millimiters cam->lens = fov_to_focallength(DEG2RADF(x), cam->sensor_x); } break; } } break; case COLLADAFW::Camera::SINGLE_Y: { switch (cam->type) { case CAM_ORTHO: cam->ortho_scale = (float)camera->getYMag().getValue(); break; case CAM_PERSP: default: { double yfov = camera->getYFov().getValue(); // yfov is in degrees, cam->lens is in millimiters cam->lens = fov_to_focallength(DEG2RADF(yfov), cam->sensor_x); } break; } } break; case COLLADAFW::Camera::UNDEFINED: // read nothing, use blender defaults. break; } this->uid_camera_map[camera->getUniqueId()] = cam; this->FW_object_map[camera->getUniqueId()] = camera; // XXX import camera options return true; }
static void rna_Camera_angle_set(PointerRNA *ptr, float value) { Camera *cam = ptr->id.data; float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); cam->lens = fov_to_focallength(value, sensor); }