• [转](C++) How to animate and move an entity


    [http://irrlicht.sourceforge.net/phpBB2/viewtopic.php?t=12238]
     
    So far my contributions for this community had been rather miserable, so I decided it's time to make up for it by posting piece of code from my own test application. Maybe it's not as decent as I would like it to be, but I nonetheless decided to share it with you. It's a method for moving an entity through the scenery, setting appropiate animation loop and detecting whether it collides with the scenery or not. The method itself goes like this:
    Code:
    void Character::Walk(float speed, ISceneCollisionManager* colmanger, ITriangleSelector* selector)
    {
       core::vector3df OriginalPosition;
       core::vector3df TranslationVector;
       core::triangle3df triout;

       bool isfalling = true; //set it to "false" if you want the gravity off
     
       OriginalPosition=this->position;
       TranslationVector.X=((float)(cos(this->heading*PI/180))*speed);
       TranslationVector.Z=-((float)(sin(this->heading*PI/180))*speed);
       this->position = colmanger->getCollisionResultPosition(selector, OriginalPosition, vector3df(10,50,10), TranslationVector, triout, isfalling, 10);
       this->model->setPosition(position);
       if (this->state!=STATE_WALK)
       {
          this->state=STATE_WALK;
          this->model->setMD2Animation("run");
          this->model->setLoopMode(true);
       }


    "This" refers to character type object. "State" is an integer value that indicates in what state the entity is at the moment. For now I've only defined two states, namely STATE_WALK the character is in when walking and STATE_STAND the character type object is in when it's not moving. "Model" is an Irrlicht scene node representing the entity. For stopping characters' movement, I'm using this method:
    Code:
    void Character::Stop()
    {
       this->state=STATE_STAND;
       this->model->setMD2Animation("stand");
    }

    I hope this post will be of some help to newcomers who want to create their own Irrlicht-based 3-person type game without resorting to external libraries (like Newton) but don't know where to start.

    以上主要是调用ISceneCollisionManager::getCollisionResultPosition来得到人物与3d world碰撞后的新position。
    This can be used for moving a character in a 3d world: The character will slide at walls and is able to walk up stairs.
  • 相关阅读:
    路径问题
    移动端推荐使用
    js获取各种宽高方法
    html 符号大全
    bzoj4923 K小值查询
    bzoj3781 小B的询问
    bzoj1799 [Ahoi2009]self 同类分布
    bzoj2005 [Noi2010]能量采集
    bzoj4039 集会
    bzoj2516 电梯
  • 原文地址:https://www.cnblogs.com/flysnow/p/457831.html
Copyright © 2020-2023  润新知