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