Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Ray.h
Go to the documentation of this file.
1/*
2 * Ray class, for use with the optimized ray-box
3 * intersection test described in:
4 *
5 * Amy Williams, Steve Barrus, R. Keith Morley, and Peter Shirley
6 * "An Efficient and Robust Ray-Box Intersection Algorithm"
7 * Journal of graphics tools, 10(1):49-54, 2005
8 *
9 */
10
11/*
12 Copyright (c) 2018 DIVIDE-Studio
13 Copyright (c) 2009 Ionut Cava
14
15 This file is part of DIVIDE Framework.
16
17 Permission is hereby granted, free of charge, to any person obtaining a copy
18 of this software
19 and associated documentation files (the "Software"), to deal in the Software
20 without restriction,
21 including without limitation the rights to use, copy, modify, merge, publish,
22 distribute, sublicense,
23 and/or sell copies of the Software, and to permit persons to whom the
24 Software is furnished to do so,
25 subject to the following conditions:
26
27 The above copyright notice and this permission notice shall be included in
28 all copies or substantial portions of the Software.
29
30 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31 IMPLIED,
32 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
33 PARTICULAR PURPOSE AND NONINFRINGEMENT.
34 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
35 DAMAGES OR OTHER LIABILITY,
36 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
37 IN CONNECTION WITH THE SOFTWARE
38 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
40 */
41
42#pragma once
43#ifndef DVD_RAY_H_
44#define DVD_RAY_H_
45
46namespace Divide {
48{
49 bool hit = false;
50 bool inside = false;
52};
53
54struct Ray {
58 };
59
62
63 void identity() noexcept {
66 }
67
68 [[nodiscard]] CollisionHelpers getCollisionHelpers() const noexcept {
69 CollisionHelpers ret = {};
70 if (!IS_ZERO(_direction.x)) {
71 ret._invDirection.x = 1.0f / _direction.x;
72 } else {
74 }
75 if (!IS_ZERO(_direction.y)) {
76 ret._invDirection.y = 1.0f / _direction.y;
77 } else {
79 }
80 if (!IS_ZERO(_direction.z)) {
81 ret._invDirection.z = 1.0f / _direction.z;
82 } else {
84 }
85 ret._sign.x = ret._invDirection.x < 0.0f;
86 ret._sign.y = ret._invDirection.y < 0.0f;
87 ret._sign.z = ret._invDirection.z < 0.0f;
88 return ret;
89 }
90};
91
92} // namespace Divide
93
94#endif //DVD_RAY_H_
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool IS_ZERO(const T X) noexcept
constexpr F32 F32_INFINITY
static const vec3< F32 > VECTOR3_ZERO
Definition: MathVectors.h:1434
static const vec3< F32 > WORLD_Y_AXIS
Definition: MathVectors.h:1440
vec3< F32 > _invDirection
Definition: Ray.h:56
vec3< F32 > _origin
Definition: Ray.h:60
void identity() noexcept
Definition: Ray.h:63
vec3< F32 > _direction
Definition: Ray.h:61
CollisionHelpers getCollisionHelpers() const noexcept
Definition: Ray.h:68
bool inside
Definition: Ray.h:50
bool hit
Definition: Ray.h:49