roller.cpp

00001 #include "roller.h"
00002 #include "debug.h"
00003 
00004 extern Debug* dbg;
00005 
00006 using namespace irr;
00007 using namespace core;
00008 using namespace scene;
00009 using namespace video;
00010 
00011 Roller::Roller(IrrlichtDevice* d, stringc filePath, vector3df pos)
00012 : Object(d)
00013 {
00014     //ctor
00015     dbg->log("create Roller");
00016     if (!d)
00017     {
00018         dbg->log("Roller() device==NULL");
00019         return;
00020     }
00021     collisionAnimator = NULL;
00022     load(filePath);
00023     position = pos;
00024     velocity = vector3df(0, 0, 0);
00025     mesh->setPosition(pos);
00026 }
00027 
00028 Roller::~Roller()
00029 {
00030     //dtor
00031     dbg->log("Roller deleted");
00032 }
00033 
00034 void Roller::update(u32 deltaTime)
00035 {
00036     vector3df force = velocity * (deltaTime/1000.0f);
00037     position = mesh->getPosition();
00038     mesh->setPosition(position + force);
00039     device->getVideoDriver()->draw3DBox(mesh->getBoundingBox());
00040 }
00041 
00042 void Roller::addVelocity(vector3df v)
00043 {
00044     velocity += v;
00045 }
00046 
00047 void Roller::setCollisionTriangles(ITriangleSelector* world)
00048 {
00049     if (! world)
00050     {
00051         return;
00052     }
00053 
00054     if (! collisionAnimator)
00055     {
00056         setUpCollision(world);
00057     }
00058     else
00059     {
00060         collisionAnimator->setWorld(world);
00061     }
00062 }
00063 
00064 void Roller::load(stringc filePath)
00065 {
00066     ISceneManager* smgr = device->getSceneManager();
00067     mesh = smgr->addAnimatedMeshSceneNode(smgr->getMesh(filePath.c_str()) );
00068     if (mesh)
00069     {
00070         //mesh->setMaterialFlag(EMF_LIGHTING, false);
00071         mesh->setMaterialFlag(EMF_WIREFRAME, true);
00072     }
00073     else
00074     {
00075         dbg->log("Roller::load() cannot load", filePath );
00076         mesh = (IAnimatedMeshSceneNode*) smgr->addTextSceneNode(device->getGUIEnvironment()->getBuiltInFont(),
00077             L"Roller: cannot load mesh", SColor(100,255,255,255));
00078     }
00079 }
00080 
00081 void Roller::safe(stringc filePath)
00082 {
00083 
00084 }
00085 
00086 void Roller::setUpCollision(ITriangleSelector* world)
00087 {
00088     aabbox3d<f32> box = mesh->getBoundingBox();
00089     vector3df ellipsoidRadius = (box.MaxEdge - box.getCenter()) * 10.0f;
00090     vector3df gravityPerSecond = vector3df(0,-1.0f, 0);
00091     vector3df ellipsoidTranslation = vector3df(0, 0, 0);
00092     f32 slidingValue = 0.00005f;
00093 
00094     collisionAnimator = device->getSceneManager()->createCollisionResponseAnimator(world,
00095                                                                       mesh,
00096                                                                       ellipsoidRadius,
00097                                                                       gravityPerSecond,
00098                                                                       ellipsoidTranslation,
00099                                                                       slidingValue);
00100     mesh->addAnimator(collisionAnimator);
00101     collisionAnimator->drop();
00102 /*
00103     ISceneNodeAnimator* anim = device->getSceneManager()->createFlyCircleAnimator(position, 1000);
00104     mesh->addAnimator(anim);
00105     anim->drop();
00106 */
00107 }

Generated on Sun Dec 2 17:09:58 2007 for Swarm by  doxygen 1.4.6-NO