kopia lustrzana https://github.com/jameshball/osci-render
Cement FOV and camera placement changes
rodzic
1a90e7af96
commit
abb1dbf44f
|
|
@ -103,7 +103,7 @@ public:
|
|||
perspectiveEffect,
|
||||
std::vector<osci::EffectParameter*>{
|
||||
new osci::EffectParameter("Perspective", "Controls the strength of the 3D perspective projection.", "perspectiveStrength", VERSION_HINT, 1.0, 0.0, 1.0),
|
||||
new osci::EffectParameter("FOV", "Controls the focal length of the 3D perspective effect. A higher focal length makes the image look more flat, and a lower focal length makes the image look more 3D.", "perspectiveFocalLength", VERSION_HINT, 70.0, 1.0, 150.0),
|
||||
new osci::EffectParameter("FOV", "Controls the camera's field of view in degrees. A lower field of view makes the image look more flat, and a higher field of view makes the image look more 3D.", "perspectiveFov", VERSION_HINT, 55.0, 5.0, 140.0),
|
||||
});
|
||||
|
||||
osci::BooleanParameter* midiEnabled = new osci::BooleanParameter("MIDI Enabled", "midiEnabled", VERSION_HINT, false, "Enable MIDI input for the synth. If disabled, the synth will play a constant tone, as controlled by the frequency slider.");
|
||||
|
|
|
|||
|
|
@ -6,18 +6,14 @@ class PerspectiveEffect : public osci::EffectApplication {
|
|||
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);
|
||||
double fovDegrees = juce::jmax(values[1].load(), 0.1);
|
||||
// Far plane clipping happens at about 1.2 deg for 100 far plane dist
|
||||
double fovDegrees = juce::jlimit(1.5, 179.0, values[1].load());
|
||||
double fov = juce::degreesToRadians(fovDegrees);
|
||||
double focalLength = 1.0 / std::tan(0.5 * fov);
|
||||
|
||||
|
||||
// Place such that view frustum is tangent to unit sphere
|
||||
//Vec3 origin = Vec3(0, 0, -std::sqrt(1 + focalLength * focalLength));
|
||||
// TODO
|
||||
// Place camera such that field of view is tangent to unit sphere
|
||||
Vec3 origin = Vec3(0, 0, -1.0f / std::sin(0.5f * (float)fov));
|
||||
camera.setPosition(origin);
|
||||
camera.setFocalLength(focalLength);
|
||||
camera.setFov(fov);
|
||||
Vec3 vec = Vec3(input.x, input.y, input.z);
|
||||
|
||||
Vec3 projected = camera.project(vec);
|
||||
|
|
@ -30,6 +26,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Camera camera;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "Camera.h"
|
||||
|
||||
Camera::Camera() : frustum(1, 1, 0.1, 100) {
|
||||
Camera::Camera() : frustum(1, 1, 0.001, 100) {
|
||||
viewMatrix = mathter::Identity();
|
||||
}
|
||||
|
||||
|
|
@ -18,8 +18,8 @@ Vec3 Camera::toWorldSpace(Vec3& point) {
|
|||
return mathter::Inverse(viewMatrix) * point;
|
||||
}
|
||||
|
||||
void Camera::setFocalLength(double focalLength) {
|
||||
frustum.setCameraInternals(focalLength, frustum.ratio, frustum.nearDistance, frustum.farDistance);
|
||||
void Camera::setFov(double fov) {
|
||||
frustum.setCameraInternals(fov, frustum.ratio, frustum.nearDistance, frustum.farDistance);
|
||||
}
|
||||
|
||||
Vec3 Camera::project(Vec3& pWorld) {
|
||||
|
|
@ -27,10 +27,10 @@ Vec3 Camera::project(Vec3& pWorld) {
|
|||
|
||||
frustum.clipToFrustum(p);
|
||||
|
||||
double start = p.x * frustum.focalLength / p.z;
|
||||
double end = p.y * frustum.focalLength / p.z;
|
||||
float x = p.x * frustum.focalLength / p.z;
|
||||
float y = p.y * frustum.focalLength / p.z;
|
||||
|
||||
return Vec3(start, end, 0);
|
||||
return Vec3(x, y, 0);
|
||||
}
|
||||
|
||||
Frustum Camera::getFrustum() {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public:
|
|||
void setPosition(Vec3& position);
|
||||
Vec3 toCameraSpace(Vec3& point);
|
||||
Vec3 toWorldSpace(Vec3& point);
|
||||
void setFocalLength(double focalLength);
|
||||
void setFov(double fov);
|
||||
Vec3 project(Vec3& p);
|
||||
Frustum getFrustum();
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
#include "Frustum.h"
|
||||
|
||||
void Frustum::setCameraInternals(float focalLength, float ratio, float nearDistance, float farDistance) {
|
||||
void Frustum::setCameraInternals(float fov, float ratio, float nearDistance, float farDistance) {
|
||||
// store the information
|
||||
this->focalLength = focalLength;
|
||||
this->fov = fov;
|
||||
this->ratio = ratio;
|
||||
this->nearDistance = nearDistance;
|
||||
this->farDistance = farDistance;
|
||||
|
||||
// compute width and height of the near section
|
||||
float fov = 2 * std::atan(1 / focalLength);
|
||||
tang = (float) std::tan(fov * 0.5);
|
||||
tang = std::tan(fov * 0.5f);
|
||||
focalLength = 1.0f / tang;
|
||||
height = nearDistance * tang;
|
||||
width = height * ratio;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,16 +9,13 @@ using Vec3 = mathter::Vector<float, 3, false>;
|
|||
|
||||
class Frustum {
|
||||
public:
|
||||
float ratio, nearDistance, farDistance, width, height, tang, focalLength;
|
||||
float ratio, nearDistance, farDistance, width, height, tang, fov, focalLength;
|
||||
|
||||
Frustum(float focalLength, float ratio, float nearDistance, float farDistance) {
|
||||
setCameraInternals(focalLength, ratio, nearDistance, farDistance);
|
||||
Frustum(float fov, float ratio, float nearDistance, float farDistance) {
|
||||
setCameraInternals(fov, ratio, nearDistance, farDistance);
|
||||
}
|
||||
~Frustum() {};
|
||||
|
||||
void setCameraInternals(float focalLength, float ratio, float nearD, float farD);
|
||||
void setCameraInternals(float fov, float ratio, float nearD, float farD);
|
||||
void clipToFrustum(Vec3 &p);
|
||||
float getFocalLength() {
|
||||
return focalLength;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue