| 125 | } |
| 126 | |
| 127 | fl::vector_fixed<Tile2x2_u8_wrap, 2> Tile2x2_u8_wrap::Interpolate(const Tile2x2_u8_wrap& a, const Tile2x2_u8_wrap& b, float t) { |
| 128 | fl::vector_fixed<Tile2x2_u8_wrap, 2> result; |
| 129 | |
| 130 | // Clamp t to [0, 1] |
| 131 | if (t <= 0.0f) { |
| 132 | result.push_back(a); |
| 133 | return result; |
| 134 | } |
| 135 | if (t >= 1.0f) { |
| 136 | result.push_back(b); |
| 137 | return result; |
| 138 | } |
| 139 | |
| 140 | // Create interpolated tile |
| 141 | Tile2x2_u8_wrap interpolated; |
| 142 | |
| 143 | // Interpolate each of the 4 positions |
| 144 | for (u16 x = 0; x < 2; ++x) { |
| 145 | for (u16 y = 0; y < 2; ++y) { |
| 146 | const auto& data_a = a.at(x, y); |
| 147 | const auto& data_b = b.at(x, y); |
| 148 | |
| 149 | // For now, assume positions are the same or close enough |
| 150 | // Use position from 'a' as the base |
| 151 | vec2<u16> pos = data_a.first; |
| 152 | |
| 153 | // Simple linear interpolation for alpha values |
| 154 | u8 alpha_a = data_a.second; |
| 155 | u8 alpha_b = data_b.second; |
| 156 | |
| 157 | // Linear interpolation: a + t * (b - a) |
| 158 | float alpha_float = alpha_a + t * (alpha_b - alpha_a); |
| 159 | u8 interpolated_alpha = static_cast<u8>(alpha_float + 0.5f); // Round to nearest |
| 160 | |
| 161 | interpolated.mData[y][x] = {pos, interpolated_alpha}; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | result.push_back(interpolated); |
| 166 | return result; |
| 167 | } |
| 168 | |
| 169 | } // namespace fl |