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


C++ QuadTree::getItemsInBounds方法代码示例

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


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

示例1: applyForces

void RDirNode::applyForces(QuadTree& quadtree) {

    //child nodes
    for(std::list<RDirNode*>::iterator it = children.begin(); it != children.end(); it++) {
        RDirNode* node = (*it);

        node->applyForces(quadtree);
    }

    if(parent == 0) return;

    std::vector<QuadItem*> inbounds;
    int found = quadtree.getItemsInBounds(inbounds, quadItemBounds);

    std::set<std::string> seen;
    std::set<std::string>::iterator seentest;

    //apply forces with other that are inside the 'box' of this nodes radius
    for(std::vector<QuadItem*>::iterator it = inbounds.begin(); it != inbounds.end(); it++) {

        RDirNode* d = (RDirNode*) (*it);

        if(d==this) continue;
        if(d==parent) continue;
        if(d->parent==this) continue;

        if((seentest = seen.find(d->getPath())) != seen.end()) {
            continue;
        }

        seen.insert(d->getPath());

        if(isParentOf(d)) continue;
        if(d->isParentOf(this)) continue;

        applyForceDir(d);

        gGourceDirNodeInnerLoops++;
    }

    //always call on parent no matter how far away
    applyForceDir(parent);

    //pull towards parent
    float parent_dist = distanceTo(parent);

    //  * dirs should attract to sit on the radius of the parent dir ie:
    //    should attract to distance_to_parent * normal_to_parent

    accel += gGourceForceGravity * parent_dist * (parent->getPos() - pos).normal();

    //  * dirs should be pushed along the parent_parent to parent normal by a force smaller than the parent radius force
    RDirNode* pparent = parent->getParent();

    if(pparent != 0) {
        vec2f parent_edge = (parent->getPos() - pparent->getPos());
        vec2f parent_edge_normal = parent_edge.normal();

        vec2f dest = (parent->getPos() + (parent->getRadius() + getRadius()) * parent_edge_normal) - pos;

        accel += dest;
    }

    //  * dirs should repulse from other dirs of this parent
    std::list<RDirNode*>* siblings = parent->getChildren();
    if(siblings->size() > 0) {
        vec2f sib_accel;

        int visible = 1;

        for(std::list<RDirNode*>::iterator it = siblings->begin(); it != siblings->end(); it++) {
            RDirNode* node = (*it);

            if(node == this) continue;
            if(!node->isVisible()) continue;

            visible++;

            sib_accel -= (node->getPos() - pos).normal();
        }

        //parent circumfrence divided by the number of visible child nodes
        if(visible>1) {
            float slice_size = (parent->getRadius() * PI) / (float) (visible+1);
            sib_accel *= slice_size;

            accel += sib_accel;
        }
    }

}
开发者ID:bitshifter,项目名称:Gource,代码行数:91,代码来源:dirnode.cpp


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