KiCad PCB EDA Suite
CVCYLINDER Class Reference

A vertical cylinder. More...

#include <ccylinder.h>

Inheritance diagram for CVCYLINDER:
COBJECT

Public Member Functions

 CVCYLINDER (SFVEC2F aCenterPoint, float aZmin, float aZmax, float aRadius)
 Constructor CVCYLINDER. 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

SFVEC2F m_center
 
float m_radius_squared
 
float m_inv_radius
 
SFVEC3F m_diffusecolor
 

Detailed Description

A vertical cylinder.

Definition at line 38 of file ccylinder.h.

Constructor & Destructor Documentation

CVCYLINDER::CVCYLINDER ( SFVEC2F  aCenterPoint,
float  aZmin,
float  aZmax,
float  aRadius 
)

Constructor CVCYLINDER.

Parameters
aCenterPoint= position of the vertical cylinder axis in the XY plane
aZmin= bottom position (Z axis)
aZmax= top position (Z axis)
aRadius= radius of the cylinder

Definition at line 34 of file ccylinder.cpp.

References CBBOX::GetCenter(), COBJECT::m_bbox, m_center, COBJECT::m_centroid, m_inv_radius, m_radius_squared, CBBOX::ScaleNextUp(), and CBBOX::Set().

38 {
39  m_center = aCenterPoint;
40  m_radius_squared = aRadius * aRadius;
41  m_inv_radius = 1.0f / aRadius;
42 
43  m_bbox.Set( SFVEC3F( aCenterPoint.x - aRadius,
44  aCenterPoint.y - aRadius,
45  aZmin ),
46  SFVEC3F( aCenterPoint.x + aRadius,
47  aCenterPoint.y + aRadius,
48  aZmax ) );
51 }
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
COBJECT(OBJECT3D_TYPE aObjType)
Definition: cobject.cpp:38
void ScaleNextUp()
Function ScaleNextUp scales a bounding box to the next float representation making it larger...
Definition: cbbox.cpp:206
SFVEC3F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox.cpp:135
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
float m_inv_radius
Definition: ccylinder.h:62
SFVEC2F m_center
Definition: ccylinder.h:60
float m_radius_squared
Definition: ccylinder.h:61

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 CVCYLINDER::GetDiffuseColor ( const HITINFO aHitInfo) const
overridevirtual

Implements COBJECT.

Definition at line 185 of file ccylinder.cpp.

References m_diffusecolor.

186 {
187  (void)aHitInfo; // unused
188 
189  return m_diffusecolor;
190 }
SFVEC3F m_diffusecolor
Definition: ccylinder.h:63
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 CVCYLINDER::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 54 of file ccylinder.cpp.

References RAY::at(), delta, COBJECT::m_bbox, m_center, RAY::m_Dir, HITINFO::m_HitNormal, HITINFO::m_HitPoint, m_inv_radius, COBJECT::m_material, RAY::m_Origin, m_radius_squared, HITINFO::m_tHit, CBBOX::Max(), CBBOX::Min(), CMATERIAL::PerturbeNormal(), and HITINFO::pHitObject.

55 {
56  // Based on:
57  // http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
58  // Ray-sphere intersection: geometric
59  // /////////////////////////////////////////////////////////////////////////
60  const double OCx_Start = aRay.m_Origin.x - m_center.x;
61  const double OCy_Start = aRay.m_Origin.y - m_center.y;
62 
63  const double p_dot_p = OCx_Start * OCx_Start + OCy_Start * OCy_Start;
64 
65  const double a = (double)aRay.m_Dir.x * (double)aRay.m_Dir.x +
66  (double)aRay.m_Dir.y * (double)aRay.m_Dir.y;
67  const double b = (double)aRay.m_Dir.x * (double)OCx_Start +
68  (double)aRay.m_Dir.y * (double)OCy_Start;
69  const double c = p_dot_p - m_radius_squared;
70 
71  const float delta = (float)(b * b - a * c);
72 
73  bool hitResult = false;
74 
75  if( delta > FLT_EPSILON )
76  {
77  const float inv_a = 1.0 / a;
78 
79  const float sdelta = sqrtf( delta );
80  const float t = (-b - sdelta) * inv_a;
81  const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
82 
83  if( (z >= m_bbox.Min().z) &&
84  (z <= m_bbox.Max().z) )
85  {
86  if( t < aHitInfo.m_tHit )
87  {
88  hitResult = true;
89  aHitInfo.m_tHit = t;
90  }
91  }
92 
93  if( !hitResult )
94  {
95  const float t1 = (-b + sdelta) * inv_a;
96  const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z;
97 
98  if( (z1 > m_bbox.Min().z ) &&
99  (z1 < m_bbox.Max().z ) )
100  {
101  if( t1 < aHitInfo.m_tHit )
102  {
103  hitResult = true;
104  aHitInfo.m_tHit = t1;
105  }
106  }
107  }
108  }
109 
110  if( hitResult )
111  {
112  aHitInfo.m_HitPoint = aRay.at( aHitInfo.m_tHit );
113 
114  const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x,
115  aHitInfo.m_HitPoint.y );
116 
117  aHitInfo.m_HitNormal = SFVEC3F( -(hitPoint2D.x - m_center.x) * m_inv_radius,
118  -(hitPoint2D.y - m_center.y) * m_inv_radius,
119  0.0f );
120 
121  m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
122 
123  aHitInfo.pHitObject = this;
124  }
125 
126  return hitResult;
127 }
const SFVEC3F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox.h:205
SFVEC3F at(float t) const
Definition: ray.h:65
CBBOX m_bbox
Definition: cobject.h:53
const CMATERIAL * m_material
Definition: cobject.h:56
float m_tHit
( 4) distance
Definition: hitinfo.h:43
static const int delta[8][2]
Definition: solve.cpp:112
SFVEC3F m_HitPoint
(12) hit position
Definition: hitinfo.h:49
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
void PerturbeNormal(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: cmaterial.cpp:88
const SFVEC3F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox.h:212
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
float m_inv_radius
Definition: ccylinder.h:62
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
SFVEC2F m_center
Definition: ccylinder.h:60
float m_radius_squared
Definition: ccylinder.h:61
bool CVCYLINDER::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 130 of file ccylinder.cpp.

References delta, COBJECT::m_bbox, m_center, RAY::m_Dir, RAY::m_Origin, m_radius_squared, CBBOX::Max(), and CBBOX::Min().

131 {
132  // Based on:
133  // http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
134  // Ray-sphere intersection: geometric
135  // /////////////////////////////////////////////////////////////////////////
136  const double OCx_Start = aRay.m_Origin.x - m_center.x;
137  const double OCy_Start = aRay.m_Origin.y - m_center.y;
138 
139  const double p_dot_p = OCx_Start * OCx_Start + OCy_Start * OCy_Start;
140 
141  const double a = (double)aRay.m_Dir.x * (double)aRay.m_Dir.x +
142  (double)aRay.m_Dir.y * (double)aRay.m_Dir.y;
143  const double b = (double)aRay.m_Dir.x * (double)OCx_Start +
144  (double)aRay.m_Dir.y * (double)OCy_Start;
145  const double c = p_dot_p - m_radius_squared;
146 
147  const float delta = (float)(b * b - a * c);
148 
149  if( delta > FLT_EPSILON )
150  {
151  const float inv_a = 1.0 / a;
152 
153  const float sdelta = sqrtf( delta );
154  const float t = (-b - sdelta) * inv_a;
155  const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
156 
157  if( (z >= m_bbox.Min().z) &&
158  (z <= m_bbox.Max().z) )
159  {
160  if( t < aMaxDistance )
161  return true;
162  }
163 
164  const float t1 = (-b + sdelta) * inv_a;
165  const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z;
166 
167  if( (z1 > m_bbox.Min().z ) &&
168  (z1 < m_bbox.Max().z ) )
169  {
170  if( t1 < aMaxDistance )
171  return true;
172  }
173  }
174 
175  return false;
176 }
const SFVEC3F & Min() const
Function Min return the minimun vertex pointer.
Definition: cbbox.h:205
CBBOX m_bbox
Definition: cobject.h:53
static const int delta[8][2]
Definition: solve.cpp:112
const SFVEC3F & Max() const
Function Max return the maximum vertex pointer.
Definition: cbbox.h:212
SFVEC3F m_Dir
Definition: ray.h:48
SFVEC3F m_Origin
Definition: ray.h:45
SFVEC2F m_center
Definition: ccylinder.h:60
float m_radius_squared
Definition: ccylinder.h:61
bool CVCYLINDER::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 179 of file ccylinder.cpp.

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

180 {
181  // !TODO: improove
182  return m_bbox.Intersects( aBBox );
183 }
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 CVCYLINDER::SetColor ( SFVEC3F  aObjColor)
inline

Definition at line 51 of file ccylinder.h.

References m_diffusecolor.

Referenced by C3D_RENDER_RAYTRACING::reload().

51 { m_diffusecolor = aObjColor; }
SFVEC3F m_diffusecolor
Definition: ccylinder.h:63
void COBJECT::SetMaterial ( const CMATERIAL aMaterial)
inlineinherited

Member Data Documentation

SFVEC2F CVCYLINDER::m_center
private

Definition at line 60 of file ccylinder.h.

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

SFVEC3F CVCYLINDER::m_diffusecolor
private

Definition at line 63 of file ccylinder.h.

Referenced by GetDiffuseColor(), and SetColor().

float CVCYLINDER::m_inv_radius
private

Definition at line 62 of file ccylinder.h.

Referenced by CVCYLINDER(), and Intersect().

OBJECT3D_TYPE COBJECT::m_obj_type
protectedinherited

Definition at line 55 of file cobject.h.

Referenced by COBJECT::COBJECT().

float CVCYLINDER::m_radius_squared
private

Definition at line 61 of file ccylinder.h.

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


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