/** * This source file is part of OgreColladaPlugin * an addon for OGRE (Object-oriented Graphics Rendering Engine) * For the latest info, see http://www.ogre3d.org/ * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser 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 Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA, or go to * http://www.gnu.org/copyleft/lesser.txt. * * @author Philipp Hartl * @see README */ #include "OgreColladaCamera.h" #include "OgreColladaDocument.h" #include "OgreColladaSyntax.h" #include "OgreColladaUtils.h" #include "OgreSceneManager.h" #include "OgreCamera.h" #include "OgreStringConverter.h" namespace Ogre { //------------------------------------------------------------------------- ColladaCamera::ColladaCamera(ColladaDocument *d, xmlNode *n) : ColladaEntity(d, n) { mType = UNKNOWN; mXFov = 0; mYFov = 0; mZNear = 0; mZFar = 0; mBottom = 0; mLeft = 0; mRight = 0; mTop = 0; } //------------------------------------------------------------------------- ColladaCamera::~ColladaCamera(void) { } //------------------------------------------------------------------------- MovableObject *ColladaCamera::getOgreInstance(void) const { // Camera *camera = new Camera(mId, mDoc->getSceneManager()); Camera *camera = mDoc->getSceneManager()->createCamera(mId); // standard projection type should be perspective if (mType == ORTHOGRAPHIC) { camera->setProjectionType(PT_ORTHOGRAPHIC); // map from Collada [-1,1] to Ogre [0,1] // camera->setWindow(mLeft, mTop, mRight, mBottom); } else if (mType == PERSPECTIVE) { camera->setProjectionType(PT_PERSPECTIVE); float fov = mYFov; if (fov == 0 && mXFov > 0) fov = mXFov / camera->getAspectRatio(); camera->setFOVy(Radian(Math::DegreesToRadians(fov))); camera->setNearClipDistance(mZNear); camera->setFarClipDistance(mZFar); } Quaternion rot = mDoc->getUpRotation(); camera->rotate(rot); return camera; } //------------------------------------------------------------------------- bool ColladaCamera::doImport(void) { if (mLoaded) return mStatus; else mLoaded = true; // nodes xmlNodePtrVector techniques = ColladaUtils::getChildsByTagName(mNode, CS_ELM_TECHNIQUE); // currently we are only interested in "COMMON" profile xmlNode *technique = NULL; xmlNodePtrVector::const_iterator it; for (it = techniques.begin(); it != techniques.end(); ++it) { String profile = ColladaUtils::getProperty(*it, CS_ATR_PROFILE); if (profile == CS_VAL_TECHNIQUE_PROFILE_COMMON) { technique = *it; break; } } if (technique == NULL) return false; // one child xmlNode *optics = ColladaUtils::getChildByTagName(technique, CS_ELM_OPTICS); mStatus = importOptics(optics); // [0,*] xmlNodePtrVector imagers = ColladaUtils::getChildsByTagName(technique, CS_ELM_IMAGER); for (it = imagers.begin(); it != imagers.end() && mStatus; ++it) mStatus = importImager(*it); return mStatus; } //------------------------------------------------------------------------- bool ColladaCamera::importImager(xmlNode *node) { if (node == NULL) return false; // currently not implemented return true; } //------------------------------------------------------------------------- bool ColladaCamera::importOptics(xmlNode *node) { if (node == NULL) return false; // xmlNode *program = ColladaUtils::getChildByTagName(node, CS_ELM_PROGRAM); if (program == NULL) return false; // camera type String url = ColladaUtils::getProperty(program, CS_ATR_URL); mType = UNKNOWN; if (url == CS_VAL_CAMERA_TYPE_ORTHOGRAPHIC) mType = ORTHOGRAPHIC; else if (url == CS_VAL_CAMERA_TYPE_PERSPECTIVE) mType = PERSPECTIVE; if (mType == UNKNOWN) { LogManager::getSingleton().logMessage("ColladaCamera::importOptics - unknown! " + mId); return false; } // childs xmlNodePtrVector params = ColladaUtils::getChildsByTagName(program, CS_ELM_PARAM); for (xmlNodePtrVector::const_iterator it = params.begin(); it != params.end(); ++it) { String name = ColladaUtils::getProperty(*it, CS_ATR_NAME); String content = ColladaUtils::getContentDirect(*it); float tmp = StringConverter::parseReal(content); /** * The field of view may be specified separately for the X and Y directions. * If only one is specified, the other should be derived using the aspect ratio * of the rendering view-port (to avoid image distortion). */ if (name == CS_VAL_CAMERA_PARAM_BOTTOM) mBottom = tmp; else if (name == CS_VAL_CAMERA_PARAM_LEFT) mLeft = tmp; else if (name == CS_VAL_CAMERA_PARAM_RIGHT) mRight = tmp; else if (name == CS_VAL_CAMERA_PARAM_TOP) mTop = tmp; else if (name == CS_VAL_CAMERA_PARAM_XFOV) mXFov = tmp; else if (name == CS_VAL_CAMERA_PARAM_YFOV) mYFov = tmp; else if (name == CS_VAL_CAMERA_PARAM_ZFAR) mZFar = tmp; else if (name == CS_VAL_CAMERA_PARAM_ZNEAR) mZNear = tmp; else { LogManager::getSingleton().logMessage("ColladaCamera::importOptics -