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