Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Dwindows

Pages: [1]
1
General / Re: Unwanted Motion Blur
« on: March 03, 2024, 09:55:08 pm »
Thanks man!  ;D

I didn’t know what Monitor Ghosting was  :P  and you really helped me!

2
General / Unwanted Motion Blur
« on: March 02, 2024, 05:39:42 pm »
Hi! (and thank u for reading this  ;D)

Now that I've implemented interpolation and I have a very smooth movement, I encountered a problem while moving my rectangle.
If I move it slowly, it goes perfectly; but when I move it fast, there's like a motion blur effect that makes it strange.
I'm using Windows 10 with an Nvidia GPU (GeForce RTX 2060) and my program uses SFML 2.6.1.

Minimal Example of code:
#include <SFML/Graphics.hpp>
#include <Kairos/Timestep.hpp>

sf::Vector2f lerpV(sf::Vector2f a, sf::Vector2f b, float t)
{
    return a * (1 - t) + b * t;
}

void Update(sf::Shape* s, float dt, sf::Vector2f* vel, sf::Vector2f* pos)
{
    float mass = 1.f;
    float f = 100.f;
    sf::Vector2f force = sf::Vector2f(0.f, 0.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
        force += sf::Vector2f(0.f, -f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
        force += sf::Vector2f(-f, 0.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
        force += sf::Vector2f(0.f, f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
        force += sf::Vector2f(f, 0.f);

    // Inertia:
    force += sf::Vector2f(-vel->x * 1.f * mass * 9.81f, -vel->y * 1.f * mass * 9.81f);

    float acceleration_x = force.x / mass;
    float acceleration_y = force.y / mass;
    *vel += sf::Vector2f(acceleration_x * dt, acceleration_y * dt);
    *pos += *vel;
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(1200, 800), "Motion Blur Problem");
    window.setVerticalSyncEnabled(false);
    window.setFramerateLimit(144);

    sf::RectangleShape shape(sf::Vector2f(200.f, 200.f));
    shape.setFillColor(sf::Color::Green);
    sf::Vector2f velocity = sf::Vector2f(0.f, 0.f);

    sf::Vector2f pre = shape.getPosition();
    sf::Vector2f position = shape.getPosition();

    kairos::Timestep timestep;
    timestep.setStep(1.f / 60.f);
    timestep.setMaxAccumulation(0.25f);
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        timestep.addFrame();
        while (timestep.isUpdateRequired())
        {
            pre = position;
            float dt = timestep.getStepAsFloat();

            Update(&shape, dt, &velocity, &position);
        }
        float interpolation = timestep.getInterpolationAlphaAsFloat();

        window.clear();
       
        shape.setPosition(lerpV(pre, position, interpolation));
        window.draw(shape);

        window.display();
    }

    return 0;
}

My main questions are:
1. is this an optical illusion made by its movement? (so I should only move it slowly)
2. is this a problem of my monitor or my eyes? (so I should cry)
3. or is this a bug? and if yes, how can I fix it?

3
General / Re: Casual Stuttering Problem
« on: February 27, 2024, 05:27:16 pm »
Thanks man, you saved me!

4
General / Casual Stuttering Problem
« on: February 27, 2024, 07:49:15 am »
Hi,
(and thank you for reading this)

I'm having an issue where: when I run my application and I move my object, sometimes it runs perfectly and with smooth movements, and other times it stutters a lot.
I'm using Windows 10 with an Nvidia GPU (GeForce RTX 2060) and my program uses SFML 2.6.1.


(sorry but I don't know how to put the code in the "white scrollable box")
Minimal Example:
#include <SFML/Graphics.hpp>
//#include <iostream>

void Update(sf::CircleShape* s, float dt, sf::Vector2f* vel)
{
    float mass = 1.f;
    sf::Vector2f force = sf::Vector2f(0.f, 0.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
        force += sf::Vector2f(0.f, -100.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
        force += sf::Vector2f(-100.f, 0.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
        force += sf::Vector2f(0.f, 100.f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
        force += sf::Vector2f(100.f, 0.f);

    // Inerzia:
    force += sf::Vector2f(-vel->x * 1.f * mass * 9.81f, -vel->y * 1.f * mass * 9.81f);

    float acceleration_x = force.x / mass;
    float acceleration_y = force.y / mass;
    *vel += sf::Vector2f(acceleration_x * dt, acceleration_y * dt);
    s->move(*vel);
}

int main()
{
    const float dt = 1.f / 60.f;

    sf::RenderWindow window(sf::VideoMode(1200, 800), "Stutter Problem");
    window.setVerticalSyncEnabled(false);
    window.setFramerateLimit(144);
    sf::Clock clock;

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);
    sf::Vector2f velocity = sf::Vector2f(0.f, 0.f);

    float newTime = 0.f, frameTime = 0.f;
    float currentTime = clock.getElapsedTime().asSeconds();
    float accumulator = 0.f;
    while (window.isOpen())
    {
        newTime = clock.getElapsedTime().asSeconds();
        frameTime = newTime - currentTime;
        if (frameTime > 0.25f)
            frameTime = 0.25f;
        currentTime = newTime;
        accumulator += frameTime;

        // Handle Inputs:
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        while (accumulator >= dt)
        {
            Update(&shape, dt, &velocity);
            accumulator -= dt;
        }

        window.clear();
        window.draw(shape);
        window.display();
        sf::sleep(sf::milliseconds(1));
    }

    return 0;
}

and attached here I put a video with the type of stutter that I encounter often.

Pages: [1]
anything