KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dummy_block_3d.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 <[email protected]>
5 * Copyright The 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
29
30#include "dummy_block_3d.h"
31
32
34{
35 m_centroid = aBBox.GetCenter();
36 m_bbox.Reset();
37 m_bbox.Set( aBBox );
38}
39
40
41bool DUMMY_BLOCK::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 // Determine which face was hit by checking which box face
54 // the hit point is closest to
55 const SFVEC3F hitPt = aHitInfo.m_HitPoint;
56 const float eps = 0.0001f;
57
58 if( std::abs( hitPt.x - m_bbox.Min().x ) < eps )
59 aHitInfo.m_HitNormal = SFVEC3F( -1.0f, 0.0f, 0.0f );
60 else if( std::abs( hitPt.x - m_bbox.Max().x ) < eps )
61 aHitInfo.m_HitNormal = SFVEC3F( 1.0f, 0.0f, 0.0f );
62 else if( std::abs( hitPt.y - m_bbox.Min().y ) < eps )
63 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, -1.0f, 0.0f );
64 else if( std::abs( hitPt.y - m_bbox.Max().y ) < eps )
65 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 1.0f, 0.0f );
66 else if( aRay.m_dirIsNeg[2] )
67 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
68 else
69 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, -1.0f );
70
71 m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
72
73 aHitInfo.pHitObject = this;
74
75 return true;
76 }
77
78 return false;
79}
80
81
82bool DUMMY_BLOCK::IntersectP(const RAY& aRay, float aMaxDistance ) const
83{
84 float t;
85
86 if( !m_bbox.Intersect( aRay, &t ) )
87 return false;
88
89 if( t < aMaxDistance )
90 return true;
91
92 return false;
93}
94
95
96bool DUMMY_BLOCK::Intersects( const BBOX_3D& aBBox ) const
97{
98 return m_bbox.Intersects( aBBox );
99}
100
101
102SFVEC3F DUMMY_BLOCK::GetDiffuseColor( const HITINFO& /* aHitInfo */ ) const
103{
104 return m_diffusecolor;
105}
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
SFVEC3F m_diffusecolor
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
bool Intersects(const BBOX_3D &aBBox) const override
SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const override
DUMMY_BLOCK(const BBOX_3D &aBBox)
BBOX_3D m_bbox
Definition object_3d.h:97
SFVEC3F m_centroid
Definition object_3d.h:98
OBJECT_3D(OBJECT_3D_TYPE aObjType)
Definition object_3d.cpp:40
const MATERIAL * m_material
Definition object_3d.h:100
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:400
OBJECT_3D_TYPE
Definition object_3d.h:39
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:43
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition bbox_3d.cpp:132
Stores the hit information of a ray with a point on the surface of a object.
Definition hitinfo.h:36
float m_tHit
( 4) distance
Definition hitinfo.h:38
const OBJECT_3D * pHitObject
( 4) Object that was hitted
Definition hitinfo.h:40
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition hitinfo.h:37
SFVEC3F m_HitPoint
(12) hit position
Definition hitinfo.h:44
Definition ray.h:63
unsigned int m_dirIsNeg[3]
Definition ray.h:75
SFVEC3F at(float t) const
Definition ray.h:84
glm::vec3 SFVEC3F
Definition xv3d_types.h:44