当前位置: 首页>>代码示例>>C++>>正文


C++ Motion::resolveCollision方法代码示例

本文整理汇总了C++中Motion::resolveCollision方法的典型用法代码示例。如果您正苦于以下问题:C++ Motion::resolveCollision方法的具体用法?C++ Motion::resolveCollision怎么用?C++ Motion::resolveCollision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Motion的用法示例。


在下文中一共展示了Motion::resolveCollision方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    TypeNode type("test_type");
    Entity tlve("0", 0), ent("1", 1), other("2", 2);

    ent.m_location.m_loc = &tlve;
    ent.m_location.m_pos = Point3D(1, 1, 0);
    ent.m_location.m_velocity = Vector3D(1,0,0);
    ent.setType(&type);

    // Set up another entity to test collisions with.
    other.m_location.m_loc = &tlve;
    other.m_location.m_pos = Point3D(10, 0, 0);
    other.setType(&type);

    tlve.m_contains = new LocatedEntitySet;
    tlve.m_contains->insert(&ent);
    tlve.m_contains->insert(&other);
    tlve.setType(&type);
    tlve.incRef();
    tlve.incRef();

    Motion * motion = new Motion(ent);

    std::string example_mode("walking");

    motion->setMode(example_mode);
    assert(motion->mode() == example_mode);

    motion->adjustPostion();

    motion->genUpdateOperation();

    motion->genMoveOperation();

    // No collisions yet
    motion->checkCollisions();
    assert(!motion->collision());

    // Set up our moving entity with a bbox so collisions can be checked for.
    ent.m_location.m_bBox = BBox(Point3D(-1,-1,-1), Point3D(1,1,1));

    // No collision yet, as other still has no big box
    motion->checkCollisions();
    assert(!motion->collision());

    // Set up the other entity with a bbox so collisions can be checked for.
    other.m_location.m_bBox = BBox(Point3D(-1,-1,-1), Point3D(5,1,1));

    // No collision yet, as other is still too far away
    motion->checkCollisions();
    assert(!motion->collision());

    // Move it closer
    other.m_location.m_pos = Point3D(3, 0, 0);

    // Now it can collide
    motion->checkCollisions();
    assert(motion->collision());
    motion->resolveCollision();

    // Put the velocity back, as it was affected by the collision
    ent.m_location.m_velocity = Vector3D(1,0,0);

    // Set up the collision again
    motion->checkCollisions();
    assert(motion->collision());
    // But this time break the hierarchy to hit the error message
    other.m_location.m_loc = &ent;

    motion->resolveCollision();

    // Repair the hierarchy, and restore the velocity
    other.m_location.m_loc = &tlve;
    ent.m_location.m_velocity = Vector3D(1,0,0);

    // Set up the collision again
    motion->checkCollisions();
    assert(motion->collision());

    // Re-align the velocity so some is preserved by the collision normal
    ent.m_location.m_velocity = Vector3D(1,1,0);

    motion->resolveCollision();

    // Put the velocity back, as it was affected by the collision
    ent.m_location.m_velocity = Vector3D(1,0,0);

    // Add another entity inside other
    Entity inner("3", 3);

    inner.m_location.m_loc = &other;
    inner.m_location.m_pos = Point3D(0,0,0);

    other.m_contains = new LocatedEntitySet;
    other.m_contains->insert(&inner);
    // Make other non-simple so that collision checks go inside
    other.m_location.setSimple(false);

    motion->checkCollisions();
//.........这里部分代码省略.........
开发者ID:anthonypesce,项目名称:cyphesis,代码行数:101,代码来源:Motiontest.cpp


注:本文中的Motion::resolveCollision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。