コード例 #1
0
ファイル: SkeletonModel.cpp プロジェクト: pcerioli/hifi
void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha) {
    const int BALL_SUBDIVISIONS = 10;

    auto geometryCache = DependencyManager::get<GeometryCache>();
    auto deferredLighting = DependencyManager::get<DeferredLightingEffect>();
    Transform transform; // = Transform();

    // draw a blue sphere at the capsule top point
    glm::vec3 topPoint = _translation + _boundingCapsuleLocalOffset + (0.5f * _boundingCapsuleHeight) * glm::vec3(0.0f, 1.0f, 0.0f);
    transform.setTranslation(topPoint);
    batch.setModelTransform(transform);
    deferredLighting->bindSimpleProgram(batch);
    geometryCache->renderSphere(batch, _boundingCapsuleRadius, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS,
                                glm::vec4(0.6f, 0.6f, 0.8f, alpha));

    // draw a yellow sphere at the capsule bottom point 
    glm::vec3 bottomPoint = topPoint - glm::vec3(0.0f, -_boundingCapsuleHeight, 0.0f);
    glm::vec3 axis = topPoint - bottomPoint;
    transform.setTranslation(bottomPoint);
    batch.setModelTransform(transform);
    deferredLighting->bindSimpleProgram(batch);
    geometryCache->renderSphere(batch, _boundingCapsuleRadius, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS,
                                glm::vec4(0.8f, 0.8f, 0.6f, alpha));

    // draw a green cylinder between the two points
    glm::vec3 origin(0.0f);
    Avatar::renderJointConnectingCone(batch, origin, axis, _boundingCapsuleRadius, _boundingCapsuleRadius,
                                      glm::vec4(0.6f, 0.8f, 0.6f, alpha));
}
コード例 #2
0
void Rectangle3DOverlay::render(RenderArgs* args) {
    if (!_visible) {
        return; // do nothing if we're not visible
    }

    float alpha = getAlpha();
    xColor color = getColor();
    const float MAX_COLOR = 255.0f;
    glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);

    glm::vec3 position = getPosition();
    glm::vec2 dimensions = getDimensions();
    glm::vec2 halfDimensions = dimensions * 0.5f;
    glm::quat rotation = getRotation();

    auto batch = args->_batch;

    if (batch) {
        Transform transform;
        transform.setTranslation(position);
        transform.setRotation(rotation);

        batch->setModelTransform(transform);
        auto geometryCache = DependencyManager::get<GeometryCache>();

        if (getIsSolid()) {
            glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f);
            glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f);
            geometryCache->bindSimpleProgram(*batch);
            geometryCache->renderQuad(*batch, topLeft, bottomRight, rectangleColor);
        } else {
            geometryCache->bindSimpleProgram(*batch, false, false, false, true, true);
            if (getIsDashedLine()) {
                glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f);
                glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f);
                glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f);
                glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f);

                geometryCache->renderDashedLine(*batch, point1, point2, rectangleColor);
                geometryCache->renderDashedLine(*batch, point2, point3, rectangleColor);
                geometryCache->renderDashedLine(*batch, point3, point4, rectangleColor);
                geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor);
            } else {
                if (halfDimensions != _previousHalfDimensions) {
                    QVector<glm::vec3> border;
                    border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
                    border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
                    border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
                    border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
                    border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
                    geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);

                    _previousHalfDimensions = halfDimensions;
                }
                geometryCache->renderVertices(*batch, gpu::LINE_STRIP, _geometryCacheID);
            }
        }
    }
}
コード例 #3
0
ファイル: Line3DOverlay.cpp プロジェクト: aoighost/hifi
void Line3DOverlay::render(RenderArgs* args) {
    if (!_visible) {
        return; // do nothing if we're not visible
    }

    float alpha = getAlpha();
    xColor color = getColor();
    const float MAX_COLOR = 255.0f;
    glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);

    auto batch = args->_batch;
    if (batch) {
        batch->setModelTransform(_transform);

        auto geometryCache = DependencyManager::get<GeometryCache>();
        geometryCache->bindSimpleProgram(*batch, false, false, true, true);
        if (getIsDashedLine()) {
            // TODO: add support for color to renderDashedLine()
            geometryCache->renderDashedLine(*batch, _start, _end, colorv4, _geometryCacheID);
        } else {

            geometryCache->renderLine(*batch, _start, _end, colorv4, _geometryCacheID);
        }
    }
}
コード例 #4
0
ファイル: SkeletonModel.cpp プロジェクト: disigma/hifi
void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float scale, float alpha) {
    auto geometryCache = DependencyManager::get<GeometryCache>();
    auto deferredLighting = DependencyManager::get<DeferredLightingEffect>();
    // draw a blue sphere at the capsule top point
    glm::vec3 topPoint = _translation + getRotation() * (scale * (_boundingCapsuleLocalOffset + (0.5f * _boundingCapsuleHeight) * Vectors::UNIT_Y));

    deferredLighting->renderSolidSphereInstance(batch,
        Transform().setTranslation(topPoint).postScale(scale * _boundingCapsuleRadius),
    	glm::vec4(0.6f, 0.6f, 0.8f, alpha));

    // draw a yellow sphere at the capsule bottom point
    glm::vec3 bottomPoint = topPoint - glm::vec3(0.0f, scale * _boundingCapsuleHeight, 0.0f);
    glm::vec3 axis = topPoint - bottomPoint;

    deferredLighting->renderSolidSphereInstance(batch,
        Transform().setTranslation(bottomPoint).postScale(scale * _boundingCapsuleRadius),
        glm::vec4(0.8f, 0.8f, 0.6f, alpha));

    // draw a green cylinder between the two points
    glm::vec3 origin(0.0f);
    batch.setModelTransform(Transform().setTranslation(bottomPoint));
    deferredLighting->bindSimpleProgram(batch);
    Avatar::renderJointConnectingCone(batch, origin, axis, scale * _boundingCapsuleRadius, scale * _boundingCapsuleRadius,
                                      glm::vec4(0.6f, 0.8f, 0.6f, alpha));
}
コード例 #5
0
ファイル: SkeletonModel.cpp プロジェクト: MarcelEdward/hifi
void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha) {
    const int BALL_SUBDIVISIONS = 10;
    if (_shapes.isEmpty()) {
        // the bounding shape has not been properly computed
        // so no need to render it
        return;
    }

    auto geometryCache = DependencyManager::get<GeometryCache>();
    auto deferredLighting = DependencyManager::get<DeferredLightingEffect>();
    Transform transform; // = Transform();

    // draw a blue sphere at the capsule end point
    glm::vec3 endPoint;
    _boundingShape.getEndPoint(endPoint);
    endPoint = endPoint + _translation;
    transform.setTranslation(endPoint);
    batch.setModelTransform(transform);
    deferredLighting->bindSimpleProgram(batch);
    geometryCache->renderSphere(batch, _boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS,
                                glm::vec4(0.6f, 0.6f, 0.8f, alpha));

    // draw a yellow sphere at the capsule start point
    glm::vec3 startPoint;
    _boundingShape.getStartPoint(startPoint);
    startPoint = startPoint + _translation;
    glm::vec3 axis = endPoint - startPoint;
    transform.setTranslation(startPoint);
    batch.setModelTransform(transform);
    deferredLighting->bindSimpleProgram(batch);
    geometryCache->renderSphere(batch, _boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS,
                                glm::vec4(0.8f, 0.8f, 0.6f, alpha));

    // draw a green cylinder between the two points
    glm::vec3 origin(0.0f);
    Avatar::renderJointConnectingCone(batch, origin, axis, _boundingShape.getRadius(), _boundingShape.getRadius(), 
                                      glm::vec4(0.6f, 0.8f, 0.6f, alpha));
}
コード例 #6
0
void FloorTextureTest::renderTest(size_t testId, RenderArgs* args) {
    gpu::Batch& batch = *(args->_batch);
    auto geometryCache = DependencyManager::get<GeometryCache>();
    static auto start = usecTimestampNow();
    auto now = usecTimestampNow();
    if ((now - start) > USECS_PER_SECOND * 1) {
        start = now;
        texture->incremementMinMip();
    }

    geometryCache->bindSimpleProgram(batch, true, false, true, true);
    batch.setInputBuffer(0, vertexBuffer, 0, sizeof(Vertex));
    batch.setInputFormat(vertexFormat);
    batch.setIndexBuffer(gpu::UINT16, indexBuffer, 0);
    batch.setResourceTexture(0, texture);
    batch.setModelTransform(glm::translate(glm::mat4(), vec3(0, -0.1, 0)));
    batch.drawIndexed(gpu::TRIANGLES, 6, 0);
}
コード例 #7
0
void renderInstances(const std::string& name, gpu::Batch& batch, const Transform& transform, const glm::vec4& color, F f) {
    {
        gpu::BufferPointer instanceTransformBuffer = batch.getNamedBuffer(name, INSTANCE_TRANSFORM_BUFFER);
        glm::mat4 glmTransform;
        instanceTransformBuffer->append(transform.getMatrix(glmTransform));

        gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER);
        auto compactColor = toCompactColor(color);
        instanceColorBuffer->append(compactColor);
    }

    auto that = DependencyManager::get<DeferredLightingEffect>();
    batch.setupNamedCalls(name, [=](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
        auto pipeline = that->bindSimpleProgram(batch);
        auto location = pipeline->getProgram()->getUniforms().findLocation("Instanced");

        batch._glUniform1i(location, 1);
        f(batch, data);
        batch._glUniform1i(location, 0);
    });
}
コード例 #8
0
void DeferredLightingEffect::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2,
                                        const glm::vec4& color1, const glm::vec4& color2) {
    bindSimpleProgram(batch);
    DependencyManager::get<GeometryCache>()->renderLine(batch, p1, p2, color1, color2);
    releaseSimpleProgram(batch);
}
コード例 #9
0
void DeferredLightingEffect::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner,
                                        const glm::vec4& color) {
    bindSimpleProgram(batch);
    DependencyManager::get<GeometryCache>()->renderQuad(batch, minCorner, maxCorner, color);
    releaseSimpleProgram(batch);
}
コード例 #10
0
void DeferredLightingEffect::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) {
    bindSimpleProgram(batch);
    DependencyManager::get<GeometryCache>()->renderWireCube(batch, size, color);
    releaseSimpleProgram(batch);
}
コード例 #11
0
void DeferredLightingEffect::renderWireSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color) {
    bindSimpleProgram(batch);
    DependencyManager::get<GeometryCache>()->renderSphere(batch, radius, slices, stacks, color, false);
    releaseSimpleProgram(batch);
}
コード例 #12
0
void DeferredLightingEffect::renderSolidCone(float base, float height, int slices, int stacks) {
    bindSimpleProgram();
    Application::getInstance()->getGeometryCache()->renderCone(base, height, slices, stacks);
    releaseSimpleProgram();
}
コード例 #13
0
void DeferredLightingEffect::renderWireCube(float size) {
    bindSimpleProgram();
    glutWireCube(size);
    releaseSimpleProgram();
}
コード例 #14
0
void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks) {
    bindSimpleProgram();
    glutWireSphere(radius, slices, stacks);
    releaseSimpleProgram();
}
コード例 #15
0
void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks) {
    bindSimpleProgram();
    Application::getInstance()->getGeometryCache()->renderSphere(radius, slices, stacks); 
    releaseSimpleProgram();
}