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 - DGYLLEANN

Pages: [1]
1
General / Re: Cosine Interpolation Rendering as linear
« on: September 01, 2022, 07:59:16 am »
Thanks Kojack, had just figured it out before I saw your post :)
Yeah my issue was that I was interpolating on both axis, rather than just the Y, and so the cosine waves were going in opposite directions, cancelling out and making a straight(linear) interpolation.
All sorted now, just had to change this
return sf::Vector2f(a.x * (1-f) + b.x * f,
        a.y * (1 - f) + b.y * f);

to this:
    return sf::Vector2f(a.x * (1-randN ) + b.x * randN ,
        a.y * (1 - f) + b.y * f);
but yeah thanks for help regardless.
Also I'm not interpolating between 1000 points, those 1000 points are the points being drawn between the two points i am interpolating between, to make a solid line. Ik using a random number to pick numbers between 0 and 1 isnt most efficient but I am not going to be ending up rendering these lines in future, it was just so I could see my cosine interpolation function was working.

2
General / Re: Help With Interpolation
« on: August 31, 2022, 11:31:24 pm »
Figured it out, basically just got a function that gave me pixel values and rendered them as a single vertex along the coordinates returned by the function. However still asking for more help in my new post :)

3
General / Cosine Interpolation Rendering as linear
« on: August 31, 2022, 11:24:58 pm »
Hi Guys
Yesterday I made a post about help manually making a draw function to render my interpolation. I have got that working now however my cosine interpolation is rendering as linear. My linear one works fine, but my cosine one doesn't look any different.

here is my function for linear interpolation (which works correctly):
sf::Vector2f game::linearInterpolate(sf::Vector2f a, sf::Vector2f b, float randN) {
        return sf::Vector2f(a.x * (1 - randN) + b.x * randN,
            a.y * (1 - randN) + b.y * randN);
}
A is the point to interpolate from, B is the point to interpolate to, and randN is obv random number

Here is my function for cosine interpolation:
sf::Vector2f game::cosineInterpolate(sf::Vector2f a, sf::Vector2f b, float randN) {
    float ft = randN * 3.1415927f;
    float f = (1 - cos(ft)) * 0.5f;

    return sf::Vector2f(a.x * (1-f) + b.x * f,
        a.y * (1 - f) + b.y * f);
   
}
same variables as above :)

And here is my manual drawing function:

//For each point to interpolate between:
    for (sf::Vector2f &l : this->noiseSpots) {
       
        //How many pixels between each point:
        for (unsigned long xScreen = 0; xScreen < 1000; xScreen++) {
            //random number between 0 and one
            float r = this->rand01();
           
            //calculate points to draw
            sf::Vector2f lInterpolatedVec = linearInterpolate(l, this->noiseSpots.at(a + 1), r);
            sf::Vector2f coInterpolatedVec = cosineInterpolate(l, this->noiseSpots.at(a + 1), r);

            //draw linear interpolated graph
            this->graph.setPixel(lInterpolatedVec.x, lInterpolatedVec.y, sf::Color(255, 255, 255));
            //draw cosine interpolated graph
            this->graph.setPixel(coInterpolatedVec.x, coInterpolatedVec.y, sf::Color(255, 0, 0));
        }
        if (a < fidelity-1) { a++; }else{};
    }

fidelity is the number of points, and noisespots is a vector of sf::Vector2f's that stores the coOrdinants of all points to interpolate between. I think the issue is with my draw function but I'm not sure what it could be. If you guys could give any help that would be much appreciated

an image is attached of each interpolation method. the red one is the "Cubic interpolation" and the white one is the linear

Edit: Ok after rigorous testing, the draw function is fine, but the cosine interpolation function seems to be outputting linear interpolation function coordinates. If I change one of the values of f in the return, I get curvy lines but they aren't cosine interpolation

4
General / Help With Interpolation
« on: August 31, 2022, 04:25:21 am »
Hiya Guys
I am trying to work on a 2D perlin noise generation algorithm, but thought I better make a 1D one first so I can understand it better. However, I am completely stuck on linear interpolation between my points. I am using a vector of SFML vertex arrays to store each pixel and its coordinants, but I don't know how to draw lines between them manually. I don't want to set a primitive type, as these lines are really jagged and pointy. Looking to implement either cubic or cosine linear interpolation. I am fine with swapping out of a vertex array, but I just don't know how to draw custom, bendy lines directly to the screen.

Basically just looking for help on how to draw connecting lines  that don't go straight there between the two points.



 

Pages: [1]