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 "PosComponent.hpp" 00023 #include "../thing/Actor.hpp" 00024 #include "../config/all.hpp" 00025 #include "../area/Area.hpp" 00026 #include "util/error/Log.hpp" 00027 #include <cstring> 00028 00029 00030 namespace se_core { 00031 00032 PosComponent 00033 ::PosComponent(Composite* owner) 00034 : Component(sct_POS, owner) 00035 , didMove_(false) { 00036 } 00037 00038 00039 PosComponent 00040 ::~PosComponent() { 00041 } 00042 00043 00044 void PosComponent 00045 ::flip() { 00046 if(position_.parent() != nextPosition_.parent()) { 00047 changeParent(); 00048 } 00049 if(position_.area() != nextPosition_.area()) { 00050 Composite* to = 0; 00051 if(nextPosition_.hasArea()) { 00052 to = nextPosition_.area_->owner(); 00053 } 00054 Composite* from = 0; 00055 if(position_.hasArea()) { 00056 from = position_.area_->owner(); 00057 } 00058 owner()->zoneChanged(st_AREA, to, from); 00059 } 00060 position_.setPos(nextPosition_); 00061 } 00062 00063 00064 void PosComponent 00065 ::updateWorldViewPoint() { 00066 nextPosition_.world_.setViewPoint(nextPosition_.local_); 00067 if(nextPos().hasParent()) { 00068 nextPosition_.world_.add( nextPos().parent()->nextPos().world_ ); 00069 } 00070 } 00071 00072 00073 void PosComponent 00074 ::worldCoor(scale_t alpha, Point3& dest) const { 00075 dest.set(position_.worldCoor()); 00076 dest.interpolate(nextPosition_.worldCoor(), alpha); 00077 } 00078 00079 00080 void PosComponent 00081 ::worldViewPoint(scale_t alpha, ViewPoint& dest) const { 00082 dest.setViewPoint(position_.world_); 00083 dest.coor_.interpolate(nextPosition_.worldCoor(), alpha); 00084 dest.face_.interpolate(nextPosition_.worldFace(), alpha); 00085 } 00086 00087 00088 void PosComponent 00089 ::leaveCurrentParent() { 00090 if(position_.hasParent()) { 00091 owner_->resetParent(); 00092 } 00093 } 00094 00095 00096 void PosComponent 00097 ::cleanup() { 00098 leaveCurrentParent(); 00099 nextPos().resetArea(); 00100 flip(); 00101 } 00102 00103 00104 bool PosComponent 00105 ::changeParent() { 00106 if(nextPos().hasParent()) { 00107 owner_->setParent(*nextPos().parent()->owner()); 00108 owner_->setActive(nextPos().parent()->isActive()); 00109 } 00110 else { 00111 owner_->resetParent(); 00112 owner_->setActive(false); 00113 return false; 00114 } 00115 return true; 00116 } 00117 00118 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.