예제 #1
0
    //p* as in physics*
    bool PhysicsModelManager::onAgentLinkedToModel(Agent *agent, ModelId pmid)
    {
        Ogre::String intro = logName() + "::onLinked(): ";

        PhysicsModel *pmodel = at(pmid);
#ifdef DEBUG
        assert(agent->modelId(ModelType::PHYSICS) == pmid);
        assert(agent->model(ModelType::PHYSICS) == pmodel);
#endif

        ModelId omid = agent->ogreModelId();

        if(INVALID_ID == omid)
        {
            Debug::error(intro)("Invalid OgreModel id for agent ")(agent->id()).endl();
            return false;
        }

        OgreModel *omodel = mLevel->ogreModelMan()->at(omid);
        pmodel->init(mWorld, omodel);
        pmodel->setUserPointer(agent);

        // stop the physics simulation in case the agent is selected
        pmodel->setSelected(agent->isSelected());

        return true;
    }
예제 #2
0
int main () {

    // just iterate through array of moves and check that they display correctly
    // in the model

    PhysicsModel testMod = PhysicsModel();
    testMod.init();
    char testMoves[] = {'+','+','+','+','+','+','+',
                        'd','d','d','a','a','a',
                        'w','w','w','x','x', 'x',
                        'q','q','q','e','e','e',
                        '-','-','-','-','-','-','-'
                       };
    // Used to see result of move
    double positionBefore[sizeof(testMoves)/sizeof(testMoves[0])][3];
    double positionAfter[sizeof(testMoves)/sizeof(testMoves[0])][3];
    usleep(2000000);

    if(testMod.err != simx_error_noerror) {
        cout << "Test failed: " << testMod.err << endl;
        return 0;
    }

    for(int i = 0; i < (sizeof(testMoves)/sizeof(testMoves[0])); i++) {
        testMod.getPosition(positionBefore[i]);
        testMod.sendCommand(testMoves[i]);
        usleep(500000);            // Slowed down for clarity
        testMod.getPosition(positionAfter[i]);
    }

    for(int i = 0; i < (sizeof(testMoves)/sizeof(testMoves[0])); i++) {
        switch(testMoves[i]) {
        case 'a' :
            test_a(positionBefore[i], positionAfter[i]);
            break;
        case 'd' :
            test_d(positionBefore[i], positionAfter[i]);
            break;
        case 'w' :
            test_w(positionBefore[i], positionAfter[i]);
            break;
        case 'x' :
            test_x(positionBefore[i], positionAfter[i]);
            break;
        case 'q' :
            test_q(positionBefore[i], positionAfter[i]);
            break;
        case 'e' :
            test_e(positionBefore[i], positionAfter[i]);
            break;
        case '+' :
            test_up(positionBefore[i], positionAfter[i]);
            break;
        case '-' :
            test_down(positionBefore[i], positionAfter[i]);
            break;
        }
    }

    testMod.getPosition(positionBefore[0]);
    double target_move[] = {3, 3, 3};
    testMod.moveTarget(target_move);
    usleep(2000000);
    testMod.getPosition(positionAfter[0]);

    if(positionBefore[0][0] < positionAfter[0][0] &&
            positionBefore[0][1] < positionAfter[0][1] &&
            positionBefore[0][2] < positionAfter[0][2]) {
        cout << "Target move successful, and quad follows it as planned" << endl;
    }
    else cout << "Target move FAILED" << endl;

    usleep(1000000);

//Quad should jump back to(wards?) where it was before the target was moved;
    testMod.rectify(positionBefore[0][0], positionBefore[0][1], positionBefore[0][2], 1.1);
    usleep(1000000);

//and back again
    testMod.setPosition(positionAfter[0]);


    testMod.stop();
    return 0;
}