zoukankan      html  css  js  c++  java
  • [转](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.
  • 相关阅读:
    项目构建之maven篇:2.HelloWorld项目构建过程
    求最大子段和的一些算法
    多线程编程(四)--线程同步
    SICP 解题集 — SICP 解题集
    函数式编程很难,这正是你要学习它的原因 | 外刊IT评论网
    haskell,lisp,erlang你们更喜欢哪个?
    欧舒丹 L'Occitane 活力清泉保湿面霜
    段子
    宽带中国战略_百度百科
    brutal是什么意思_brutal在线翻译_英语_读音_用法_例句_海词词典
  • 原文地址:https://www.cnblogs.com/flysnow/p/457831.html
Copyright © 2011-2022 走看看