Example #1
0
void CartWheel3D::addHuman(const string& name, const std::string& characterFile, const std::string& controllerFile, const std::string& actionFile,
        const Math::Point3d& pos, double heading) {
    bool foundMatch = (_humans.find(name) != _humans.end());
    if (foundMatch) {
        ostringstream osError;
        osError << name << " already exists!";
        throwError(osError.str().c_str());
    }

    string sFile = _path + characterFile;
    _world->loadRBsFromFile(sFile.c_str(), _path.c_str(), name.c_str());
    Character* ch = new Character(_world->getAF(_world->getAFCount() - 1));
//    printf("AF: %s\n", _world->getAF(_world->getAFCount() - 1)->getName());
    ArticulatedRigidBody* body = ch->getArticulatedRigidBody(4);
    printf("Trying to get a Body\n");
    if (body==NULL)
        printf("Body not found\n");
    else {
        printf("Body found!!!\n");
////        body->addMeshObj("data/models/bipv3/head.obj", Vector3d(0,0,0), Vector3d(0.5,2,0.5));
//        body->replaceMeshObj("data/models/box3.obj");
//        body->getMesh(0)->scale(Vector3d(0.06,0.06,0.06));
//        body->getMesh(0)->computeNormals();
//        body->setColour(1,0,0,1);
//        body->setMass(-10);
    }

    CompositeController* con = new CompositeController(ch, _oracle, controllerFile.c_str());
    ActionCollectionPolicy* policy = new ActionCollectionPolicy(con);
    policy->loadActionsFromFile(actionFile.c_str());

    // Create a new human
    Human* human = new Human(name, ch, con, policy);
    // Initialize
    human->init();

    human->setHeading(heading);
    human->setPosition(pos);

    ch->setHeading(heading);

    _humans[name] = human;
    ch->getState(&_hStates[name]);
//    doBehavior("Standing", name, NULL);
    setController(name, 0);
    
    
//    printf("\n\nJoints:\n");
//    for(int i=0; i<ch->getJointCount(); i++) {
//        Point3d p1 = ch->getJoint(i)->getChildJointPosition();
//        Point3d p2 = ch->getJoint(i)->getParentJointPosition();
//        printf("Joint: %s, Parent-Joint: %s, Pos: (%f, %f, %f)\n", ch->getJoint(i)->getName(), ch->getJoint(i)->getParent()->getName(), p2.x, p2.y, p2.z);
//        printf("Joint: %s, Child-Joint: %s, Pos: (%f, %f, %f)\n\n", ch->getJoint(i)->getName(), ch->getJoint(i)->getChild()->getName(), p1.x, p1.y, p1.z);
//    }
    printf("\n\n\nArticulated Rigid Bodies:\n");
    for(int i=0; i<ch->getArticulatedRigidBodyCount(); i++) {
        Vector3d p = ch->getArticulatedRigidBody(i)->getCMPosition();
        printf("ARB: %s, Pos: (%f, %f, %f)\n", ch->getArticulatedRigidBody(i)->getName(), p.x, p.y, p.z);
    }
}
Example #2
0
void CartWheel3D::addHuman(const string& name, const string& characterFile, const string& controllerFile, const Point3d& pos, double heading) {
    bool foundMatch = (_humans.find(name) != _humans.end());
    if (foundMatch) {
        ostringstream osError;
        osError << name << " already exists!";
        throwError(osError.str().c_str());
    }

    string sFile = _path + characterFile;
    _world->loadRBsFromFile(sFile.c_str(), _path.c_str(), name.c_str());
    Character* ch = new Character(_world->getAF(_world->getAFCount() - 1));

    IKVMCController* c = new IKVMCController(ch);

    sFile = _path + controllerFile;
    c->loadFromFile(sFile.c_str());

    BehaviourController* behaviour = new TurnController(ch, c, _oracle);

    Human* human = new Human(name, ch, c, behaviour);
    // Initialize
    human->init();

    human->setHeading(heading);
    human->setPosition(pos);

    ch->setHeading(heading);

    _humans[name] = human;
    ch->getState(&_hStates[name]);
    setController(name, 0);
//    doBehavior("Standing", name, NULL);
}