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, see <https://www.gnu.org/licenses/>.
19 */
20
25
26#include "dummy_block_3d.h"
27
28
30{
31 m_centroid = aBBox.GetCenter();
32 m_bbox.Reset();
33 m_bbox.Set( aBBox );
34}
35
36
37bool DUMMY_BLOCK::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
38{
39 float t;
40
41 if( !m_bbox.Intersect( aRay, &t ) )
42 return false;
43
44 if( t < aHitInfo.m_tHit )
45 {
46 aHitInfo.m_tHit = t;
47 aHitInfo.m_HitPoint = aRay.at( t );
48
49 if( aRay.m_dirIsNeg[2] )
50 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
51 else
52 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, -1.0f );
53
54 m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
55
56 aHitInfo.pHitObject = this;
57
58 return true;
59 }
60
61 return false;
62}
63
64
65bool DUMMY_BLOCK::IntersectP(const RAY& aRay, float aMaxDistance ) const
66{
67 float t;
68
69 if( !m_bbox.Intersect( aRay, &t ) )
70 return false;
71
72 if( t < aMaxDistance )
73 return true;
74
75 return false;
76}
77
78
79bool DUMMY_BLOCK::Intersects( const BBOX_3D& aBBox ) const
80{
81 return m_bbox.Intersects( aBBox );
82}
83
84
85SFVEC3F DUMMY_BLOCK::GetDiffuseColor( const HITINFO& /* aHitInfo */ ) const
86{
87 return m_diffusecolor;
88}
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:93
SFVEC3F m_centroid
Definition object_3d.h:94
OBJECT_3D(OBJECT_3D_TYPE aObjType)
Definition object_3d.cpp:36
const MATERIAL * m_material
Definition object_3d.h:96
OBJECT_3D_TYPE
Definition object_3d.h:35
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:39
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition bbox_3d.cpp:128
Stores the hit information of a ray with a point on the surface of a object.
Definition hitinfo.h:32
float m_tHit
( 4) distance
Definition hitinfo.h:34
const OBJECT_3D * pHitObject
( 4) Object that was hitted
Definition hitinfo.h:36
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition hitinfo.h:33
SFVEC3F m_HitPoint
(12) hit position
Definition hitinfo.h:40
Definition ray.h:59
unsigned int m_dirIsNeg[3]
Definition ray.h:71
SFVEC3F at(float t) const
Definition ray.h:80
glm::vec3 SFVEC3F
Definition xv3d_types.h:40