Added covers, cross-fade
This commit is contained in:
1 parent
0f2b2e55af
commit
e618c91415
29 files changed
+40462
-29
No files matched your search
@@ -63,6 +63,23 @@ namespace ZL {
|
||||
isAnimating = true;
|
||||
}
|
||||
|
||||
void InteractiveObject::fadeTo(float targetAlpha, float durationSec, std::function<void()> onComplete) {
|
||||
if (isAnimating) return;
|
||||
AnimTask task;
|
||||
task.type = AnimTask::Type::Fade;
|
||||
task.startPos = position;
|
||||
task.startRotY = rotationY;
|
||||
task.startScale = alpha; // reuse startScale to hold start alpha
|
||||
task.targetPos = position;
|
||||
task.targetRotY = rotationY;
|
||||
task.targetScale = targetAlpha; // reuse targetScale to hold target alpha
|
||||
task.durationMs = durationSec * 1000.f;
|
||||
task.elapsedMs = 0.f;
|
||||
task.onComplete = std::move(onComplete);
|
||||
animTask = std::move(task);
|
||||
isAnimating = true;
|
||||
}
|
||||
|
||||
void InteractiveObject::update(int64_t deltaMs) {
|
||||
if (!isAnimating || !animTask) return;
|
||||
|
||||
@@ -81,6 +98,9 @@ namespace ZL {
|
||||
case AnimTask::Type::Scale:
|
||||
scale = task.startScale + (task.targetScale - task.startScale) * t;
|
||||
break;
|
||||
case AnimTask::Type::Fade:
|
||||
alpha = task.startScale + (task.targetScale - task.startScale) * t;
|
||||
break;
|
||||
}
|
||||
|
||||
if (t >= 1.0f) {
|
||||
@@ -99,6 +119,12 @@ namespace ZL {
|
||||
|
||||
void InteractiveObject::draw(Renderer& renderer) const {
|
||||
if (!isActive || !loadedObject.texture) return;
|
||||
|
||||
if (alpha < 0.999f) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
renderer.PushMatrix();
|
||||
renderer.TranslateMatrix(position);
|
||||
if (rotationY != 0.f) {
|
||||
@@ -109,9 +135,13 @@ namespace ZL {
|
||||
if (scale != 1.f)
|
||||
renderer.ScaleMatrix(scale);
|
||||
renderer.RenderUniform1i(textureUniformName, 0);
|
||||
renderer.RenderUniform1f("uAlpha", alpha);
|
||||
glBindTexture(GL_TEXTURE_2D, loadedObject.texture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(loadedObject.mesh);
|
||||
renderer.PopMatrix();
|
||||
|
||||
// Restore uAlpha so subsequent fog-shader users (character weapons, etc.) are not affected.
|
||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||
}
|
||||
|
||||
} // namespace ZL
|
||||
Reference in new issue
Block a user