00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __SCENECOMPONENT_H__
00017 #define __SCENECOMPONENT_H__
00018
00019
00020 #include "../../dependencies.h"
00021 #include "../../core/EntityComponent.h"
00022
00023
00024
00026 class SceneComponent : public EntityComponent
00027 {
00028 public:
00029
00030
00032 SceneComponent(Entity *parent);
00034 ~SceneComponent();
00035
00036
00039 static SceneComponent* refFactory(Entity *parent);
00040
00041
00044 ISceneNode* getSceneNode();
00047 IMetaTriangleSelector* getMetaSelector() const;
00050 ITriangleSelector* getTriangleSelector() const;
00051
00055 void addAnimator(ISceneNodeAnimator *animator);
00056
00068 void addCollisionResponseAnimator(const vector3df &ellipsoidRadius = vector3df(30, 60, 30),
00069 const vector3df &gravityPerSecond = vector3df(0, -10, 0),
00070 const vector3df &ellipsoidTranslation = vector3df(0, 0, 0),
00071 f32 slidingValue = 0.0005f);
00072
00079 void addFlyCircleAnimator(const vector3df ¢er = vector3df(0, 0, 0), f32 radius = 100,
00080 f32 speed = 0.001f, const vector3df &direction = vector3df(0, 0, 0));
00081
00090 void addFlyStraightAnimator(const vector3df &startPoint, const vector3df &endPoint,
00091 u32 timeForWay, bool loop = false);
00092
00096 void addToMetaSelector(Entity *entity);
00100 void addToMetaSelector(SceneComponent *component);
00104 void addToMetaSelector(ITriangleSelector *selector);
00105
00107 vector3df getAbsolutePosition() const;
00109 E_CULLING_TYPE getAutomaticCulling() const;
00111 virtual const aabbox3df& getBoundingBox() const;
00113 u32 getMaterialCount() const;
00115 matrix4 getRelativeTransformation() const;
00117 const vector3df getPosition() const;
00119 const vector3df& getRotation() const;
00121 const vector3df& getScale() const;
00122
00124 void removeAnimators();
00125
00128 void setAbsolutePosition(const vector3df &position);
00131 void setAutomaticCulling(E_CULLING_TYPE state);
00137 void setCanAffectParent(bool value);
00140 void setDebugDataVisible(s32 state);
00144 void setMaterialFlag(E_MATERIAL_FLAG flag, bool value);
00149 void setMaterialTexture(u32 layer, const std::string &fileName);
00155 void setMaterialTexture(u32 layer, ITexture *texture);
00158 void setMaterialType(E_MATERIAL_TYPE type);
00161 void setPosition(const vector3df &position);
00164 void setRotation(const vector3df &rotation);
00167 void setScale(const vector3df &scale);
00170 void setVisible(bool value);
00171
00172
00175 void onPositionChange(void *p);
00178 void onUpdate(void *p);
00181 void onPause(void *p);
00184 void onUnPause(void *p);
00185
00186 protected:
00187
00188
00190 SceneComponent(Entity *parent, bool isDerived);
00191
00192
00193 ISceneNode *mSceneNode;
00194 IMetaTriangleSelector *mMetaSelector;
00195 ITriangleSelector *mTriSelector;
00196
00197 private:
00198
00199
00200 vector3df mLastPos;
00201 bool mCanAffectParent;
00202
00203 bool mEvokedParentChange;
00204 bool mWasVisible;
00205 };
00206
00207
00208
00210 extern void bindSceneComponent(asIScriptEngine *engine);
00211
00212
00215 template<typename T>
00216 void bindSceneComponentBase(asIScriptEngine *engine, const char *type)
00217 {
00218
00219 int r;
00220 std::string sType = type;
00221
00222
00223 bindEntityComponentBase<SceneComponent>(engine, type);
00224
00225
00226 r = engine->RegisterGlobalBehaviour(asBEHAVE_REF_CAST, std::string(sType + "@ f(SceneComponent @)").c_str(),
00227 asFUNCTION((asRefCast<SceneComponent,T>)), asCALL_CDECL); assert( r >= 0 );
00228 r = engine->RegisterGlobalBehaviour(asBEHAVE_IMPLICIT_REF_CAST, std::string("SceneComponent@ f(" + sType +" @)").c_str(),
00229 asFUNCTION((asRefCast<T,SceneComponent>)), asCALL_CDECL); assert( r >= 0 );
00230
00231
00232 r = engine->RegisterObjectMethod(type, "void addCollisionResponseAnimator(const vector3df &in, " \
00233 "const vector3df &in, const vector3df &in, f32)",
00234 asMETHOD(T, addCollisionResponseAnimator), asCALL_THISCALL); assert(r >= 0);
00235 r = engine->RegisterObjectMethod(type, "void addFlyCircleAnimator(const vector3df &in, f32, " \
00236 "f32, const vector3df &in)",
00237 asMETHOD(T, addFlyCircleAnimator), asCALL_THISCALL); assert(r >= 0);
00238 r = engine->RegisterObjectMethod(type, "void addFlyStraightAnimator(const vector3df &in, " \
00239 "const vector3df &in, u32, bool)",
00240 asMETHOD(T, addFlyStraightAnimator), asCALL_THISCALL); assert(r >= 0);
00241
00242 r = engine->RegisterObjectMethod(type, "void addToMetaSelector(Entity@)",
00243 asMETHODPR(T, addToMetaSelector, (Entity*), void), asCALL_THISCALL); assert(r >= 0);
00244 r = engine->RegisterObjectMethod(type, "void addToMetaSelector(SceneComponent@)",
00245 asMETHODPR(T, addToMetaSelector, (SceneComponent*), void), asCALL_THISCALL); assert(r >= 0);
00246
00247 r = engine->RegisterObjectMethod(type, "const vector3df& getAbsolutePosition()",
00248 asMETHOD(T, getAbsolutePosition), asCALL_THISCALL); assert(r >= 0);
00249 r = engine->RegisterObjectMethod(type, "E_CULLING_TYPE getAutomaticCulling()",
00250 asMETHOD(T, getAutomaticCulling), asCALL_THISCALL); assert(r >= 0);
00251 r = engine->RegisterObjectMethod(type, "const aabbox3df& getBoundingBox()",
00252 asMETHODPR(T, getBoundingBox, (void) const, const aabbox3df&), asCALL_THISCALL); assert(r >= 0);
00253 r = engine->RegisterObjectMethod(type, "u32 getMaterialCount()",
00254 asMETHOD(T, getMaterialCount), asCALL_THISCALL); assert(r >= 0);
00255 r = engine->RegisterObjectMethod(type, "const matrix4& getRelativeTransformation()",
00256 asMETHOD(T, getRelativeTransformation), asCALL_THISCALL); assert(r >= 0);
00257 r = engine->RegisterObjectMethod(type, "const vector3df& getPosition()",
00258 asMETHOD(T, getPosition), asCALL_THISCALL); assert(r >= 0);
00259 r = engine->RegisterObjectMethod(type, "const vector3df& getRotation()",
00260 asMETHOD(T, getRotation), asCALL_THISCALL); assert(r >= 0);
00261 r = engine->RegisterObjectMethod(type, "const vector3df& getScale()",
00262 asMETHOD(T, getScale), asCALL_THISCALL); assert(r >= 0);
00263
00264 r = engine->RegisterObjectMethod(type, "void removeAnimators()",
00265 asMETHOD(T, removeAnimators), asCALL_THISCALL); assert(r >= 0);
00266
00267 r = engine->RegisterObjectMethod(type, "void setAbsolutePosition(const vector3df &in)",
00268 asMETHOD(T, setAbsolutePosition), asCALL_THISCALL); assert(r >= 0);
00269 r = engine->RegisterObjectMethod(type, "void setAutomaticCulling(E_CULLING_TYPE)",
00270 asMETHOD(T, setAutomaticCulling), asCALL_THISCALL); assert(r >= 0);
00271 r = engine->RegisterObjectMethod(type, "void setCanAffectParent(bool)",
00272 asMETHOD(T, setCanAffectParent), asCALL_THISCALL); assert(r >= 0);
00273 r = engine->RegisterObjectMethod(type, "void setDebugDataVisible(s32)",
00274 asMETHOD(T, setDebugDataVisible), asCALL_THISCALL); assert(r >= 0);
00275 r = engine->RegisterObjectMethod(type, "void setMaterialFlag(E_MATERIAL_FLAG, bool)",
00276 asMETHOD(T, setMaterialFlag), asCALL_THISCALL); assert(r >= 0);
00277 r = engine->RegisterObjectMethod(type, "void setMaterialTexture(u32, const string &)",
00278 asMETHODPR(T, setMaterialTexture, (u32 layer, const std::string &fileName), void),
00279 asCALL_THISCALL); assert(r >= 0);
00280 r = engine->RegisterObjectMethod(type, "void setMaterialType(E_MATERIAL_TYPE)",
00281 asMETHOD(T, setMaterialType), asCALL_THISCALL); assert(r >= 0);
00282 r = engine->RegisterObjectMethod(type, "void setPosition(const vector3df &in)",
00283 asMETHOD(T, setPosition), asCALL_THISCALL); assert(r >= 0);
00284 r = engine->RegisterObjectMethod(type, "void setRotation(const vector3df &in)",
00285 asMETHOD(T, setRotation), asCALL_THISCALL); assert(r >= 0);
00286 r = engine->RegisterObjectMethod(type, "void setScale(const vector3df &in)",
00287 asMETHOD(T, setScale), asCALL_THISCALL); assert(r >= 0);
00288 r = engine->RegisterObjectMethod(type, "void setVisible(bool)",
00289 asMETHOD(T, setVisible), asCALL_THISCALL); assert(r >= 0);
00290 }
00291
00292 #endif