Problem with Physics

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
zapada
Posts: 4
Joined: Mon Oct 29, 2012 10:09 am

Problem with Physics

Post by zapada »

I made this but sydney is not affected by the gravity or any command (like impulse, force) and i don't know if it's correct what i wrote in the code
I was read exemples files(H and C++) files until now, but i can't make the "follow" the gravity :(

Code: Select all

void main()
{
    MyEventExample receiver;
    IrrlichtDevice* device = createDevice(EDT_OPENGL,dimension2d<u32>(800,600),32,false,false,false,&receiver);
    ISceneManager* smgr = device->getSceneManager();
    IVideoDriver* driver = device->getVideoDriver();
    //smgr->addLightSceneNode(0,vector3df(0,0,0),SColor(1,1,1,1),1000,-1);
    smgr->addLightSceneNode(0,vector3df(200,80,100 ), SColorf(1.0f, 1.0f, 1.0f), 4000.0f);
 
    //int rows = 10;
    //int colums = 10;
 
    irrBulletWorld* world = createIrrBulletWorld(device,true,true);
    ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
 
    //double amprenta = device->getTimer()->getTime();
    //u32 myTime = device->getTimer()->getTime();
 
    IAnimatedMesh* sid = smgr->getMesh("media/sydney.md2");
    ISceneNode* sidney = smgr->addAnimatedMeshSceneNode(sid);
    sidney->setMaterialTexture(0,driver->getTexture("sydney.bmp"));
    sidney->setPosition(vector3df(600,32,100));
 
 
 
    ISceneNode* ground = smgr->addCubeSceneNode(1);
    ground->setMaterialTexture(0,driver->getTexture("media/terrain.jpg"));
    ground->setScale(vector3df(600,32,200));
    ground->setPosition(vector3df(200,0,100));
    ground->setMaterialFlag(EMF_LIGHTING,true);
    ground->setMaterialFlag(EMF_NORMALIZE_NORMALS,true);
 
    camera->setPosition(vector3df(600,40,-200));
 
    ICollisionShape* groundShape =new IBoxShape(ground,0,false);
    ICollisionShape* sidneyShape = new IBoxShape(sidney,0,false);
 
    IRigidBody* groundRigid;
    IRigidBody* sidneyRigid;
 
    groundRigid = world->addRigidBody(groundShape);
    sidneyRigid = world->addRigidBody(sidneyShape);
    world->setGravity(vector3df(0,-10,0));
 
 
 
    u32 TimeStamp = device->getTimer()->getTime();
    u32 DeltaTime = 0;
 
    u32 force = rand() % 40 + 20;
    //static_cast<IRigidBody*>(world->getCollisionObjectByIndex(world->getNumCollisionObjects()-1))->setLinearVelocity(vector3df(0,0,force));
 
 
    while(device->run()) {
        
        driver->beginScene(true,true,SColor(1,0,0,0));
        smgr->drawAll();
        sidneyRigid->applyGravity();
        DeltaTime = device->getTimer()->getTime() - TimeStamp;
        TimeStamp = device->getTimer()->getTime();
        world->stepSimulation(DeltaTime*0.001f, 120);
        driver->endScene();
 
    }
    device->drop();
    return;
}
serengeor
Posts: 1712
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Problem with Physics

Post by serengeor »

Your both objects have 0 mass, how are they supposed to move?
Working on game: Marrbles (Currently stopped).
Post Reply