MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / SampleBL

Method SampleBL

olcPixelGameEngine.h:2096–2116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2094 }
2095
2096 Pixel Sprite::SampleBL(float u, float v) const
2097 {
2098 u = u * width - 0.5f;
2099 v = v * height - 0.5f;
2100 int x = (int)floor(u); // cast to int rounds toward zero, not downward
2101 int y = (int)floor(v); // Thanks @joshinils
2102 float u_ratio = u - x;
2103 float v_ratio = v - y;
2104 float u_opposite = 1 - u_ratio;
2105 float v_opposite = 1 - v_ratio;
2106
2107 olc::Pixel p1 = GetPixel(std::max(x, 0), std::max(y, 0));
2108 olc::Pixel p2 = GetPixel(std::min(x + 1, (int)width - 1), std::max(y, 0));
2109 olc::Pixel p3 = GetPixel(std::max(x, 0), std::min(y + 1, (int)height - 1));
2110 olc::Pixel p4 = GetPixel(std::min(x + 1, (int)width - 1), std::min(y + 1, (int)height - 1));
2111
2112 return olc::Pixel(
2113 (uint8_t)((p1.r * u_opposite + p2.r * u_ratio) * v_opposite + (p3.r * u_opposite + p4.r * u_ratio) * v_ratio),
2114 (uint8_t)((p1.g * u_opposite + p2.g * u_ratio) * v_opposite + (p3.g * u_opposite + p4.g * u_ratio) * v_ratio),
2115 (uint8_t)((p1.b * u_opposite + p2.b * u_ratio) * v_opposite + (p3.b * u_opposite + p4.b * u_ratio) * v_ratio));
2116 }
2117
2118 Pixel Sprite::SampleBL(const olc::vf2d& uv) const
2119 {

Callers

nothing calls this directly

Calls 1

PixelClass · 0.85

Tested by

no test coverage detected