-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPicking.hpp
More file actions
54 lines (43 loc) · 1.88 KB
/
Copy pathPicking.hpp
File metadata and controls
54 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef JET_PICKING_HPP
#define JET_PICKING_HPP
#include <cstdint>
#include "JetConfig.hpp"
/// @file Picking.hpp
/// @brief Screen-space cursor picking.
///
/// Active only when MAX_PICK_QUERIES > 0; the rest of the renderer guards
/// every reference behind that same #if so the entire feature compiles
/// out cleanly when not needed.
///
/// Example usage (host side, once per frame, before Scene::render()):
/// @code
/// Renderer::PickQuery q[2];
/// q[0] = { mouseX, mouseY };
/// scene.setPickQueries(q, 1);
/// scene.render();
/// const auto* r = scene.getPickResults();
/// if (r[0].hit) { ... r[0].object, r[0].triangleIndex ... }
/// @endcode
namespace Renderer {
class Object;
#if MAX_PICK_QUERIES > 0
/// @brief Screen-space pick request.
struct PickQuery {
int16_t x = -1; ///< Pixel X. Negative disables the slot.
int16_t y = -1; ///< Pixel Y. Negative disables the slot.
};
/// @brief Result of a single pick query for the most recent frame.
struct PickResult {
bool hit = false; ///< True if any non-cleared geometry covered the pixel this frame.
Object* object = nullptr;///< Closest object hit (borrowed from Scene::objects). Do not free.
/// Index into `object->triangles` of the hit triangle. -1 when !hit.
/// When SORT_TRIANGLES is enabled the source mesh is sorted in place
/// every frame, so this index is valid until the next render() call.
int32_t triangleIndex = -1;
int32_t depth = 0; ///< Camera-space Z of the hit (smaller = closer). Same units as Camera::nearPlane / farPlane.
int16_t x = -1; ///< Pixel actually sampled (echoes input x).
int16_t y = -1; ///< Pixel actually sampled (input y, possibly nudged for FIELD_BUFFERS parity).
};
#endif // MAX_PICK_QUERIES > 0
} // namespace Renderer
#endif // JET_PICKING_HPP