RavEngine
Loading...
Searching...
No Matches
sphere.h
1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SPHERE_H_
18#define RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SPHERE_H_
19
20#include "embree2/rtcore.h"
21#include "embree2/rtcore_ray.h"
22
23namespace vraudio {
24
25// A user defined sphere geometry that enables Embree to test ray intersections.
26struct RTCORE_ALIGN(16) Sphere {
27 // Center of the sphere.
28 float center[3];
29
30 // Radius of the sphere.
31 float radius;
32
33 // Geometry Id. This will be reported by ray intersections.
34 unsigned int geometry_id;
35};
36
37// The following functions are to be called by Embree internally to enable fast
38// ray-sphere intersections tests.
39
40// Calculates the RTCBounds (essentially a bounding box) of a given sphere.
41//
42// @param sphere Sphere of interest.
43// @param output_bounds Output RTCBounds of the sphere.
44inline void SphereBounds(const Sphere& sphere, RTCBounds* output_bounds) {
45 output_bounds->lower_x = sphere.center[0] - sphere.radius;
46 output_bounds->lower_y = sphere.center[1] - sphere.radius;
47 output_bounds->lower_z = sphere.center[2] - sphere.radius;
48 output_bounds->upper_x = sphere.center[0] + sphere.radius;
49 output_bounds->upper_y = sphere.center[1] + sphere.radius;
50 output_bounds->upper_z = sphere.center[2] + sphere.radius;
51}
52
53// Tests whether a sphere and a ray intersects and sets the related data for
54// the ray when an intersection is found:
55// - |ray.tfar| will be set to corresponding to the first intersection point.
56// - |ray.geomID| will be set to the geometry id of the sphere.
57// - |ray.Ng| will be set to the normal at the first intersection point,
58// pointing radially outward
59//
60// Because this function will be called internally by Embree, it works on
61// Embree's native type RTCRay as opposed to AcousticRay.
62//
63// @param spheres Sphere of interest.
64// @param ray RTCRay with which intersections are tested and related data set.
65void SphereIntersection(const Sphere& sphere, RTCRay* ray);
66
67} // namespace vraudio
68
69#endif // RESONANCE_AUDIO_GEOMETRICAL_ACOUSTICS_SPHERE_H_