Exemplo n.º 1
0
void Inventory::useActiveItemSecondary(World& world, Unit& unit) {
    WorldItem* item = this->wieldedItems[this->active_item];
    if(item == 0) {
    } else {
        item->onSecondaryActivate(world, unit);
    }
}
Exemplo n.º 2
0
void Inventory::reloadAction(World& world, Unit& unit) {
    WorldItem* item = this->wieldedItems[this->active_item];
    if(item == 0) {
    } else {
        item->onReload(world, unit);
    }
}
Exemplo n.º 3
0
void Inventory::useActiveItemPrimary(World& world, Unit& unit) {
    if(unit["HEALTH"] > 0) {
        WorldItem* item = this->wieldedItems[this->active_item];
        if(item == 0) {
        } else {
            item->onActivate(world, unit);
        }
    }
}
Exemplo n.º 4
0
bool BodyItemImpl::onSelfCollisionDetectionPropertyChanged(bool on)
{
    if(on != isSelfCollisionDetectionEnabled){
        isSelfCollisionDetectionEnabled = on;
        WorldItem* worldItem = self->findOwnerItem<WorldItem>();
        if(worldItem){
            worldItem->updateCollisionDetector();
        }
        return true;
    }
    return false;
}
Exemplo n.º 5
0
void InventoryRenderer::draw(const Inventory& inventory) {
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

    glEnable(GL_BLEND);

    TextureHandler::getSingleton().bindTexture(0, "item_texture");

    drawArmorItem(inventory, inventory.HEAD_SLOT, 0.0f, +0.19f, 0.07f * 0.5f, 0.10f * 0.5f);
    drawArmorItem(inventory, inventory.TORSO_SLOT, 0.0f, 0.02f, 0.14f * 0.5f, 0.22f * 0.5f);
    drawArmorItem(inventory, inventory.LEGS_SLOT, 0.0f, -0.21f, 0.15f * 0.5f, 0.24f * 0.5f);
    drawArmorItem(inventory, inventory.BELT_SLOT, 0.0f, -0.07f, 0.1f * 0.5f, 0.1f * 0.5f);
    drawArmorItem(inventory, inventory.ARMS_SLOT, +0.135f, +0.08f, 0.15f * 0.5f, 0.13f * 0.5f);
    drawArmorItem(inventory, inventory.ARMS_SLOT, -0.135f, +0.08f, 0.15f * 0.5f, 0.13f * 0.5f, +1);
    drawArmorItem(inventory, inventory.AMULET_SLOT, 0.0f, +0.08f, 0.1f * 0.5f, 0.1f * 0.5f);

    drawWeaponItem(inventory, 6, 6);
    drawWeaponItem(inventory, 7, 6);
    drawWeaponItem(inventory, 8, 7);
    drawWeaponItem(inventory, 9, 7);
    drawWeaponItem(inventory, 10, 7);
    //drawWeaponItem(inventory, inventory.getItemSlot(10), 7);
    //drawWeaponItem(inventory, inventory.getItemSlot(11), 7);

    // draw the name of the active item.
    {
        WorldItem* activeItem = inventory.getItemActive();
        if(activeItem != 0) {
            std::vector<std::string> details;
            activeItem->getDetails(details);
            for(size_t i = 0; i<details.size(); ++i)
                this->textRenderer.drawString(details[i], -0.9f, -0.035f * i, 1.1f);
        }
    }
    

    glDisable(GL_BLEND);

    glEnable(GL_DEPTH_TEST);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
    glDisable(GL_TEXTURE_2D);
}
Exemplo n.º 6
0
void BodyItemImpl::createPenetrationBlocker(Link* link, bool excludeSelfCollisions, PenetrationBlockerPtr& blocker)
{
    WorldItem* worldItem = self->findOwnerItem<WorldItem>();
    if(worldItem){
        blocker = boost::make_shared<PenetrationBlocker>(worldItem->collisionDetector()->clone(), link);
        const ItemList<BodyItem>& bodyItems = worldItem->bodyItems();
        for(int i=0; i < bodyItems.size(); ++i){
            BodyItem* bodyItem = bodyItems.get(i);
            if(bodyItem != self && bodyItem->body()->isStaticModel()){
                blocker->addOpponentLink(bodyItem->body()->rootLink());
            }
        }
        blocker->setDepth(kinematicsBar->penetrationBlockDepth());
        blocker->start();
    }
}
int KinematicFaultCheckerImpl::checkFaults
(BodyItem* bodyItem, BodyMotionItem* motionItem, std::ostream& os,
 bool checkPosition, bool checkVelocity, bool checkCollision, dynamic_bitset<> linkSelection,
 double beginningTime, double endingTime)
{
    numFaults = 0;

    BodyPtr body = bodyItem->body();
    BodyMotionPtr motion = motionItem->motion();
    MultiValueSeqPtr qseq = motion->jointPosSeq();;
    MultiSE3SeqPtr pseq = motion->linkPosSeq();
    
    if((!checkPosition && !checkVelocity && !checkCollision) || body->isStaticModel() || !qseq->getNumFrames()){
        return numFaults;
    }

    BodyState orgKinematicState;
    
    if(USE_DUPLICATED_BODY){
        body = body->clone();
    } else {
        bodyItem->storeKinematicState(orgKinematicState);
    }

    CollisionDetectorPtr collisionDetector;
    WorldItem* worldItem = bodyItem->findOwnerItem<WorldItem>();
    if(worldItem){
        collisionDetector = worldItem->collisionDetector()->clone();
    } else {
        int index = CollisionDetector::factoryIndex("AISTCollisionDetector");
        if(index >= 0){
            collisionDetector = CollisionDetector::create(index);
        } else {
            collisionDetector = CollisionDetector::create(0);
            os << _("A collision detector is not found. Collisions cannot be detected this time.") << endl;
        }
    }

    addBodyToCollisionDetector(*body, *collisionDetector);
    collisionDetector->makeReady();

    const int numJoints = std::min(body->numJoints(), qseq->numParts());
    const int numLinks = std::min(body->numLinks(), pseq->numParts());

    frameRate = motion->frameRate();
    double stepRatio2 = 2.0 / frameRate;
    angleMargin = radian(angleMarginSpin.value());
    translationMargin = translationMarginSpin.value();
    velocityLimitRatio = velocityLimitRatioSpin.value() / 100.0;

    int beginningFrame = std::max(0, (int)(beginningTime * frameRate));
    int endingFrame = std::min((motion->numFrames() - 1), (int)lround(endingTime * frameRate));

    lastPosFaultFrames.clear();
    lastPosFaultFrames.resize(numJoints, std::numeric_limits<int>::min());
    lastVelFaultFrames.clear();
    lastVelFaultFrames.resize(numJoints, std::numeric_limits<int>::min());
    lastCollisionFrames.clear();

    if(checkCollision){
        Link* root = body->rootLink();
        root->p().setZero();
        root->R().setIdentity();
    }
        
    for(int frame = beginningFrame; frame <= endingFrame; ++frame){

        int prevFrame = (frame == beginningFrame) ? beginningFrame : frame - 1;
        int nextFrame = (frame == endingFrame) ? endingFrame : frame + 1;

        for(int i=0; i < numJoints; ++i){
            Link* joint = body->joint(i);
            double q = qseq->at(frame, i);
            joint->q() = q;
            if(joint->index() >= 0 && linkSelection[joint->index()]){
                if(checkPosition){
                    bool fault = false;
                    if(joint->isRotationalJoint()){
                        fault = (q > (joint->q_upper() - angleMargin) || q < (joint->q_lower() + angleMargin));
                    } else if(joint->isSlideJoint()){
                        fault = (q > (joint->q_upper() - translationMargin) || q < (joint->q_lower() + translationMargin));
                    }
                    if(fault){
                        putJointPositionFault(frame, joint, os);
                    }
                }
                if(checkVelocity){
                    double dq = (qseq->at(nextFrame, i) - qseq->at(prevFrame, i)) / stepRatio2;
                    joint->dq() = dq;
                    if(dq > (joint->dq_upper() * velocityLimitRatio) || dq < (joint->dq_lower() * velocityLimitRatio)){
                        putJointVelocityFault(frame, joint, os);
                    }
                }
            }
        }

        if(checkCollision){

            Link* link = body->link(0);
            if(!pseq->empty())
            {
                const SE3& p = pseq->at(frame, 0);
                link->p() = p.translation();
                link->R() = p.rotation().toRotationMatrix();
            }
            else
            {
                link->p() = Vector3d(0., 0., 0.);
                link->R() = Matrix3d::Identity();
            }

            body->calcForwardKinematics();

            for(int i=1; i < numLinks; ++i){
                link = body->link(i);
                if(!pseq->empty())
                {
                    const SE3& p = pseq->at(frame, i);
                    link->p() = p.translation();
                    link->R() = p.rotation().toRotationMatrix();
                }
            }

            for(int i=0; i < numLinks; ++i){
                link = body->link(i);
                collisionDetector->updatePosition(i, link->position());
            }
            collisionDetector->detectCollisions(
                boost::bind(&KinematicFaultCheckerImpl::putSelfCollision, this, body.get(), frame, _1, boost::ref(os)));
        }
    }

    if(!USE_DUPLICATED_BODY){
        bodyItem->restoreKinematicState(orgKinematicState);
    }

    return numFaults;
}