Ejemplo n.º 1
0
bool ParticleTreeElement::findSpherePenetration(const glm::vec3& center, float radius,
        glm::vec3& penetration, void** penetratedObject) const {
    QList<Particle>::iterator particleItr = _particles->begin();
    QList<Particle>::const_iterator particleEnd = _particles->end();
    while(particleItr != particleEnd) {
        Particle& particle = (*particleItr);
        glm::vec3 particleCenter = particle.getPosition();
        float particleRadius = particle.getRadius();

        // don't penetrate yourself
        if (particleCenter == center && particleRadius == radius) {
            return false;
        }

        // We've considered making "inHand" particles not collide, if we want to do that,
        // we should change this setting... but now, we do allow inHand particles to collide
        const bool IN_HAND_PARTICLES_DONT_COLLIDE = false;
        if (IN_HAND_PARTICLES_DONT_COLLIDE) {
            // don't penetrate if the particle is "inHand" -- they don't collide
            if (particle.getInHand()) {
                ++particleItr;
                continue;
            }
        }

        if (findSphereSpherePenetration(center, radius, particleCenter, particleRadius, penetration)) {
            // return true on first valid particle penetration
            *penetratedObject = (void*)(&particle);
            return true;
        }
        ++particleItr;
    }
    return false;
}
Ejemplo n.º 2
0
bool HandData::findSpherePenetration(const glm::vec3& penetratorCenter, float penetratorRadius, glm::vec3& penetration, 
                                        const PalmData*& collidingPalm) const {
    
    for (size_t i = 0; i < _palms.size(); ++i) {
        const PalmData& palm = _palms[i];
        if (!palm.isActive()) {
            continue;
        }
        glm::vec3 palmPosition = palm.getPosition();
        const float PALM_RADIUS = 0.05f; // in world (not voxel) coordinates
        if (findSphereSpherePenetration(penetratorCenter, penetratorRadius, palmPosition, PALM_RADIUS, penetration)) {
            collidingPalm = &palm;
            return true;
        }
    }
    return false;
}
Ejemplo n.º 3
0
bool HandData::findSpherePenetration(const glm::vec3& penetratorCenter, float penetratorRadius, glm::vec3& penetration,
                                        const PalmData*& collidingPalm) const {
    QReadLocker locker(&_palmsLock);

    for (const auto& palm : _palms) {
        if (!palm.isActive()) {
            continue;
        }
        glm::vec3 palmPosition = palm.getPosition();
        const float PALM_RADIUS = 0.05f; // in world (not voxel) coordinates
        if (findSphereSpherePenetration(penetratorCenter, penetratorRadius, palmPosition, PALM_RADIUS, penetration)) {
            collidingPalm = &palm;
            return true;
        }
    }
    return false;
}
Ejemplo n.º 4
0
bool ModelTreeElement::findSpherePenetration(const glm::vec3& center, float radius,
                                    glm::vec3& penetration, void** penetratedObject) const {
    QList<ModelItem>::iterator modelItr = _modelItems->begin();
    QList<ModelItem>::const_iterator modelEnd = _modelItems->end();
    while(modelItr != modelEnd) {
        ModelItem& model = (*modelItr);
        glm::vec3 modelCenter = model.getPosition();
        float modelRadius = model.getRadius();

        // don't penetrate yourself
        if (modelCenter == center && modelRadius == radius) {
            return false;
        }

        if (findSphereSpherePenetration(center, radius, modelCenter, modelRadius, penetration)) {
            // return true on first valid model penetration
            *penetratedObject = (void*)(&model);
            return true;
        }
        ++modelItr;
    }
    return false;
}