00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "BillboardComponent.h"
00018 #include "../../core/GameManager.h"
00019
00020
00021
00022
00023 BillboardComponent::BillboardComponent(Entity *parent, const dimension2df &size,
00024 const SColor &colorTop, const SColor &colorBottom)
00025 : SceneComponent(parent, true)
00026 {
00027 if(pParent != NULL)
00028 {
00029
00030 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00031
00032
00033 mBillboardSN = pSceneMgr->addBillboardSceneNode(0, size, parent->getAbsolutePosition(),
00034 parent->getID(), colorTop, colorBottom);
00035 mSceneNode = mBillboardSN;
00036
00037
00038 mTriSelector = pSceneMgr->createTriangleSelectorFromBoundingBox(mBillboardSN);
00039 mMetaSelector = pSceneMgr->createMetaTriangleSelector();
00040 }
00041 }
00042
00043
00044 BillboardComponent::BillboardComponent(Entity *parent, bool isDerived)
00045 : SceneComponent(parent, true)
00046 {
00047 }
00048
00049
00050 BillboardComponent::~BillboardComponent()
00051 {
00052 if(pParent != NULL)
00053 {
00054 if(mBillboardSN != NULL)
00055 {
00056 mBillboardSN->remove();
00057 mSceneNode = NULL;
00058 }
00059 }
00060 }
00061
00062
00063 IBillboardSceneNode* BillboardComponent::getBillboardSceneNode()
00064 {
00065 return mBillboardSN;
00066 }
00067
00068
00069 void BillboardComponent::getColor(SColor &topColor, SColor &bottomColor) const
00070 {
00071 mBillboardSN->getColor(topColor, bottomColor);
00072 }
00073
00074
00075 const dimension2df& BillboardComponent::getSize() const
00076 {
00077 return mBillboardSN->getSize();
00078 }
00079
00080
00081 void BillboardComponent::setColor(const SColor &overallColor)
00082 {
00083 mBillboardSN->setColor(overallColor);
00084 }
00085
00086
00087 void BillboardComponent::setColor(const SColor &topColor, const SColor &bottomColor)
00088 {
00089 mBillboardSN->setColor(topColor, bottomColor);
00090 }
00091
00092
00093 void BillboardComponent::setSize(const dimension2df &size)
00094 {
00095 mBillboardSN->setSize(size);
00096 }
00097
00098
00099 bool BillboardComponent::parseXML(IXMLReader *file, Entity *entity)
00100 {
00101
00102 BillboardComponent *component = NULL;
00103
00104
00105 if(file->getNodeType() == io::EXN_ELEMENT)
00106 {
00107 if(stringw("BillboardComponent") == file->getNodeName())
00108 {
00109
00110 component = new BillboardComponent(entity);
00111 }
00112 }
00113
00114 if(component == NULL)
00115 return false;
00116
00117
00118 while(file->read())
00119 {
00120 switch(file->getNodeType())
00121 {
00122 case io::EXN_ELEMENT:
00123
00124
00125 if(!BillboardComponent::parseBaseXML(file, component))
00126 SceneComponent::parseBaseXML(file, component);
00127
00128 break;
00129
00130 case io::EXN_ELEMENT_END:
00131
00132
00133 if(stringw("BillboardComponent") == file->getNodeName())
00134 return true;
00135
00136 break;
00137
00138 default:
00139
00140 break;
00141 }
00142
00143 }
00144
00145
00146 return false;
00147 }
00148
00149
00150 bool BillboardComponent::parseBaseXML(IXMLReader *file, BillboardComponent *component)
00151 {
00152
00153 if(stringw("color") == file->getNodeName())
00154 {
00155 if(stringw("") != file->getAttributeValue(L"overallR"))
00156 {
00157 component->setColor( SColor( file->getAttributeValueAsInt(L"overallA"),
00158 file->getAttributeValueAsInt(L"overallR"),
00159 file->getAttributeValueAsInt(L"overallG"),
00160 file->getAttributeValueAsInt(L"overallB") ) );
00161
00162 return true;
00163 }
00164
00165 else
00166 {
00167 component->setColor( SColor( file->getAttributeValueAsInt(L"topA"),
00168 file->getAttributeValueAsInt(L"topR"),
00169 file->getAttributeValueAsInt(L"topG"),
00170 file->getAttributeValueAsInt(L"topB") ),
00171 SColor( file->getAttributeValueAsInt(L"bottomA"),
00172 file->getAttributeValueAsInt(L"bottomR"),
00173 file->getAttributeValueAsInt(L"bottomG"),
00174 file->getAttributeValueAsInt(L"bottomB") ) );
00175
00176 return true;
00177 }
00178 }
00179
00180
00181 else if(stringw("size") == file->getNodeName())
00182 {
00183 component->setSize(dimension2df( file->getAttributeValueAsFloat(L"width"),
00184 file->getAttributeValueAsFloat(L"height") ) );
00185
00186 return true;
00187 }
00188
00189
00190 return false;
00191 }
00192
00193