Blender V2.61 - r43446

CameraExporter.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
00019  *                 Nathan Letwory
00020  *
00021  * ***** END GPL LICENSE BLOCK *****
00022  */
00023 
00029 #include <string>
00030 
00031 #include "COLLADASWCamera.h"
00032 #include "COLLADASWCameraOptic.h"
00033 
00034 #include "DNA_camera_types.h"
00035 
00036 #include "CameraExporter.h"
00037 
00038 #include "collada_internal.h"
00039 
00040 CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryCameras(sw), export_settings(export_settings) {}
00041 
00042 template<class Functor>
00043 void forEachCameraObjectInScene(Scene *sce, Functor &f, bool export_selected)
00044 {
00045     Base *base= (Base*) sce->base.first;
00046     while(base) {
00047         Object *ob = base->object;
00048             
00049         if (ob->type == OB_CAMERA && ob->data
00050             && !(export_selected && !(ob->flag & SELECT))) {
00051             f(ob, sce);
00052         }
00053         base= base->next;
00054     }
00055 }
00056 
00057 void CamerasExporter::exportCameras(Scene *sce)
00058 {
00059     openLibrary();
00060     
00061     forEachCameraObjectInScene(sce, *this, this->export_settings->selected);
00062     
00063     closeLibrary();
00064 }
00065 void CamerasExporter::operator()(Object *ob, Scene *sce)
00066 {
00067     // TODO: shiftx, shifty, YF_dofdist
00068     Camera *cam = (Camera*)ob->data;
00069     std::string cam_id(get_camera_id(ob));
00070     std::string cam_name(id_name(cam));
00071     
00072     if (cam->type == CAM_PERSP) {
00073         COLLADASW::PerspectiveOptic persp(mSW);
00074         persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
00075         persp.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch),false,"aspect_ratio");
00076         persp.setZFar(cam->clipend, false , "zfar");
00077         persp.setZNear(cam->clipsta,false , "znear");
00078         COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
00079         addCamera(ccam);
00080     }
00081     else {
00082         COLLADASW::OrthographicOptic ortho(mSW);
00083         ortho.setXMag(cam->ortho_scale,"xmag");
00084         ortho.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch),false,"aspect_ratio");
00085         ortho.setZFar(cam->clipend , false , "zfar");
00086         ortho.setZNear(cam->clipsta, false , "znear");
00087         COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
00088         addCamera(ccam);
00089     }
00090 }