Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
cdf867d
add operator= for glm:: matrices corresponding to our at home matrice…
AnastaZIuk Oct 25, 2024
6ef4f89
I'm stupid, I have explicit at home matrix constructor taking glm:: m…
AnastaZIuk Oct 25, 2024
22f505c
steal include/nbl/builtin/hlsl/matrix_utils/transformation_matrix_uti…
AnastaZIuk Oct 25, 2024
51f4ced
fix getMatrix3x4As4x4 (return type issues) & buildCameraLookAtMatrixR…
AnastaZIuk Oct 25, 2024
7f2c085
update examples_tests submodule
AnastaZIuk Oct 25, 2024
f1daa25
actually *this* addresses https://github.com/Devsh-Graphics-Programmi…
AnastaZIuk Oct 25, 2024
2192e99
update examples_tests submodule
AnastaZIuk Oct 25, 2024
520b1f5
update examples_tests submodule
AnastaZIuk Oct 28, 2024
a0890f0
forgot to commit projection build methods, update examples_tests subm…
AnastaZIuk Nov 2, 2024
0109b22
add is_smart_refctd_ptr_v, update examples_tests submodule
AnastaZIuk Nov 2, 2024
2a29a2f
update examples_tests submodule
AnastaZIuk Nov 3, 2024
7673769
update examples_tests submodule
AnastaZIuk Nov 3, 2024
fc7bc33
pull master & resolve conflicts
AnastaZIuk Nov 4, 2024
8fc4f89
pull mastrer & resolve conflicts
AnastaZIuk Nov 6, 2024
9a139df
update examples_tests submodule
AnastaZIuk Nov 6, 2024
24a80c9
create ui::E_MOUSE_CODE & constexpr ui::mouseCodeToString - we really…
AnastaZIuk Nov 8, 2024
03fa2ca
pull master & resolve conflicts
AnastaZIuk Nov 11, 2024
21b89b4
@alichraghi small homework - read https://en.cppreference.com/w/cpp/l…
AnastaZIuk Nov 11, 2024
68bc7be
update examples_tests submodule
AnastaZIuk Nov 12, 2024
866e844
update examples_tests submodule
AnastaZIuk Nov 15, 2024
8bd6436
update examples_tests submodule
AnastaZIuk Nov 15, 2024
de69afe
update examples_tests submodule
AnastaZIuk Nov 18, 2024
a55bd39
update imguizmo with its upstream
AnastaZIuk Nov 18, 2024
6f3c5fc
update examples_tests submodule
AnastaZIuk Nov 18, 2024
0d126df
update examples_tests submodule
AnastaZIuk Dec 2, 2024
31e85e7
update examples_tests submodule
AnastaZIuk Dec 2, 2024
08f11f6
update examples_tests submodule
AnastaZIuk Dec 3, 2024
5bcd6ef
add getCastedMatrix & getCastedVector, update examples_tests submodule
AnastaZIuk Dec 12, 2024
5a07fe7
update examples_tests submodule
AnastaZIuk Dec 13, 2024
f55b268
update examples_tests submodule
AnastaZIuk Dec 13, 2024
01f909a
add examples_tests submodule
AnastaZIuk Dec 13, 2024
ab90d33
update examples_tests submodule
AnastaZIuk Dec 13, 2024
c9f0960
update examples_tests submodule
AnastaZIuk Dec 14, 2024
3727ae3
update examples_tests submodule
AnastaZIuk Dec 14, 2024
e9f78a2
update examples_tests submodule
AnastaZIuk Dec 14, 2024
33f8d01
add constexpr stringToKeyCode & stringToMouseCode
AnastaZIuk Dec 16, 2024
b3d7710
update examples_tests submodule
AnastaZIuk Dec 17, 2024
53f72ec
update examples_tests submodule
AnastaZIuk Dec 18, 2024
e3d282b
update examples_tests submodule
AnastaZIuk Dec 19, 2024
5124136
update examples_tests submodule
AnastaZIuk Dec 19, 2024
fb2ce01
update examples_tests submodule
AnastaZIuk Dec 20, 2024
7ce37ba
update examples_tests submodule
AnastaZIuk Dec 20, 2024
406fef8
update examples_tests submodule
AnastaZIuk Dec 21, 2024
661dae9
update examples_tests submodule
AnastaZIuk Dec 21, 2024
183a8fd
update examples_tests submodule
AnastaZIuk Dec 22, 2024
a30c409
update examples_tests submodule
AnastaZIuk Dec 22, 2024
5f033af
update examples_tests submodule
AnastaZIuk Dec 23, 2024
0529f8a
update examples_tests submodule
AnastaZIuk Dec 23, 2024
74b8c11
update examples_tests submodule
AnastaZIuk Dec 23, 2024
2fdf296
update examples_tests submodule
AnastaZIuk Dec 23, 2024
3b68444
update examples_tests submodule
AnastaZIuk Dec 30, 2024
b21de61
pull master & resolve conflicts
AnastaZIuk Jan 24, 2025
2693caf
update examples_tests submodule
AnastaZIuk Jan 24, 2025
ae315a0
a comment for glslFunctions, update examples_tests submodule
AnastaZIuk Jan 24, 2025
07eeef7
small temporary updates to transformation_matrix_utils.hlsl, update e…
AnastaZIuk Jan 31, 2025
15aa72f
introduce reference frame concept to imguizmo - commit submodule update
AnastaZIuk Feb 2, 2025
661f999
update examples_tests submodule
AnastaZIuk Feb 2, 2025
db1102c
update examples_tests submodule
AnastaZIuk Feb 6, 2025
329d98f
pull master & resolve conflicts
AnastaZIuk Feb 17, 2025
52901f2
pull master, resolve conflicts
AnastaZIuk Jan 13, 2026
ba3d7a0
adjust to code, precompile remaining runtime shaders
AnastaZIuk Feb 3, 2026
7d81d9c
imgui log polish
AnastaZIuk Feb 5, 2026
04ce784
Update camera module and async dispatcher exit
AnastaZIuk Feb 7, 2026
b25a81f
Merge remote-tracking branch 'origin/master' into cameraz
AnastaZIuk Feb 7, 2026
40c1fdb
Restore transformation matrix utils compatibility
AnastaZIuk Feb 7, 2026
749175c
Update examples_tests submodule pointer
AnastaZIuk Feb 14, 2026
037fc08
Update examples_tests submodule pointer
AnastaZIuk Feb 18, 2026
4b7cbe8
Update examples_tests pointer for world axis fix
AnastaZIuk Feb 18, 2026
8e76424
Update examples tests camera smoke integration
AnastaZIuk Feb 18, 2026
69d49fd
Add frustum extension and camera smoke updates
AnastaZIuk Feb 18, 2026
1108584
Update examples tests continuity frustum script
AnastaZIuk Feb 18, 2026
ef5429f
Merge remote-tracking branch 'origin/master' into cameraz
AnastaZIuk Feb 19, 2026
848aabe
Update camera test submodule revision
AnastaZIuk Feb 19, 2026
7d97b8b
Update examples_tests submodule revision
AnastaZIuk Feb 19, 2026
cadefbb
Update examples_tests for cameraz smoke fixes
AnastaZIuk Apr 3, 2026
d97f18d
Update examples_tests after master merge
AnastaZIuk Apr 3, 2026
a38d167
Merge master
AnastaZIuk Apr 3, 2026
3c6fd0e
Update examples_tests after json alias fix
AnastaZIuk Apr 3, 2026
530883e
Update examples_tests checkpoint
AnastaZIuk Apr 3, 2026
abbcfe7
Update examples_tests after goal solver rename
AnastaZIuk Apr 3, 2026
38d92c2
Update examples_tests after camera goal cleanup
AnastaZIuk Apr 3, 2026
e7b8b4f
Update examples_tests after camera goal solver changes
AnastaZIuk Apr 4, 2026
5cae47e
Update examples_tests after preset compatibility changes
AnastaZIuk Apr 4, 2026
23fa6b6
Update examples_tests after preset policy changes
AnastaZIuk Apr 4, 2026
0fb9e90
Update examples_tests after Chase and Dolly preset flow checks
AnastaZIuk Apr 4, 2026
dac6e97
Update examples_tests after planar binding cleanup
AnastaZIuk Apr 4, 2026
53f960a
Update examples_tests after camera contract cleanup
AnastaZIuk Apr 4, 2026
944f5cb
Update examples_tests after input binding helper cleanup
AnastaZIuk Apr 4, 2026
630b7bd
Update examples_tests after transform editor cleanup
AnastaZIuk Apr 4, 2026
760acaa
Update examples_tests after binding layout rename
AnastaZIuk Apr 4, 2026
7eb2a91
Update examples_tests after binding storage split
AnastaZIuk Apr 4, 2026
0b50aea
Update examples_tests after binding layout header split
AnastaZIuk Apr 4, 2026
5de70ac
Update examples_tests after JSON binding rename
AnastaZIuk Apr 4, 2026
1817146
Update examples_tests after input processor rename
AnastaZIuk Apr 4, 2026
405b434
Update examples_tests after camera rig setup cleanup
AnastaZIuk Apr 4, 2026
37b7075
Update examples_tests after rig config routing
AnastaZIuk Apr 4, 2026
0314dbf
Update examples_tests after rig preset helper cleanup
AnastaZIuk Apr 4, 2026
4a244ca
Update examples_tests after camera binding layout decoupling
AnastaZIuk Apr 4, 2026
f12b5b6
Update examples_tests after binding naming cleanup
AnastaZIuk Apr 4, 2026
3393bbd
Update examples_tests after camera binding cleanup
AnastaZIuk Apr 4, 2026
fa953f1
Update examples_tests after motion config split
AnastaZIuk Apr 4, 2026
90b7c19
Update examples_tests after scoped motion overrides
AnastaZIuk Apr 4, 2026
1b7a8d8
Update examples_tests after unit motion wrapper
AnastaZIuk Apr 4, 2026
9cd1fc8
Update examples_tests after goal alias cleanup
AnastaZIuk Apr 4, 2026
d8776fd
Update examples_tests after preset UI cleanup
AnastaZIuk Apr 4, 2026
5add016
Update examples_tests after playback summary changes
AnastaZIuk Apr 4, 2026
70e2ce9
Update examples_tests after preset banner cleanup
AnastaZIuk Apr 4, 2026
e80ef0c
Update examples_tests after playback scrub preview
AnastaZIuk Apr 4, 2026
ee188ff
Update examples_tests after capture gating
AnastaZIuk Apr 4, 2026
da75579
Update examples_tests after shared goal API cleanup
AnastaZIuk Apr 4, 2026
0b3ec40
Update examples_tests after shared preset API cleanup
AnastaZIuk Apr 4, 2026
1234059
Update examples_tests after playback keyframe authoring cleanup
AnastaZIuk Apr 4, 2026
f821947
Update examples_tests after keyframe storage changes
AnastaZIuk Apr 4, 2026
0bab320
Update examples_tests after shared analysis cleanup
AnastaZIuk Apr 4, 2026
7f78cc2
Update examples_tests after shared keyframe track cleanup
AnastaZIuk Apr 4, 2026
9a32427
Update examples_tests after camera docs
AnastaZIuk Apr 4, 2026
1ac6209
Update examples_tests after header docs
AnastaZIuk Apr 4, 2026
bfae93a
Update examples_tests after playback timeline cleanup
AnastaZIuk Apr 4, 2026
c6fa314
Update examples_tests after camera persistence cleanup
AnastaZIuk Apr 4, 2026
fd191f1
Update examples_tests after preset flow cleanup
AnastaZIuk Apr 4, 2026
19ebf8b
Update examples_tests after preset apply summary cleanup
AnastaZIuk Apr 4, 2026
11d9347
Update examples_tests after camera helper smoke hardening
AnastaZIuk Apr 4, 2026
9cfdb18
Update examples_tests after camera helper polish
AnastaZIuk Apr 4, 2026
ca1d35b
Update examples_tests after camera manipulation cleanup
AnastaZIuk Apr 4, 2026
eada28c
Update examples_tests after camera text cleanup
AnastaZIuk Apr 4, 2026
2bf4590
Update examples_tests after camera projection cleanup
AnastaZIuk Apr 4, 2026
6289e65
Update examples_tests after analysis text cleanup
AnastaZIuk Apr 4, 2026
6c0d131
Update examples_tests after helper smoke hardening
AnastaZIuk Apr 4, 2026
777117d
Update examples_tests after presentation cleanup
AnastaZIuk Apr 4, 2026
b88598a
Update examples_tests after presentation badge cleanup
AnastaZIuk Apr 4, 2026
ea56b53
Update examples_tests after preset comparison cleanup
AnastaZIuk Apr 4, 2026
e21be7e
Update examples_tests after presentation label cleanup
AnastaZIuk Apr 4, 2026
b52527e
Update examples_tests after preset collection cleanup
AnastaZIuk Apr 4, 2026
36f2668
Update examples_tests after continuity scripting cleanup
AnastaZIuk Apr 6, 2026
2cb9950
Update examples_tests after follow integration
AnastaZIuk Apr 6, 2026
c257396
Update examples_tests after follow integration
AnastaZIuk Apr 6, 2026
7a7172f
Update examples_tests after sequence policy cleanup
AnastaZIuk Apr 6, 2026
d2fe6b1
Update examples_tests after scripted runtime cleanup
AnastaZIuk Apr 7, 2026
016c2bf
Update examples_tests after camera docs rewrite
AnastaZIuk Apr 7, 2026
f783968
Update examples_tests after camera API cleanup
AnastaZIuk Apr 7, 2026
c937315
Update examples_tests after camera cleanup
AnastaZIuk Apr 7, 2026
24fc3fb
Update examples_tests after camera contract cleanup
AnastaZIuk Apr 7, 2026
3cac470
Update examples_tests after ui presentation cleanup
AnastaZIuk Apr 7, 2026
885e330
Update examples_tests after follow label cleanup
AnastaZIuk Apr 7, 2026
d74490f
Update examples_tests after system follow cleanup
AnastaZIuk Apr 7, 2026
f56a8fb
Update examples_tests after hlsl cleanup
AnastaZIuk Apr 7, 2026
0068d09
Update examples_tests after docs cleanup
AnastaZIuk Apr 7, 2026
5254830
Update examples_tests after header docs
AnastaZIuk Apr 7, 2026
8c2b795
Polish hlsl transform utility cleanup
AnastaZIuk Apr 7, 2026
4182b2d
Update examples_tests after camera cleanup
AnastaZIuk Apr 8, 2026
cc9521f
Update examples_tests after camera cleanup
AnastaZIuk Apr 8, 2026
3a88506
Move cameras module into ext
AnastaZIuk Apr 10, 2026
6afa742
Clean up cameras ext module
AnastaZIuk Apr 10, 2026
5b0e78c
Polish cameras README
AnastaZIuk Apr 10, 2026
5009f8b
Trim non-camera drift from cameras ext
AnastaZIuk Apr 10, 2026
28cc1d3
Use shared quaternion cast in cameras
AnastaZIuk Apr 10, 2026
d5335f2
Restore dxc submodule pointer
AnastaZIuk Apr 10, 2026
b582488
Split cameras utilities into source files
AnastaZIuk Apr 10, 2026
e9ac109
Move gimbal input processing into source files
AnastaZIuk Apr 10, 2026
f5629c7
Revert shared quaternion cast change
AnastaZIuk Apr 10, 2026
f83004a
Restore shared quaternion cast
AnastaZIuk Apr 10, 2026
d825ef2
Use bitmask helpers for goal solver issues
AnastaZIuk Apr 10, 2026
b9be28a
Update examples_tests submodule
AnastaZIuk Apr 10, 2026
5f901e7
Merge latest master into cameraz
AnastaZIuk Apr 10, 2026
a80bb82
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
96e0ccd
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
7130af4
Fix GitHub math in cameras README
AnastaZIuk Apr 10, 2026
06b1a4b
Fix Path Rig math rendering
AnastaZIuk Apr 10, 2026
33a7793
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
f89e4f3
Refresh examples cameraz submodule
AnastaZIuk Apr 10, 2026
8f4cc2f
Refresh examples cameraz submodule
AnastaZIuk Apr 11, 2026
c92b9b2
Fix camera scaling and view accessors
AnastaZIuk Apr 11, 2026
89cfa0b
Merge master into cameraz
AnastaZIuk Apr 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples_tests
Submodule examples_tests updated 114 files
138 changes: 135 additions & 3 deletions include/nbl/builtin/hlsl/math/quaternions.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,150 @@ struct static_cast_helper<math::truncated_quaternion<T>, math::quaternion<T> >
template<typename T>
struct static_cast_helper<matrix<T,3,3>, math::quaternion<T> >
{
static inline matrix<T,3,3> cast(const math::quaternion<T> q)
static inline matrix<T,3,3> cast(NBL_CONST_REF_ARG(math::quaternion<T>) q)
{
return q.__constructMatrix();
}
};

template<typename T>
inline bool is_finite_quaternion(NBL_CONST_REF_ARG(math::quaternion<T>) q)
{
return !hlsl::isnan(q.data.x) &&
!hlsl::isnan(q.data.y) &&
!hlsl::isnan(q.data.z) &&
!hlsl::isnan(q.data.w);
}

template<typename T>
inline T score_matrix_to_quaternion_cast_candidate(
NBL_CONST_REF_ARG(matrix<T,3,3>) target,
NBL_CONST_REF_ARG(math::quaternion<T>) candidate)
{
if (!is_finite_quaternion(candidate))
return bit_cast<T>(numeric_limits<T>::infinity);

const vector<T,3> rebuiltRight = candidate.transformVector(vector<T,3>(T(1), T(0), T(0)), true);
const vector<T,3> rebuiltUp = candidate.transformVector(vector<T,3>(T(0), T(1), T(0)), true);
const vector<T,3> rebuiltForward = candidate.transformVector(vector<T,3>(T(0), T(0), T(1)), true);
return
hlsl::length(rebuiltRight - target[0]) +
hlsl::length(rebuiltUp - target[1]) +
hlsl::length(rebuiltForward - target[2]);
}

template<typename T>
inline math::quaternion<T> direct_matrix_to_quaternion_cast(NBL_CONST_REF_ARG(matrix<T,3,3>) input)
{
typedef math::quaternion<T> quaternion_t;
typedef typename quaternion_t::data_type data_type;

const T xLengthSq = hlsl::dot(input[0], input[0]);
const T yLengthSq = hlsl::dot(input[1], input[1]);
const T zLengthSq = hlsl::dot(input[2], input[2]);
const T uniformScaleSq = (xLengthSq + yLengthSq + zLengthSq) / T(3.0);
if (uniformScaleSq < numeric_limits<T>::min)
{
quaternion_t retval;
retval.data = hlsl::promote<data_type>(bit_cast<T>(numeric_limits<T>::quiet_NaN));
return retval;
}

const T uniformScale = hlsl::sqrt(uniformScaleSq);
matrix<T,3,3> m = input;
m /= uniformScale;

const T m00 = m[0][0];
const T m11 = m[1][1];
const T m22 = m[2][2];
const T neg_m00 = -m00;
const T neg_m11 = -m11;
const T neg_m22 = -m22;
const data_type Qx = data_type(m00, m00, neg_m00, neg_m00);
const data_type Qy = data_type(m11, neg_m11, m11, neg_m11);
const data_type Qz = data_type(m22, neg_m22, neg_m22, m22);
const data_type tmp = Qx + Qy + Qz;

quaternion_t retval;
if (tmp.x > T(0.0))
{
const T scales = hlsl::sqrt(tmp.x + T(1.0));
const T invscales = T(0.5) / scales;
retval.data.x = (m[2][1] - m[1][2]) * invscales;
retval.data.y = (m[0][2] - m[2][0]) * invscales;
retval.data.z = (m[1][0] - m[0][1]) * invscales;
retval.data.w = scales * T(0.5);
}
else if (tmp.y > T(0.0))
{
const T scales = hlsl::sqrt(tmp.y + T(1.0));
const T invscales = T(0.5) / scales;
retval.data.x = scales * T(0.5);
retval.data.y = (m[0][1] + m[1][0]) * invscales;
retval.data.z = (m[2][0] + m[0][2]) * invscales;
retval.data.w = (m[2][1] - m[1][2]) * invscales;
}
else if (tmp.z > T(0.0))
{
const T scales = hlsl::sqrt(tmp.z + T(1.0));
const T invscales = T(0.5) / scales;
retval.data.x = (m[0][1] + m[1][0]) * invscales;
retval.data.y = scales * T(0.5);
retval.data.z = (m[1][2] + m[2][1]) * invscales;
retval.data.w = (m[0][2] - m[2][0]) * invscales;
}
else
{
const T scales = hlsl::sqrt(tmp.w + T(1.0));
const T invscales = T(0.5) / scales;
retval.data.x = (m[0][2] + m[2][0]) * invscales;
retval.data.y = (m[1][2] + m[2][1]) * invscales;
retval.data.z = scales * T(0.5);
retval.data.w = (m[1][0] - m[0][1]) * invscales;
}

retval.data *= uniformScale;
return retval;
}

template<typename T>
inline math::quaternion<T> matrix_to_quaternion_cast(NBL_CONST_REF_ARG(matrix<T,3,3>) m)
{
const math::quaternion<T> directCandidate = math::quaternion<T>::create(m, true);
const math::quaternion<T> transposedCandidate = math::quaternion<T>::create(hlsl::transpose(m), true);
const math::quaternion<T> directFallback = direct_matrix_to_quaternion_cast(m);
const math::quaternion<T> transposedFallback = direct_matrix_to_quaternion_cast(hlsl::transpose(m));

const T directScore = score_matrix_to_quaternion_cast_candidate(m, directCandidate);
const T transposedScore = score_matrix_to_quaternion_cast_candidate(m, transposedCandidate);
const T directFallbackScore = score_matrix_to_quaternion_cast_candidate(m, directFallback);
const T transposedFallbackScore = score_matrix_to_quaternion_cast_candidate(m, transposedFallback);

math::quaternion<T> bestCandidate = directCandidate;
T bestScore = directScore;

if (transposedScore < bestScore)
{
bestCandidate = transposedCandidate;
bestScore = transposedScore;
}
if (directFallbackScore < bestScore)
{
bestCandidate = directFallback;
bestScore = directFallbackScore;
}
if (transposedFallbackScore < bestScore)
bestCandidate = transposedFallback;

return bestCandidate;
}

template<typename T>
struct static_cast_helper<math::quaternion<T>, matrix<T,3,3> >
{
static inline math::quaternion<T> cast(const matrix<T,3,3> m)
static inline math::quaternion<T> cast(NBL_CONST_REF_ARG(matrix<T,3,3>) m)
{
return math::quaternion<T>::create(m, true);
return matrix_to_quaternion_cast(m);
}
};
}
Expand Down
89 changes: 89 additions & 0 deletions include/nbl/ext/Cameras/CArcballCamera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (C) 2018-2024 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h

#ifndef _C_ARCBALL_CAMERA_HPP_
#define _C_ARCBALL_CAMERA_HPP_

#include <algorithm>
#include <cmath>

#include "CSphericalTargetCamera.hpp"

namespace nbl::core
{

/// @brief Target-relative camera with planar target translation and bounded arcball orbiting.
///
/// The runtime state is inherited from `CSphericalTargetCamera`. Translation
/// moves the target in the current view plane. Rotation updates orbit yaw and
/// pitch under a symmetric pitch limit.
class CArcballCamera final : public CSphericalTargetCamera
{
public:
using base_t = CSphericalTargetCamera;

CArcballCamera(const hlsl::float64_t3& position, const hlsl::float64_t3& target)
: base_t(position, target)
{
m_orbitUv.y = std::clamp(m_orbitUv.y, MinPitch, MaxPitch);
applyPose();
}
~CArcballCamera() = default;

const typename base_t::CGimbal& getGimbal() override { return m_gimbal; }

/// @brief Apply one frame of semantic translation and rotation input to the arcball rig.
virtual bool manipulate(std::span<const CVirtualGimbalEvent> virtualEvents, const hlsl::float64_t4x4* referenceFrame = nullptr) override
{
if (not virtualEvents.size() and not referenceFrame)
return false;

if (referenceFrame)
{
CReferenceTransform reference = {};
SCameraTargetRelativeState resolvedState = {};
if (!tryExtractReferenceTransform(reference, referenceFrame) ||
!tryResolveReferenceTargetRelativeState(reference, resolvedState))
{
return false;
}

resolvedState.orbitUv.y = std::clamp(resolvedState.orbitUv.y, MinPitch, MaxPitch);
adoptTargetRelativeState(resolvedState);
}

const auto impulse = m_gimbal.accumulate<AllowedVirtualEvents>(virtualEvents);

const auto deltaRotation = scaleVirtualRotation(impulse.dVirtualRotation);
const auto deltaTranslation = scaleVirtualTranslation(impulse.dVirtualTranslate);
const double deltaDistance = scaleUnscaledVirtualTranslation(impulse.dVirtualTranslate.z);

m_orbitUv.x += deltaRotation.y;
m_orbitUv.y = std::clamp(m_orbitUv.y + deltaRotation.x, MinPitch, MaxPitch);
m_distance = std::clamp<float>(m_distance + static_cast<float>(deltaDistance), MinDistance, MaxDistance);

const auto basis = computeBasis(m_orbitUv, m_distance);
applyPlanarTargetTranslation(deltaTranslation, basis);

return applyPose();
}

virtual uint32_t getAllowedVirtualEvents() const override { return AllowedVirtualEvents; }
virtual CameraKind getKind() const override { return CameraKind::Arcball; }
/// @brief Return the stable user-facing identifier for this concrete camera kind.
virtual std::string_view getIdentifier() const override { return "Arcball Camera"; }

static inline constexpr float MinDistance = base_t::MinDistance;
static inline constexpr float MaxDistance = base_t::MaxDistance;

private:

static inline constexpr auto AllowedVirtualEvents = CVirtualGimbalEvent::Translate | CVirtualGimbalEvent::Rotate;
static inline constexpr double MaxPitch = SCameraTargetRelativeRigDefaults::ArcballPitchLimitRad;
static inline constexpr double MinPitch = -MaxPitch;
};

}

#endif
94 changes: 94 additions & 0 deletions include/nbl/ext/Cameras/CCameraFileUtilities.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef _C_CAMERA_FILE_UTILITIES_HPP_
#define _C_CAMERA_FILE_UTILITIES_HPP_

#include <string>
#include <string_view>
#include <vector>

#include "nbl/system/IFile.h"
#include "nbl/system/ISystem.h"

namespace nbl::system
{

/// @brief Shared file I/O helpers used by camera persistence and scripted-runtime loaders.
///
/// The helpers keep camera-facing persistence code independent from ad-hoc file
/// handling and provide one place for consistent error propagation.
struct CCameraFileUtilities final
{
public:
/// @brief Read a whole file into a byte buffer.
static inline bool readBinaryFile(
ISystem& system,
const path& filePath,
std::vector<uint8_t>& outPayload,
std::string* error = nullptr,
const std::string_view openError = {})
{
ISystem::future_t<core::smart_refctd_ptr<IFile>> future;
system.createFile(future, filePath, IFile::ECF_READ | IFile::ECF_MAPPABLE);
auto file = future.acquire();
if (!file || !file->get())
{
if (error && !openError.empty())
*error = std::string(openError);
return false;
}

auto& input = *file->get();
const auto fileSize = input.getSize();
outPayload.resize(fileSize);
if (outPayload.empty())
return true;

IFile::success_t readResult;
input.read(readResult, outPayload.data(), 0, fileSize);
if (!static_cast<bool>(readResult))
{
if (error && !openError.empty())
*error = std::string(openError);
return false;
}
return true;
}

/// @brief Read a whole file and interpret its payload as UTF-8 text.
static inline bool readTextFile(
ISystem& system,
const path& filePath,
std::string& outText,
std::string* error = nullptr,
const std::string_view openError = {})
{
std::vector<uint8_t> payload;
if (!readBinaryFile(system, filePath, payload, error, openError))
return false;

outText.assign(reinterpret_cast<const char*>(payload.data()), payload.size());
return true;
}

/// @brief Overwrite a file with the provided text payload.
static inline bool writeTextFile(
ISystem& system,
const path& filePath,
const std::string_view text)
{
ISystem::future_t<core::smart_refctd_ptr<IFile>> future;
system.createFile(future, filePath, IFile::ECF_WRITE);
auto file = future.acquire();
if (!file || !file->get())
return false;
if (text.empty())
return true;

IFile::success_t writeResult;
(*file)->write(writeResult, text.data(), 0, text.size());
return static_cast<bool>(writeResult);
}
};

} // namespace nbl::system

#endif // _C_CAMERA_FILE_UTILITIES_HPP_
Loading
Loading