2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
|
|
|
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file plane_3d.cpp
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "plane_3d.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
XY_PLANE::XY_PLANE( const BBOX_3D& aBBox ) : OBJECT_3D( OBJECT_3D_TYPE::XYPLANE )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
m_centerPoint = aBBox.GetCenter();
|
|
|
|
m_centroid = m_centerPoint;
|
|
|
|
|
|
|
|
m_bbox.Reset();
|
|
|
|
m_bbox.Set( aBBox );
|
|
|
|
m_xsize = aBBox.GetExtent().x;
|
|
|
|
m_ysize = aBBox.GetExtent().y;
|
2021-01-02 21:05:29 +00:00
|
|
|
m_xsize_inv2 = 1.0f / ( 2.0f * m_xsize );
|
|
|
|
m_ysize_inv2 = 1.0f / ( 2.0f * m_ysize );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
XY_PLANE::XY_PLANE( SFVEC3F aCenterPoint, float aXSize, float aYSize )
|
|
|
|
: OBJECT_3D( OBJECT_3D_TYPE::XYPLANE )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
m_centerPoint = aCenterPoint;
|
|
|
|
m_xsize = aXSize;
|
|
|
|
m_ysize = aYSize;
|
2021-01-02 21:05:29 +00:00
|
|
|
m_xsize_inv2 = 1.0f / ( 2.0f * aXSize );
|
|
|
|
m_ysize_inv2 = 1.0f / ( 2.0f * aYSize );
|
|
|
|
m_bbox.Set( SFVEC3F( aCenterPoint.x - aXSize / 2.0f, aCenterPoint.y - aYSize / 2.0f,
|
2016-07-19 17:35:25 +00:00
|
|
|
aCenterPoint.z ),
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F( aCenterPoint.x + aXSize / 2.0f, aCenterPoint.y + aYSize / 2.0f,
|
2016-07-19 17:35:25 +00:00
|
|
|
aCenterPoint.z ) );
|
|
|
|
m_centroid = aCenterPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
bool XY_PLANE::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
const float t = (m_centerPoint.z - aRay.m_Origin.z) * aRay.m_InvDir.z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( t < FLT_EPSILON ) || ( t >= aHitInfo.m_tHit ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
|
|
|
|
|
|
|
|
if( (vSU < -m_xsize) || (vSU > m_xsize) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
aHitInfo.m_tHit = t;
|
2016-10-02 08:11:00 +00:00
|
|
|
aHitInfo.m_HitPoint = aRay.at( t );
|
2016-07-19 17:35:25 +00:00
|
|
|
aHitInfo.pHitObject = this;
|
|
|
|
|
|
|
|
if( aRay.m_dirIsNeg[2] )
|
|
|
|
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, 1.0f );
|
|
|
|
else
|
|
|
|
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f,-1.0f );
|
|
|
|
|
2016-10-02 08:11:00 +00:00
|
|
|
m_material->PerturbeNormal( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
bool XY_PLANE::IntersectP(const RAY& aRay, float aMaxDistance ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
const float t = ( m_centerPoint.z - aRay.m_Origin.z ) * aRay.m_InvDir.z;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( t < FLT_EPSILON ) || ( t >= aMaxDistance ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const float vSU = t * aRay.m_Dir.x + aRay.m_Origin.x - m_centerPoint.x;
|
|
|
|
|
|
|
|
if( (vSU < -m_xsize) || (vSU > m_xsize) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const float vSV = t * aRay.m_Dir.y + aRay.m_Origin.y - m_centerPoint.y;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( vSV < -m_ysize ) || ( vSV > m_ysize ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
bool XY_PLANE::Intersects( const BBOX_3D& aBBox ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
return m_bbox.Intersects( aBBox );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
SFVEC3F XY_PLANE::GetDiffuseColor( const HITINFO& aHitInfo ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
(void)aHitInfo; // unused
|
|
|
|
|
|
|
|
return m_diffusecolor;
|
|
|
|
}
|