KiCad PCB EDA Suite
CXYPLANE Class Reference

A plane that is parallel to XY plane. More...

#include <cplane.h>

Inheritance diagram for CXYPLANE:
COBJECT

Public Member Functions

 CXYPLANE (const CBBOX &aBBox)
 
 CXYPLANE (SFVEC3F aCenterPoint, float aXSize, float aYSize)
 Constructor CXYPLANE. More...
 
void SetColor (SFVEC3F aObjColor)
 
bool Intersect (const RAY &aRay, HITINFO &aHitInfo) const override
 Functions Intersect. More...
 
bool IntersectP (const RAY &aRay, float aMaxDistance) const override
 Functions Intersect for shadow test. More...
 
bool Intersects (const CBBOX &aBBox) const override
 Function Intersects. More...
 
SFVEC3F GetDiffuseColor (const HITINFO &aHitInfo) const override
 
void SetMaterial (const CMATERIAL *aMaterial)
 
const CMATERIALGetMaterial () const
 
const CBBOXGetBBox () const
 
const SFVEC3FGetCentroid () const
 

Protected Attributes

CBBOX m_bbox
 
SFVEC3F m_centroid
 
OBJECT3D_TYPE m_obj_type
 
const CMATERIALm_material
 

Private Attributes

SFVEC3F m_centerPoint
 
float m_xsize
 
float m_ysize
 
float m_xsize_inv2
 
float m_ysize_inv2
 
SFVEC3F m_diffusecolor
 

Detailed Description

A plane that is parallel to XY plane.

Definition at line 38 of file cplane.h.

Constructor & Destructor Documentation

CXYPLANE::CXYPLANE ( const CBBOX aBBox)
explicit

Definition at line 33 of file cplane.cpp.

References CBBOX::GetCenter(), CBBOX::GetExtent(), COBJECT::m_bbox, m_centerPoint, COBJECT::m_centroid, m_xsize, m_xsize_inv2, m_ysize, m_ysize_inv2, CBBOX::Reset(), and CBBOX::Set().

34 {
35  m_centerPoint = aBBox.GetCenter();
37 
38  m_bbox.Reset();
39  m_bbox.Set( aBBox );
40  m_xsize = aBBox.GetExtent().x;
41  m_ysize = aBBox.GetExtent().y;
42  m_xsize_inv2 = 1.0f / (2.0f * m_xsize);
43  m_ysize_inv2 = 1.0f / (2.0f * m_ysize);
44 }
SFVEC3F m_centroid
Definition: cobject.h:54
CBBOX m_bbox
Definition: cobject.h:53
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox.cpp:67
float m_xsize
Definition: cplane.h:62
COBJECT(OBJECT3D_TYPE aObjType)
Definition: cobject.cpp:38
float m_xsize_inv2
Definition: cplane.h:64
SFVEC3F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox.cpp:135
SFVEC3F m_centerPoint
Definition: cplane.h:61
const SFVEC3F GetExtent() const
Function GetExtent.
Definition: cbbox.cpp:148
float m_ysize
Definition: cplane.h:63
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox.cpp:98
float m_ysize_inv2
Definition: cplane.h:65
CXYPLANE::CXYPLANE ( SFVEC3F  aCenterPoint,
float  aXSize,
float  aYSize 
)

Constructor CXYPLANE.

Parameters
aCenterPoint= position of the center of the plane
aXSize= size by X axis
aYSize= size by Y axis

Definition at line 47 of file cplane.cpp.

References COBJECT::m_bbox, m_centerPoint, COBJECT::m_centroid, m_xsize, m_xsize_inv2, m_ysize, m_ysize_inv2, and CBBOX::Set().

50 {
51  m_centerPoint = aCenterPoint;
52  m_xsize = aXSize;
53  m_ysize = aYSize;
54  m_xsize_inv2 = 1.0f / (2.0f * aXSize);
55  m_ysize_inv2 = 1.0f / (2.0f * aYSize);
56  m_bbox.Set( SFVEC3F( aCenterPoint.x - aXSize / 2.0f,
57  aCenterPoint.y - aYSize / 2.0f,
58  aCenterPoint.z ),
59  SFVEC3F( aCenterPoint.x + aXSize / 2.0f,
60  aCenterPoint.y + aYSize / 2.0f,
61  aCenterPoint.z ) );
62  m_centroid = aCenterPoint;
63 }
SFVEC3F m_centroid
Definition: cobject.h:54
CBBOX m_bbox
Definition: cobject.h:53
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox.cpp:67
float m_xsize
Definition: cplane.h:62
COBJECT(OBJECT3D_TYPE aObjType)
Definition: cobject.cpp:38
float m_xsize_inv2
Definition: cplane.h:64
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC3F m_centerPoint
Definition: cplane.h:61
float m_ysize
Definition: cplane.h:63
float m_ysize_inv2
Definition: cplane.h:65

Member Function Documentation

const CBBOX& COBJECT::GetBBox ( ) const
inlineinherited

Definition at line 94 of file cobject.h.

References COBJECT::m_bbox.

Referenced by CGENERICCONTAINER::Add(), and CBVH_PBRT::Intersect().

94 { return m_bbox; }
CBBOX m_bbox
Definition: cobject.h:53
const SFVEC3F& COBJECT::GetCentroid ( ) const
inlineinherited

Definition at line 96 of file cobject.h.

References COBJECT::m_centroid.

96 { return m_centroid; }
SFVEC3F m_centroid
Definition: cobject.h:54
SFVEC3F CXYPLANE::GetDiffuseColor ( const HITINFO aHitInfo) const
overridevirtual

Implements COBJECT.

Definition at line 127 of file cplane.cpp.

References m_diffusecolor.

128 {
129  (void)aHitInfo; // unused
130 
131  return m_diffusecolor;
132 }
SFVEC3F m_diffusecolor
Definition: cplane.h:66
const CMATERIAL* COBJECT::GetMaterial ( ) const
inlineinherited

Definition at line 63 of file cobject.h.

References COBJECT::m_material.

Referenced by CBVH_PBRT::IntersectP(), and C3D_RENDER_RAYTRACING::shadeHit().

63 { return m_material; }
const CMATERIAL * m_material
Definition: cobject.h:56
bool CXYPLANE::Intersect ( const RAY aRay,
HITINFO aHitInfo 
) const
overridevirtual

Functions Intersect.

Intersect

Parameters
aRay
aHitInfo
Returns
true if the aRay intersects the object

Implements COBJECT.

Definition at line 66 of file cplane.cpp.

References RAY::at(), m_centerPoint, RAY::m_Dir, RAY::m_dirIsNeg, HITINFO::m_HitNormal, HITINFO::m_HitPoint, RAY::m_InvDir, COBJECT::m_material, RAY::m_Origin, HITINFO::m_tHit, m_xsize, m_ysize, CMATERIAL::PerturbeNormal(), and HITINFO::pHitObject.

67 {
68  const float t = (m_centerPoint.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
69 
70  if( ( t < FLT_EPSILON ) ||
71  ( t >= aHitInfo.m_tHit ) )
72  return false;
73 
74  const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
75 
76  if( (vSU < -m_xsize) || (vSU > m_xsize) )
77  return false;
78 
79  const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
80 
81  if( (vSV < -m_ysize) || (vSV > m_ysize) )
82  return false;
83 
84  aHitInfo.m_tHit = t;
85  aHitInfo.m_HitPoint = aRay.at( t );
86  aHitInfo.pHitObject = this;
87 
88  if( aRay.m_dirIsNeg[2] )
89  aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
90  else
91  aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f,-1.0f );
92 
93  m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
94 
95  return true;
96 }
SFVEC3F at(float t) const
Definition: ray.h:65
const CMATERIAL * m_material
Definition: cobject.h:56
float m_tHit
( 4) distance
Definition: hitinfo.h:43
SFVEC3F m_InvDir
Definition: ray.h:51
SFVEC3F m_HitPoint
(12) hit position
Definition: hitinfo.h:49
float m_xsize
Definition: cplane.h:62
void PerturbeNormal(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: cmaterial.cpp:88
unsigned int m_dirIsNeg[3]
Definition: ray.h:56
const COBJECT * pHitObject
( 4) Object that was hitted
Definition: hitinfo.h:45
SFVEC3F m_Dir
Definition: ray.h:48
SFVEC3F m_Origin
Definition: ray.h:45
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
SFVEC3F m_centerPoint
Definition: cplane.h:61
float m_ysize
Definition: cplane.h:63
bool CXYPLANE::IntersectP ( const RAY aRay,
float  aMaxDistance 
) const
overridevirtual

Functions Intersect for shadow test.

Intersect

Parameters
aRay
aMaxDistance- max distance of the test
Returns
true if the aRay intersects the object

Implements COBJECT.

Definition at line 99 of file cplane.cpp.

References m_centerPoint, RAY::m_Dir, RAY::m_InvDir, RAY::m_Origin, m_xsize, and m_ysize.

100 {
101  const float t = (m_centerPoint.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
102 
103  if( ( t < FLT_EPSILON ) ||
104  ( t >= aMaxDistance ) )
105  return false;
106 
107  const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
108 
109  if( (vSU < -m_xsize) || (vSU > m_xsize) )
110  return false;
111 
112  const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
113 
114  if( (vSV < -m_ysize) || (vSV > m_ysize) )
115  return false;
116 
117  return true;
118 }
SFVEC3F m_InvDir
Definition: ray.h:51
float m_xsize
Definition: cplane.h:62
SFVEC3F m_Dir
Definition: ray.h:48
SFVEC3F m_Origin
Definition: ray.h:45
SFVEC3F m_centerPoint
Definition: cplane.h:61
float m_ysize
Definition: cplane.h:63
bool CXYPLANE::Intersects ( const CBBOX aBBox) const
overridevirtual

Function Intersects.

Intersects - a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅) It intersects if the result intersection is not null

Parameters
aBBox
Returns

Implements COBJECT.

Definition at line 121 of file cplane.cpp.

References CBBOX::Intersects(), and COBJECT::m_bbox.

122 {
123  return m_bbox.Intersects( aBBox );
124 }
bool Intersects(const CBBOX &aBBox) const
Function Intersects test if a bounding box intersects this box.
Definition: cbbox.cpp:230
CBBOX m_bbox
Definition: cobject.h:53
void CXYPLANE::SetColor ( SFVEC3F  aObjColor)
inline

Definition at line 52 of file cplane.h.

References m_diffusecolor.

Referenced by C3D_RENDER_RAYTRACING::create_3d_object_from().

52 { m_diffusecolor = aObjColor; }
SFVEC3F m_diffusecolor
Definition: cplane.h:66
void COBJECT::SetMaterial ( const CMATERIAL aMaterial)
inlineinherited

Member Data Documentation

SFVEC3F CXYPLANE::m_centerPoint
private

Definition at line 61 of file cplane.h.

Referenced by CXYPLANE(), Intersect(), and IntersectP().

SFVEC3F CXYPLANE::m_diffusecolor
private

Definition at line 66 of file cplane.h.

Referenced by GetDiffuseColor(), and SetColor().

OBJECT3D_TYPE COBJECT::m_obj_type
protectedinherited

Definition at line 55 of file cobject.h.

Referenced by COBJECT::COBJECT().

float CXYPLANE::m_xsize
private

Definition at line 62 of file cplane.h.

Referenced by CXYPLANE(), Intersect(), and IntersectP().

float CXYPLANE::m_xsize_inv2
private

Definition at line 64 of file cplane.h.

Referenced by CXYPLANE().

float CXYPLANE::m_ysize
private

Definition at line 63 of file cplane.h.

Referenced by CXYPLANE(), Intersect(), and IntersectP().

float CXYPLANE::m_ysize_inv2
private

Definition at line 65 of file cplane.h.

Referenced by CXYPLANE().


The documentation for this class was generated from the following files: