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::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.

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

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

Member Function Documentation

◆ GetBBox()

const CBBOX& COBJECT::GetBBox ( ) const
inlineinherited

Definition at line 94 of file cobject.h.

94 { return m_bbox; }
CBBOX m_bbox
Definition: cobject.h:53

References COBJECT::m_bbox.

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

◆ GetCentroid()

const SFVEC3F& COBJECT::GetCentroid ( ) const
inlineinherited

Definition at line 96 of file cobject.h.

96 { return m_centroid; }
SFVEC3F m_centroid
Definition: cobject.h:54

References COBJECT::m_centroid.

◆ GetDiffuseColor()

SFVEC3F CVCYLINDER::GetDiffuseColor ( const HITINFO aHitInfo) const
overridevirtual

Implements COBJECT.

Definition at line 183 of file ccylinder.cpp.

184 {
185  (void)aHitInfo; // unused
186 
187  return m_diffusecolor;
188 }
SFVEC3F m_diffusecolor
Definition: ccylinder.h:63

References m_diffusecolor.

◆ GetMaterial()

const CMATERIAL* COBJECT::GetMaterial ( ) const
inlineinherited

Definition at line 63 of file cobject.h.

63 { return m_material; }
const CMATERIAL * m_material
Definition: cobject.h:56

References COBJECT::m_material.

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

◆ Intersect()

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 52 of file ccylinder.cpp.

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

References RAY::at(), 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.

◆ IntersectP()

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 128 of file ccylinder.cpp.

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

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

◆ Intersects()

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 177 of file ccylinder.cpp.

178 {
179  // !TODO: improove
180  return m_bbox.Intersects( aBBox );
181 }
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

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

◆ SetColor()

void CVCYLINDER::SetColor ( SFVEC3F  aObjColor)
inline

Definition at line 51 of file ccylinder.h.

51 { m_diffusecolor = aObjColor; }
SFVEC3F m_diffusecolor
Definition: ccylinder.h:63

References m_diffusecolor.

Referenced by C3D_RENDER_RAYTRACING::reload().

◆ SetMaterial()

void COBJECT::SetMaterial ( const CMATERIAL aMaterial)
inlineinherited

Member Data Documentation

◆ m_bbox

◆ m_center

SFVEC2F CVCYLINDER::m_center
private

Definition at line 60 of file ccylinder.h.

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

◆ m_centroid

◆ m_diffusecolor

SFVEC3F CVCYLINDER::m_diffusecolor
private

Definition at line 63 of file ccylinder.h.

Referenced by GetDiffuseColor(), and SetColor().

◆ m_inv_radius

float CVCYLINDER::m_inv_radius
private

Definition at line 62 of file ccylinder.h.

Referenced by CVCYLINDER(), and Intersect().

◆ m_material

◆ m_obj_type

OBJECT3D_TYPE COBJECT::m_obj_type
protectedinherited

Definition at line 55 of file cobject.h.

Referenced by COBJECT::COBJECT().

◆ m_radius_squared

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: