-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eyden-tracer-01 (makeup) #7
base: master
Are you sure you want to change the base?
Changes from all commits
6c5e1c4
0f69641
86fc4e3
be02f99
3912ff4
efd5e94
0b40482
d81e123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ class IPrim | |
* @brief Constructor | ||
*/ | ||
IPrim(void) = default; | ||
IPrim(const IPrim&) = delete; | ||
// IPrim(const IPrim&) = delete; | ||
IPrim(const IPrim&) = default; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not modify this file... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, professor, but it was giving me an error that function I was referencing does not exist. |
||
virtual ~IPrim(void) = default; | ||
const IPrim& operator=(const IPrim&) = delete; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,41 @@ | |
#include "IPrim.h" | ||
#include "ray.h" | ||
|
||
// --- IMPLENET class CPrimDisc --- | ||
// --- PUT YOUR CODE HERE --- | ||
// --- IMPLEMENT class CPrimDisc --- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suspicion for plagiarism There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just corrected the typo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant the whole implementation for disc primitive |
||
// --- PUT YOUR CODE HERE --- | ||
class CPrimDisc: public IPrim { | ||
public: | ||
// constructor | ||
CPrimDisc(const Vec3f& origin, const Vec3f normal, double radius) : IPrim(), m_origin(origin), m_normal(normal), m_radius(radius) {} | ||
|
||
// destructor | ||
virtual ~CPrimDisc(void) = default; | ||
|
||
// intersect method | ||
virtual bool intersect(Ray& ray) const override { | ||
auto plane = CPrimPlane(m_origin, m_normal); | ||
Ray r_copy = ray; | ||
if(!plane.intersect(r_copy)) { | ||
return false; | ||
} | ||
|
||
auto pt = r_copy.org + r_copy.dir * r_copy.t; | ||
auto distance = norm(pt - m_origin); | ||
if(distance > m_radius) { | ||
return false; | ||
} | ||
|
||
if(r_copy.t > ray.t) { | ||
return false; | ||
} | ||
|
||
ray.t = r_copy.t; | ||
return true; | ||
} | ||
|
||
|
||
private: | ||
Vec3f m_origin; | ||
Vec3f m_normal; | ||
double m_radius; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,28 @@ class CPrimTriangle : public IPrim | |
virtual bool intersect(Ray& ray) const override | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return false; | ||
Vec3f n_ab = (m_b - ray.org).cross(m_a - ray.org); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suspicion for plagiarism |
||
Vec3f n_bc = (m_c - ray.org).cross(m_b - ray.org); | ||
Vec3f n_ca = (m_a - ray.org).cross(m_c - ray.org); | ||
|
||
float area = n_ab.dot(ray.dir) + n_bc.dot(ray.dir) + n_ca.dot(ray.dir); | ||
float lambda1 = n_ab.dot(ray.dir) / area; | ||
float lambda2 = n_bc.dot(ray.dir) / area; | ||
float lambda3 = n_ca.dot(ray.dir) / area; | ||
|
||
if(lambda1 < 0 || lambda2 < 0 || lambda3 < 0) { | ||
return false; | ||
} | ||
|
||
Vec3f p = m_a * lambda1 + m_b * lambda2 + m_c *lambda3; | ||
float t = p[0] / ray.dir[0]; | ||
|
||
if(t < Epsilon || t > ray.t) { | ||
return false; | ||
} | ||
|
||
ray.t = t; | ||
return true; | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suspicion for plagiarism