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


C++ AACube类代码示例

本文整理汇总了C++中AACube的典型用法代码示例。如果您正苦于以下问题:C++ AACube类的具体用法?C++ AACube怎么用?C++ AACube使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: cubeInKeyhole

// A box is inside a sphere if all of its corners are inside the sphere
// A box intersects a sphere if any of its edges (as rays) interesect the sphere
// A box is outside a sphere if none of its edges (as rays) interesect the sphere
ViewFrustum::location ViewFrustum::cubeInKeyhole(const AACube& cube) const {

    // First check to see if the cube is in the bounding cube for the sphere, if it's not, then we can short circuit
    // this and not check with sphere penetration which is more expensive
    if (!_keyholeBoundingCube.contains(cube)) {
        return OUTSIDE;
    }

    glm::vec3 penetration;
    bool intersects = cube.findSpherePenetration(_position, _keyholeRadius, penetration);

    ViewFrustum::location result = OUTSIDE;

    // if the cube intersects the sphere, then it may also be inside... calculate further
    if (intersects) {
        result = INTERSECT;

        // test all the corners, if they are all inside the sphere, the entire cube is in the sphere
        bool allPointsInside = true; // assume the best
        for (int v = BOTTOM_LEFT_NEAR; v < TOP_LEFT_FAR; v++) {
            glm::vec3 vertex = cube.getVertex((BoxVertex)v);
            if (!pointInKeyhole(vertex)) {
                allPointsInside = false;
                break;
            }
        }

        if (allPointsInside) {
            result = INSIDE;
        }
    }

    return result;
}
开发者ID:DaveDubUK,项目名称:hifi,代码行数:37,代码来源:ViewFrustum.cpp

示例2: cubeInFrustum

ViewFrustum::location ViewFrustum::cubeInFrustum(const AACube& cube) const {

    ViewFrustum::location regularResult = INSIDE;
    ViewFrustum::location keyholeResult = OUTSIDE;

    // If we have a keyholeRadius, check that first, since it's cheaper
    if (_keyholeRadius >= 0.0f) {
        keyholeResult = cubeInKeyhole(cube);
    }
    if (keyholeResult == INSIDE) {
        return keyholeResult;
    }

    // TODO: These calculations are expensive, taking up 80% of our time in this function.
    // This appears to be expensive because we have to test the distance to each plane.
    // One suggested optimization is to first check against the approximated cone. We might
    // also be able to test against the cone to the bounding sphere of the box.
    for(int i=0; i < 6; i++) {
        const glm::vec3& normal = _planes[i].getNormal();
        const glm::vec3& boxVertexP = cube.getVertexP(normal);
        float planeToBoxVertexPDistance = _planes[i].distance(boxVertexP);

        const glm::vec3& boxVertexN = cube.getVertexN(normal);
        float planeToBoxVertexNDistance = _planes[i].distance(boxVertexN);

        if (planeToBoxVertexPDistance < 0) {
            // This is outside the regular frustum, so just return the value from checking the keyhole
            return keyholeResult;
        } else if (planeToBoxVertexNDistance < 0) {
            regularResult =  INTERSECT;
        }
    }
    return regularResult;
}
开发者ID:DaveDubUK,项目名称:hifi,代码行数:34,代码来源:ViewFrustum.cpp

示例3: getFurthestPointFromCamera

// Similar strategy to getProjectedPolygon() we use the knowledge of camera position relative to the
// axis-aligned voxels to determine which of the voxels vertices must be the furthest. No need for
// squares and square-roots. Just compares.
void ViewFrustum::getFurthestPointFromCamera(const AACube& box, glm::vec3& furthestPoint) const {
    const glm::vec3& bottomNearRight = box.getCorner();
    float scale = box.getScale();
    float halfScale = scale * 0.5f;

    if (_position.x < bottomNearRight.x + halfScale) {
        // we are to the right of the center, so the left edge is furthest
        furthestPoint.x = bottomNearRight.x + scale;
    } else {
        furthestPoint.x = bottomNearRight.x;
    }

    if (_position.y < bottomNearRight.y + halfScale) {
        // we are below of the center, so the top edge is furthest
        furthestPoint.y = bottomNearRight.y + scale;
    } else {
        furthestPoint.y = bottomNearRight.y;
    }

    if (_position.z < bottomNearRight.z + halfScale) {
        // we are to the near side of the center, so the far side edge is furthest
        furthestPoint.z = bottomNearRight.z + scale;
    } else {
        furthestPoint.z = bottomNearRight.z;
    }
}
开发者ID:DaveDubUK,项目名称:hifi,代码行数:29,代码来源:ViewFrustum.cpp

示例4: getAngularSize

float ConicalViewFrustum::getAngularSize(const AACube& cube) const {
    auto radius = 0.5f * SQRT_THREE * cube.getScale(); // radius of bounding sphere
    auto position = cube.calcCenter() - _position; // position of bounding sphere in view-frame
    float distance = glm::length(position);

    return getAngularSize(distance, radius);
}
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:7,代码来源:ConicalViewFrustum.cpp

示例5: getScale

int OctreeElement::getMyChildContaining(const AACube& cube) const {
    float ourScale = getScale();
    float cubeScale = cube.getScale();

    // TODO: consider changing this to assert()
    if (cubeScale > ourScale) {
        qCDebug(octree) << "UNEXPECTED -- OctreeElement::getMyChildContaining() -- (cubeScale > ourScale)";
        qCDebug(octree) << "    cube=" << cube;
        qCDebug(octree) << "    elements AACube=" << _cube;
        qCDebug(octree) << "    cubeScale=" << cubeScale;
        qCDebug(octree) << "    ourScale=" << ourScale;
        assert(false);
    }

    // Determine which of our children the minimum and maximum corners of the cube live in...
    glm::vec3 cubeCornerMinimum = glm::clamp(cube.getCorner(), (float)-HALF_TREE_SCALE, (float)HALF_TREE_SCALE);
    glm::vec3 cubeCornerMaximum = glm::clamp(cube.calcTopFarLeft(), (float)-HALF_TREE_SCALE, (float)HALF_TREE_SCALE);

    if (_cube.contains(cubeCornerMinimum) && _cube.contains(cubeCornerMaximum)) {
        int childIndexCubeMinimum = getMyChildContainingPoint(cubeCornerMinimum);
        int childIndexCubeMaximum = getMyChildContainingPoint(cubeCornerMaximum);

        // If the minimum and maximum corners of the cube are in two different children's cubes, then we are the containing element
        if (childIndexCubeMinimum != childIndexCubeMaximum) {
            return CHILD_UNKNOWN;
        }

        return childIndexCubeMinimum; // either would do, they are the same
    }
    return CHILD_UNKNOWN; // since cube is not contained in our element, it can't be in one of our children
}
开发者ID:rabedik,项目名称:hifi,代码行数:31,代码来源:OctreeElement.cpp

示例6: if

void DiffTraversal::Waypoint::getNextVisibleElementDifferential(DiffTraversal::VisibleElement& next,
        const DiffTraversal::View& view, const DiffTraversal::View& lastView) {
    if (_nextIndex == -1) {
        // root case is special
        ++_nextIndex;
        EntityTreeElementPointer element = _weakElement.lock();
        next.element = element;
        next.intersection = ViewFrustum::INTERSECT;
        return;
    } else if (_nextIndex < NUMBER_OF_CHILDREN) {
        EntityTreeElementPointer element = _weakElement.lock();
        if (element) {
            while (_nextIndex < NUMBER_OF_CHILDREN) {
                EntityTreeElementPointer nextElement = element->getChildAtIndex(_nextIndex);
                ++_nextIndex;
                if (nextElement) {
                    AACube cube = nextElement->getAACube();
                    // check for LOD truncation
                    float distance = glm::distance(view.viewFrustum.getPosition(), cube.calcCenter()) + MIN_VISIBLE_DISTANCE;
                    float angularDiameter = cube.getScale() / distance;
                    if (angularDiameter > MIN_ELEMENT_ANGULAR_DIAMETER * view.lodScaleFactor) {
                        if (view.viewFrustum.calculateCubeKeyholeIntersection(cube) != ViewFrustum::OUTSIDE) {
                            next.element = nextElement;
                            next.intersection = ViewFrustum::OUTSIDE;
                            return;
                        }
                    }
                }
            }
        }
    }
    next.element.reset();
    next.intersection = ViewFrustum::OUTSIDE;
}
开发者ID:ZappoMan,项目名称:hifi,代码行数:34,代码来源:DiffTraversal.cpp

示例7: touches

bool AABox::touches(const AACube& otherCube) const {
    glm::vec3 relativeCenter = _corner - otherCube.getCorner() + ((_scale - otherCube.getDimensions()) * 0.5f);

    glm::vec3 totalHalfScale = (_scale + otherCube.getDimensions()) * 0.5f;

    return fabsf(relativeCenter.x) <= totalHalfScale.x &&
        fabsf(relativeCenter.y) <= totalHalfScale.y &&
        fabsf(relativeCenter.z) <= totalHalfScale.z;
}
开发者ID:JamesLinus,项目名称:hifi,代码行数:9,代码来源:AABox.cpp

示例8: aaCubeToScriptValue

QScriptValue aaCubeToScriptValue(QScriptEngine* engine, const AACube& aaCube) {
    QScriptValue obj = engine->newObject();
    const glm::vec3& corner = aaCube.getCorner();
    obj.setProperty("x", corner.x);
    obj.setProperty("y", corner.y);
    obj.setProperty("z", corner.z);
    obj.setProperty("scale", aaCube.getScale());
    return obj;
}
开发者ID:disigma,项目名称:hifi,代码行数:9,代码来源:RegisteredMetaTypes.cpp

示例9: appendValue

bool OctreePacketData::appendValue(const AACube& aaCube) {
    aaCubeData cube { aaCube.getCorner(), aaCube.getScale() };
    const unsigned char* data = (const unsigned char*)&cube;
    int length = sizeof(aaCubeData);
    bool success = append(data, length);
    if (success) {
        _bytesOfValues += length;
        _totalBytesOfValues += length;
    }
    return success;
}
开发者ID:ZappoMan,项目名称:hifi,代码行数:11,代码来源:OctreePacketData.cpp

示例10: subTreeContainsSomeEntitiesToDelete

// does this entity tree element contain the old entity
bool DeleteEntityOperator::subTreeContainsSomeEntitiesToDelete(OctreeElement* element) {
    bool containsEntity = false;

    // If we don't have an old entity, then we don't contain the entity, otherwise
    // check the bounds
    if (_entitiesToDelete.size() > 0) {
        AACube elementCube = element->getAACube();
        foreach(const EntityToDeleteDetails& details, _entitiesToDelete) {
            if (elementCube.contains(details.cube)) {
                containsEntity = true;
                break; // if it contains at least one, we're good to go
            }
        }
    }
开发者ID:ey6es,项目名称:hifi,代码行数:15,代码来源:DeleteEntityOperator.cpp

示例11: getParticles

void ParticleTreeElement::getParticles(const AACube& box, QVector<Particle*>& foundParticles) {
    QList<Particle>::iterator particleItr = _particles->begin();
    QList<Particle>::iterator particleEnd = _particles->end();
    AACube particleCube;
    while(particleItr != particleEnd) {
        Particle* particle = &(*particleItr);
        float radius = particle->getRadius();
        // NOTE: we actually do box-box collision queries here, which is sloppy but good enough for now
        // TODO: decide whether to replace particleBox-box query with sphere-box (requires a square root
        // but will be slightly more accurate).
        particleCube.setBox(particle->getPosition() - glm::vec3(radius), 2.f * radius);
        if (particleCube.touches(_cube)) {
            foundParticles.push_back(particle);
        }
        ++particleItr;
    }
}
开发者ID:CoderPaulK,项目名称:hifi,代码行数:17,代码来源:ParticleTreeElement.cpp

示例12: contains

bool AACube::contains(const AACube& otherCube) const {
    for (int v = BOTTOM_LEFT_NEAR; v < TOP_LEFT_FAR; v++) {
        glm::vec3 vertex = otherCube.getVertex((BoxVertex)v);
        if (!contains(vertex)) {
            return false;
        }
    }
    return true;
}
开发者ID:Ian-Mills,项目名称:hifi,代码行数:9,代码来源:AACube.cpp

示例13: aaCubeFromScriptValue

void aaCubeFromScriptValue(const QScriptValue &object, AACube& aaCube) {
    glm::vec3 corner;
    corner.x = object.property("x").toVariant().toFloat();
    corner.y = object.property("y").toVariant().toFloat();
    corner.z = object.property("z").toVariant().toFloat();
    float scale = object.property("scale").toVariant().toFloat();

    aaCube.setBox(corner, scale);
}
开发者ID:disigma,项目名称:hifi,代码行数:9,代码来源:RegisteredMetaTypes.cpp

示例14: qCDebug

void MovingEntitiesOperator::addEntityToMoveList(EntityItemPointer entity, const AACube& newCube) {
    EntityTreeElementPointer oldContainingElement = entity->getElement();
    AABox newCubeClamped = newCube.clamp((float)-HALF_TREE_SCALE, (float)HALF_TREE_SCALE);

    if (_wantDebug) {
        qCDebug(entities) << "MovingEntitiesOperator::addEntityToMoveList() -----------------------------";
        qCDebug(entities) << "    newCube:" << newCube;
        qCDebug(entities) << "    newCubeClamped:" << newCubeClamped;
        if (oldContainingElement) {
            qCDebug(entities) << "    oldContainingElement:" << oldContainingElement->getAACube();
            qCDebug(entities) << "    oldContainingElement->bestFitBounds(newCubeClamped):" 
                            << oldContainingElement->bestFitBounds(newCubeClamped);
        } else {
            qCDebug(entities) << "    WARNING NO OLD CONTAINING ELEMENT for entity" << entity->getEntityItemID();
        }
    }

    if (!oldContainingElement) {
        return; // bail without adding.
    }

    // If the original containing element is the best fit for the requested newCube locations then
    // we don't actually need to add the entity for moving and we can short circuit all this work
    if (!oldContainingElement->bestFitBounds(newCubeClamped)) {
        // check our tree, to determine if this entity is known
        EntityToMoveDetails details;
        details.oldContainingElement = oldContainingElement;
        details.oldContainingElementCube = oldContainingElement->getAACube();
        details.entity = entity;
        details.oldFound = false;
        details.newFound = false;
        details.newCube = newCube;
        details.newCubeClamped = newCubeClamped;
        _entitiesToMove << details;
        _lookingCount++;

        if (_wantDebug) {
            qCDebug(entities) << "MovingEntitiesOperator::addEntityToMoveList() -----------------------------";
            qCDebug(entities) << "    details.entity:" << details.entity->getEntityItemID();
            qCDebug(entities) << "    details.oldContainingElementCube:" << details.oldContainingElementCube;
            qCDebug(entities) << "    details.newCube:" << details.newCube;
            qCDebug(entities) << "    details.newCubeClamped:" << details.newCubeClamped;
            qCDebug(entities) << "    _lookingCount:" << _lookingCount;
            qCDebug(entities) << "--------------------------------------------------------------------------";
        }
    } else {
        if (_wantDebug) {
            qCDebug(entities) << "    oldContainingElement->bestFitBounds(newCubeClamped) IS BEST FIT... NOTHING TO DO";
        }
    }

    if (_wantDebug) {
        qCDebug(entities) << "--------------------------------------------------------------------------";
    }
}
开发者ID:AndrewMeadows,项目名称:hifi,代码行数:55,代码来源:MovingEntitiesOperator.cpp

示例15: getSimulation

void VoxelShapeManager::updateVoxels(const quint64& now, CubeList& cubes) {
    const quint64 VOXEL_UPDATE_PERIOD = 100000; // usec
    _updateExpiry = now + VOXEL_UPDATE_PERIOD;
    PhysicsSimulation* simulation = getSimulation();
    if (!simulation) {
        return;
    }

    int numChanges = 0;
    VoxelPool::iterator voxelItr = _voxels.begin();
    while (voxelItr != _voxels.end()) {
        // look for this voxel in cubes
        CubeList::iterator cubeItr = cubes.find(voxelItr.key());
        if (cubeItr == cubes.end()) {
            // did not find it --> remove the voxel
            simulation->removeShape(voxelItr.value()._shape);
            voxelItr = _voxels.erase(voxelItr);
            ++numChanges;
        } else {
            // found it --> remove the cube
            cubes.erase(cubeItr);
            voxelItr++;
        }
    }

    // add remaining cubes to _voxels
    glm::vec3 simulationOrigin = simulation->getTranslation();
    CubeList::const_iterator cubeItr = cubes.constBegin();
    while (cubeItr != cubes.constEnd()) {
        AACube cube = cubeItr.value();
        AACubeShape* shape = new AACubeShape(cube.getScale(), cube.calcCenter() - simulationOrigin);
        shape->setEntity(this);
        VoxelInfo voxel = {cube, shape };
        _voxels.insert(cubeItr.key(), voxel);
        ++numChanges;
        ++cubeItr;
    }

    if (numChanges > 0) {
        buildShapes();
    }
}
开发者ID:Schackasawa,项目名称:hifi,代码行数:42,代码来源:VoxelShapeManager.cpp


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