ThingStaticGeometry.cpp

Go to the documentation of this file.
00001 /*
00002 SagaEngine library
00003 Copyright (c) 2002-2006 Skalden Studio AS
00004 
00005 This software is provided 'as-is', without any express or implied 
00006 warranty. In no event will the authors be held liable for any 
00007 damages arising from the use of this software.
00008 
00009 Permission is granted to distribute the library under the terms of the 
00010 Q Public License version 1.0. Be sure to read and understand the license
00011 before using the library. It should be included here, or you may read it
00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl
00013 
00014 The original version of this library can be located at:
00015 http://www.sagaengine.com/
00016 
00017 Rune Myrland
00018 rune@skalden.com
00019 */
00020 
00021 
00022 #include "ThingStaticGeometry.hpp"
00023 #include "ThingMOInfo.hpp"
00024 #include "all.hpp"
00025 #include "O3dPre.hpp"
00026 #include "../config/o3d_config.hpp"
00027 #include "../schema/O3dSchema.hpp"
00028 #include "o3d/schema/O3dSchema.hpp"
00029 #include "o3d/thing/all.hpp"
00030 #include "EntityUtil.hpp"
00031 #include <OgreSceneManager.h>
00032 #include <OgreStaticGeometry.h>
00033 #include <OgreEntity.h>
00034 
00035 using namespace se_core;
00036 
00037 
00038 namespace se_ogre {
00039     ThingStaticGeometry
00040     ::ThingStaticGeometry(se_core::PosComponent& thing, const ThingMOInfo& info, const ThingMOFactory& factory)
00041         : ThingMO(thing, info, factory), entity_(0) {
00042 
00043         // Create a unique entity name
00044         char name[128];
00045         static int pool = 1000;
00046         sprintf(name, "sg-%d-%s", ++pool, thing_.name());
00047 
00048         // Create entity
00049         Ogre::MovableObject* mo = O3dSchema::sceneManager->createMovableObject(name, Ogre::EntityFactory::FACTORY_TYPE_NAME, &info_.params_);
00050         //node_->attachObject(mo);
00051         entity_ = static_cast<Ogre::Entity*>(mo);
00052         hasAnimation_ = false;
00053 
00054         try {
00055             addToStaticGeometry(name);
00056         }
00057         catch(...) {}
00058     }
00059 
00060 
00061     ThingStaticGeometry
00062     ::~ThingStaticGeometry() {
00063         O3dSchema::sceneManager->destroyMovableObject(entity_);
00064         entity_ = 0;
00065     }
00066 
00067 
00068     void ThingStaticGeometry
00069     ::addToStaticGeometry(const char* name) {
00070         const char* staticName = thing_.nextPos().area()->name();
00071         Ogre::SceneManager* sm = O3dSchema::sceneManager;
00072         staticGeometry_ = sm->getStaticGeometry(staticName);
00073 
00074         se_core::ViewPoint& nextPos = thing_.nextPos().world_;
00075         Quat4 face(nextPos.face_);
00076 
00078         Ogre::Vector3 pos(
00079             CoorT::toFloat(nextPos.coor_.x_),
00080             CoorT::toFloat(nextPos.coor_.y_),
00081             CoorT::toFloat(nextPos.coor_.z_)
00082             );
00083 
00084         Ogre::Quaternion rot(
00085             QuatT::toFloat(face.w_),
00086             QuatT::toFloat(face.x_),
00087             QuatT::toFloat(face.y_),
00088             QuatT::toFloat(face.z_)
00089             );
00090 
00091 
00092         Ogre::Real scale = info_.scale_;
00093         // If radius scales the model
00094         if(info_.doScaleByRadius_) {
00095             // Interpolate between present radius and next radius
00096             scale *= CoorT::toFloat(thing_.nextPos().radius());
00097 
00098             // If scale has changed
00099             if(scale != currentScale_) {
00100                 // Scale all children of this node
00101                 //node_->setScale(scale, scale, scale);
00102 
00103                 // Store scale for future scale change checks
00104                 currentScale_ = scale;
00105             }
00106         }
00107 
00108         Ogre::Vector3 s(scale, scale, scale);
00109         staticGeometry_->addEntity(entity_, pos, rot, s);
00110     }
00111 
00112 }

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:09 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo