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


C++ Proxy::translate方法代码示例

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


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

示例1: main

int main() {
    WorldParameters parameters;
    parameters.setWorldMinMax(Vector3(-1000, -1000, -1000), Vector3(50000, 50000, 50000));
    World world(parameters);

    std::vector<Proxy*> boxes;

    int countPerDimension = 10;
    int proxyCount = countPerDimension * countPerDimension * countPerDimension;
    Vector3 boxSize = Vector3(10.0, 10.0, 10.0);
    Vector3 boxOffset = Vector3(10.0, 10.0, 10.0); // distance between two boxes
    boxes = createManyRigidBoxes(&world, boxSize, proxyCount);

    int box = 0;
    Vector3 dist = boxSize + boxOffset;
    for (int x = 0; x < countPerDimension; x++) {
        for (int y = 0; y < countPerDimension; y++) {
            for (int z = 0; z < countPerDimension; z++) {
                Proxy* p = boxes.at(box);

                p->translate(dist.getX() * x,
                        dist.getY() * y,
                        dist.getZ() * z);

                box++;
            }
        }
    }

    world.prepareSimulation();


    std::vector<Vector3> translationPerStep;
    translationPerStep.reserve(proxyCount);

    /*
     * 0 = constant translation for all proxies
     * 1 = disable movement
     */
    int translationMode = 0;
    switch (translationMode) {
        case 0: // constant translation
        {
            Vector3 translation = Vector3(1.0, 1.0, 1.0);
            for (int i = 0; i < proxyCount; i++) {
                translationPerStep.push_back(translation);
            }
            break;
        }
        case 1:
         break;
        default:
            error() << "unknown translationMode " << translationMode;
            return 1;
    }

    /*
     * >= 0: do that many iterations
     *  < 0: do infinite iterations
     */
    int maxIterations = 20;
    bool useThreads = true;

    debug() << "starting collision detection with " << proxyCount << " proxies";
    int reverseMovementCounter = 0;
    for (int iteration = 0; maxIterations < 0 || iteration < maxIterations; iteration++) {
        // move all proxies by one step
        for (int i = 0; i < proxyCount; i++) {
            boxes[i]->translate(translationPerStep[i]);
        }
        reverseMovementCounter++;
        if (reverseMovementCounter > 100) {
            reverseMovementCounter = 0;
            for (std::vector<Vector3>::iterator it = translationPerStep.begin(); it != translationPerStep.end(); ++it) {
                (*it) = (*it) * -1;
            }
        }


        unsigned int flags = World::COLLISIONFLAG_SKIP_MIDDLE_PHASE;
        if (useThreads) {
            flags |= World::COLLISIONFLAG_USE_THREADS;
        }
        world.calculateAllCollisions(flags);

        if (world.getDebugLog()) {
//            world.getDebugLog()->printSummary();
        }
    }

    return 0;
}
开发者ID:ColinGilbert,项目名称:d-collide,代码行数:92,代码来源:broadphaseperformancetest.cpp

示例2: simulationTestUncached

    void WorldTest::simulationTestUncached() {
        World* world = new World(Vector3(200000, 200000, 200000));
        world->setUseCollisionCaching(false);
        Vector3 boxDimensions(10, 10, 10);
        Proxy* box1 = world->createProxy(new Box(boxDimensions));
        //Proxy* childBox = world->createProxy(new Box(boxDimensions));
        //childBox->translate(5, 5, 5);
        //box->addChild(childBox);

        world->addProxy(box1);

        Proxy* box2 = world->createProxy(new Box(boxDimensions));
        box2->translate(0, -20, 0);
        world->addProxy(box2);

        Proxy* box3 = world->createProxy(new Box(boxDimensions)); //always colliding with box2
        box3->translate(5, -25, 0);
        world->addProxy(box3);

        
        Proxy* moveBox = world->createProxy(new Box(Vector3(10, 50, 10)));
        moveBox->translate(20, -25, 0); //starting in no-collision state
        world->addProxy(moveBox);

        //WorldCollisions coll;
        
        world->prepareSimulation();
//std::cout << "-----------Starting simulation test-----------"<<std::endl;
//std::cout << "doing pre-move collisionCheck"<<std::endl;
        //test and ensure 1 BPC and rigid C
        WorldCollisions coll0 = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(1,
                (int)coll0.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(1, (int)coll0.getRigidBoundingVolumeCollisions().size());

        //Step 1 -> move moveBox to collidy with box3
//std::cout <<std::endl<< "doing step 1 - move in to collide with box3"<<std::endl;
        moveBox->translate(-6, 0, 0);

        //ensure 2 BPC/RC
        WorldCollisions coll1  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(2,
                (int)coll1.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(2, (int)coll1.getRigidBoundingVolumeCollisions().size());

        //Step 2-> move to collide with all boxes
//std::cout <<std::endl<<"doing step 2 - move further to collide with all"<<std::endl;
        moveBox->translate(-5, 0, 0);
        //ensure 4 collisions
        WorldCollisions coll2  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(4,
                (int)coll2.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(4, (int)coll2.getRigidBoundingVolumeCollisions().size());

        //Step 3-> move out again
//std::cout << std::endl<<"doing step 3 - moving out"<<std::endl;
        moveBox->translate(11, 0, 0);
        //ensure 1 collisions
        WorldCollisions coll3  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(1,
                (int)coll3.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(1, (int)coll3.getRigidBoundingVolumeCollisions().size());

        //Step 4-> move in again
//std::cout << std::endl<<"doing step 4 - moving back in"<<std::endl;
        moveBox->translate(-11, 0, 0);
        //ensure 4 collisions
        WorldCollisions coll4  = world->calculateAllCollisions();
        CPPUNIT_ASSERT_EQUAL(4,
                (int)coll4.getBroadPhaseCollisions()->getResults().size());
        CPPUNIT_ASSERT_EQUAL(4, (int)coll4.getRigidBoundingVolumeCollisions().size());

        delete world;
    }
开发者ID:ColinGilbert,项目名称:d-collide,代码行数:74,代码来源:worldtest.cpp

示例3: testUndo

void UndoTest::testUndo() {
    // we maintain 2 World objects, a "undo" World and a "reference" world
    //
    // we will do some changes on both worlds and then do some changes on
    // the "undo" world only. after calling undo, both worlds should be
    // synced again.
    //
    // whenever we start tests, both worlds should be synced.
    World undoWorld;
    World referenceWorld;

    // add simple proxies and never move them
    // this tests in particular that a undoStep() call does not change
    // things that shouldnt change
    undoWorld.addProxy(undoWorld.createProxy(new Box(10, 10, 10)));
    referenceWorld.addProxy(referenceWorld.createProxy(new Box(10, 10, 10)));

    // add simple proxies, move them before adding, never move them
    // afterwards
    // this tests in particular that a undoStep() call does not change
    // things that shouldnt change
    Proxy* staticUndoProxy = undoWorld.createProxy(new Box(10, 10, 10));
    Proxy* staticRefereceProxy = referenceWorld.createProxy(new Box(10, 10, 10));
    staticUndoProxy->translate(-10, 10, 5);
    staticRefereceProxy->translate(-10, 10, 5);
    undoWorld.addProxy(staticUndoProxy);
    referenceWorld.addProxy(staticRefereceProxy);

    // add simple proxies, but move them before adding
    Proxy* proxyUndoWorld = undoWorld.createProxy(new Box(10, 10, 10));
    Proxy* proxyReferenceWorld = referenceWorld.createProxy(new Box(10, 10, 10));
    proxyUndoWorld->translate(-10, 10, 5);
    proxyReferenceWorld->translate(-10, 10, 5);
    undoWorld.addProxy(proxyUndoWorld);
    referenceWorld.addProxy(proxyReferenceWorld);

    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));
    undoWorld.startNextStep();
    referenceWorld.startNextStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo simple translations
    proxyUndoWorld->translate(100, 100, 100);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo multiple translations
    proxyUndoWorld->translate(100, 100, 100);
    proxyUndoWorld->translate(100, 300, 200);
    proxyUndoWorld->translate(100, 400, 500);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo simple rotations
    proxyUndoWorld->rotate(45, 1, 0, 0);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo multiple simple rotations
    proxyUndoWorld->rotate(45, 1, 0, 0);
    proxyUndoWorld->rotate(15, 1, 0, 0);
    proxyUndoWorld->rotate(45, 0, 1, 0);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo translations and rotations
    proxyUndoWorld->translate(100, 100, 100);
    proxyUndoWorld->rotate(45, 1, 0, 0);
    proxyUndoWorld->translate(100, 1, 100);
    proxyUndoWorld->rotate(15, 1, 0, 0);
    proxyUndoWorld->translate(100, 20, 100);
    proxyUndoWorld->rotate(45, 0, 1, 0);
    proxyUndoWorld->translate(100, 100, 400);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo setTransformation()
    Matrix m;
    m.translate(100, 0, 0);
    proxyUndoWorld->setTransformation(m);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo multiple setTransformation()
    m = Matrix();
    m.translate(100, 0, 0);
    proxyUndoWorld->setTransformation(m);
    m.translate(0, 50, 0);
    proxyUndoWorld->setTransformation(m);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo setProxyType()
    proxyUndoWorld->setProxyType(PROXYTYPE_DEFORMABLE);
    undoWorld.undoStep();
    CPPUNIT_ASSERT_EQUAL(true, checkWorldsAreEqual(&undoWorld, &referenceWorld));

    // undo multiple setProxyType()
    proxyUndoWorld->setProxyType(PROXYTYPE_DEFORMABLE);
    proxyUndoWorld->setProxyType(PROXYTYPE_FIXED);
//.........这里部分代码省略.........
开发者ID:ColinGilbert,项目名称:d-collide,代码行数:101,代码来源:undotest.cpp


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