Example #1
0
fp_t URatPSeriesFlint::pow(const fp_t &s, int n, unsigned prec) {
    if (n > 0)
        return fp_t(s.pow(unsigned(n)));
    else if (n < 0)
        return fp_t(s.inv_series(prec).pow(unsigned(-n)));
    return fp_t(1);
}
Example #2
0
void Image::scale(int newWidth, int newHeight)
{
    if(newWidth == width_ && newHeight == height_)
    {
        return;
    }

    if(isCompressed(format_))
    {
        throw runtime_error("Cannot scale compressed image");
    }

    int nchannels = bitsPerPixel(format_) / 8;

    vector<uint8_t> newData(newWidth * newHeight * nchannels);

    for(int dstY = 0; dstY < newHeight; dstY++)
    {
        for(int dstX = 0; dstX < newWidth; dstX++)
        {
            fp_t srcFX = static_cast<fp_t>(dstX) / static_cast<fp_t>(newWidth) * static_cast<fp_t>(width_);
            fp_t srcFY = static_cast<fp_t>(dstY) / static_cast<fp_t>(newHeight) * static_cast<fp_t>(height_);

            int srcX = static_cast<int>(srcFX);
            int srcY = static_cast<int>(srcFY);

            fp_t xDiff = srcFX - srcX;
            fp_t yDiff = srcFY - srcY;

            fp_t xOpposite = fp_t(1.0) - xDiff;
            fp_t yOpposite = fp_t(1.0) - yDiff;

#define SRCPX(x, y, cn) static_cast<fp_t>(data_[(min(x, width_ - 1) + min(y, height_ - 1) * width_) * nchannels + cn])
#define DSTPX(x, y, cn) newData[((x) + (y) * newWidth) * nchannels + cn]

            for(int c = 0; c < nchannels; c++)
            {
                DSTPX(dstX, dstY, c) = static_cast<uint8_t>(
                    (SRCPX(srcX, srcY, c) * xOpposite + SRCPX(srcX + 1, srcY, c) * xDiff) * yOpposite +
                    (SRCPX(srcX, srcY + 1, c) * xOpposite + SRCPX(srcX + 1, srcY + 1, c) * xDiff) * yDiff);
            }

#undef SRCPX
#undef DSTPX
        }
    }

    data_ = move(newData);
    width_ = newWidth;
    height_ = newHeight;
}
Example #3
0
void Renderer::render(fp_t interp)
{
    UNUSED(interp);

#ifdef OCULUSVR
    if(hmd_ != nullptr)
    {
        return renderOVR(interp);
    }
#endif

    int windowWidth, windowHeight;
    SDL_GetWindowSize(window_, &windowWidth, &windowHeight);

    // projection * view * model * vertex
    glm::mat4 projectionMat = glm::perspective(fieldOfView_ / fp_t(180.0) * pi(), static_cast<fp_t>(windowWidth) / static_cast<fp_t>(windowHeight), fp_t(0.1), fp_t(1000.0));

    const glm::mat4& viewMat = Core::get().camera().viewMatrix();

    glClear(GL_DEPTH_BUFFER_BIT);

    skyRenderer_->render();
    landRenderer_->render(projectionMat, viewMat);
    structureRenderer_->render(projectionMat, viewMat);
    modelRenderer_->render(projectionMat, viewMat);

    SDL_GL_SwapWindow(window_);
}
Example #4
0
void Core::run()
{
    uint64_t frequency = SDL_GetPerformanceFrequency();
    uint64_t fixedStep = frequency / static_cast<uint64_t>(kStepRate);
    uint64_t maxTotalDelta = fixedStep * 6;
    uint64_t stepTime = SDL_GetPerformanceCounter();

    while(!done_)
    {
        uint64_t loopTime = SDL_GetPerformanceCounter();

        if(loopTime > stepTime + maxTotalDelta)
        {
            stepTime = loopTime - maxTotalDelta;
        }

        while(loopTime >= stepTime + fixedStep)
        {
            handleEvents();
            sessionManager_->handleBlobs();
            step(fp_t(1.0) / kStepRate);
            stepTime += fixedStep;
        }

#ifndef HEADLESS
        fp_t interp = static_cast<fp_t>(loopTime - stepTime) / static_cast<fp_t>(frequency);
        renderer_->render(interp);
#else
        // simulate ~83 without game logic
        SDL_Delay(12);
#endif
    }
}
Example #5
0
void Renderer::init()
{
#ifdef OCULUSVR
    initOVR();
#endif

    SDL_GL_SetSwapInterval(1); // vsync
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // the default is 4
    glEnable(GL_PRIMITIVE_RESTART);
    glPrimitiveRestartIndex(0xFFFF);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    skyRenderer_.reset(new SkyRenderer());
    landRenderer_.reset(new LandRenderer());
    structureRenderer_.reset(new StructureRenderer());
    modelRenderer_.reset(new ModelRenderer());

    landRenderer_->setLightPosition(skyRenderer_->sunVector() * fp_t(1000.0));
}
Example #6
0
fp_t URatPSeriesFlint::convert(const rational_class &x)
{
    return fp_t(get_mpq_t(x));
}
Example #7
0
fp_t URatPSeriesFlint::convert(const integer_class &x)
{
    return fp_t(get_mpz_t(x));
}
Example #8
0
fp_t URatPSeriesFlint::subs(const fp_t &s, const fp_t &var, const fp_t &r, unsigned prec) {
    return fp_t(s(r));
}
Example #9
0
fp_t URatPSeriesFlint::integrate(const fp_t &s, const fp_t &var) {
    return fp_t(s.integral());
}
Example #10
0
fp_t URatPSeriesFlint::diff(const fp_t &s, const fp_t &var) {
    return fp_t(s.derivative());
}