Ejemplo n.º 1
0
void Extents::rotate(const glm::quat& rotation) {
    glm::vec3 bottomLeftNear(minimum.x, minimum.y, minimum.z);
    glm::vec3 bottomRightNear(maximum.x, minimum.y, minimum.z);
    glm::vec3 bottomLeftFar(minimum.x, minimum.y, maximum.z);
    glm::vec3 bottomRightFar(maximum.x, minimum.y, maximum.z);
    glm::vec3 topLeftNear(minimum.x, maximum.y, minimum.z);
    glm::vec3 topRightNear(maximum.x, maximum.y, minimum.z);
    glm::vec3 topLeftFar(minimum.x, maximum.y, maximum.z);
    glm::vec3 topRightFar(maximum.x, maximum.y, maximum.z);

    glm::vec3 bottomLeftNearRotated =  rotation * bottomLeftNear;
    glm::vec3 bottomRightNearRotated = rotation * bottomRightNear;
    glm::vec3 bottomLeftFarRotated = rotation * bottomLeftFar;
    glm::vec3 bottomRightFarRotated = rotation * bottomRightFar;
    glm::vec3 topLeftNearRotated = rotation * topLeftNear;
    glm::vec3 topRightNearRotated = rotation * topRightNear;
    glm::vec3 topLeftFarRotated = rotation * topLeftFar;
    glm::vec3 topRightFarRotated = rotation * topRightFar;
    
    minimum = glm::min(bottomLeftNearRotated,
                        glm::min(bottomRightNearRotated,
                        glm::min(bottomLeftFarRotated,
                        glm::min(bottomRightFarRotated,
                        glm::min(topLeftNearRotated,
                        glm::min(topRightNearRotated,
                        glm::min(topLeftFarRotated,topRightFarRotated)))))));

    maximum = glm::max(bottomLeftNearRotated,
                        glm::max(bottomRightNearRotated,
                        glm::max(bottomLeftFarRotated,
                        glm::max(bottomRightFarRotated,
                        glm::max(topLeftNearRotated,
                        glm::max(topRightNearRotated,
                        glm::max(topLeftFarRotated,topRightFarRotated)))))));
}
Ejemplo n.º 2
0
void AABox::rotate(const glm::quat& rotation) {
    auto minimum = _corner;
    auto maximum = _corner + _scale;

    glm::vec3 bottomLeftNear(minimum.x, minimum.y, minimum.z);
    glm::vec3 bottomRightNear(maximum.x, minimum.y, minimum.z);
    glm::vec3 bottomLeftFar(minimum.x, minimum.y, maximum.z);
    glm::vec3 bottomRightFar(maximum.x, minimum.y, maximum.z);
    glm::vec3 topLeftNear(minimum.x, maximum.y, minimum.z);
    glm::vec3 topRightNear(maximum.x, maximum.y, minimum.z);
    glm::vec3 topLeftFar(minimum.x, maximum.y, maximum.z);
    glm::vec3 topRightFar(maximum.x, maximum.y, maximum.z);

    glm::vec3 bottomLeftNearRotated = rotation * bottomLeftNear;
    glm::vec3 bottomRightNearRotated = rotation * bottomRightNear;
    glm::vec3 bottomLeftFarRotated = rotation * bottomLeftFar;
    glm::vec3 bottomRightFarRotated = rotation * bottomRightFar;
    glm::vec3 topLeftNearRotated = rotation * topLeftNear;
    glm::vec3 topRightNearRotated = rotation * topRightNear;
    glm::vec3 topLeftFarRotated = rotation * topLeftFar;
    glm::vec3 topRightFarRotated = rotation * topRightFar;

    minimum = glm::min(bottomLeftNearRotated,
        glm::min(bottomRightNearRotated,
        glm::min(bottomLeftFarRotated,
        glm::min(bottomRightFarRotated,
        glm::min(topLeftNearRotated,
        glm::min(topRightNearRotated,
        glm::min(topLeftFarRotated,
        topRightFarRotated)))))));

    maximum = glm::max(bottomLeftNearRotated,
        glm::max(bottomRightNearRotated,
        glm::max(bottomLeftFarRotated,
        glm::max(bottomRightFarRotated,
        glm::max(topLeftNearRotated,
        glm::max(topRightNearRotated,
        glm::max(topLeftFarRotated,
        topRightFarRotated)))))));

    _corner = minimum;
    _scale = maximum - minimum;
}
Ejemplo n.º 3
0
void Cube3DOverlay::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 cubeColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);

    // TODO: handle registration point??
    glm::vec3 position = getPosition();
    glm::vec3 center = getCenter();
    glm::vec3 dimensions = getDimensions();
    glm::quat rotation = getRotation();

    auto batch = args->_batch;

    if (batch) {
        Transform transform;
        transform.setTranslation(position);
        transform.setRotation(rotation);
        if (_isSolid) {
            // if (_borderSize > 0) {
            //     // Draw a cube at a larger size behind the main cube, creating
            //     // a border effect.
            //     // Disable writing to the depth mask so that the "border" cube will not
            //     // occlude the main cube.  This means the border could be covered by
            //     // overlays that are further back and drawn later, but this is good
            //     // enough for the use-case.
            //     transform.setScale(dimensions * _borderSize);
            //     batch->setModelTransform(transform);
            //     DependencyManager::get<GeometryCache>()->renderSolidCube(*batch, 1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
            // }

            transform.setScale(dimensions);
            batch->setModelTransform(transform);
            DependencyManager::get<GeometryCache>()->renderSolidCube(*batch, 1.0f, cubeColor);
        } else {

            if (getIsDashedLine()) {
                transform.setScale(1.0f);
                batch->setModelTransform(transform);

                glm::vec3 halfDimensions = dimensions / 2.0f;
                glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
                glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
                glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
                glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);

                glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
                glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
                glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
                glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);

                auto geometryCache = DependencyManager::get<GeometryCache>();

                geometryCache->renderDashedLine(*batch, bottomLeftNear, bottomRightNear, cubeColor);
                geometryCache->renderDashedLine(*batch, bottomRightNear, bottomRightFar, cubeColor);
                geometryCache->renderDashedLine(*batch, bottomRightFar, bottomLeftFar, cubeColor);
                geometryCache->renderDashedLine(*batch, bottomLeftFar, bottomLeftNear, cubeColor);

                geometryCache->renderDashedLine(*batch, topLeftNear, topRightNear, cubeColor);
                geometryCache->renderDashedLine(*batch, topRightNear, topRightFar, cubeColor);
                geometryCache->renderDashedLine(*batch, topRightFar, topLeftFar, cubeColor);
                geometryCache->renderDashedLine(*batch, topLeftFar, topLeftNear, cubeColor);

                geometryCache->renderDashedLine(*batch, bottomLeftNear, topLeftNear, cubeColor);
                geometryCache->renderDashedLine(*batch, bottomRightNear, topRightNear, cubeColor);
                geometryCache->renderDashedLine(*batch, bottomLeftFar, topLeftFar, cubeColor);
                geometryCache->renderDashedLine(*batch, bottomRightFar, topRightFar, cubeColor);

            } else {
                transform.setScale(dimensions);
                batch->setModelTransform(transform);
                DependencyManager::get<DeferredLightingEffect>()->renderWireCube(*batch, 1.0f, cubeColor);
            }
        }
    }
}
Ejemplo n.º 4
0
void Cube3DOverlay::render(RenderArgs* args) {
    if (!_visible) {
        return; // do nothing if we're not visible
    }


    float glowLevel = getGlowLevel();
    Glower* glower = NULL;
    if (glowLevel > 0.0f) {
        glower = new Glower(glowLevel);
    }

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

    //glDisable(GL_LIGHTING);

    // TODO: handle registration point??
    glm::vec3 position = getPosition();
    glm::vec3 center = getCenter();
    glm::vec3 dimensions = getDimensions();
    glm::quat rotation = getRotation();

    glPushMatrix();
    glTranslatef(position.x, position.y, position.z);
    glm::vec3 axis = glm::axis(rotation);
    glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
    glPushMatrix();
    glm::vec3 positionToCenter = center - position;
    glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
    if (_isSolid) {
        if (_borderSize > 0) {
            // Draw a cube at a larger size behind the main cube, creating
            // a border effect.
            // Disable writing to the depth mask so that the "border" cube will not
            // occlude the main cube.  This means the border could be covered by
            // overlays that are further back and drawn later, but this is good
            // enough for the use-case.
            glDepthMask(GL_FALSE);
            glPushMatrix();
            glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize);

            if (_drawOnHUD) {
                DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
            } else {
                DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
            }

            glPopMatrix();
            glDepthMask(GL_TRUE);
        }

        glPushMatrix();
        glScalef(dimensions.x, dimensions.y, dimensions.z);
        if (_drawOnHUD) {
            DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
        } else {
            DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
        }
        glPopMatrix();
    } else {
        glLineWidth(_lineWidth);

        if (getIsDashedLine()) {
            glm::vec3 halfDimensions = dimensions / 2.0f;
            glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
            glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
            glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
            glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);

            glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
            glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
            glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
            glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);

            auto geometryCache = DependencyManager::get<GeometryCache>();

            geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear, cubeColor);
            geometryCache->renderDashedLine(bottomRightNear, bottomRightFar, cubeColor);
            geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar, cubeColor);
            geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear, cubeColor);

            geometryCache->renderDashedLine(topLeftNear, topRightNear, cubeColor);
            geometryCache->renderDashedLine(topRightNear, topRightFar, cubeColor);
            geometryCache->renderDashedLine(topRightFar, topLeftFar, cubeColor);
            geometryCache->renderDashedLine(topLeftFar, topLeftNear, cubeColor);

            geometryCache->renderDashedLine(bottomLeftNear, topLeftNear, cubeColor);
            geometryCache->renderDashedLine(bottomRightNear, topRightNear, cubeColor);
            geometryCache->renderDashedLine(bottomLeftFar, topLeftFar, cubeColor);
            geometryCache->renderDashedLine(bottomRightFar, topRightFar, cubeColor);

        } else {
            glScalef(dimensions.x, dimensions.y, dimensions.z);
            DependencyManager::get<DeferredLightingEffect>()->renderWireCube(1.0f, cubeColor);
        }
    }
    glPopMatrix();
    glPopMatrix();

    if (glower) {
        delete glower;
    }
}