OpenMW
components/nifbullet/bulletnifloader.hpp
Go to the documentation of this file.
00001 /*
00002   OpenMW - The completely unofficial reimplementation of Morrowind
00003   Copyright (C) 2008-2010  Nicolay Korslund
00004   Email: < korslund@gmail.com >
00005   WWW: http://openmw.sourceforge.net/
00006 
00007   This file (ogre_nif_loader.h) is part of the OpenMW package.
00008 
00009   OpenMW is distributed as free software: you can redistribute it
00010   and/or modify it under the terms of the GNU General Public License
00011   version 3, as published by the Free Software Foundation.
00012 
00013   This program is distributed in the hope that it will be useful, but
00014   WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   version 3 along with this program. If not, see
00020   http://www.gnu.org/licenses/ .
00021 
00022  */
00023 
00024 #ifndef OPENMW_COMPONENTS_NIFBULLET_BULLETNIFLOADER_HPP
00025 #define OPENMW_COMPONENTS_NIFBULLET_BULLETNIFLOADER_HPP
00026 
00027 #include <cassert>
00028 #include <string>
00029 #include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
00030 #include <BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h>
00031 #include <btBulletDynamicsCommon.h>
00032 #include <openengine/bullet/BulletShapeLoader.h>
00033 
00034 // For warning messages
00035 #include <iostream>
00036 
00037 namespace Nif
00038 {
00039     class Node;
00040     class Transformation;
00041     class NiTriShape;
00042 }
00043 
00044 namespace NifBullet
00045 {
00046 
00050 class ManualBulletShapeLoader : public OEngine::Physic::BulletShapeLoader
00051 {
00052 public:
00053     ManualBulletShapeLoader()
00054       : mShape(NULL)
00055       , mBoundingBox(NULL)
00056       , mHasShape(false)
00057     {
00058     }
00059 
00060     virtual ~ManualBulletShapeLoader();
00061 
00062     void warn(const std::string &msg)
00063     {
00064         std::cerr << "NIFLoader: Warn:" << msg << "\n";
00065     }
00066 
00067     void fail(const std::string &msg)
00068     {
00069         std::cerr << "NIFLoader: Fail: "<< msg << std::endl;
00070         abort();
00071     }
00072 
00076     void loadResource(Ogre::Resource *resource);
00077 
00083     void load(const std::string &name,const std::string &group);
00084 
00085 private:
00086     btVector3 getbtVector(Ogre::Vector3 const &v);
00087 
00091     void handleNode(btTriangleMesh* mesh, Nif::Node const *node, int flags, bool isCollisionNode, bool raycasting, bool isMarker);
00092 
00096     bool hasRootCollisionNode(const Nif::Node *node);
00097 
00101     void handleNiTriShape(btTriangleMesh* mesh, const Nif::NiTriShape *shape, int flags, const Ogre::Matrix4 &transform, bool raycasting);
00102 
00103     std::string mResourceName;
00104 
00105     OEngine::Physic::BulletShape* mShape;//current shape
00106     btBoxShape *mBoundingBox;
00107 
00108     bool mHasShape;
00109 };
00110 
00111 }
00112 
00113 #endif