Decompile fn_01727 (SampleModelTexture)
Batch #18030 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_01727 SampleModelTexture: logic confirmed by peer review Peer-reviewed-by: Yommy, KWDev, bibinir Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes).
This commit is contained in:
parent
d07aba10b0
commit
3e3d18512e
2 changed files with 18 additions and 22 deletions
|
|
@ -12,7 +12,7 @@ struct ModelTextureTransform {
|
|||
/* 0000 */ float values[5] = {0, 0, 1, 1, 0};
|
||||
};
|
||||
|
||||
void SampleModelTexture(const ModelTextureChannels& channels, float frame, ModelTextureTransform& output);
|
||||
void SampleModelTexture(ModelTextureChannels& channels, float frame, ModelTextureTransform& output);
|
||||
|
||||
class C3dNode {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -3,34 +3,30 @@
|
|||
|
||||
// OFFSET: 0x00540EA0
|
||||
// FUNCTION: fn_01727
|
||||
void SampleModelTexture(const ModelTextureChannels& channels, float frame, ModelTextureTransform& output) {
|
||||
void SampleModelTexture(ModelTextureChannels& channels, float frame, ModelTextureTransform& output) {
|
||||
float* targets[5] = {&output.values[0], &output.values[1], &output.values[2], &output.values[3], &output.values[4]};
|
||||
|
||||
for (int channel = 0; channel < 5; ++channel) {
|
||||
const auto found = channels.find(channel);
|
||||
|
||||
if (found == channels.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto& keys = found->second;
|
||||
const int last = keys.back().frame;
|
||||
|
||||
if (frame >= static_cast<float>(last)) {
|
||||
output.values[channel] = keys.back().value;
|
||||
if (channels.find(channel) == channels.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<ModelTextureKey>& keys = channels[channel];
|
||||
unsigned next = 1;
|
||||
if (frame < static_cast<float>(keys.back().frame)) {
|
||||
const unsigned count = keys.size();
|
||||
for (; next < count; ++next) {
|
||||
if (frame < static_cast<float>(keys[next].frame)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (next < keys.size() && !(static_cast<float>(keys[next].frame) > frame)) {
|
||||
++next;
|
||||
const int previous = keys[next - 1].frame;
|
||||
const float amount = (frame - static_cast<float>(previous)) / static_cast<float>(keys[next].frame - previous);
|
||||
*targets[channel] = (1.0f - amount) * keys[next - 1].value + amount * keys[next].value;
|
||||
} else {
|
||||
*targets[channel] = keys.back().value;
|
||||
}
|
||||
|
||||
const int previous = keys[next - 1].frame;
|
||||
const int difference = keys[next].frame - keys[next - 1].frame;
|
||||
const float amount = (frame - static_cast<float>(previous)) / static_cast<float>(difference);
|
||||
const float first = (1.0f - amount) * keys[next - 1].value;
|
||||
const float second = amount * keys[next].value;
|
||||
output.values[channel] = first + second;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue