osci-render/Source/audio/PerspectiveEffect.cpp

27 wiersze
719 B
C++
Czysty Zwykły widok Historia

2023-07-21 16:42:29 +00:00
#include "PerspectiveEffect.h"
#include <numbers>
#include "../MathUtil.h"
#include "../obj/Camera.h"
2023-07-21 16:42:29 +00:00
PerspectiveEffect::PerspectiveEffect() {}
2023-07-21 16:42:29 +00:00
PerspectiveEffect::~PerspectiveEffect() {}
2024-01-07 16:17:20 +00:00
Point PerspectiveEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
2023-07-21 16:42:29 +00:00
auto effectScale = values[0];
auto focalLength = juce::jmax(values[1], 0.001);
2024-01-21 22:22:03 +00:00
Vec3 origin = Vec3(0, 0, -focalLength);
camera.setPosition(origin);
camera.setFocalLength(focalLength);
Vec3 vec = Vec3(input.x, input.y, input.z);
2024-01-21 22:22:03 +00:00
Vec3 projected = camera.project(vec);
2024-01-07 16:17:20 +00:00
return Point(
(1 - effectScale) * input.x + effectScale * projected.x,
(1 - effectScale) * input.y + effectScale * projected.y,
0
2023-07-21 16:42:29 +00:00
);
}