osci-render/Source/audio/PerspectiveEffect.h

29 wiersze
768 B
C
Czysty Zwykły widok Historia

2023-07-21 16:42:29 +00:00
#pragma once
#include <JuceHeader.h>
#include "../obj/Camera.h"
2023-07-21 16:42:29 +00:00
class PerspectiveEffect : public osci::EffectApplication {
2023-07-21 16:42:29 +00:00
public:
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
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-07-21 16:42:29 +00:00
private:
Camera camera;
2023-09-01 18:52:36 +00:00
};