Able to wiggle the camera now
This commit is contained in:
parent
35ad6e7497
commit
b43e27a03a
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
namespace orange
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
struct Time
|
||||
{
|
||||
static constexpr bool is_steady = true;
|
||||
|
||||
using rep = int64_t;
|
||||
using period = std::nano;
|
||||
using duration = std::chrono::nanoseconds;
|
||||
using time_point = std::chrono::time_point<Time>;
|
||||
|
||||
static inline time_point now() noexcept
|
||||
{
|
||||
// Keep the frequency static, this doesn't change at all.
|
||||
static const int64_t freq = getFrequency();
|
||||
const int64_t counter = getCounter();
|
||||
|
||||
const int64_t whole = (counter / freq) * period::den;
|
||||
const int64_t part = (counter % freq) * period::den / freq;
|
||||
|
||||
return time_point(duration(whole + part));
|
||||
}
|
||||
|
||||
static inline int64_t getFrequency() noexcept
|
||||
{
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
|
||||
return freq.QuadPart;
|
||||
}
|
||||
|
||||
static inline int64_t getCounter() noexcept
|
||||
{
|
||||
LARGE_INTEGER count;
|
||||
QueryPerformanceCounter(&count);
|
||||
|
||||
return count.QuadPart;
|
||||
}
|
||||
};
|
||||
#else
|
||||
using Time = std::chrono::high_resolution_clock;
|
||||
#endif
|
||||
|
||||
using TimePoint = Time::time_point;
|
||||
|
||||
using Seconds = std::chrono::duration<float>;
|
||||
}
|
|
@ -80,4 +80,12 @@ namespace orange
|
|||
|
||||
constexpr Degree operator"" _deg(long double value) { return Degree{static_cast<float>(value)}; }
|
||||
constexpr Degree operator"" _deg(unsigned long long value) { return Degree{static_cast<float>(value)}; }
|
||||
|
||||
struct EulerAngles
|
||||
{
|
||||
Radian pitch;
|
||||
Radian yaw;
|
||||
Radian roll;
|
||||
};
|
||||
|
||||
}
|
|
@ -302,22 +302,21 @@ namespace orange
|
|||
return Math::asin(-2.0f * (q[0] * q[2] - q[3] * q[1]));
|
||||
}
|
||||
|
||||
#if 0
|
||||
EulerAngles quaternionToEulerAngles(const quat& q)
|
||||
inline EulerAngles quaternionToEulerAngles(const quat& q)
|
||||
{
|
||||
return {pitch(q), yaw(q), roll(q)};
|
||||
}
|
||||
|
||||
Quaternion eulerAnglesToQuaternion(const EulerAngles& e,
|
||||
const vec3& xAxis,
|
||||
const vec3& yAxis,
|
||||
const vec3& zAxis)
|
||||
inline quat eulerAnglesToQuaternion(
|
||||
const EulerAngles& e,
|
||||
const vec3& xAxis = {1.0f, 0.0f, 0.0f},
|
||||
const vec3& yAxis = {0.0f, 1.0f, 0.0f},
|
||||
const vec3& zAxis = {0.0f, 0.0f, 1.0f})
|
||||
{
|
||||
quat p{angleAxis(e.pitch, xAxis)};
|
||||
quat y{angleAxis(e.pitch, yAxis)};
|
||||
quat r{angleAxis(e.pitch, zAxis)};
|
||||
quat p = angleAxis(e.pitch, xAxis);
|
||||
quat y = angleAxis(e.yaw, yAxis);
|
||||
quat r = angleAxis(e.roll, zAxis);
|
||||
|
||||
return y * p * r;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <Orange/Math/Transformation.h>
|
||||
#include <Orange/Core/Parse.h>
|
||||
#include <Orange/Core/Variant.h>
|
||||
#include <Orange/Core/Time.h>
|
||||
|
||||
#include <Orange/Render/Window.h>
|
||||
#include <Orange/Render/RenderContext.h>
|
||||
|
@ -550,8 +551,9 @@ int main(int argc, char** argv)
|
|||
Camera camera;
|
||||
camera.transform.position = vec3{0.0f, 0.0f, 80.0f};
|
||||
camera.viewportAspectRatio = 16.0f / 9.0f;
|
||||
camera.offsetOrientation(10_deg, 0_deg);
|
||||
//camera.offsetOrientation(1_deg * Seconds(t2 - t1).count(), 0_deg);
|
||||
//camera.lookAt(vec3{40.0f, 40.0f, 0.0f});
|
||||
camera.transform.orientation = eulerAnglesToQuaternion(EulerAngles{ 0_deg, 0_deg, 0_deg });
|
||||
|
||||
UniformData uniformData
|
||||
{
|
||||
|
@ -606,13 +608,33 @@ int main(int argc, char** argv)
|
|||
|
||||
r_window->EnableRelativeMouse(true);
|
||||
|
||||
auto t1 = Time::now();
|
||||
while (r_window->Update())
|
||||
{
|
||||
auto mouseDelta = r_window->GetMouseDelta();
|
||||
//if (mouseDelta.x || mouseDelta.y)
|
||||
//{
|
||||
// log::info("mouse: %d %d", mouseDelta.x, mouseDelta.y);
|
||||
//}
|
||||
const auto t2 = Time::now();
|
||||
const float dt = Seconds(t2 - t1).count();
|
||||
t1 = t2;
|
||||
|
||||
{
|
||||
auto mouseDelta = r_window->GetMouseDelta();
|
||||
//if (mouseDelta.x || mouseDelta.y)
|
||||
//{
|
||||
// log::info("mouse: %d %d", mouseDelta.x, mouseDelta.y);
|
||||
//}
|
||||
|
||||
const float sensitivity = 6.0f;
|
||||
|
||||
camera.offsetOrientation(
|
||||
-sensitivity * dt * Radian( mouseDelta.x ),
|
||||
sensitivity * dt * Radian( mouseDelta.y ));
|
||||
UniformData uniformData
|
||||
{
|
||||
.projection = camera.projection(),
|
||||
.view = camera.view(),
|
||||
};
|
||||
// NEED TO SYNCHRONIZE THIS
|
||||
memcpy((uint8_t*)(r_buffer->ptr) + uniformSlice.offset, &uniformData, sizeof(uniformData));
|
||||
}
|
||||
|
||||
VkCommandBuffer cmdBuf = r_swapchain->CommandBuffer();
|
||||
r_renderContext->BeginCommandBuffer(cmdBuf);
|
||||
|
|
Loading…
Reference in New Issue