KiCad PCB EDA Suite
cdummyblock.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include "cdummyblock.h"
31 
32 
34 {
35  m_centroid = aBBox.GetCenter();
36  m_bbox.Reset();
37  m_bbox.Set( aBBox );
38 }
39 
40 
41 bool CDUMMYBLOCK::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
42 {
43  float t;
44 
45  if( !m_bbox.Intersect( aRay, &t ) )
46  return false;
47 
48  if( t < aHitInfo.m_tHit )
49  {
50  aHitInfo.m_tHit = t;
51  aHitInfo.m_HitPoint = aRay.at( t );
52 
53  if( aRay.m_dirIsNeg[2] )
54  aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
55  else
56  aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f,-1.0f );
57 
58  m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
59 
60  aHitInfo.pHitObject = this;
61 
62  return true;
63  }
64 
65  return false;
66 }
67 
68 
69 bool CDUMMYBLOCK::IntersectP(const RAY &aRay , float aMaxDistance ) const
70 {
71  float t;
72 
73  if( !m_bbox.Intersect( aRay, &t ) )
74  return false;
75 
76  if( t < aMaxDistance )
77  return true;
78 
79  return false;
80 }
81 
82 
83 bool CDUMMYBLOCK::Intersects( const CBBOX &aBBox ) const
84 {
85  return m_bbox.Intersects( aBBox );
86 }
87 
88 
90 {
91  (void)aHitInfo; // unused
92 
93  return m_diffusecolor;
94 }
SFVEC3F m_centroid
Definition: cobject.h:54
SFVEC3F at(float t) const
Definition: ray.h:65
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
const CMATERIAL * m_material
Definition: cobject.h:56
Definition: ray.h:43
float m_tHit
( 4) distance
Definition: hitinfo.h:43
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Function Set Set bounding box with new parameters.
Definition: cbbox.cpp:67
SFVEC3F m_HitPoint
(12) hit position
Definition: hitinfo.h:49
void PerturbeNormal(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: cmaterial.cpp:88
bool Intersects(const CBBOX &aBBox) const override
Function Intersects.
Definition: cdummyblock.cpp:83
unsigned int m_dirIsNeg[3]
Definition: ray.h:56
bool Intersect(const RAY &aRay, float *t) const
Function Intersect.
Definition: cbbox_ray.cpp:46
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
Functions Intersect.
Definition: cdummyblock.cpp:41
const COBJECT * pHitObject
( 4) Object that was hitted
Definition: hitinfo.h:45
SFVEC3F m_diffusecolor
Definition: cdummyblock.h:53
SFVEC3F GetCenter() const
Function GetCenter return the center point of the bounding box.
Definition: cbbox.cpp:135
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42
SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const override
Definition: cdummyblock.cpp:89
CDUMMYBLOCK(const CBBOX &aBBox)
Definition: cdummyblock.cpp:33
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
Functions Intersect for shadow test.
Definition: cdummyblock.cpp:69
Class CBBOX manages a bounding box defined by two SFVEC3F min max points.
Definition: cbbox.h:40
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox.cpp:98