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
5e3fd8e2
Commit
5e3fd8e2
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
CirclePlane refactor: New method used in intersect
parent
fbbdc537
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RayTracer/shape/CirclePlane.cpp
+11
-4
11 additions, 4 deletions
RayTracer/shape/CirclePlane.cpp
RayTracer/shape/CirclePlane.h
+2
-0
2 additions, 0 deletions
RayTracer/shape/CirclePlane.h
with
13 additions
and
4 deletions
RayTracer/shape/CirclePlane.cpp
+
11
−
4
View file @
5e3fd8e2
...
...
@@ -28,11 +28,18 @@ std::optional<cam::Hit> CirclePlane::intersect(const cam::Ray& r) const {
util
::
Vec3
t_hitpoint
=
r
(
t
);
if
(
r
.
in_range
(
t
)
&&
t_hitpoint
.
length
()
<=
radius
)
{
return
std
::
optional
<
cam
::
Hit
>
({
t_hitpoint
,
n
,
t
,
material
});
return
std
::
optional
<
cam
::
Hit
>
(
{
t_hitpoint
,
n
,
texture_coordinates
(
t_hitpoint
),
t
,
material
});
}
else
{
return
std
::
nullopt
;
}
}
std
::
pair
<
float
,
float
>
CirclePlane
::
texture_coordinates
(
const
util
::
Vec3
&
pos
)
const
{
return
std
::
pair
<
float
,
float
>
(
{
pos
.
x
()
/
radius
+
0.5
,
pos
.
z
()
/
radius
+
0.5
});
}
util
::
AxisAlignedBoundingBox
CirclePlane
::
bounds
()
const
{
return
util
::
AxisAlignedBoundingBox
(
util
::
Vec3
(
-
radius
,
0
,
-
radius
),
util
::
Vec3
(
radius
,
0
,
radius
));
...
...
@@ -43,9 +50,9 @@ util::SurfacePoint CirclePlane::sampleLight() const {
// Degreee of the sampled point.
float
theta
=
2
*
M_PI
*
util
::
dis0to1
(
util
::
gen
);
// Polar coordinates have to be converted to cartesian.
return
util
::
SurfacePoint
(
util
::
Vec3
(
r
*
std
::
cos
(
theta
),
0
,
r
*
std
::
sin
(
theta
)
),
util
::
Vec3
(
0
,
1
,
0
),
material
);
util
::
Vec3
pos
(
r
*
std
::
cos
(
theta
),
0
,
r
*
std
::
sin
(
theta
));
return
util
::
SurfacePoint
(
pos
,
util
::
Vec3
(
0
,
1
,
0
),
texture_coordinates
(
pos
),
material
);
// The sampled point will be in local coordinates.
}
util
::
Vec3
CirclePlane
::
calculateLightEmission
(
const
util
::
SurfacePoint
&
p
,
...
...
This diff is collapsed.
Click to expand it.
RayTracer/shape/CirclePlane.h
+
2
−
0
View file @
5e3fd8e2
...
...
@@ -9,6 +9,8 @@ class CirclePlane : public Light, public Shape {
CirclePlane
(
float
radius
,
bool
twofaced
,
const
std
::
shared_ptr
<
material
::
Material
>&
material
);
std
::
optional
<
cam
::
Hit
>
intersect
(
const
cam
::
Ray
&
r
)
const
override
;
std
::
pair
<
float
,
float
>
texture_coordinates
(
const
util
::
Vec3
&
pos
)
const
override
;
util
::
AxisAlignedBoundingBox
bounds
()
const
override
;
util
::
SurfacePoint
sampleLight
()
const
override
;
...
...
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