3173 lines · 138.0 KB · C++
RawDownload
int DefaultMetavoxelRendererImplementation::_baseColorScaleLocation;ProgramObject DefaultMetavoxelRendererImplementation::_splatHeightfieldProgram;DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatHeightfieldLocations;ProgramObject DefaultMetavoxelRendererImplementation::_heightfieldCursorProgram;ProgramObject DefaultMetavoxelRendererImplementation::_baseVoxelProgram;ProgramObject DefaultMetavoxelRendererImplementation::_splatVoxelProgram;DefaultMetavoxelRendererImplementation::SplatLocations DefaultMetavoxelRendererImplementation::_splatVoxelLocations;ProgramObject DefaultMetavoxelRendererImplementation::_voxelCursorProgram; static void enableClipPlane(GLenum plane, float x, float y, float z, float w) {    GLdouble coefficients[] = { x, y, z, w };    glClipPlane(plane, coefficients);    glEnable(plane);} void ClippedRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) {    if (clipSize == 0.0f) {        renderUnclipped(color, mode);        return;    }    enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize);    enableClipPlane(GL_CLIP_PLANE1, 1.0f, 0.0f, 0.0f, -clipMinimum.x);    enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipSize);    enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y);    enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize);    enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z);        renderUnclipped(color, mode);        glDisable(GL_CLIP_PLANE0);    glDisable(GL_CLIP_PLANE1);    glDisable(GL_CLIP_PLANE2);    glDisable(GL_CLIP_PLANE3);    glDisable(GL_CLIP_PLANE4);    glDisable(GL_CLIP_PLANE5);} SphereRenderer::SphereRenderer() {} void SphereRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) {    if (clipSize == 0.0f) {        renderUnclipped(color, mode);        return;    }    // slight performance optimization: don't render if clip bounds are entirely within sphere    Sphere* sphere = static_cast<Sphere*>(_spanner);    Box clipBox(clipMinimum, clipMinimum + glm::vec3(clipSize, clipSize, clipSize));    for (int i = 0; i < Box::VERTEX_COUNT; i++) {        const float CLIP_PROPORTION = 0.95f;        if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) {            ClippedRenderer::render(color, mode, clipMinimum, clipSize);            return;        }    }} void SphereRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {    Sphere* sphere = static_cast<Sphere*>(_spanner);    const QColor& ownColor = sphere->getColor();    glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a);        glPushMatrix();    const glm::vec3& translation = sphere->getTranslation();    glTranslatef(translation.x, translation.y, translation.z);    glm::quat rotation = sphere->getRotation();    glm::vec3 axis = glm::axis(rotation);    glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);        Application::getInstance()->getGeometryCache()->renderSphere(sphere->getScale(), 10, 10);        glPopMatrix();} CuboidRenderer::CuboidRenderer() {} void CuboidRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {    Cuboid* cuboid = static_cast<Cuboid*>(_spanner);    const QColor& ownColor = cuboid->getColor();    glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a);        glPushMatrix();    const glm::vec3& translation = cuboid->getTranslation();    glTranslatef(translation.x, translation.y, translation.z);    glm::quat rotation = cuboid->getRotation();    glm::vec3 axis = glm::axis(rotation);    glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);    glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ());        glutSolidCube(cuboid->getScale() * 2.0f);        glPopMatrix();} StaticModelRenderer::StaticModelRenderer() :    _model(new Model(this)) {} void StaticModelRenderer::init(Spanner* spanner) {    SpannerRenderer::init(spanner);     _model->init();        StaticModel* staticModel = static_cast<StaticModel*>(spanner);    applyTranslation(staticModel->getTranslation());    applyRotation(staticModel->getRotation());    applyScale(staticModel->getScale());    applyURL(staticModel->getURL());        connect(spanner, SIGNAL(translationChanged(const glm::vec3&)), SLOT(applyTranslation(const glm::vec3&)));    connect(spanner, SIGNAL(rotationChanged(const glm::quat&)), SLOT(applyRotation(const glm::quat&)));    connect(spanner, SIGNAL(scaleChanged(float)), SLOT(applyScale(float)));    connect(spanner, SIGNAL(urlChanged(const QUrl&)), SLOT(applyURL(const QUrl&)));} void StaticModelRenderer::simulate(float deltaTime) {    // update the bounds    Box bounds;    if (_model->isActive()) {        const Extents& extents = _model->getGeometry()->getFBXGeometry().meshExtents;        bounds = Box(extents.minimum, extents.maximum);    }    static_cast<StaticModel*>(_spanner)->setBounds(glm::translate(_model->getTranslation()) *        glm::mat4_cast(_model->getRotation()) * glm::scale(_model->getScale()) * bounds);    _model->simulate(deltaTime);} void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {    switch (mode) {        case DIFFUSE_MODE:            _model->render(color.a, Model::DIFFUSE_RENDER_MODE);            break;                    case NORMAL_MODE:            _model->render(color.a, Model::NORMAL_RENDER_MODE);            break;                    default:            _model->render(color.a);            break;    }    _model->render(color.a);} bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,        const glm::vec3& clipMinimum, float clipSize, float& distance) const {    RayIntersectionInfo info;    info._rayStart = origin;    info._rayDirection = direction;    if (!_model->findRayIntersection(info)) {        return false;    }    distance = info._hitDistance;    return true;} void StaticModelRenderer::applyTranslation(const glm::vec3& translation) {    _model->setTranslation(translation);} void StaticModelRenderer::applyRotation(const glm::quat& rotation) {    _model->setRotation(rotation);} void StaticModelRenderer::applyScale(float scale) {    const float SCALE_MULTIPLIER = 0.0006f;    _model->setScale(glm::vec3(scale, scale, scale) * SCALE_MULTIPLIER);} void StaticModelRenderer::applyURL(const QUrl& url) {    _model->setURL(url);}

Lines 3001–3173 of 3173. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t