mirror of
https://github.com/slendidev/lunar.git
synced 2026-01-30 16:28:58 +02:00
37
src/Types.h
37
src/Types.h
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <smath.hpp>
|
||||
#include <vk_mem_alloc.h>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
@@ -55,4 +57,39 @@ struct GPUSceneData {
|
||||
smath::Vec4 sunlight_color;
|
||||
};
|
||||
|
||||
struct Camera {
|
||||
smath::Vec3 position {};
|
||||
smath::Vec3 target { 0, 0, -1 };
|
||||
smath::Vec3 up { 0, 1, 0 };
|
||||
float fovy { smath::deg(70.0f) };
|
||||
};
|
||||
|
||||
struct PolarCoordinate {
|
||||
float r, theta, phi;
|
||||
|
||||
static PolarCoordinate from_vec3(smath::Vec3 const &v)
|
||||
{
|
||||
PolarCoordinate p;
|
||||
p.r = std::sqrt(v.x() * v.x() + v.y() * v.y() + v.z() * v.z());
|
||||
|
||||
if (p.r == 0.0f) {
|
||||
p.theta = 0.0f;
|
||||
p.phi = 0.0f;
|
||||
return p;
|
||||
}
|
||||
|
||||
p.theta = std::atan2(v.z(), v.x());
|
||||
p.phi = std::acos(v.y() / p.r);
|
||||
return p;
|
||||
}
|
||||
|
||||
smath::Vec3 to_vec3() const
|
||||
{
|
||||
float sin_phi = std::sin(phi);
|
||||
|
||||
return smath::Vec3 { r * sin_phi * std::cos(theta), r * std::cos(phi),
|
||||
r * sin_phi * std::sin(theta) };
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Lunar
|
||||
|
||||
Reference in New Issue
Block a user