Debian Codegraph @

core/math/static_raycaster.h

raw symbols SCIP
1 /**************************************************************************/
2 /* static_raycaster.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/object/ref_counted.h"
34
35 class StaticRaycaster : public RefCounted {
36 GDCLASS(StaticRaycaster, RefCounted)
37 protected:
38 static StaticRaycaster *(*create_function)();
39
40 public:
41 // Compatible with embree4 rays.
42 struct alignas(16) Ray {
43 const static unsigned int INVALID_GEOMETRY_ID = ((unsigned int)-1); // from rtcore_common.h
44
45 /*! Default construction does nothing. */
46 _FORCE_INLINE_ Ray() :
47 geomID(INVALID_GEOMETRY_ID) {}
48
49 /*! Constructs a ray from origin, direction, and ray segment. Near
50 * has to be smaller than far. */
51 _FORCE_INLINE_ Ray(const Vector3 &p_org,
52 const Vector3 &p_dir,
53 float p_tnear = 0.0f,
54 float p_tfar = Math::INF) :
55 org(p_org),
56 tnear(p_tnear),
57 dir(p_dir),
58 time(0.0f),
59 tfar(p_tfar),
60 mask(-1),
61 u(0.0),
62 v(0.0),
63 primID(INVALID_GEOMETRY_ID),
64 geomID(INVALID_GEOMETRY_ID),
65 instID(INVALID_GEOMETRY_ID) {}
66
67 /*! Tests if we hit something. */
68 _FORCE_INLINE_ explicit operator bool() const { return geomID != INVALID_GEOMETRY_ID; }
69
70 public:
71 Vector3 org; //!< Ray origin + tnear
72 float tnear; //!< Start of ray segment
73 Vector3 dir; //!< Ray direction + tfar
74 float time; //!< Time of this ray for motion blur.
75 float tfar; //!< End of ray segment
76 unsigned int mask; //!< used to mask out objects during traversal
77 unsigned int id; //!< ray ID
78 unsigned int flags; //!< ray flags
79
80 Vector3 normal; //!< Not normalized geometry normal
81 float u; //!< Barycentric u coordinate of hit
82 float v; //!< Barycentric v coordinate of hit
83 unsigned int primID; //!< primitive ID
84 unsigned int geomID; //!< geometry ID
85 unsigned int instID; //!< instance ID
86 };
87
88 virtual bool intersect(Ray &p_ray) = 0;
89 virtual void intersect(Vector<Ray> &r_rays) = 0;
90
91 virtual void add_mesh(const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices, unsigned int p_id) = 0;
92 virtual void commit() = 0;
93
94 virtual void set_mesh_filter(const HashSet<int> &p_mesh_ids) = 0;
95 virtual void clear_mesh_filter() = 0;
96
97 static Ref<StaticRaycaster> create();
98 };