2023-07-21 16:42:29 +00:00
|
|
|
#pragma once
|
2025-04-23 14:26:33 +00:00
|
|
|
#include <JuceHeader.h>
|
2024-02-11 22:06:35 +00:00
|
|
|
#include "../obj/Camera.h"
|
2023-07-21 16:42:29 +00:00
|
|
|
|
2025-04-23 14:26:33 +00:00
|
|
|
class PerspectiveEffect : public osci::EffectApplication {
|
2023-07-21 16:42:29 +00:00
|
|
|
public:
|
2025-04-24 09:47:03 +00:00
|
|
|
osci::Point apply(int index, osci::Point input, const std::vector<std::atomic<double>>& values, double sampleRate) override {
|
|
|
|
auto effectScale = values[0].load();
|
|
|
|
auto focalLength = juce::jmax(values[1].load(), 0.001);
|
2023-07-21 16:42:29 +00:00
|
|
|
|
2025-04-24 09:47:03 +00:00
|
|
|
Vec3 origin = Vec3(0, 0, -focalLength);
|
|
|
|
camera.setPosition(origin);
|
|
|
|
camera.setFocalLength(focalLength);
|
|
|
|
Vec3 vec = Vec3(input.x, input.y, input.z);
|
|
|
|
|
|
|
|
Vec3 projected = camera.project(vec);
|
|
|
|
|
|
|
|
return osci::Point(
|
|
|
|
(1 - effectScale) * input.x + effectScale * projected.x,
|
|
|
|
(1 - effectScale) * input.y + effectScale * projected.y,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
}
|
2023-10-19 11:20:24 +00:00
|
|
|
|
2023-07-21 16:42:29 +00:00
|
|
|
private:
|
2024-02-11 22:06:35 +00:00
|
|
|
|
|
|
|
Camera camera;
|
2023-09-01 18:52:36 +00:00
|
|
|
};
|