コード例 #1
0
/**
 *  Hover beacons up & down when deployed.
 */
void BeaconVisual::operator() (osg::Node *node, osg::NodeVisitor *nv)
{
    RigidBodyVisual::operator()(node, nv);


    float time = (float)nv->getFrameStamp()->getSimulationTime();
    
    Beacon * beacon = (Beacon*)object_;
    if (beacon->getTeamId() == TEAM_ID_ATTACKER &&
        (beacon->isDeployed() || beacon->getState() == BS_HOVERING))
    {
        Vector pos = beacon->getTarget()->getPosition();
        pos.y_ += sin(time*BEACON_HOVER_OMEGA) * BEACON_HOVER_AMPLITUDE;
        osg_wrapper_->setPosition(pos);
    }



    
    // set health bars value depending on beacons health
    float health_percentage = (float)beacon->getHitpoints()/(float)beacon->getMaxHitpoints();
    health_bar_->setValue(health_percentage);


    
    osg::Matrix mat;
    mat.makeRotate(BEACON_ROTATE_SPEED * time, 0.0f, 1.0f, 0.0f);
    outer_node_->setMatrix(mat);







    
    // make billboard invisible on full health or if beacon is carried
    if (beacon->getHitpoints() == beacon->getMaxHitpoints() ||
        beacon->getState() == BS_CARRIED)
    {
        health_billboard_->setNodeMask(NODE_MASK_INVISIBLE);
    } else
    {
        health_billboard_->setNodeMask(NODE_MASK_VISIBLE);
    }

    if (prev_healing_ != beacon->isGainingHealth())
    {
        prev_healing_ = beacon->isGainingHealth();
        EnableGroupVisitor g(BEACON_HEAL_EFFECT_GROUP_NAME, prev_healing_);
        osg_wrapper_->getOsgNode()->accept(g);
    }
}
コード例 #2
0
//------------------------------------------------------------------------------
void BeaconVisual::onBeaconStateChanged()
{
    Beacon * beacon = (Beacon*)object_;

    bool deployed_group   = false;
    bool hover_group      = false;
    bool undeployed_group = false;

    if (beacon->isDeployed())
    {
        deployed_group = true;
    } else
    {
        if (beacon->isInsideRadius() && beacon->getState() != BS_DISPENSED)
        {
            hover_group = true;
        } else
        {
            undeployed_group = true;
        }
    }

    assert(!(deployed_group && hover_group));
    assert(!(deployed_group && undeployed_group));
    assert(!(hover_group    && undeployed_group));
    
    EnableGroupVisitor v1(HOVERING_GROUP_NAME,     hover_group);    
    EnableGroupVisitor v2(DEPLOYED_GROUP_NAME,     deployed_group);
    EnableGroupVisitor v3(NOT_DEPLOYED_GROUP_NAME, undeployed_group);

    osg_wrapper_->getOsgNode()->accept(v1);
    osg_wrapper_->getOsgNode()->accept(v2);
    osg_wrapper_->getOsgNode()->accept(v3);
}