Avara3D 0.2.0
C++ API reference
HitTestResult.h
1//
2// HitTestResult.h
3// avara3d
4//
5// Created by Morgan Davis on 8/6/26.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_SCENE_HITTESTRESULT_H
10#define AVARA3D_SCENE_HITTESTRESULT_H
11
12#include <cstdint>
13#include <memory>
14#include <optional>
15
16#include "a3d/Math.h"
17
18namespace a3d {
19
20 class Mesh;
21 class MeshElement;
22 class Node;
23
24 // [Public Types]
25
27 enum class HitTestSearchMode : uint8_t {
28 Any,
29 Closest,
30 All
31 };
32
44
45 public:
46 // [Public Member Functions]
47
49 std::shared_ptr<Node> node() const;
50
52 const MeshElement* meshElement() const;
53
60 std::optional<uint32_t> faceIndex() const;
61
64
67
69 const math::vec3& localNormal() const;
70
72 const math::vec3& worldNormal() const;
73
75 const math::mat4& modelTransform() const;
76
77 // [Internal Lifecycle Functions]
78
79 HitTestResult(std::weak_ptr<Node> node,
80 std::shared_ptr<Mesh> mesh,
82 std::optional<uint32_t> faceIndex,
88
89 private:
90 // [Private Member Variables]
91
92 std::weak_ptr<Node> _node;
93
94 // keeps _meshElement alive for the lifetime of a visual hit result
95 std::shared_ptr<Mesh> _mesh;
96 const MeshElement* _meshElement;
97 std::optional<uint32_t> _faceIndex;
98
99 math::vec3 _localCoordinates;
100 math::vec3 _worldCoordinates;
101 math::vec3 _localNormal;
102 math::vec3 _worldNormal;
103 math::mat4 _modelTransform;
104 };
105
106}
107
108#endif // AVARA3D_SCENE_HITTESTRESULT_H
Describes an intersection with scene geometry or a physics body.
Definition: HitTestResult.h:43
const math::vec3 & localNormal() const
Returns the hit surface normal in the node's local coordinate system.
const math::vec3 & worldCoordinates() const
Returns the hit position in world coordinates.
const math::mat4 & modelTransform() const
Returns the local-to-world model transform used for this hit.
const math::vec3 & localCoordinates() const
Returns the hit position in the node's local coordinate system.
const math::vec3 & worldNormal() const
Returns the hit surface normal in world coordinates.
std::optional< uint32_t > faceIndex() const
Returns the zero-based triangle index within meshElement().
const MeshElement * meshElement() const
Returns the hit visual mesh element, or nullptr when no visual mesh element is identified.
std::shared_ptr< Node > node() const
Returns the hit node, or nullptr if it has since been destroyed.
Owns the vertex and optional index data for one mesh primitive.
Definition: MeshElement.h:43