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
6745d5ea
Commit
6745d5ea
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Complete implementation of BoundingVolumes
parent
7565f2c8
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
+59
-0
59 additions, 0 deletions
RayTracer/tools/AxisAlignedBoundingBox.cpp
RayTracer/tools/AxisAlignedBoundingBox.h
+23
-0
23 additions, 0 deletions
RayTracer/tools/AxisAlignedBoundingBox.h
with
82 additions
and
0 deletions
RayTracer/tools/AxisAlignedBoundingBox.cpp
0 → 100644
+
59
−
0
View file @
6745d5ea
#include
"AxisAlignedBoundingBox.h"
#include
<algorithm>
#include
<limits>
namespace
util
{
// Constructor
AxisAlignedBoundingBox
::
AxisAlignedBoundingBox
()
:
min
(
Vec3
(
0
)),
max
(
Vec3
(
0
))
{
}
AxisAlignedBoundingBox
::
AxisAlignedBoundingBox
(
Vec3
&
min
,
Vec3
&
max
)
:
min
(
min
),
max
(
max
)
{
}
// Operator
AxisAlignedBoundingBox
AxisAlignedBoundingBox
::
operator
+
(
AxisAlignedBoundingBox
&
rhs
)
const
{
Vec3
min
(
std
::
min
<
float
>
(
min
.
x
(),
rhs
.
min
.
x
()),
std
::
min
<
float
>
(
min
.
y
(),
rhs
.
min
.
y
()),
std
::
min
<
float
>
(
min
.
z
(),
rhs
.
min
.
z
()));
Vec3
max
(
std
::
max
<
float
>
(
max
.
x
(),
rhs
.
max
.
x
()),
std
::
max
<
float
>
(
max
.
y
(),
rhs
.
max
.
y
()),
std
::
max
<
float
>
(
max
.
z
(),
rhs
.
max
.
z
()));
return
AxisAlignedBoundingBox
(
min
,
max
);
}
// Methods
// https://education.siggraph.org/static/HyperGraph/raytrace/rtinter3.htm
bool
AxisAlignedBoundingBox
::
intersects
(
cam
::
Ray
&
r
)
const
{
float
t1x
=
(
min
.
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
t2y
=
(
max
.
y
()
-
r
.
x0
.
y
())
/
r
.
d
.
y
();
float
t1z
=
(
min
.
z
()
-
r
.
x0
.
z
())
/
r
.
d
.
z
();
float
t2z
=
(
max
.
z
()
-
r
.
x0
.
z
())
/
r
.
d
.
z
();
float
tmin
=
std
::
max
<
float
>
({
std
::
min
<
float
>
(
t1x
,
t2x
),
std
::
min
<
float
>
(
t1y
,
t2y
),
std
::
min
<
float
>
(
t1z
,
t2z
)});
float
tmax
=
std
::
min
<
float
>
({
std
::
max
<
float
>
(
t1x
,
t2x
),
std
::
max
<
float
>
(
t1y
,
t2y
),
std
::
max
<
float
>
(
t1z
,
t2z
)});
return
tmax
>=
tmin
&&
tmax
>
0
;
}
bool
AxisAlignedBoundingBox
::
contains
(
Vec3
&
v
)
const
{
bool
x
=
min
.
x
()
<=
v
.
x
()
&&
v
.
x
()
<=
max
.
x
();
bool
y
=
min
.
y
()
<=
v
.
y
()
&&
v
.
y
()
<=
max
.
y
();
bool
z
=
min
.
z
()
<=
v
.
z
()
&&
v
.
z
()
<=
max
.
z
();
return
x
&&
y
&&
z
;
}
Vec3
AxisAlignedBoundingBox
::
minBound
()
const
{
return
min
;
}
Vec3
AxisAlignedBoundingBox
::
maxBound
()
const
{
return
max
;
}
}
// namespace util
\ No newline at end of file
This diff is collapsed.
Click to expand it.
RayTracer/tools/AxisAlignedBoundingBox.h
0 → 100644
+
23
−
0
View file @
6745d5ea
#pragma once
#include
"../camera/Ray.h"
#include
"Vec3.h"
namespace
util
{
class
AxisAlignedBoundingBox
{
public:
AxisAlignedBoundingBox
();
AxisAlignedBoundingBox
(
Vec3
&
min
,
Vec3
&
max
);
// Operator
AxisAlignedBoundingBox
operator
+
(
AxisAlignedBoundingBox
&
rhs
)
const
;
// Methods
bool
intersects
(
cam
::
Ray
&
r
)
const
;
bool
contains
(
Vec3
&
v
)
const
;
Vec3
minBound
()
const
;
Vec3
maxBound
()
const
;
private:
const
Vec3
min
,
max
;
};
}
// namespace util
\ No newline at end of file
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