/** * 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 */ #ifndef __COLLADA_SCENE_H__ #define __COLLADA_SCENE_H__ #include "OgreColladaPrerequisites.h" #include "OgreColladaEntity.h" #include "OgreMatrix4.h" namespace Ogre { // specific child nodes of or class ColladaNodeElement; class ColladaBoundingBox; class ColladaTransform; class ColladaTLookAt; class ColladaTMatrix; class ColladaTPerspective; class ColladaTRotate; class ColladaTScale; class ColladaTSkew; class ColladaTTranslate; typedef std::vector ColladaSceneNodePtrVector; typedef std::vector ColladaTransformPtrVector; /** * ColladaSceneNode * traversing the DAG collada scene graph * start with element node * and build up corresponding OGRE scene graph */ class _OgreColladaExport ColladaSceneNode : public ColladaEntity { public: ColladaSceneNode(ColladaDocument *doc, xmlNode *node); virtual ~ColladaSceneNode(void); /** * attach entities of current collada scene node * to Ogre scene graph by iterative traversing * if ogrenode is NULL, then we start with root scene node * * @param ogrenode, where we start in Ogre scene graph * @return void */ void createOgreInstance(SceneNode *ogrenode) const; /** * import element * * @see base class ColladaEntity */ virtual bool doImport(void); ColladaBoundingBox *getBoundingBox(void) const { return mBB; } virtual EntityTypes getEntityType(void) const { return ColladaEntity::NODE; } // the (root) node will be handled like a /** * find a scene node in the DAG graph by its unique id * start traversing always at first child * * @param the unique id of the node we are looking for * @return a pointer on the founded node, NULL otherwise */ ColladaSceneNode *getNode(const String &id); // an ogre instance of an scene node does not make sense virtual MovableObject *getOgreInstance(void) const { return NULL; } private: enum NodeType { JOINT, NODE }; // by default the type is NODE NodeType mType; ColladaSceneNode *mParent; // for root it's empty ;) ColladaBoundingBox *mBB; // [0,1] ColladaEntity *mEntity; // a pointer at loaded instance ColladaTransformPtrVector mTransforms; // [*] ColladaSceneNodePtrVector mChilds; // a vector of s [*] /** * create an ogre instance of mEntity and attach it * * @param ogrenode, where the instance will be attached to * @return void */ void attachEntityToOgreSceneNode(SceneNode *ogrenode) const; /** * set all transformations of a collada node to ogre scene node * traversing iterative corresponds to appearance of collada * * @param ogrenode, where the transforms should affect * @return void */ void attachTransformsToOgreSceneNode(SceneNode *ogrenode) const; /** * import information of current node * currently not implemented * * @param the current node * @return void */ void importExtra(xmlNode *node); /** * try to find the instance (entity) of current node * import the instance and save the pointer of the entity * * @param the current node * @return void */ void importInstance(xmlNode *node); }; /** * abstract class to import and specific childs * @see inheritence for more information */ class ColladaNodeElement { public: ColladaNodeElement(ColladaSceneNode *parent) { mParent = parent; } virtual ~ColladaNodeElement(void) { mParent = NULL; } /** * abstract method to import node information * * @param node the node to import * @return void */ virtual void doImport(xmlNode *node) = 0; protected: ColladaSceneNode *mParent; // pointer back to parent node (should be a or ) }; /** * import a node * fill up minimum and maximum vectors */ class ColladaBoundingBox : public ColladaNodeElement { public: ColladaBoundingBox(ColladaSceneNode *p); /** * special constructor * should only be used by ColladaGeometry * do not call doImport * * @param min, max bounds */ ColladaBoundingBox(const Vector3 &min, const Vector3 &max); virtual ~ColladaBoundingBox(void); virtual void doImport(xmlNode *node); AxisAlignedBox getAABB(void) const; /** * calculate the distance between center * of the box and a corner * in world units * * @param none * @return float, the outer radius of the AABB */ float getRadius(void) const; /** * return min,max vectors as string * * @param none * @return string */ String toString(void) const; private: Vector3 mMin, mMax; }; /** * abstract transform class * @see enum Type (e.g. translate, rotate, scale, ...) */ class ColladaTransform : public ColladaNodeElement { public: enum Type { LOOKAT, MATRIX, PERSPECTIVE, ROTATE, SCALE, SKEW, TRANSLATE }; ColladaTransform(ColladaSceneNode *p) : ColladaNodeElement(p) { } virtual ~ColladaTransform(void) { } // @see ColladaNodeElement virtual void doImport(xmlNode *node) = 0; /** * which type of transform is this element * * @param none * @return enum type */ virtual Type getType(void) const = 0; /** * return a transformation matrix * * @param none * @return a new Ogre Matrix */ virtual Ogre::Matrix4 getMatrix4(void) const = 0; }; // class ColladaTLookAt : public ColladaTransform { public: ColladaTLookAt(ColladaSceneNode *p); virtual ~ColladaTLookAt(void); virtual void doImport(xmlNode *node); virtual Type getType(void) const { return LOOKAT; } virtual Matrix3 getMatrix3(void) const; virtual Matrix4 getMatrix4(void) const; Vector3 getEye(void) const; Vector3 getTarget(void) const; Vector3 getUp(void) const; private: Matrix3 mMatrix; }; // class ColladaTMatrix : public ColladaTransform { public: ColladaTMatrix(ColladaSceneNode *p); virtual ~ColladaTMatrix(void); virtual void doImport(xmlNode *node); virtual Type getType(void) const { return MATRIX; } virtual Matrix4 getMatrix4(void) const; private: Matrix4 mMatrix; }; // class ColladaTPerspective : public ColladaTransform { public: ColladaTPerspective(ColladaSceneNode *p); virtual ~ColladaTPerspective(void); virtual void doImport(xmlNode *node); virtual Type getType(void) const { return PERSPECTIVE; } virtual Matrix4 getMatrix4(void) const; // the identity matrix float getFieldOfView(void) const { return mFOV; } private: float mFOV; // horizontal field of view [°] }; // class ColladaTRotate : public ColladaTransform { public: ColladaTRotate(ColladaSceneNode *p); virtual ~ColladaTRotate(void); virtual void doImport(xmlNode *node); virtual Type getType(void) const { return ROTATE; } virtual Matrix3 getMatrix3(void) const; virtual Matrix4 getMatrix4(void) const; Vector3 getAxis(void) const { return mAxis; } float getAngle(void) const { return mAngle; } private: Vector3 mAxis; float mAngle; // [°] }; // class ColladaTScale : public ColladaTransform { public: ColladaTScale(ColladaSceneNode *p); virtual ~ColladaTScale(void); virtual void doImport(xmlNode *node); virtual Type getType(void) const { return SCALE; } virtual Matrix3 getMatrix3(void) const; virtual Matrix4 getMatrix4(void) const; Vector3 getScale(void) const { return mScale; } private: Vector3 mScale; }; // class ColladaTSkew : public ColladaTransform { public: ColladaTSkew(ColladaSceneNode *p); virtual ~ColladaTSkew(void); virtual void doImport(xmlNode *node); virtual Type getType(void) const { return SKEW; } virtual Matrix3 getMatrix3(void) const; virtual Matrix4 getMatrix4(void) const; Vector3 getRotation(void) const { return mRotation; } Vector3 getTranslation(void) const { return mTranslation; } float getAngle(void) const { return mAngle; } private: Vector3 mRotation, mTranslation; float mAngle; // [°] }; // class ColladaTTranslate : public ColladaTransform { public: ColladaTTranslate(ColladaSceneNode *p); virtual ~ColladaTTranslate(void); virtual void doImport(xmlNode *node); virtual Type getType(void) const { return TRANSLATE; } virtual Matrix4 getMatrix4(void) const; Vector3 getTranslate(void) const { return mTranslate; } private: Vector3 mTranslate; }; } #endif // __COLLADA_SCENE_H__