00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "LightComponent.h"
00018 #include "../../core/GameManager.h"
00019
00020
00021
00022
00023 LightComponent::LightComponent(Entity *parent, const SColorf &color, f32 radius)
00024 : SceneComponent(parent, true)
00025 {
00026
00027 ISceneManager *pSceneMgr = GameManager::Instance()->getSceneManager();
00028
00029
00030 mLightSN = pSceneMgr->addLightSceneNode(0, parent->getPosition(), color, radius,
00031 parent->getID());
00032 mSceneNode = mLightSN;
00033
00034
00035 mTriSelector = NULL;
00036 mMetaSelector = NULL;
00037 }
00038
00039
00040 LightComponent::~LightComponent()
00041 {
00042 mLightSN->remove();
00043 mSceneNode = NULL;
00044 }
00045
00046
00047 LightComponent* LightComponent::refFactory(Entity *parent)
00048 {
00049 return new LightComponent(parent);
00050 }
00051
00052
00053 LightComponent* LightComponent::refFactory(Entity *parent, const SColor &color, f32 radius)
00054 {
00055 return new LightComponent(parent, color, radius);
00056 }
00057
00058
00059 ILightSceneNode* LightComponent::getLightSceneNode()
00060 {
00061 return mLightSN;
00062 }
00063
00064
00065 bool LightComponent::getCastShadow() const
00066 {
00067 return mLightSN->getCastShadow();
00068 }
00069
00070
00071 E_LIGHT_TYPE LightComponent::getLightType() const
00072 {
00073 return mLightSN->getLightType();
00074 }
00075
00076
00077 f32 LightComponent::getRadius() const
00078 {
00079 return mLightSN->getRadius();
00080 }
00081
00082
00083 void LightComponent::setCastShadow(bool shadow)
00084 {
00085 mLightSN->enableCastShadow(shadow);
00086 }
00087
00088
00089 void LightComponent::setLightType(E_LIGHT_TYPE type)
00090 {
00091 mLightSN->setLightType(type);
00092 }
00093
00094
00095 void LightComponent::setRadius(f32 radius)
00096 {
00097 mLightSN->setRadius(radius);
00098 }
00099
00100
00101
00102 void bindLightComponent(asIScriptEngine *engine)
00103 {
00104
00105 int r;
00106
00107
00108 r = engine->RegisterObjectType("LightComponent", sizeof(LightComponent), asOBJ_REF); assert(r >= 0);
00109
00110
00111 bindSceneComponentBase<LightComponent>(engine, "LightComponent");
00112
00113
00114 r = engine->RegisterObjectBehaviour("LightComponent", asBEHAVE_FACTORY, "LightComponent@ f(Entity @)",
00115 asFUNCTIONPR(LightComponent::refFactory, (Entity*), LightComponent*),
00116 asCALL_CDECL); assert(r >= 0);
00117 r = engine->RegisterObjectBehaviour("LightComponent", asBEHAVE_FACTORY, "LightComponent@ f(Entity @, " \
00118 "const SColor&in, f32)",asFUNCTIONPR(LightComponent::refFactory,
00119 (Entity*, const SColor &color, f32), LightComponent*), asCALL_CDECL);
00120 assert(r >= 0);
00121
00122
00123 r = engine->RegisterObjectMethod("LightComponent", "bool getCastShadow()",
00124 asMETHOD(LightComponent, getCastShadow), asCALL_THISCALL); assert(r >= 0);
00125 r = engine->RegisterObjectMethod("LightComponent", "E_LIGHT_TYPE getLightType()",
00126 asMETHOD(LightComponent, getLightType), asCALL_THISCALL); assert(r >= 0);
00127 r = engine->RegisterObjectMethod("LightComponent", "f32 getRadius()",
00128 asMETHOD(LightComponent, getRadius), asCALL_THISCALL); assert(r >= 0);
00129
00130 r = engine->RegisterObjectMethod("LightComponent", "void setCastShadow(bool)",
00131 asMETHOD(LightComponent, setCastShadow), asCALL_THISCALL); assert(r >= 0);
00132 r = engine->RegisterObjectMethod("LightComponent", "void setLightType(E_LIGHT_TYPE)",
00133 asMETHOD(LightComponent, setLightType), asCALL_THISCALL); assert(r >= 0);
00134 r = engine->RegisterObjectMethod("LightComponent", "void setRadius(f32)",
00135 asMETHOD(LightComponent, setRadius), asCALL_THISCALL); assert(r >= 0);
00136 }
00137
00138