Moved more files around, working on VN engine

This commit is contained in:
2023-04-20 14:08:02 -07:00
parent 6d86fc10bc
commit cacda495d3
5 changed files with 103 additions and 11 deletions

View File

@ -41,17 +41,11 @@ namespace Dawn {
*/
void setEvent(VNEvent *event);
/**
* Ends the current event, and moves to the next one.
*/
void nextEvent();
// template <class T>
// T * setEvent(T *event) {
// auto oldCurrent = this->currentEvent;
// this->currentEvent = event;
// if(this->hasInitialized && event != nullptr) event->start(oldCurrent);
// delete oldCurrent;
// return event;
// }
void onStart() override;
void onDispose() override;

View File

@ -0,0 +1,58 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "VNEvent.hpp"
#include "scene/SceneItem.hpp"
#include "display/animation/SimplerCallbackAnimation.hpp"
#define VN_POSITION_EVENT_VALUE_UNCHANGED -123456789
namespace Dawn {
class VNPositionEvent : public VNEvent {
public:
float_t x = VN_POSITION_EVENT_VALUE_UNCHANGED;
float_t y = VN_POSITION_EVENT_VALUE_UNCHANGED;
float_t z = VN_POSITION_EVENT_VALUE_UNCHANGED;
SceneItem *item = nullptr;
float_t duration;
protected:
SimplerCallbackAnimation<glm::vec3> animation;
void onStart() override {
assertNotNull(item);
auto start = item->transform.getLocalPosition();
auto destination = glm::vec3(
x == VN_POSITION_EVENT_VALUE_UNCHANGED ? start.x : x,
y == VN_POSITION_EVENT_VALUE_UNCHANGED ? start.y : y,
z == VN_POSITION_EVENT_VALUE_UNCHANGED ? start.z : z
);
if(duration > 0) {
animation.clear();
animation.addKeyframe(0, start);
animation.addKeyframe(duration, destination);
animation.callback = [&](glm::vec3 v){
this->item->transform.setLocalPosition(v);
};
useEvent([&]() {
this->next();
}, animation.event2AnimationEnd);
useEvent([&](float_t delta) {
animation.tick(delta);
}, getScene()->eventSceneUpdate);
} else {
this->item->transform.setLocalPosition(destination);
this->next();
}
}
};
}