ThingDebug.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 "ThingDebug.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/area/O3dManager.hpp"
00030 #include "o3d/thing/all.hpp"
00031 #include "EntityUtil.hpp"
00032 #include <OgreSceneManager.h>
00033 #include <OgreEntity.h>
00034 
00035 
00036 using namespace se_core;
00037 
00038 
00039 namespace se_ogre {
00040     ThingDebug
00041     ::ThingDebug(se_core::PosComponent& thing, const ThingMOInfo& info, const ThingMOFactory& factory)
00042         : ThingMO(thing, info, factory), entity_(0) {
00043 
00044         // Create a unique entity name
00045         char name[128];
00046         static int pool = 1000;
00047         sprintf(name, "%d-debug-%s", ++pool, thing_.name());
00048 
00049         // Create entity
00050         entity_ = O3dSchema::sceneManager->createEntity(name, "cylinder.mesh");
00051         node_->attachObject(entity_);
00052         entity_->setNormaliseNormals(true);
00053         entity_->setCastShadows(false);
00054 
00055         // Get default material, if one
00056         //const char* material = info_.defaultMaterial_.get();
00057         // If material is defined (default or special), set it
00058         //if(material) {
00059         //  setMaterial(material);
00060         //}
00061 
00062         hasAnimation_ = true;
00063     }
00064 
00065 
00066     ThingDebug
00067     ::~ThingDebug() {
00068         if(O3dSchema::sceneManager)
00069             O3dSchema::sceneManager->destroyMovableObject(entity_);
00070         entity_ = 0;
00071     }
00072 
00073 
00074     void ThingDebug
00075     ::setMaterial(const char* material) {
00076         entity_->setMaterialName(material);
00077     }
00078 
00079 
00080     void ThingDebug
00081     ::animate(long when, float stepDelta, float timeSinceLastFrame) {
00082         bool shouldShow = thing_.isActive() && O3dSchema::worldManager->isShowingDebugInfo();
00083         if(shouldShow != isVisible()) {
00084             setVisible(shouldShow);
00085         }
00086         if(!isVisible())
00087             return;
00088 
00089         // Interpolate between present radius and next radius
00090         BoundingBox& b = thing_.nextPos().bounds_;
00091         Point3 center;
00092         b.center(center);
00093         //center.add(thing_.nextPos().worldCoor());
00094 
00096         Ogre::Vector3 nextPos
00097             (
00098                 CoorT::toFloat(center.x_),
00099                 CoorT::toFloat(b.minY_),
00100                 CoorT::toFloat(center.z_)
00101              );
00102 
00103         Ogre::Vector3 s;
00104         s.x = CoorT::half(b.maxX_ - b.minX_);
00105         s.y = b.maxY_ - b.minY_;
00106         s.z = CoorT::half(b.maxZ_ - b.minZ_);
00107 
00108 
00109         // Scale all children of this node
00110         node_->setPosition(nextPos);
00111         node_->setScale(s);
00112     }
00113 
00114 
00115 }

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