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 "ThingBillboard.hpp" 00025 #include "../schema/O3dSchema.hpp" 00026 #include "util/math/ScaleT.hpp" 00027 #include <cstdio> 00028 #include <cstring> 00029 #include <OgreSceneManager.h> 00030 #include <OgreBillboardSet.h> 00031 #include <OgreBillboard.h> 00032 00033 using namespace se_core; 00034 00035 namespace se_ogre { 00036 00037 ThingBillboard 00038 ::ThingBillboard(se_core::PosComponent& thing, const ThingMOInfo& info, const ThingMOFactory& factory) 00039 : ThingMO(thing, info, factory) { 00040 00041 const char* bbsName = info_.defaultMaterial_.get(); 00042 00043 Ogre::SceneManager* sm = O3dSchema::sceneManager; 00044 if(sm->hasBillboardSet(bbsName)) { 00045 billboardSet_ = sm->getBillboardSet(bbsName); 00046 } 00047 else { 00048 billboardSet_ = sm->createBillboardSet(bbsName); 00049 billboardSet_->setMaterialName(info_.defaultMaterial_.get()); 00050 billboardSet_->setUseAccurateFacing(false); 00051 billboardSet_->setPointRenderingEnabled(false); 00052 sm->getRootSceneNode()->attachObject(billboardSet_); 00053 } 00054 00055 last_ = thing.nextPos().world_; 00056 billboard_ = billboardSet_->createBillboard( 00057 CoorT::toFloat(last_.coor_.x_), 00058 CoorT::toFloat(last_.coor_.y_), 00059 CoorT::toFloat(last_.coor_.z_) 00060 ); 00061 Ogre::Real scale = info_.scale_; 00062 if(info_.doScaleByRadius_) 00063 scale *= CoorT::toFloat(thing_.nextPos().radius()); 00064 billboard_->setDimensions( scale, scale ); 00065 00066 currentBillboardScale_ = scale; 00067 00068 //billboard_->setRotation( Ogre::Radian(BrayT::toRad(last_.face_.roll_)) ); 00069 //billboardSet_->_updateBounds(); 00070 00071 hasAnimation_ = true; 00072 } 00073 00074 00075 ThingBillboard 00076 ::~ThingBillboard() { 00077 billboardSet_->removeBillboard(billboard_); 00078 billboard_ = 0; 00079 } 00080 00081 00082 void ThingBillboard 00083 ::animate(long when, float stepDelta, float timeSinceLastFrame) { 00084 // Visible 00085 /* 00086 if(isVisible()) { 00087 billboard_->setTexcoordIndex(1); 00088 } 00089 else { 00090 // Texture 0 is transparent 00091 billboard_->setTexcoordIndex(0); 00092 } 00093 */ 00094 Ogre::Real currentScale_ = info_.scale_; 00095 // If radius scales the model 00096 if(info_.doScaleByRadius_) { 00097 // Interpolate between present radius and next radius 00098 currentScale_ *= CoorT::toFloat(thing_.nextPos().radius()); 00099 } 00100 00101 // If scale has changed 00102 if(currentScale_ != currentBillboardScale_) { 00103 // Interpolate between present radius and next radius 00104 const float scale = currentScale_; 00105 00106 billboard_->setDimensions( scale, scale ); 00107 00108 // Store scale for future scale change checks 00109 currentBillboardScale_ = scale; 00110 } 00111 00112 const scale_t alpha = ScaleT::fromFloat(stepDelta); 00113 thing_.worldViewPoint(alpha, last_); 00114 billboard_->setPosition( 00115 CoorT::toFloat(last_.coor_.x_), 00116 CoorT::toFloat(last_.coor_.y_), 00117 CoorT::toFloat(last_.coor_.z_) 00118 ); 00119 00120 //billboard_->setPosition(node_->_getDerivedPosition()); 00121 //billboard_->setRotation( Ogre::Radian(BrayT::toRad(last_.face_.roll_)) ); 00122 } 00123 00124 00125 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:09 2007 by Doxygen version 1.3.9.1.