Plane problem (simple 3d rotation formula)

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
scarface
Posts: 5
Joined: Sun Jun 11, 2006 7:34 am

Plane problem (simple 3d rotation formula)

Post by scarface »

I'm working for a plane game, it's my first 3d project.

My code has some problems I couldn't figure out. When I rotate to right and go back to the beginning point it doesn't stop moving. I found this function to rotate, but if you have a better or simpler one, please share.

Thanks very much.

Code: Select all

class Player
{
    float xv, yv, zv, rotx, roty, rotz, rotxs, rotys, rotzs;
    scene::IAnimatedMeshSceneNode* player;
    public:
    float x, y, z;
    Player(scene::ISceneManager* smgr,video::IVideoDriver* driver, int x, int y, int z)
        {
    this->x=x;this->y=y;this->z=z;
    xv=9, yv=0, zv=0;//velocity
    rotx=0,roty=0,rotz=0;//rotation variables
    rotxs=18, rotys=0, rotzs=0;//step 10°
    player = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../../media/ship.x"));//f16.x
    player->setScale(core::vector3df(0.5,0.5f,0.5));
    player->setMaterialTexture(5, driver->getTexture("../../media/ship.jpg"));
    player->setMaterialFlag(video::EMF_LIGHTING, false);
    player->setPosition(core::vector3df(x,y,z));
    player->setRotation(core::vector3df(rotx+270,roty,rotz+180));//Normal=-90,180,0
        }void Control()
    {
        if(Go_Down>0){yv+=0.1;Go_Down=0;}
        if(Go_Up>0){yv-=0.1;Go_Up=0;}
        if(Go_Left>0){if(rotx>-90){rotx-=10;roty+=10;}Go_Left=0;rotxs--;}
        if(Go_Right>0){if(rotx<90){rotx+=10;roty-=10;}Go_Right=0;rotxs++;}

        if(rotxs>-1&&rotxs<10){zv=9-rotxs;xr=9-zv;}
        if(rotxs>9&&rotxs<19){zv=18-rotxs;xv=9-zv;}
        if(rotxs>18&&rotxs<28){zv=27-rotxs;xv=9-zv;}
        if(rotxs>27&&rotxs<37){zv=36-rotxs;xv=9-zv;}
        if(rotxs==-1){rotxs=36;zv=36-rotxs;xv=9-zv;}
        if(rotxs==37){rotxs=1;zv=9-rotxs;xv=9-zv;}
    }
    void Update()
    {
        x+=-xv/5;y+=yv/5;z+=zv/5;//10 out
        player->setPosition(core::vector3df(x,y,z));
        player->setRotation(core::vector3df(rotx,roty,rotz));
    }}
Post Reply