diff options
author | Nathan Letwory <nathan@letworyinteractive.com> | 2010-10-06 11:13:42 +0400 |
---|---|---|
committer | Nathan Letwory <nathan@letworyinteractive.com> | 2010-10-06 11:13:42 +0400 |
commit | fdadab10062cd9fbef6a6585fd19f344280a9d5b (patch) | |
tree | 52f819576cff389159b13255e28d50972583d249 /source/blender/collada/CameraExporter.cpp | |
parent | 02d97e4da297b8fa112811470846c0ae4598412a (diff) |
COLLADA exporter: split camera and light export into own files.
Diffstat (limited to 'source/blender/collada/CameraExporter.cpp')
-rw-r--r-- | source/blender/collada/CameraExporter.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/source/blender/collada/CameraExporter.cpp b/source/blender/collada/CameraExporter.cpp new file mode 100644 index 00000000000..b4ccfd5d6d1 --- /dev/null +++ b/source/blender/collada/CameraExporter.cpp @@ -0,0 +1,86 @@ +/** + * $Id: DocumentExporter.cpp 32309 2010-10-05 00:05:14Z jesterking $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed, + * Nathan Letwory + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <string> + +#include "COLLADASWCamera.h" +#include "COLLADASWCameraOptic.h" + +#include "DNA_camera_types.h" + +#include "CameraExporter.h" + +#include "collada_internal.h" + +CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryCameras(sw){} + +template<class Functor> +void forEachCameraObjectInScene(Scene *sce, Functor &f) +{ + Base *base= (Base*) sce->base.first; + while(base) { + Object *ob = base->object; + + if (ob->type == OB_CAMERA && ob->data) { + f(ob, sce); + } + base= base->next; + } +} + +void CamerasExporter::exportCameras(Scene *sce) +{ + openLibrary(); + + forEachCameraObjectInScene(sce, *this); + + closeLibrary(); +} +void CamerasExporter::operator()(Object *ob, Scene *sce) +{ + // TODO: shiftx, shifty, YF_dofdist + Camera *cam = (Camera*)ob->data; + std::string cam_id(get_camera_id(ob)); + std::string cam_name(id_name(cam)); + + if (cam->type == CAM_PERSP) { + COLLADASW::PerspectiveOptic persp(mSW); + persp.setXFov(lens_to_angle(cam->lens)*(180.0f/M_PI)); + persp.setAspectRatio(1.0); + persp.setZFar(cam->clipend); + persp.setZNear(cam->clipsta); + COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name); + addCamera(ccam); + } + else { + COLLADASW::OrthographicOptic ortho(mSW); + ortho.setXMag(cam->ortho_scale); + ortho.setAspectRatio(1.0); + ortho.setZFar(cam->clipend); + ortho.setZNear(cam->clipsta); + COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name); + addCamera(ccam); + } +} |