Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
PTriangle.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/TVector3.h"
6
7#include <Common/assertion.h>
8
9namespace ph
10{
11
16class PTriangle : public Primitive
17{
18public:
19 PTriangle(const math::Vector3R& vA, const math::Vector3R& vB, const math::Vector3R& vC);
20
21 bool isIntersecting(const Ray& ray, HitProbe& probe) const override;
22
23 bool reintersect(
24 const Ray& ray,
25 HitProbe& probe,
26 const Ray& srcRay,
27 HitProbe& srcProbe) const override;
28
29 void calcHitDetail(
30 const Ray& ray,
31 HitProbe& probe,
32 HitDetail* out_detail) const override;
33
34 bool mayOverlapVolume(const math::AABB3D& volume) const override;
35 math::AABB3D calcAABB() const override;
36
37 void genPosSample(
39 SampleFlow& sampleFlow,
40 HitProbe& probe) const override;
41
42 void calcPosPdf(PrimitivePosPdfQuery& query) const override;
43
44 real calcExtendedArea() const override;
45
50 void setNa(const math::Vector3R& nA);
51 void setNb(const math::Vector3R& nB);
52 void setNc(const math::Vector3R& nC);
54
59 void setUVWa(const math::Vector3R& uvwA);
60 void setUVWb(const math::Vector3R& uvwB);
61 void setUVWc(const math::Vector3R& uvwC);
63
64 const math::Vector3R& getNa() const;
65 const math::Vector3R& getNb() const;
66 const math::Vector3R& getNc() const;
67
68 const math::Vector3R& getUVWa() const;
69 const math::Vector3R& getUVWb() const;
70 const math::Vector3R& getUVWc() const;
71
72private:
74
75 Triangle m_triangle;
76
77 math::Vector3R m_nA;
78 math::Vector3R m_nB;
79 math::Vector3R m_nC;
80
81 math::Vector3R m_uvwA;
82 math::Vector3R m_uvwB;
83 math::Vector3R m_uvwC;
84
85 math::Vector3R m_faceNormal;
86};
87
88inline void PTriangle::setNa(const math::Vector3R& nA)
89{
90 PH_ASSERT_MSG(nA.isFinite(), nA.toString());
91 PH_ASSERT_IN_RANGE(nA.lengthSquared(), 0.9_r, 1.1_r);
92
93 m_nA = nA;
94}
95
96inline void PTriangle::setNb(const math::Vector3R& nB)
97{
98 PH_ASSERT_MSG(nB.isFinite(), nB.toString());
99 PH_ASSERT_IN_RANGE(nB.lengthSquared(), 0.9_r, 1.1_r);
100
101 m_nB = nB;
102}
103
104inline void PTriangle::setNc(const math::Vector3R& nC)
105{
106 PH_ASSERT_MSG(nC.isFinite(), nC.toString());
107 PH_ASSERT_IN_RANGE(nC.lengthSquared(), 0.9_r, 1.1_r);
108
109 m_nC = nC;
110}
111
112inline void PTriangle::setUVWa(const math::Vector3R& uvwA)
113{
114 m_uvwA = uvwA;
115}
116
117inline void PTriangle::setUVWb(const math::Vector3R& uvwB)
118{
119 m_uvwB = uvwB;
120}
121
122inline void PTriangle::setUVWc(const math::Vector3R& uvwC)
123{
124 m_uvwC = uvwC;
125}
126
127inline const math::Vector3R& PTriangle::getNa() const
128{
129 return m_nC;
130}
131
132inline const math::Vector3R& PTriangle::getNb() const
133{
134 return m_nB;
135}
136
137inline const math::Vector3R& PTriangle::getNc() const
138{
139 return m_nA;
140}
141
143{
144 return m_uvwA;
145}
146
148{
149 return m_uvwB;
150}
151
153{
154 return m_uvwC;
155}
156
157}// end namespace ph
Detailed information regarding a ray-primitive intersection.
Definition HitDetail.h:26
Lightweight ray intersection testing and reporting object. If an intersection is found,...
Definition HitProbe.h:27
A single triangle. This triangle type is for constructing simple shapes such as a quad or box....
Definition PTriangle.h:17
void setUVWb(const math::Vector3R &uvwB)
Definition PTriangle.h:117
const math::Vector3R & getNb() const
Definition PTriangle.h:132
const math::Vector3R & getUVWb() const
Definition PTriangle.h:147
void setUVWa(const math::Vector3R &uvwA)
Set vertex parametric coordinates. Surface parametric coordinates are set to 0 by default.
Definition PTriangle.h:112
void genPosSample(PrimitivePosSampleQuery &query, SampleFlow &sampleFlow, HitProbe &probe) const override
Generates a sample point on the surface of this primitive.
Definition PTriangle.cpp:269
const math::Vector3R & getUVWa() const
Definition PTriangle.h:142
void setNa(const math::Vector3R &nA)
Set vertex normals. Vertex normals are set to face normal by default.
Definition PTriangle.h:88
const math::Vector3R & getNc() const
Definition PTriangle.h:137
void setNb(const math::Vector3R &nB)
Definition PTriangle.h:96
bool reintersect(const Ray &ray, HitProbe &probe, const Ray &srcRay, HitProbe &srcProbe) const override
Intersect the intersected object again with a different ray.
Definition PTriangle.cpp:51
void setNc(const math::Vector3R &nC)
Definition PTriangle.h:104
const math::Vector3R & getUVWc() const
Definition PTriangle.h:152
void setUVWc(const math::Vector3R &uvwC)
Definition PTriangle.h:122
PTriangle(const math::Vector3R &vA, const math::Vector3R &vB, const math::Vector3R &vC)
Definition PTriangle.cpp:19
math::AABB3D calcAABB() const override
Calculates Axis-Aligned Bounding Box (AABB) of itself.
Definition PTriangle.cpp:137
const math::Vector3R & getNa() const
Definition PTriangle.h:127
real calcExtendedArea() const override
Calculates the area extended by this primitive. The term "extended" implies single-sided,...
Definition PTriangle.cpp:300
bool isIntersecting(const Ray &ray, HitProbe &probe) const override
Determine whether a given ray hits the object.
Definition PTriangle.cpp:37
void calcHitDetail(const Ray &ray, HitProbe &probe, HitDetail *out_detail) const override
Calculates properties of a hit, such as coordinates and normal.
Definition PTriangle.cpp:66
void calcPosPdf(PrimitivePosPdfQuery &query) const override
Given a point on the surface of this primitive, calculates the PDF of sampling this point.
Definition PTriangle.cpp:295
bool mayOverlapVolume(const math::AABB3D &volume) const override
Conservatively checks whether this object overlaps a volume.
Definition PTriangle.cpp:145
A physical shape in the scene.
Definition Primitive.h:23
Information for the probability of generating a specific sample point on a primitive.
Definition PrimitivePosPdfQuery.h:91
Information for generating a sample point on a primitive.
Definition PrimitivePosSampleQuery.h:132
Represents a ray in space.
Definition Ray.h:21
A sample with arbitrary dimensions with fine-grained sampling control.
Definition SampleFlow.h:19
std::string toString() const
Definition TArithmeticArrayBase.ipp:825
bool isFinite() const
Definition TArithmeticArrayBase.ipp:585
T lengthSquared() const
Definition TVectorNBase.ipp:44
The root for all renderer implementations.
Definition EEngineProject.h:6