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 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
24
25#include "plane_3d.h"
26
27
29{
30 m_centerPoint = aBBox.GetCenter();
32
33 m_bbox.Reset();
34 m_bbox.Set( aBBox );
35 m_xsize = aBBox.GetExtent().x;
36 m_ysize = aBBox.GetExtent().y;
37 m_xsize_inv2 = 1.0f / ( 2.0f * m_xsize );
38 m_ysize_inv2 = 1.0f / ( 2.0f * m_ysize );
39}
40
41
42XY_PLANE::XY_PLANE( SFVEC3F aCenterPoint, float aXSize, float aYSize )
44{
45 m_centerPoint = aCenterPoint;
46 m_xsize = aXSize;
47 m_ysize = aYSize;
48 m_xsize_inv2 = 1.0f / ( 2.0f * aXSize );
49 m_ysize_inv2 = 1.0f / ( 2.0f * aYSize );
50 m_bbox.Set( SFVEC3F( aCenterPoint.x - aXSize / 2.0f, aCenterPoint.y - aYSize / 2.0f,
51 aCenterPoint.z ),
52 SFVEC3F( aCenterPoint.x + aXSize / 2.0f, aCenterPoint.y + aYSize / 2.0f,
53 aCenterPoint.z ) );
54 m_centroid = aCenterPoint;
55}
56
57
58bool XY_PLANE::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
59{
60 const float t = ( m_centerPoint.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
61
62 if( ( t < FLT_EPSILON ) || ( t >= aHitInfo.m_tHit ) )
63 return false;
64
65 const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
66
67 if( (vSU < -m_xsize) || (vSU > m_xsize) )
68 return false;
69
70 const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
71
72 if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
73 return false;
74
75 aHitInfo.m_tHit = t;
76 aHitInfo.m_HitPoint = aRay.at( t );
77 aHitInfo.pHitObject = this;
78
79 if( aRay.m_dirIsNeg[2] )
80 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
81 else
82 aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f,-1.0f );
83
84 m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
85
86 return true;
87}
88
89
90bool XY_PLANE::IntersectP(const RAY& aRay, float aMaxDistance ) const
91{
92 const float t = ( m_centerPoint.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
93
94 if( ( t < FLT_EPSILON ) || ( t >= aMaxDistance ) )
95 return false;
96
97 const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
98
99 if( ( vSU < -m_xsize ) || ( vSU > m_xsize ) )
100 return false;
101
102 const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
103
104 if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
105 return false;
106
107 return true;
108}
109
110
111bool XY_PLANE::Intersects( const BBOX_3D& aBBox ) const
112{
113 return m_bbox.Intersects( aBBox );
114}
115
116
117SFVEC3F XY_PLANE::GetDiffuseColor( const HITINFO& /* aHitInfo */ ) const
118{
119 return m_diffusecolor;
120}
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
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
Definition plane_3d.cpp:58
SFVEC3F m_centerPoint
Definition plane_3d.h:53
SFVEC3F m_diffusecolor
Definition plane_3d.h:58
float m_xsize
Definition plane_3d.h:54
bool Intersects(const BBOX_3D &aBBox) const override
Definition plane_3d.cpp:111
float m_ysize_inv2
Definition plane_3d.h:57
XY_PLANE(const BBOX_3D &aBBox)
Definition plane_3d.cpp:28
SFVEC3F GetDiffuseColor(const HITINFO &aHitInfo) const override
Definition plane_3d.cpp:117
float m_ysize
Definition plane_3d.h:55
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
Definition plane_3d.cpp:90
float m_xsize_inv2
Definition plane_3d.h:56
OBJECT_3D_TYPE
Definition object_3d.h:35
Manage a bounding box defined by two SFVEC3F min max points.
Definition bbox_3d.h:39
const SFVEC3F GetExtent() const
Definition bbox_3d.cpp:141
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
SFVEC3F m_Dir
Definition ray.h:63
unsigned int m_dirIsNeg[3]
Definition ray.h:71
SFVEC3F m_InvDir
Definition ray.h:66
SFVEC3F m_Origin
Definition ray.h:60
SFVEC3F at(float t) const
Definition ray.h:80
glm::vec3 SFVEC3F
Definition xv3d_types.h:40