【问题标题】:Collision Avoidance using ogre3 on visual 2010在视觉 2010 上使用 ogre3 避免碰撞
【发布时间】:2017-04-14 20:46:38
【问题描述】:

我使用 ogre3d 和 visual 2010,我在实现两个机器人并排行走时避免碰撞的问题,我想要:第一个机器人停下来,然后第一个机器人继续行走。

【问题讨论】:

  • 第一步:过马路前用iPad抬头看左右....
  • 你是机器人中的一员吗?
  • 不,我的意思是,我想让机器人停下 2 秒钟然后他继续走

标签: c++ ogre3d


【解决方案1】:

使用 Ogre 最简单的方法是检查实体的轴对齐边界框之间的交集。

例如:

  Ogre::Entity *robot1(NULL), *robot2(NULL);
  Ogre::AnimationState* move_anim(NULL);
  Ogre::Real stop_t_s(0.0f);

  void app::init() {
    robot1 = scene_mgr_->createEntity("robot.mesh");
    robot2 = scene_mgr_->createEntity("robot.mesh");
    move_anim = robot1->getAnimationState("Walk");
    move_anim->setLoop(true);
    move_anim->setEnabled(true);
    root_->startRendering();
  }
  void app::frameRenderingQueued(const Ogre::FrameEvent& evt) {
    if (move_anim->getEnabled()) {
      move_anim->addTime(evt.timeSinceLastFrame);
    }
    else {
      stop_t_s += evt.timeSinceLastFrame;
      if (stop_t_s > 2.0f) {
        move_anim->setEnabled(true);
        stop_t_s = 0.0f;
      }
    }
    if (robot1->getBoundingBox().intersects(robot2->getBoundingBox())) {
      move_anim->setEnabled(false);
      /* more collide routine */
    }
    else {
      /* normal routine */
    }
  }

如果你想要更精确的碰撞形状,你应该考虑使用物理引擎来处理它


更新:我添加了一个示例,用于在碰撞时停止 robot.mesh 中的 "Walk" 动画并在 2 秒后重新启动它。更多动画控制见Ogre Intermediate Tutorial 1

【讨论】:

  • 我的问题是如何让机器人停下来 2 秒然后走
  • 我明白了。下次更好地澄清问题;)我将根据相应的ogre tutorial将其添加到我的答案中
猜你喜欢
  • 2012-07-18
  • 2014-07-03
  • 2012-11-27
  • 1970-01-01
  • 1970-01-01
  • 2019-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多