Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CppRaytracer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yoel
CppRaytracer
Commits
cd8430f6
Commit
cd8430f6
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Made all references const and added a new *-operator for transforming AABBs with matrices
parent
7b78ff1f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RayTracer/tools/AxisAlignedBoundingBox.cpp
+4
-4
4 additions, 4 deletions
RayTracer/tools/AxisAlignedBoundingBox.cpp
RayTracer/tools/AxisAlignedBoundingBox.h
+6
-4
6 additions, 4 deletions
RayTracer/tools/AxisAlignedBoundingBox.h
with
10 additions
and
8 deletions
RayTracer/tools/AxisAlignedBoundingBox.cpp
+
4
−
4
View file @
cd8430f6
...
@@ -11,12 +11,12 @@ AxisAlignedBoundingBox::AxisAlignedBoundingBox()
...
@@ -11,12 +11,12 @@ AxisAlignedBoundingBox::AxisAlignedBoundingBox()
max
(
Vec3
(
std
::
numeric_limits
<
float
>::
infinity
()))
{
max
(
Vec3
(
std
::
numeric_limits
<
float
>::
infinity
()))
{
}
}
AxisAlignedBoundingBox
::
AxisAlignedBoundingBox
(
Vec3
&
min
,
Vec3
&
max
)
AxisAlignedBoundingBox
::
AxisAlignedBoundingBox
(
const
Vec3
&
min
,
const
Vec3
&
max
)
:
min
(
min
),
max
(
max
)
{
:
min
(
min
),
max
(
max
)
{
}
}
// Operator
// Operator
AxisAlignedBoundingBox
AxisAlignedBoundingBox
::
operator
+
(
AxisAlignedBoundingBox
AxisAlignedBoundingBox
::
operator
+
(
AxisAlignedBoundingBox
&
rhs
)
const
{
const
AxisAlignedBoundingBox
&
rhs
)
const
{
Vec3
min
(
std
::
min
<
float
>
(
min
.
x
(),
rhs
.
min
.
x
()),
Vec3
min
(
std
::
min
<
float
>
(
min
.
x
(),
rhs
.
min
.
x
()),
std
::
min
<
float
>
(
min
.
y
(),
rhs
.
min
.
y
()),
std
::
min
<
float
>
(
min
.
y
(),
rhs
.
min
.
y
()),
std
::
min
<
float
>
(
min
.
z
(),
rhs
.
min
.
z
()));
std
::
min
<
float
>
(
min
.
z
(),
rhs
.
min
.
z
()));
...
@@ -28,7 +28,7 @@ AxisAlignedBoundingBox AxisAlignedBoundingBox::operator+(
...
@@ -28,7 +28,7 @@ AxisAlignedBoundingBox AxisAlignedBoundingBox::operator+(
}
}
// Methods
// Methods
// https://education.siggraph.org/static/HyperGraph/raytrace/rtinter3.htm
// https://education.siggraph.org/static/HyperGraph/raytrace/rtinter3.htm
bool
AxisAlignedBoundingBox
::
intersects
(
cam
::
Ray
&
r
)
const
{
bool
AxisAlignedBoundingBox
::
intersects
(
const
cam
::
Ray
&
r
)
const
{
float
t1x
=
(
min
.
x
()
-
r
.
x0
.
x
())
/
r
.
d
.
x
();
float
t1x
=
(
min
.
x
()
-
r
.
x0
.
x
())
/
r
.
d
.
x
();
float
t2x
=
(
max
.
x
()
-
r
.
x0
.
x
())
/
r
.
d
.
x
();
float
t2x
=
(
max
.
x
()
-
r
.
x0
.
x
())
/
r
.
d
.
x
();
float
t1y
=
(
min
.
y
()
-
r
.
x0
.
y
())
/
r
.
d
.
y
();
float
t1y
=
(
min
.
y
()
-
r
.
x0
.
y
())
/
r
.
d
.
y
();
...
@@ -45,7 +45,7 @@ bool AxisAlignedBoundingBox::intersects(cam::Ray& r) const {
...
@@ -45,7 +45,7 @@ bool AxisAlignedBoundingBox::intersects(cam::Ray& r) const {
return
tmax
>=
tmin
&&
r
.
in_range
(
tmax
);
return
tmax
>=
tmin
&&
r
.
in_range
(
tmax
);
}
}
bool
AxisAlignedBoundingBox
::
contains
(
Vec3
&
v
)
const
{
bool
AxisAlignedBoundingBox
::
contains
(
const
Vec3
&
v
)
const
{
bool
x
=
min
.
x
()
<=
v
.
x
()
&&
v
.
x
()
<=
max
.
x
();
bool
x
=
min
.
x
()
<=
v
.
x
()
&&
v
.
x
()
<=
max
.
x
();
bool
y
=
min
.
y
()
<=
v
.
y
()
&&
v
.
y
()
<=
max
.
y
();
bool
y
=
min
.
y
()
<=
v
.
y
()
&&
v
.
y
()
<=
max
.
y
();
bool
z
=
min
.
z
()
<=
v
.
z
()
&&
v
.
z
()
<=
max
.
z
();
bool
z
=
min
.
z
()
<=
v
.
z
()
&&
v
.
z
()
<=
max
.
z
();
...
...
This diff is collapsed.
Click to expand it.
RayTracer/tools/AxisAlignedBoundingBox.h
+
6
−
4
View file @
cd8430f6
#pragma once
#pragma once
#include
"../camera/Ray.h"
#include
"../camera/Ray.h"
#include
"Mat4.h"
#include
"Vec3.h"
#include
"Vec3.h"
namespace
util
{
namespace
util
{
...
@@ -8,12 +9,13 @@ namespace util {
...
@@ -8,12 +9,13 @@ namespace util {
class
AxisAlignedBoundingBox
{
class
AxisAlignedBoundingBox
{
public:
public:
AxisAlignedBoundingBox
();
AxisAlignedBoundingBox
();
AxisAlignedBoundingBox
(
Vec3
&
min
,
Vec3
&
max
);
AxisAlignedBoundingBox
(
const
Vec3
&
min
,
const
Vec3
&
max
);
// Operator
// Operator
AxisAlignedBoundingBox
operator
+
(
AxisAlignedBoundingBox
&
rhs
)
const
;
AxisAlignedBoundingBox
operator
+
(
const
AxisAlignedBoundingBox
&
rhs
)
const
;
AxisAlignedBoundingBox
operator
*
(
const
Mat4
&
rhs
)
const
;
// Methods
// Methods
bool
intersects
(
cam
::
Ray
&
r
)
const
;
bool
intersects
(
const
cam
::
Ray
&
r
)
const
;
bool
contains
(
Vec3
&
v
)
const
;
bool
contains
(
const
Vec3
&
v
)
const
;
Vec3
minBound
()
const
;
Vec3
minBound
()
const
;
Vec3
maxBound
()
const
;
Vec3
maxBound
()
const
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment