2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-18 22:39:02 +00:00
|
|
|
* Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@ua.pt>
|
2020-12-12 17:29:11 +00:00
|
|
|
* Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file ray.h
|
|
|
|
* @brief
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _RAY_H_
|
|
|
|
#define _RAY_H_
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
#include <plugins/3dapi/xv3d_types.h>
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
enum class RAY_CLASSIFICATION
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2019-12-30 13:01:06 +00:00
|
|
|
MMM,
|
|
|
|
MMP,
|
|
|
|
MPM,
|
|
|
|
MPP,
|
|
|
|
PMM,
|
|
|
|
PMP,
|
|
|
|
PPM,
|
|
|
|
PPP,
|
|
|
|
POO,
|
|
|
|
MOO,
|
|
|
|
OPO,
|
|
|
|
OMO,
|
|
|
|
OOP,
|
|
|
|
OOM,
|
|
|
|
OMM,
|
|
|
|
OMP,
|
|
|
|
OPM,
|
|
|
|
OPP,
|
|
|
|
MOM,
|
|
|
|
MOP,
|
|
|
|
POM,
|
|
|
|
POP,
|
|
|
|
MMO,
|
|
|
|
MPO,
|
|
|
|
PMO,
|
|
|
|
PPO
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
struct RAY
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
SFVEC3F m_Origin;
|
2017-01-18 22:39:02 +00:00
|
|
|
unsigned int rayID; ///< unique ray ID - not used - dummy
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
SFVEC3F m_Dir;
|
|
|
|
RAY_CLASSIFICATION m_Classification;
|
|
|
|
|
|
|
|
SFVEC3F m_InvDir;
|
|
|
|
|
|
|
|
float ibyj, jbyi, kbyj, jbyk, ibyk, kbyi; // slope
|
|
|
|
float c_xy, c_xz, c_yx, c_yz, c_zx, c_zy;
|
|
|
|
|
|
|
|
unsigned int m_dirIsNeg[3];
|
|
|
|
|
|
|
|
void Init( const SFVEC3F& o, const SFVEC3F& d );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
bool IntersectSphere( const SFVEC3F &aCenter,
|
|
|
|
float aRadius,
|
|
|
|
float &aOutT0,
|
|
|
|
float &aOutT1 ) const;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
SFVEC3F at( float t ) const { return m_Origin + m_Dir * t; }
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
SFVEC2F at2D( float t ) const {
|
|
|
|
return SFVEC2F( m_Origin.x + m_Dir.x * t, m_Origin.y + m_Dir.y * t ); }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
void debug() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
struct RAY2D
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
SFVEC2F m_Origin;
|
|
|
|
SFVEC2F m_Dir;
|
|
|
|
SFVEC2F m_InvDir;
|
|
|
|
|
|
|
|
RAY2D( const SFVEC2F& o, const SFVEC2F& d ) { m_Origin = o; m_Dir = d; m_InvDir = (1.0f / d); }
|
|
|
|
|
|
|
|
SFVEC2F at( float t ) const { return m_Origin + m_Dir * t; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
struct RAYSEG2D
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
SFVEC2F m_Start;
|
|
|
|
SFVEC2F m_End;
|
|
|
|
SFVEC2F m_End_minus_start;
|
|
|
|
SFVEC2F m_Dir;
|
|
|
|
SFVEC2F m_InvDir;
|
|
|
|
float m_Length;
|
|
|
|
float m_DOT_End_minus_start; ///< dot( m_End_minus_start, m_End_minus_start)
|
|
|
|
|
|
|
|
RAYSEG2D( const SFVEC2F& s, const SFVEC2F& e );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
bool IntersectSegment( const SFVEC2F &aStart,
|
|
|
|
const SFVEC2F &aEnd_minus_start,
|
|
|
|
float *aOutT ) const;
|
|
|
|
|
|
|
|
bool IntersectCircle( const SFVEC2F &aCenter,
|
|
|
|
float aRadius,
|
|
|
|
float *aOutT0,
|
|
|
|
float *aOutT1,
|
|
|
|
SFVEC2F *aOutNormalT0,
|
|
|
|
SFVEC2F *aOutNormalT1 ) const;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
float DistanceToPointSquared( const SFVEC2F &aPoint ) const;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
/**
|
2020-12-12 17:29:11 +00:00
|
|
|
* Return the position at \a t.
|
|
|
|
*
|
2015-12-08 07:31:57 +00:00
|
|
|
* t - value 0.0 ... 1.0
|
|
|
|
*/
|
|
|
|
SFVEC2F atNormalized( float t ) const { return m_Start + m_End_minus_start * t; }
|
|
|
|
|
|
|
|
SFVEC2F at( float t ) const { return m_Start + m_Dir * t; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool IntersectSegment( const SFVEC2F &aStartA, const SFVEC2F &aEnd_minus_startA,
|
|
|
|
const SFVEC2F &aStartB, const SFVEC2F &aEnd_minus_startB );
|
|
|
|
|
|
|
|
#if(GLM_ARCH != GLM_ARCH_PURE)
|
|
|
|
/*
|
2016-07-19 17:35:25 +00:00
|
|
|
struct RAY4
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
glm::simdVec4 m_orgX; ///< x coordinate of ray origin
|
|
|
|
glm::simdVec4 m_orgy; ///< y coordinate of ray origin
|
|
|
|
glm::simdVec4 m_orgz; ///< z coordinate of ray origin
|
|
|
|
|
|
|
|
glm::simdVec4 m_dirX; ///< x direction of ray
|
|
|
|
glm::simdVec4 m_diry; ///< y direction of ray
|
|
|
|
glm::simdVec4 m_dirz; ///< z direction of ray
|
|
|
|
|
|
|
|
glm::simdVec4 m_tnear; ///< Start of ray segment
|
|
|
|
glm::simdVec4 m_tfar; ///< End of ray segment
|
|
|
|
};*/
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _RAY_H_
|