KiCad PCB EDA Suite
Loading...
Searching...
No Matches
plane_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 (C) 1992-2020 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#include "plane_3d.h"
30
31
33{
34 m_centerPoint = aBBox.GetCenter();
36
37 m_bbox.Reset();
38 m_bbox.Set( aBBox );
39 m_xsize = aBBox.GetExtent().x;
40 m_ysize = aBBox.GetExtent().y;
41 m_xsize_inv2 = 1.0f / ( 2.0f * m_xsize );
42 m_ysize_inv2 = 1.0f / ( 2.0f * m_ysize );
43}
44
45
46XY_PLANE::XY_PLANE( SFVEC3F aCenterPoint, float aXSize, float aYSize )
48{
49 m_centerPoint = aCenterPoint;
50 m_xsize = aXSize;
51 m_ysize = aYSize;
52 m_xsize_inv2 = 1.0f / ( 2.0f * aXSize );
53 m_ysize_inv2 = 1.0f / ( 2.0f * aYSize );
54 m_bbox.Set( SFVEC3F( aCenterPoint.x - aXSize / 2.0f, aCenterPoint.y - aYSize / 2.0f,
55 aCenterPoint.z ),
56 SFVEC3F( aCenterPoint.x + aXSize / 2.0f, aCenterPoint.y + aYSize / 2.0f,
57 aCenterPoint.z ) );
58 m_centroid = aCenterPoint;
59}
60
61
62bool XY_PLANE::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
63{
64 const float t = ( m_centerPoint.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
65
66 if( ( t < FLT_EPSILON ) || ( t >= aHitInfo.m_tHit ) )
67 return false;
68
69 const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
70
71 if( (vSU < -m_xsize) || (vSU > m_xsize) )
72 return false;
73
74 const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
75
76 if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
77 return false;
78
79 aHitInfo.m_tHit = t;
80 aHitInfo.m_HitPoint = aRay.at( t );
81 aHitInfo.pHitObject = this;
82
83 if( aRay.m_dirIsNeg[2] )
84 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
85 else
86 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f,-1.0f );
87
88 m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
89
90 return true;
91}
92
93
94bool XY_PLANE::IntersectP(const RAY& aRay, float aMaxDistance ) const
95{
96 const float t = ( m_centerPoint.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
97
98 if( ( t < FLT_EPSILON ) || ( t >= aMaxDistance ) )
99 return false;
100
101 const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
102
103 if( ( vSU < -m_xsize ) || ( vSU > m_xsize ) )
104 return false;
105
106 const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
107
108 if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
109 return false;
110
111 return true;
112}
113
114
115bool XY_PLANE::Intersects( const BBOX_3D& aBBox ) const
116{
117 return m_bbox.Intersects( aBBox );
118}
119
120
121SFVEC3F XY_PLANE::GetDiffuseColor( const HITINFO& /* aHitInfo */ ) const
122{
123 return m_diffusecolor;
124}
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: material.cpp:89
BBOX_3D m_bbox
Definition: object_3d.h:97
SFVEC3F m_centroid
Definition: object_3d.h:98
const MATERIAL * m_material
Definition: object_3d.h:100
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
Definition: plane_3d.cpp:62
SFVEC3F m_centerPoint
Definition: plane_3d.h:57
SFVEC3F m_diffusecolor
Definition: plane_3d.h:62
float m_xsize
Definition: plane_3d.h:58
bool Intersects(const BBOX_3D &aBBox) const override
Definition: plane_3d.cpp:115
float m_ysize_inv2
Definition: plane_3d.h:61
XY_PLANE(const BBOX_3D &aBBox)
Definition: plane_3d.cpp:32
SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const override
Definition: plane_3d.cpp:121
float m_ysize
Definition: plane_3d.h:59
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
Definition: plane_3d.cpp:94
float m_xsize_inv2
Definition: plane_3d.h:60
OBJECT_3D_TYPE
Definition: object_3d.h:39
Manage a bounding box defined by two SFVEC3F min max points.
Definition: bbox_3d.h:42
const SFVEC3F GetExtent() const
Definition: bbox_3d.cpp:145
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition: bbox_3d.cpp:132
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_3d.cpp:68
void Reset()
Reset the bounding box to zero and de-initialize it.
Definition: bbox_3d.cpp:95
bool Intersects(const BBOX_3D &aBBox) const
Test if a bounding box intersects this box.
Definition: bbox_3d.cpp:218
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
SFVEC3F m_Dir
Definition: ray.h:67
unsigned int m_dirIsNeg[3]
Definition: ray.h:75
SFVEC3F m_InvDir
Definition: ray.h:70
SFVEC3F m_Origin
Definition: ray.h:64
SFVEC3F at(float t) const
Definition: ray.h:84
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44