示例#1
0
void ShapeManagerTests::addManyShapes() {
    ShapeManager shapeManager;

    int numSizes = 100;
    float startSize = 1.0f;
    float endSize = 99.0f;
    float deltaSize = (endSize - startSize) / (float)numSizes;
    ShapeInfo info;
    for (int i = 0; i < numSizes; ++i) {
        float s = startSize + (float)i * deltaSize;
        glm::vec3 scale(s, 1.23f + s, s - 0.573f);
        info.setBox(0.5f * scale);
        btCollisionShape* shape = shapeManager.getShape(info);
        if (!shape) {
            std::cout << __FILE__ << ":" << __LINE__
                << " ERROR: i = " << i << " null box shape for scale = " << scale << std::endl;
        }
        float radius = 0.5f * s;
        info.setSphere(radius);
        shape = shapeManager.getShape(info);
        if (!shape) {
            std::cout << __FILE__ << ":" << __LINE__
                << " ERROR: i = " << i << " null sphere shape for radius = " << radius << std::endl;
        }
    }
    int numShapes = shapeManager.getNumShapes();
    if (numShapes != 2 * numSizes) {
        std::cout << __FILE__ << ":" << __LINE__
            << " ERROR: expected numShapes = " << numSizes << " but found numShapes = " << numShapes << std::endl;
    }
}
示例#2
0
void ShapeManagerTests::addSphereShape() {
    ShapeInfo info;
    float radius = 1.23f;
    info.setSphere(radius);

    ShapeManager shapeManager;
    btCollisionShape* shape = shapeManager.getShape(info);

    ShapeInfo otherInfo;
    ShapeInfoUtil::collectInfoFromShape(shape, otherInfo);

    btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
    if (shape != otherShape) {
        std::cout << __FILE__ << ":" << __LINE__
            << " ERROR: Sphere ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl;
    }
}
示例#3
0
void ShapeInfoTests::testSphereShape() {
    ShapeInfo info;
    float radius = 1.23f;
    info.setSphere(radius);
    DoubleHashKey key = info.getHash();

    btCollisionShape* shape = ShapeInfoUtil::createShapeFromInfo(info);

    ShapeInfo otherInfo = info;
    DoubleHashKey otherKey = otherInfo.getHash();
    if (key.getHash() != otherKey.getHash()) {
        std::cout << __FILE__ << ":" << __LINE__
            << " ERROR: expected Sphere shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl;
    }
    if (key.getHash2() != otherKey.getHash2()) {
        std::cout << __FILE__ << ":" << __LINE__
            << " ERROR: expected Sphere shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl;
    }

    delete shape;
}
示例#4
0
void SphereEntityItem::computeShapeInfo(ShapeInfo& info) const {
    glm::vec3 halfExtents = 0.5f * getDimensionsInMeters();
    // TODO: support ellipsoid shapes
    info.setSphere(halfExtents.x);
}
示例#5
0
void ShapeInfoTests::testHashFunctions() {
    int maxTests = 10000000;
    ShapeInfo info;
    btHashMap<btHashInt, uint32_t> hashes;

    uint32_t bits[32];
    uint32_t masks[32];
    for (int i = 0; i < 32; ++i) {
        bits[i] = 0;
        masks[i] = 1U << i;
    }

    float deltaLength = 0.002f;
    float endLength = 100.0f;
    int numSteps = (int)(endLength / deltaLength);

    int testCount = 0;
    int numCollisions = 0;
    btClock timer;
    for (int x = 1; x < numSteps && testCount < maxTests; ++x) {
        float radiusX = (float)x * deltaLength;
        // test sphere
        info.setSphere(radiusX);
        ++testCount;
        DoubleHashKey key = info.getHash();
        uint32_t* hashPtr = hashes.find(key.getHash());
        if (hashPtr && *hashPtr == key.getHash2()) {
            std::cout << testCount << "  hash collision radiusX = " << radiusX 
                << "  h1 = 0x" << std::hex << key.getHash()
                << "  h2 = 0x" << std::hex << key.getHash2()
                << std::endl;
            ++numCollisions;
            assert(false);
        } else {
            hashes.insert(key.getHash(), key.getHash2());
        }
        for (int k = 0; k < 32; ++k) {
            if (masks[k] & key.getHash2()) {
                ++bits[k];
            }
        }

        for (int y = 1; y < numSteps && testCount < maxTests; ++y) {
            float radiusY = (float)y * deltaLength;
            /* TODO: reimplement Cylinder and Capsule shapes
            // test cylinder and capsule
            int types[] = { CYLINDER_SHAPE_PROXYTYPE, CAPSULE_SHAPE_PROXYTYPE };
            for (int i = 0; i < 2; ++i) {
                switch(types[i]) {
                    case CYLINDER_SHAPE_PROXYTYPE: {
                        info.setCylinder(radiusX, radiusY);
                        break;
                    }
                    case CAPSULE_SHAPE_PROXYTYPE: {
                        info.setCapsuleY(radiusX, radiusY);
                        break;
                    }
                }

                ++testCount;
                key = info.getHash();
                hashPtr = hashes.find(key.getHash());
                if (hashPtr && *hashPtr == key.getHash2()) {
                    std::cout << testCount << "  hash collision radiusX = " << radiusX << "  radiusY = " << radiusY 
                        << "  h1 = 0x" << std::hex << key.getHash()
                        << "  h2 = 0x" << std::hex << key.getHash2()
                        << std::endl;
                    ++numCollisions;
                    assert(false);
                } else {
                    hashes.insert(key.getHash(), key.getHash2());
                }
                for (int k = 0; k < 32; ++k) {
                    if (masks[k] & key.getHash2()) {
                        ++bits[k];
                    }
                }
            }
            */

            for (int z = 1; z < numSteps && testCount < maxTests; ++z) {
                float radiusZ = (float)z * deltaLength;
                // test box
                info.setBox(glm::vec3(radiusX, radiusY, radiusZ));
                ++testCount;
                DoubleHashKey key = info.getHash();
                hashPtr = hashes.find(key.getHash());
                if (hashPtr && *hashPtr == key.getHash2()) {
                    std::cout << testCount << "  hash collision radiusX = " << radiusX 
                        << "  radiusY = " << radiusY << "  radiusZ = " << radiusZ 
                        << "  h1 = 0x" << std::hex << key.getHash()
                        << "  h2 = 0x" << std::hex << key.getHash2()
                        << std::endl;
                    ++numCollisions;
                    assert(false);
                } else {
                    hashes.insert(key.getHash(), key.getHash2());
                }
                for (int k = 0; k < 32; ++k) {
                    if (masks[k] & key.getHash2()) {
                        ++bits[k];
                    }
                }
            }
        }
    }
    uint64_t msec = timer.getTimeMilliseconds();
    std::cout << msec << " msec with " << numCollisions << " collisions out of " << testCount << " hashes" << std::endl;

    // print out distribution of bits
    for (int i = 0; i < 32; ++i) {
        std::cout << "bit 0x" << std::hex << masks[i] << std::dec << " = " << bits[i] << std::endl;
    }
}