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>
|
2020-12-11 13:51:42 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* 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 round_segment_3d.cpp
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "round_segment_3d.h"
|
2021-01-05 22:19:00 +00:00
|
|
|
#include "../shapes2D/round_segment_2d.h"
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
ROUND_SEGMENT::ROUND_SEGMENT( const ROUND_SEGMENT_2D& aSeg2D, float aZmin, float aZmax ) :
|
|
|
|
OBJECT_3D( OBJECT_3D_TYPE::ROUNDSEG ),
|
|
|
|
m_segment( aSeg2D.m_segment )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
m_radius = aSeg2D.GetRadius();
|
|
|
|
m_radius_squared = m_radius * m_radius;
|
|
|
|
m_inv_radius = 1.0f / m_radius;
|
|
|
|
|
|
|
|
m_plane_dir_left = SFVEC3F( -m_segment.m_Dir.y, m_segment.m_Dir.x, 0.0f );
|
|
|
|
m_plane_dir_right = SFVEC3F( m_segment.m_Dir.y, -m_segment.m_Dir.x, 0.0f );
|
|
|
|
|
|
|
|
m_bbox.Reset();
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_bbox.Set( SFVEC3F( m_segment.m_Start.x, m_segment.m_Start.y, aZmin ),
|
|
|
|
SFVEC3F( m_segment.m_End.x, m_segment.m_End.y, aZmax ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
m_bbox.Set( m_bbox.Min() - SFVEC3F( m_radius, m_radius, 0.0f ),
|
|
|
|
m_bbox.Max() + SFVEC3F( m_radius, m_radius, 0.0f ) );
|
|
|
|
|
|
|
|
m_bbox.ScaleNextUp();
|
|
|
|
m_centroid = m_bbox.GetCenter();
|
|
|
|
|
|
|
|
m_center_left = m_centroid + m_plane_dir_left * m_radius;
|
|
|
|
m_center_right = m_centroid + m_plane_dir_right * m_radius;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
m_seglen_over_two_squared = ( m_segment.m_Length / 2.0f ) * ( m_segment.m_Length / 2.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
bool ROUND_SEGMENT::Intersect( const RAY& aRay, HITINFO& aHitInfo ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-11 13:51:42 +00:00
|
|
|
// Top / Bottom plane
|
2016-07-19 17:35:25 +00:00
|
|
|
float zPlanePos = aRay.m_dirIsNeg[2]? m_bbox.Max().z : m_bbox.Min().z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
float tPlane = ( zPlanePos - aRay.m_Origin.z ) * aRay.m_InvDir.z;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( ( tPlane >= aHitInfo.m_tHit ) || ( tPlane < FLT_EPSILON ) )
|
|
|
|
return false; // Early exit
|
|
|
|
|
|
|
|
SFVEC2F planeHitPoint2d( aRay.m_Origin.x + aRay.m_Dir.x * tPlane,
|
|
|
|
aRay.m_Origin.y + aRay.m_Dir.y * tPlane );
|
|
|
|
|
|
|
|
float dSquared = m_segment.DistanceToPointSquared( planeHitPoint2d );
|
|
|
|
|
|
|
|
if( dSquared <= m_radius_squared )
|
|
|
|
{
|
|
|
|
if( tPlane < aHitInfo.m_tHit )
|
|
|
|
{
|
|
|
|
aHitInfo.m_tHit = tPlane;
|
2021-01-02 21:05:29 +00:00
|
|
|
aHitInfo.m_HitPoint = SFVEC3F( planeHitPoint2d.x, planeHitPoint2d.y,
|
2016-10-02 08:11:00 +00:00
|
|
|
aRay.m_Origin.z + aRay.m_Dir.z * tPlane );
|
2021-01-02 21:05:29 +00:00
|
|
|
aHitInfo.m_HitNormal = SFVEC3F( 0.0f, 0.0f, aRay.m_dirIsNeg[2] ? 1.0f : -1.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
aHitInfo.pHitObject = this;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test LEFT / RIGHT plane
|
|
|
|
float normal_dot_ray = glm::dot( m_plane_dir_right, aRay.m_Dir );
|
|
|
|
|
|
|
|
if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane
|
|
|
|
{
|
|
|
|
const float n_dot_ray_origin = glm::dot( m_plane_dir_right,
|
|
|
|
m_center_right - aRay.m_Origin );
|
|
|
|
const float t = n_dot_ray_origin / normal_dot_ray;
|
|
|
|
|
|
|
|
if( t > 0.0f )
|
|
|
|
{
|
|
|
|
const SFVEC3F hitP = aRay.at( t );
|
|
|
|
|
|
|
|
const SFVEC3F v = hitP - m_center_right;
|
|
|
|
const float len = glm::dot( v, v );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( len <= m_seglen_over_two_squared ) && ( hitP.z >= m_bbox.Min().z )
|
|
|
|
&& ( hitP.z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aHitInfo.m_tHit )
|
|
|
|
{
|
|
|
|
aHitInfo.m_tHit = t;
|
2016-10-02 08:11:00 +00:00
|
|
|
aHitInfo.m_HitPoint = hitP;
|
2021-01-02 21:05:29 +00:00
|
|
|
aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_right.x, m_plane_dir_right.y,
|
2016-07-19 17:35:25 +00:00
|
|
|
0.0f );
|
|
|
|
aHitInfo.pHitObject = this;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
normal_dot_ray = glm::dot( m_plane_dir_left, aRay.m_Dir );
|
|
|
|
|
|
|
|
if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane
|
|
|
|
{
|
|
|
|
const float n_dot_ray_origin = glm::dot( m_plane_dir_left,
|
2021-01-02 21:05:29 +00:00
|
|
|
m_center_left - aRay.m_Origin );
|
2016-07-19 17:35:25 +00:00
|
|
|
const float t = n_dot_ray_origin / normal_dot_ray;
|
|
|
|
|
|
|
|
if( t > 0.0f )
|
|
|
|
{
|
|
|
|
const SFVEC3F hitP = aRay.at( t );
|
|
|
|
|
|
|
|
const SFVEC3F v = hitP - m_center_left;
|
|
|
|
const float len = glm::dot( v, v );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( len <= m_seglen_over_two_squared ) && ( hitP.z >= m_bbox.Min().z )
|
|
|
|
&& ( hitP.z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aHitInfo.m_tHit )
|
|
|
|
{
|
|
|
|
aHitInfo.m_tHit = t;
|
2016-10-02 08:11:00 +00:00
|
|
|
aHitInfo.m_HitPoint = hitP;
|
2021-01-02 21:05:29 +00:00
|
|
|
aHitInfo.m_HitNormal = SFVEC3F( m_plane_dir_left.x, m_plane_dir_left.y,
|
2016-07-19 17:35:25 +00:00
|
|
|
0.0f );
|
|
|
|
aHitInfo.pHitObject = this;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
// Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
|
2016-07-19 17:35:25 +00:00
|
|
|
// Ray-sphere intersection: geometric
|
|
|
|
const double OCx_Start = aRay.m_Origin.x - m_segment.m_Start.x;
|
|
|
|
const double OCy_Start = aRay.m_Origin.y - m_segment.m_Start.y;
|
|
|
|
|
|
|
|
const double p_dot_p_Start = OCx_Start * OCx_Start + OCy_Start * OCy_Start;
|
|
|
|
|
|
|
|
const double a = (double)aRay.m_Dir.x * (double)aRay.m_Dir.x +
|
|
|
|
(double)aRay.m_Dir.y * (double)aRay.m_Dir.y;
|
|
|
|
|
|
|
|
const double b_Start = (double)aRay.m_Dir.x * (double)OCx_Start +
|
|
|
|
(double)aRay.m_Dir.y * (double)OCy_Start;
|
|
|
|
|
|
|
|
const double c_Start = p_dot_p_Start - m_radius_squared;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float delta_Start = (float) ( b_Start * b_Start - a * c_Start );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( delta_Start > FLT_EPSILON )
|
|
|
|
{
|
|
|
|
const float sdelta = sqrtf( delta_Start );
|
2021-01-02 21:05:29 +00:00
|
|
|
const float t = ( -b_Start - sdelta ) / a;
|
2016-07-19 17:35:25 +00:00
|
|
|
const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aHitInfo.m_tHit )
|
|
|
|
{
|
|
|
|
aHitInfo.m_tHit = t;
|
2016-10-02 08:11:00 +00:00
|
|
|
aHitInfo.m_HitPoint = aRay.at( t );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x, aHitInfo.m_HitPoint.y );
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
aHitInfo.m_HitNormal =
|
|
|
|
SFVEC3F( ( hitPoint2D.x - m_segment.m_Start.x ) * m_inv_radius,
|
|
|
|
( hitPoint2D.y - m_segment.m_Start.y ) * m_inv_radius, 0.0f );
|
2016-10-02 08:11:00 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
aHitInfo.pHitObject = this;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const double OCx_End = aRay.m_Origin.x - m_segment.m_End.x;
|
|
|
|
const double OCy_End = aRay.m_Origin.y - m_segment.m_End.y;
|
|
|
|
|
|
|
|
const double p_dot_p_End = OCx_End * OCx_End + OCy_End * OCy_End;
|
|
|
|
|
|
|
|
const double b_End = (double)aRay.m_Dir.x * (double)OCx_End +
|
|
|
|
(double)aRay.m_Dir.y * (double)OCy_End;
|
|
|
|
|
|
|
|
const double c_End = p_dot_p_End - m_radius_squared;
|
|
|
|
|
|
|
|
const float delta_End = (float)(b_End * b_End - a * c_End);
|
|
|
|
|
|
|
|
if( delta_End > FLT_EPSILON )
|
|
|
|
{
|
|
|
|
const float sdelta = sqrtf( delta_End );
|
2021-01-05 22:19:00 +00:00
|
|
|
const float t = ( -b_End - sdelta ) / a;
|
2016-07-19 17:35:25 +00:00
|
|
|
const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aHitInfo.m_tHit )
|
|
|
|
{
|
|
|
|
aHitInfo.m_tHit = t;
|
2016-10-02 08:11:00 +00:00
|
|
|
aHitInfo.m_HitPoint = aRay.at( t );
|
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x, aHitInfo.m_HitPoint.y );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
aHitInfo.m_HitNormal =
|
|
|
|
SFVEC3F( ( hitPoint2D.x - m_segment.m_End.x ) * m_inv_radius,
|
|
|
|
( hitPoint2D.y - m_segment.m_End.y ) * m_inv_radius, 0.0f );
|
2016-07-19 17:35:25 +00:00
|
|
|
aHitInfo.pHitObject = this;
|
|
|
|
|
2021-01-07 19:33:43 +00:00
|
|
|
m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
|
2016-09-30 23:59:51 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
bool ROUND_SEGMENT::IntersectP( const RAY& aRay, float aMaxDistance ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-11 13:51:42 +00:00
|
|
|
// Top / Bottom plane
|
2016-07-19 17:35:25 +00:00
|
|
|
const float zPlanePos = aRay.m_dirIsNeg[2]? m_bbox.Max().z : m_bbox.Min().z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const float tPlane = ( zPlanePos - aRay.m_Origin.z ) * aRay.m_InvDir.z;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
if( ( tPlane >= aMaxDistance) || ( tPlane < FLT_EPSILON ) )
|
|
|
|
return false; // Early exit
|
|
|
|
|
|
|
|
const SFVEC2F planeHitPoint2d( aRay.m_Origin.x + aRay.m_Dir.x * tPlane,
|
|
|
|
aRay.m_Origin.y + aRay.m_Dir.y * tPlane );
|
|
|
|
|
|
|
|
const float dSquared = m_segment.DistanceToPointSquared( planeHitPoint2d );
|
|
|
|
|
|
|
|
if( dSquared <= m_radius_squared )
|
|
|
|
{
|
|
|
|
if( tPlane < aMaxDistance )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since the IntersectP is used for shadows, we are simplifying the test
|
|
|
|
// intersection and only consider the top/bottom plane of the segment
|
|
|
|
return false;
|
2021-01-07 19:33:43 +00:00
|
|
|
|
|
|
|
/// @todo Either fix the code below or get rid of it.
|
2016-07-19 17:35:25 +00:00
|
|
|
#if 0
|
|
|
|
// Test LEFT / RIGHT plane
|
|
|
|
float normal_dot_ray = glm::dot( m_plane_dir_right, aRay.m_Dir );
|
|
|
|
|
|
|
|
if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
float n_dot_ray_origin = glm::dot( m_plane_dir_right, m_center_right - aRay.m_Origin );
|
2016-07-19 17:35:25 +00:00
|
|
|
float t = n_dot_ray_origin / normal_dot_ray;
|
|
|
|
|
|
|
|
if( t > 0.0f )
|
|
|
|
{
|
|
|
|
SFVEC3F hitP = aRay.at( t );
|
|
|
|
|
|
|
|
SFVEC3F v = hitP - m_center_right;
|
|
|
|
float len = glm::dot( v, v );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( len <= m_seglen_over_two_squared ) &&
|
|
|
|
( hitP.z >= m_bbox.Min().z ) && ( hitP.z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aMaxDistance )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
normal_dot_ray = glm::dot( m_plane_dir_left, aRay.m_Dir );
|
|
|
|
|
|
|
|
if( normal_dot_ray < 0.0f ) // If the dot is neg, the it hits the plane
|
|
|
|
{
|
|
|
|
const float n_dot_ray_origin = glm::dot( m_plane_dir_left,
|
2021-01-02 21:05:29 +00:00
|
|
|
m_center_left - aRay.m_Origin );
|
2016-07-19 17:35:25 +00:00
|
|
|
const float t = n_dot_ray_origin / normal_dot_ray;
|
|
|
|
|
|
|
|
if( t > 0.0f )
|
|
|
|
{
|
|
|
|
SFVEC3F hitP = aRay.at( t );
|
|
|
|
|
|
|
|
SFVEC3F v = hitP - m_center_left;
|
|
|
|
float len = glm::dot( v, v );
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( len <= m_seglen_over_two_squared ) &&
|
|
|
|
( hitP.z >= m_bbox.Min().z ) && ( hitP.z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aMaxDistance )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
// Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
|
2016-07-19 17:35:25 +00:00
|
|
|
// Ray-sphere intersection: geometric
|
|
|
|
|
|
|
|
double OCx_Start = aRay.m_Origin.x - m_segment.m_Start.x;
|
|
|
|
double OCy_Start = aRay.m_Origin.y - m_segment.m_Start.y;
|
|
|
|
|
|
|
|
double p_dot_p_Start = OCx_Start * OCx_Start + OCy_Start * OCy_Start;
|
|
|
|
|
|
|
|
double a = (double)aRay.m_Dir.x * (double)aRay.m_Dir.x +
|
|
|
|
(double)aRay.m_Dir.y * (double)aRay.m_Dir.y;
|
|
|
|
|
|
|
|
double b_Start = (double)aRay.m_Dir.x * (double)OCx_Start +
|
|
|
|
(double)aRay.m_Dir.y * (double)OCy_Start;
|
|
|
|
|
|
|
|
double c_Start = p_dot_p_Start - m_radius_squared;
|
|
|
|
|
|
|
|
float delta_Start = (float)(b_Start * b_Start - a * c_Start);
|
|
|
|
|
|
|
|
if( delta_Start > FLT_EPSILON )
|
|
|
|
{
|
|
|
|
float sdelta = sqrtf( delta_Start );
|
|
|
|
float t = (-b_Start - sdelta) / a;
|
|
|
|
float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aMaxDistance )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double OCx_End = aRay.m_Origin.x - m_segment.m_End.x;
|
|
|
|
double OCy_End = aRay.m_Origin.y - m_segment.m_End.y;
|
|
|
|
|
|
|
|
double p_dot_p_End = OCx_End * OCx_End + OCy_End * OCy_End;
|
|
|
|
|
|
|
|
|
|
|
|
double b_End = (double)aRay.m_Dir.x * (double)OCx_End +
|
|
|
|
(double)aRay.m_Dir.y * (double)OCy_End;
|
|
|
|
|
|
|
|
double c_End = p_dot_p_End - m_radius_squared;
|
|
|
|
|
|
|
|
float delta_End = (float)(b_End * b_End - a * c_End);
|
|
|
|
|
|
|
|
if( delta_End > FLT_EPSILON )
|
|
|
|
{
|
|
|
|
float sdelta = sqrtf( delta_End );
|
2021-01-02 21:05:29 +00:00
|
|
|
float t = ( -b_End - sdelta ) / a;
|
2016-07-19 17:35:25 +00:00
|
|
|
float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
if( t < aMaxDistance )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
bool ROUND_SEGMENT::Intersects( const BBOX_3D& aBBox ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-12-11 13:51:42 +00:00
|
|
|
//!TODO: improve
|
2016-07-19 17:35:25 +00:00
|
|
|
return m_bbox.Intersects( aBBox );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-05 16:57:25 +00:00
|
|
|
SFVEC3F ROUND_SEGMENT::GetDiffuseColor( const HITINFO& /* aHitInfo */ ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
return m_diffusecolor;
|
|
|
|
}
|