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 "O3dPre.hpp" 00023 #include "ThingMOInfo.hpp" 00024 #include "ThingImpostor.hpp" 00025 #include "../schema/O3dSchema.hpp" 00026 #include <cstdio> 00027 #include <cstring> 00028 #include <OgreSceneManager.h> 00029 #include <OgreBillboard.h> 00030 #include <OgreBillboardSet.h> 00031 00032 using namespace se_core; 00033 00034 namespace se_ogre { 00035 00036 ThingImpostor 00037 ::ThingImpostor(se_core::PosComponent& thing, const ThingMOInfo& info, const ThingMOFactory& factory) 00038 : ThingMO(thing, info, factory) { 00039 00040 const char* bbsName = thing_.pos().area()->owner()->name(); 00041 Ogre::BillboardSet* bbs = O3dSchema::sceneManager->getBillboardSet(bbsName); 00042 00043 Ogre::Vector3 pos 00044 ( 00045 CoorT::toFloat(thing_.pos().worldCoor().x_), 00046 CoorT::toFloat(thing_.pos().worldCoor().y_), 00047 CoorT::toFloat(thing_.pos().worldCoor().z_) 00048 ); 00049 billboard_ = bbs->createBillboard(pos); 00050 Ogre::Real scale = info_.scale_; 00051 if(info_.doScaleByRadius_) 00052 scale *= CoorT::toFloat(thing_.nextPos().radius()); 00053 billboard_->setDimensions( bbs->getDefaultWidth() * scale, bbs->getDefaultHeight() * scale ); 00054 currentBillboardScale_ = scale; 00055 } 00056 00057 00058 ThingImpostor 00059 ::~ThingImpostor() { 00060 const char* bbsName = thing_.pos().area()->owner()->name(); 00061 Ogre::BillboardSet* bbs = O3dSchema::sceneManager->getBillboardSet(bbsName); 00062 bbs->removeBillboard(billboard_); 00063 billboard_ = 0; 00064 } 00065 00066 00067 void ThingImpostor 00068 ::animate(long when, float stepDelta, float timeSinceLastFrame) { 00069 // Visible 00070 if(isVisible()) { 00071 billboard_->setTexcoordIndex(1); 00072 } 00073 else { 00074 // Texture 0 is transparent 00075 billboard_->setTexcoordIndex(0); 00076 } 00077 00078 // If scale has changed 00079 if(currentScale_ != currentBillboardScale_) { 00080 // Interpolate between present radius and next radius 00081 const float scale = currentScale_; 00082 00083 const char* bbsName = thing_.pos().area()->owner()->name(); 00084 Ogre::BillboardSet* bbs = O3dSchema::sceneManager->getBillboardSet(bbsName); 00085 billboard_->setDimensions( bbs->getDefaultWidth() * scale 00086 , bbs->getDefaultHeight() * scale); 00087 00088 // Store scale for future scale change checks 00089 currentBillboardScale_ = scale; 00090 } 00091 00092 } 00093 00094 00095 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:09 2007 by Doxygen version 1.3.9.1.