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