From 72423af4130f9ed9610da5878f25f036d7f8d68b Mon Sep 17 00:00:00 2001 From: Pavel Kovalenko Date: Thu, 30 Oct 2014 21:52:02 +0400 Subject: [PATCH] Remove duplicated code. --- src/Layers/xrRender/DetailManager.cpp | 2 +- .../xrRender/DetailManager_Decompress.cpp | 2 +- src/Layers/xrRender/FSkinned.cpp | 2 +- src/Layers/xrRender/SkeletonCustom.cpp | 2 +- src/Layers/xrRender/SkeletonX.cpp | 2 +- src/Layers/xrRender/cl_intersect.h | 747 ------------------ src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj | 1 - .../xrRenderPC_R1/xrRender_R1.vcxproj.filters | 3 - src/Layers/xrRenderPC_R2/light_vis.cpp | 2 +- .../r2_rendertarget_enable_scissor.cpp | 2 +- src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj | 1 - .../xrRenderPC_R2/xrRender_R2.vcxproj.filters | 3 - src/Layers/xrRenderPC_R3/light_vis.cpp | 2 +- .../r3_rendertarget_enable_scissor.cpp | 2 +- src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj | 1 - .../xrRenderPC_R3/xrRender_R3.vcxproj.filters | 3 - src/Layers/xrRenderPC_R4/light_vis.cpp | 2 +- .../r4_rendertarget_enable_scissor.cpp | 2 +- src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj | 1 - .../xrRenderPC_R4/xrRender_R4.vcxproj.filters | 3 - src/editors/ECore/Engine/cl_intersect.h | 747 ------------------ src/utils/xrAI/cl_intersect.h | 747 ------------------ src/utils/xrAI/compiler.cpp | 2 +- src/utils/xrAI/compiler_build.cpp | 2 +- src/utils/xrAI/compiler_cover.cpp | 2 +- src/utils/xrAI/compiler_light.cpp | 2 +- src/utils/xrAI/compiler_smooth.cpp | 2 +- src/utils/xrAI/motion_simulator.cpp | 2 +- src/utils/xrAI/xrAI.vcxproj | 1 - src/utils/xrAI/xrAI.vcxproj.filters | 3 - src/utils/xrDO_Light/cl_intersect.h | 747 ------------------ src/utils/xrLC/cl_intersect.h | 747 ------------------ src/utils/xrLC/xrLC.vcxproj | 1 - src/utils/xrLC/xrLC.vcxproj.filters | 3 - src/utils/xrLC_Light/cl_intersect.h | 747 ------------------ .../xrLC_Light/detail_slot_calculate.cpp | 2 +- src/utils/xrLC_Light/xrDeflectorLight.cpp | 2 +- .../cl_intersect.h => xrCDB/Intersect.hpp} | 0 src/xrCDB/cl_raypick.cpp | 2 +- src/xrCDB/xrCDB.vcxproj | 1 + src/xrCDB/xrCDB.vcxproj.filters | 3 + src/xrCDB/xr_area_raypick.cpp | 2 +- src/xrEngine/Feel_Vision.cpp | 2 +- src/xrEngine/xrEngine.vcxproj | 1 - src/xrEngine/xrEngine.vcxproj.filters | 6 - src/xrEngine/xr_efflensflare.cpp | 2 +- src/xrGame/Actor.cpp | 2 +- src/xrGame/ActorCameras.cpp | 2 +- src/xrGame/DynamicHeightMap.cpp | 2 +- src/xrGame/PHMovementControl.cpp | 2 +- src/xrGame/ik_foot_collider.cpp | 2 +- src/xrPhysics/PHAICharacter.cpp | 2 +- src/xrPhysics/PHCharacter.cpp | 2 +- src/xrPhysics/PHSimpleCharacter.cpp | 2 +- .../tri-colliderknoopc/dcTriListCollider.cpp | 2 +- src/xrSound/SoundRender_Core_Processor.cpp | 2 +- src/xrSound/cl_intersect.h | 747 ------------------ src/xrSound/xrSound.vcxproj | 7 +- src/xrSound/xrSound.vcxproj.filters | 3 - 59 files changed, 40 insertions(+), 5300 deletions(-) delete mode 100644 src/Layers/xrRender/cl_intersect.h delete mode 100644 src/editors/ECore/Engine/cl_intersect.h delete mode 100644 src/utils/xrAI/cl_intersect.h delete mode 100644 src/utils/xrDO_Light/cl_intersect.h delete mode 100644 src/utils/xrLC/cl_intersect.h delete mode 100644 src/utils/xrLC_Light/cl_intersect.h rename src/{xrEngine/cl_intersect.h => xrCDB/Intersect.hpp} (100%) delete mode 100644 src/xrSound/cl_intersect.h diff --git a/src/Layers/xrRender/DetailManager.cpp b/src/Layers/xrRender/DetailManager.cpp index f03ba2f3013..a9d809427e2 100644 --- a/src/Layers/xrRender/DetailManager.cpp +++ b/src/Layers/xrRender/DetailManager.cpp @@ -6,7 +6,7 @@ #pragma hdrstop #include "DetailManager.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #ifdef _EDITOR # include "ESceneClassList.h" diff --git a/src/Layers/xrRender/DetailManager_Decompress.cpp b/src/Layers/xrRender/DetailManager_Decompress.cpp index 840cf4f8351..a22e56c039d 100644 --- a/src/Layers/xrRender/DetailManager_Decompress.cpp +++ b/src/Layers/xrRender/DetailManager_Decompress.cpp @@ -2,7 +2,7 @@ #pragma hdrstop #include "DetailManager.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #ifdef _EDITOR # include "scene.h" diff --git a/src/Layers/xrRender/FSkinned.cpp b/src/Layers/xrRender/FSkinned.cpp index 826726ae3ff..440a078106d 100644 --- a/src/Layers/xrRender/FSkinned.cpp +++ b/src/Layers/xrRender/FSkinned.cpp @@ -695,7 +695,7 @@ void CSkeletonX_ext::_Load_hw (Fvisual& V, void * _verts_) //----------------------------------------------------------------------------------------------------- // Wallmarks //----------------------------------------------------------------------------------------------------- -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #ifdef DEBUG diff --git a/src/Layers/xrRender/SkeletonCustom.cpp b/src/Layers/xrRender/SkeletonCustom.cpp index 527586f96d0..d9e812a48f0 100644 --- a/src/Layers/xrRender/SkeletonCustom.cpp +++ b/src/Layers/xrRender/SkeletonCustom.cpp @@ -541,7 +541,7 @@ void CKinematics::EnumBoneVertices (SEnumVerticesCallback &C, u16 bone_id) for ( u32 i=0; iEnumBoneVertices( C, bone_id ); } -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" DEFINE_VECTOR(Fobb,OBBVec,OBBVecIt); diff --git a/src/Layers/xrRender/SkeletonX.cpp b/src/Layers/xrRender/SkeletonX.cpp index 537b97b9987..d4726bf38db 100644 --- a/src/Layers/xrRender/SkeletonX.cpp +++ b/src/Layers/xrRender/SkeletonX.cpp @@ -420,7 +420,7 @@ void get_pos_bones(const vertBoned4W &vert, Fvector& p, CKinematics* Parent ) //----------------------------------------------------------------------------------------------------- // Wallmarks //----------------------------------------------------------------------------------------------------- -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" BOOL CSkeletonX::_PickBoneSoft1W (IKinematics::pick_result &r, float dist, const Fvector& S, const Fvector& D, u16* indices, CBoneData::FacesVec& faces) { return pick_bone( Vertices1W, Parent, r, dist, S, D, indices, faces); diff --git a/src/Layers/xrRender/cl_intersect.h b/src/Layers/xrRender/cl_intersect.h deleted file mode 100644 index 35a48410ae3..00000000000 --- a/src/Layers/xrRender/cl_intersect.h +++ /dev/null @@ -1,747 +0,0 @@ -//--------------------------------------------------------------------------- -#ifndef intersectH -#define intersectH - -namespace CDB -{ - //---------------------------------------------------------------------- - // Name : intersectRaySphere() - // Input : rO - origin of ray in world space - // rV - _vector_ describing direction of ray in world space - // sO - Origin of sphere - // sR - radius of sphere - // Notes : Normalized directional vectors expected - // ----------------------------------------------------------------------- - IC bool IntersectRaySphere(const Fvector& rO, const Fvector& rV, const Fvector& sO, float sR) - { - Fvector Q; - Q.sub(sO,rO); - - float c = Q.magnitude(); - float v = Q.dotproduct(rV); - float d = sR*sR - (c*c - v*v); - - // If there was no intersection, return -1 - return (d > 0.0); - } - - //-- Ray-Triangle : 2nd level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector** p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0 || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0 || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - //-- Ray-Triangle : 1st level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector* p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0f || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0f || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - - //-- Ray-Triangle(always return range) : 1st level of indirection -------------------------------- - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector* p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector** p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - //--------------------------------------------------------------------------- - // macros for fast arithmetic - //--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- - // compare [-r,r] to [NdD+dt*NdW] -#define TESTV0(NdD, R) \ - if (NdD> R) return false;\ - else if (NdD<-R) return false; - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d0,p+d1},max{p,p+d0,p+d1}] -#define TESTV1(p,d0,d1,r){ \ - if ( (p) > (r) ){ \ - if ( (d0) >= 0.0f ){ \ - if ( (d1) >= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - } \ - }else if ( (d1) <= (d0) ){ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) > (r) ) \ - return false; \ - } \ - }else if ( (p) < -(r) ){ \ - if ( (d0) <= 0.0f ){ \ - if ( (d1) <= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - } \ - }else if ( (d1) >= (d0) ){ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) < -(r) ) \ - return false; \ - } \ - } \ - } - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d},max{p,p+d}] -#define TESTV2(p,d,r){ \ - if ( (p) > (r) ){ \ - if ( (d) >= 0.0f ){ return false; \ - }else{ if ( (p)+(d) > (r) ) return false; } \ - }else if ( (p) < -(r) ){ \ - if ( (d) <= 0.0f ){ return false; \ - }else{ if ( (p)+(d) < -(r) ) return false; } \ - } \ - } - //--------------------------------------------------------------------------- - - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector** p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(*p[1],*p[0]); - E[1].sub(*p[2],*p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(*p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector* p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(p[1],p[0]); - E[1].sub(p[2],p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - //---------------------------------------------------------------------------} - - //---------------------------------------------------------------------------- - IC float MgcSqrDistance (const Fvector& rkPoint, const Fvector& orig, const Fvector& e0,const Fvector& e1){ - - Fvector kDiff; - kDiff.sub(orig,rkPoint); - - float fA00 = e0.square_magnitude(); - float fA01 = e0.dotproduct(e1); - float fA11 = e1.square_magnitude(); - float fB0 = kDiff.dotproduct(e0); - float fB1 = kDiff.dotproduct(e1); - float fC = kDiff.square_magnitude(); - float fDet = _abs(fA00*fA11-fA01*fA01); - float fS = fA01*fB1-fA11*fB0; - float fT = fA01*fB0-fA00*fB1; - float fSqrDist; - - if ( fS + fT <= fDet ){ - if ( fS < 0.0f ){ - if ( fT < 0.0f ){ // region 4 - if ( fB0 < 0.0f ){ - fT = 0.0f; - if ( -fB0 >= fA00 ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else{ // region 3 - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0f ){ // region 5 - fT = 0.0f; - if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else if ( -fB0 >= fA00 ){ - fS = 1.0; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ // region 0 - // minimum at interior point - float fInvDet = 1.0f/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - float fTmp0, fTmp1, fNumer, fDenom; - - if ( fS < 0.0f ){ // region 2 - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fS = 0.0f; - if ( fTmp1 <= 0.0f ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0 ){ // region 6 - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fT = 1.0f; - fS = 0.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = fNumer/fDenom; - fS = 1.0f - fT; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fT = 0.0f; - if ( fTmp1 <= 0.0f ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - } - }else{ // region 1 - fNumer = fA11 + fB1 - fA01 - fB0; - if ( fNumer <= 0.0f ){ - fS = 0.0f; - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - } - } - } - - return _abs(fSqrDist); - } - - enum EST_Result{ - stNone = 0, - stIntersect = 1, - stInside = 2, - }; - - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, - const Fvector& orig, const Fvector& e0,const Fvector& e1) - { - - float fRSqr = sphereRadius*sphereRadius; - Fvector kV0mC; - kV0mC.sub(orig, sphereOrigin); - - // count the number of triangle vertices inside the sphere - int iInside = 0; - - // test if v0 is inside the sphere - if ( kV0mC.square_magnitude() <= fRSqr ) - iInside++; - - // test if v1 is inside the sphere - Fvector kDiff; - kDiff.add(kV0mC, e0); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // test if v2 is inside the sphere - kDiff.add(kV0mC, e1); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // triangle does not traversely intersect sphere - if ( iInside == 3 ) return stInside; - - // triangle transversely intersects sphere - if ( iInside > 0 ) return stIntersect; - - // All vertices are outside the sphere, but the triangle might still - // intersect the sphere. This is the case when the distance from the - // sphere center to the triangle is smaller than the radius. - float fSqrDist = MgcSqrDistance(sphereOrigin,orig,e0,e1); - return (fSqrDist < fRSqr)?stIntersect:stNone; - } - //--------------------------------------------------------------------------- - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector* p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(p[1], p[0]); - e1.sub(p[2], p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,p[0],e0,e1); - } - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector** p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(*p[1], *p[0]); - e1.sub(*p[2], *p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,*p[0],e0,e1); - } - IC bool TestSphereOBB(const Fsphere& rkSphere, const Fobb& rkBox) - { - // Test for intersection in the coordinate system of the box by - // transforming the sphere into that coordinate system. - Fvector3 kCDiff; - kCDiff.sub(rkSphere.P,rkBox.m_translate); - - float fAx = _abs(kCDiff.dotproduct(rkBox.m_rotate.i)); - float fAy = _abs(kCDiff.dotproduct(rkBox.m_rotate.j)); - float fAz = _abs(kCDiff.dotproduct(rkBox.m_rotate.k)); - float fDx = fAx - rkBox.m_halfsize[0]; - float fDy = fAy - rkBox.m_halfsize[1]; - float fDz = fAz - rkBox.m_halfsize[2]; - - if ( fAx <= rkBox.m_halfsize[0] ){ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // sphere center inside box - return true; - }else{ - // potential sphere-face intersection with face z - return fDz <= rkSphere.R; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face y - return fDy <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces y and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDy*fDy + fDz*fDz <= fRSqr; - } - } - }else{ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face x - return fDx <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces x and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDz*fDz <= fRSqr; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-edge intersection with edge formed - // by faces x and y - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy <= fRSqr; - }else{ - // potential sphere-vertex intersection at corner formed - // by faces x,y,z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr; - } - } - } - } - //---------------------------------------------------------------------------- - IC bool TestRayOBB (const Fvector3& origin, const Fvector3& direction, const Fobb& rkBox) - { - float fWdU[3], fAWdU[3], fDdU[3], fADdU[3], fAWxDdU[3], fRhs; - - Fvector3 kDiff; - kDiff.sub (origin,rkBox.m_translate); - - fWdU[0] = direction.dotproduct(rkBox.m_rotate.i); - fAWdU[0] = _abs(fWdU[0]); - fDdU[0] = kDiff.dotproduct(rkBox.m_rotate.i); - fADdU[0] = _abs(fDdU[0]); - if ( fADdU[0] > rkBox.m_halfsize[0] && fDdU[0]*fWdU[0] >= (float)0.0 ) - return false; - - fWdU[1] = direction.dotproduct(rkBox.m_rotate.j); - fAWdU[1] = _abs(fWdU[1]); - fDdU[1] = kDiff.dotproduct(rkBox.m_rotate.j); - fADdU[1] = _abs(fDdU[1]); - if ( fADdU[1] > rkBox.m_halfsize[1] && fDdU[1]*fWdU[1] >= (float)0.0 ) - return false; - - fWdU[2] = direction.dotproduct(rkBox.m_rotate.k); - fAWdU[2] = _abs(fWdU[2]); - fDdU[2] = kDiff.dotproduct(rkBox.m_rotate.k); - fADdU[2] = _abs(fDdU[2]); - if ( fADdU[2] > rkBox.m_halfsize[2] && fDdU[2]*fWdU[2] >= (float)0.0 ) - return false; - - Fvector3 kWxD; - kWxD.crossproduct(direction,kDiff); - - fAWxDdU[0] = _abs(kWxD.dotproduct(rkBox.m_rotate.i)); - fRhs = rkBox.m_halfsize[1]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[1]; - if ( fAWxDdU[0] > fRhs ) - return false; - - fAWxDdU[1] = _abs(kWxD.dotproduct(rkBox.m_rotate.j)); - fRhs = rkBox.m_halfsize[0]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[0]; - if ( fAWxDdU[1] > fRhs ) - return false; - - fAWxDdU[2] = _abs(kWxD.dotproduct(rkBox.m_rotate.k)); - fRhs = rkBox.m_halfsize[0]*fAWdU[1] + rkBox.m_halfsize[1]*fAWdU[0]; - if ( fAWxDdU[2] > fRhs ) - return false; - - return true; - } -//---------------------------------------------------------------------------- -}; - - -#endif diff --git a/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj b/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj index ab8cf37e6cb..f587633eb66 100644 --- a/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj +++ b/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj @@ -223,7 +223,6 @@ - diff --git a/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj.filters b/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj.filters index 672349a3a71..2d386871e7b 100644 --- a/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj.filters +++ b/src/Layers/xrRenderPC_R1/xrRender_R1.vcxproj.filters @@ -156,9 +156,6 @@ - - Kernel - Kernel diff --git a/src/Layers/xrRenderPC_R2/light_vis.cpp b/src/Layers/xrRenderPC_R2/light_vis.cpp index 53817092994..48d4f94bb63 100644 --- a/src/Layers/xrRenderPC_R2/light_vis.cpp +++ b/src/Layers/xrRenderPC_R2/light_vis.cpp @@ -1,6 +1,6 @@ #include "StdAfx.h" #include "../xrRender/light.h" -#include "../../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" const u32 delay_small_min = 1; const u32 delay_small_max = 3; diff --git a/src/Layers/xrRenderPC_R2/r2_rendertarget_enable_scissor.cpp b/src/Layers/xrRenderPC_R2/r2_rendertarget_enable_scissor.cpp index 56933556e36..189d0d104e5 100644 --- a/src/Layers/xrRenderPC_R2/r2_rendertarget_enable_scissor.cpp +++ b/src/Layers/xrRenderPC_R2/r2_rendertarget_enable_scissor.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include "../../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "../xrRender/du_cone.h" //extern Fvector du_cone_vertices [DU_CONE_NUMVERTEX]; diff --git a/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj b/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj index a05e521a5d7..8146ee4a36a 100644 --- a/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj +++ b/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj @@ -322,7 +322,6 @@ - diff --git a/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj.filters b/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj.filters index d7eeb8f563a..e9922b01991 100644 --- a/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj.filters +++ b/src/Layers/xrRenderPC_R2/xrRender_R2.vcxproj.filters @@ -162,9 +162,6 @@ - - Kernel - Kernel diff --git a/src/Layers/xrRenderPC_R3/light_vis.cpp b/src/Layers/xrRenderPC_R3/light_vis.cpp index 3f8b8ee587b..425a3aabca6 100644 --- a/src/Layers/xrRenderPC_R3/light_vis.cpp +++ b/src/Layers/xrRenderPC_R3/light_vis.cpp @@ -1,6 +1,6 @@ #include "StdAfx.h" #include "../xrRender/light.h" -#include "../../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" const u32 delay_small_min = 1; const u32 delay_small_max = 3; diff --git a/src/Layers/xrRenderPC_R3/r3_rendertarget_enable_scissor.cpp b/src/Layers/xrRenderPC_R3/r3_rendertarget_enable_scissor.cpp index 31b5497094b..a1495046f24 100644 --- a/src/Layers/xrRenderPC_R3/r3_rendertarget_enable_scissor.cpp +++ b/src/Layers/xrRenderPC_R3/r3_rendertarget_enable_scissor.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include "../../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "../xrRender/du_cone.h" //extern Fvector du_cone_vertices [DU_CONE_NUMVERTEX]; diff --git a/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj b/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj index a79b3ea4cc9..6360658b895 100644 --- a/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj +++ b/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj @@ -344,7 +344,6 @@ - diff --git a/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj.filters b/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj.filters index 0e90955d3a0..9d4f9060858 100644 --- a/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj.filters +++ b/src/Layers/xrRenderPC_R3/xrRender_R3.vcxproj.filters @@ -186,9 +186,6 @@ - - Kernel - Kernel diff --git a/src/Layers/xrRenderPC_R4/light_vis.cpp b/src/Layers/xrRenderPC_R4/light_vis.cpp index 3f8b8ee587b..425a3aabca6 100644 --- a/src/Layers/xrRenderPC_R4/light_vis.cpp +++ b/src/Layers/xrRenderPC_R4/light_vis.cpp @@ -1,6 +1,6 @@ #include "StdAfx.h" #include "../xrRender/light.h" -#include "../../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" const u32 delay_small_min = 1; const u32 delay_small_max = 3; diff --git a/src/Layers/xrRenderPC_R4/r4_rendertarget_enable_scissor.cpp b/src/Layers/xrRenderPC_R4/r4_rendertarget_enable_scissor.cpp index 31b5497094b..a1495046f24 100644 --- a/src/Layers/xrRenderPC_R4/r4_rendertarget_enable_scissor.cpp +++ b/src/Layers/xrRenderPC_R4/r4_rendertarget_enable_scissor.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include "../../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "../xrRender/du_cone.h" //extern Fvector du_cone_vertices [DU_CONE_NUMVERTEX]; diff --git a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj index 635229f032a..825f5d5681d 100644 --- a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj +++ b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj @@ -346,7 +346,6 @@ - diff --git a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters index 51934285820..c07a70a2a79 100644 --- a/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters +++ b/src/Layers/xrRenderPC_R4/xrRender_R4.vcxproj.filters @@ -186,9 +186,6 @@ - - Kernel - Kernel diff --git a/src/editors/ECore/Engine/cl_intersect.h b/src/editors/ECore/Engine/cl_intersect.h deleted file mode 100644 index 35a48410ae3..00000000000 --- a/src/editors/ECore/Engine/cl_intersect.h +++ /dev/null @@ -1,747 +0,0 @@ -//--------------------------------------------------------------------------- -#ifndef intersectH -#define intersectH - -namespace CDB -{ - //---------------------------------------------------------------------- - // Name : intersectRaySphere() - // Input : rO - origin of ray in world space - // rV - _vector_ describing direction of ray in world space - // sO - Origin of sphere - // sR - radius of sphere - // Notes : Normalized directional vectors expected - // ----------------------------------------------------------------------- - IC bool IntersectRaySphere(const Fvector& rO, const Fvector& rV, const Fvector& sO, float sR) - { - Fvector Q; - Q.sub(sO,rO); - - float c = Q.magnitude(); - float v = Q.dotproduct(rV); - float d = sR*sR - (c*c - v*v); - - // If there was no intersection, return -1 - return (d > 0.0); - } - - //-- Ray-Triangle : 2nd level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector** p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0 || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0 || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - //-- Ray-Triangle : 1st level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector* p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0f || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0f || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - - //-- Ray-Triangle(always return range) : 1st level of indirection -------------------------------- - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector* p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector** p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - //--------------------------------------------------------------------------- - // macros for fast arithmetic - //--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- - // compare [-r,r] to [NdD+dt*NdW] -#define TESTV0(NdD, R) \ - if (NdD> R) return false;\ - else if (NdD<-R) return false; - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d0,p+d1},max{p,p+d0,p+d1}] -#define TESTV1(p,d0,d1,r){ \ - if ( (p) > (r) ){ \ - if ( (d0) >= 0.0f ){ \ - if ( (d1) >= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - } \ - }else if ( (d1) <= (d0) ){ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) > (r) ) \ - return false; \ - } \ - }else if ( (p) < -(r) ){ \ - if ( (d0) <= 0.0f ){ \ - if ( (d1) <= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - } \ - }else if ( (d1) >= (d0) ){ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) < -(r) ) \ - return false; \ - } \ - } \ - } - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d},max{p,p+d}] -#define TESTV2(p,d,r){ \ - if ( (p) > (r) ){ \ - if ( (d) >= 0.0f ){ return false; \ - }else{ if ( (p)+(d) > (r) ) return false; } \ - }else if ( (p) < -(r) ){ \ - if ( (d) <= 0.0f ){ return false; \ - }else{ if ( (p)+(d) < -(r) ) return false; } \ - } \ - } - //--------------------------------------------------------------------------- - - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector** p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(*p[1],*p[0]); - E[1].sub(*p[2],*p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(*p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector* p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(p[1],p[0]); - E[1].sub(p[2],p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - //---------------------------------------------------------------------------} - - //---------------------------------------------------------------------------- - IC float MgcSqrDistance (const Fvector& rkPoint, const Fvector& orig, const Fvector& e0,const Fvector& e1){ - - Fvector kDiff; - kDiff.sub(orig,rkPoint); - - float fA00 = e0.square_magnitude(); - float fA01 = e0.dotproduct(e1); - float fA11 = e1.square_magnitude(); - float fB0 = kDiff.dotproduct(e0); - float fB1 = kDiff.dotproduct(e1); - float fC = kDiff.square_magnitude(); - float fDet = _abs(fA00*fA11-fA01*fA01); - float fS = fA01*fB1-fA11*fB0; - float fT = fA01*fB0-fA00*fB1; - float fSqrDist; - - if ( fS + fT <= fDet ){ - if ( fS < 0.0f ){ - if ( fT < 0.0f ){ // region 4 - if ( fB0 < 0.0f ){ - fT = 0.0f; - if ( -fB0 >= fA00 ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else{ // region 3 - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0f ){ // region 5 - fT = 0.0f; - if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else if ( -fB0 >= fA00 ){ - fS = 1.0; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ // region 0 - // minimum at interior point - float fInvDet = 1.0f/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - float fTmp0, fTmp1, fNumer, fDenom; - - if ( fS < 0.0f ){ // region 2 - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fS = 0.0f; - if ( fTmp1 <= 0.0f ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0 ){ // region 6 - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fT = 1.0f; - fS = 0.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = fNumer/fDenom; - fS = 1.0f - fT; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fT = 0.0f; - if ( fTmp1 <= 0.0f ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - } - }else{ // region 1 - fNumer = fA11 + fB1 - fA01 - fB0; - if ( fNumer <= 0.0f ){ - fS = 0.0f; - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - } - } - } - - return _abs(fSqrDist); - } - - enum EST_Result{ - stNone = 0, - stIntersect = 1, - stInside = 2, - }; - - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, - const Fvector& orig, const Fvector& e0,const Fvector& e1) - { - - float fRSqr = sphereRadius*sphereRadius; - Fvector kV0mC; - kV0mC.sub(orig, sphereOrigin); - - // count the number of triangle vertices inside the sphere - int iInside = 0; - - // test if v0 is inside the sphere - if ( kV0mC.square_magnitude() <= fRSqr ) - iInside++; - - // test if v1 is inside the sphere - Fvector kDiff; - kDiff.add(kV0mC, e0); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // test if v2 is inside the sphere - kDiff.add(kV0mC, e1); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // triangle does not traversely intersect sphere - if ( iInside == 3 ) return stInside; - - // triangle transversely intersects sphere - if ( iInside > 0 ) return stIntersect; - - // All vertices are outside the sphere, but the triangle might still - // intersect the sphere. This is the case when the distance from the - // sphere center to the triangle is smaller than the radius. - float fSqrDist = MgcSqrDistance(sphereOrigin,orig,e0,e1); - return (fSqrDist < fRSqr)?stIntersect:stNone; - } - //--------------------------------------------------------------------------- - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector* p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(p[1], p[0]); - e1.sub(p[2], p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,p[0],e0,e1); - } - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector** p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(*p[1], *p[0]); - e1.sub(*p[2], *p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,*p[0],e0,e1); - } - IC bool TestSphereOBB(const Fsphere& rkSphere, const Fobb& rkBox) - { - // Test for intersection in the coordinate system of the box by - // transforming the sphere into that coordinate system. - Fvector3 kCDiff; - kCDiff.sub(rkSphere.P,rkBox.m_translate); - - float fAx = _abs(kCDiff.dotproduct(rkBox.m_rotate.i)); - float fAy = _abs(kCDiff.dotproduct(rkBox.m_rotate.j)); - float fAz = _abs(kCDiff.dotproduct(rkBox.m_rotate.k)); - float fDx = fAx - rkBox.m_halfsize[0]; - float fDy = fAy - rkBox.m_halfsize[1]; - float fDz = fAz - rkBox.m_halfsize[2]; - - if ( fAx <= rkBox.m_halfsize[0] ){ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // sphere center inside box - return true; - }else{ - // potential sphere-face intersection with face z - return fDz <= rkSphere.R; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face y - return fDy <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces y and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDy*fDy + fDz*fDz <= fRSqr; - } - } - }else{ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face x - return fDx <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces x and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDz*fDz <= fRSqr; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-edge intersection with edge formed - // by faces x and y - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy <= fRSqr; - }else{ - // potential sphere-vertex intersection at corner formed - // by faces x,y,z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr; - } - } - } - } - //---------------------------------------------------------------------------- - IC bool TestRayOBB (const Fvector3& origin, const Fvector3& direction, const Fobb& rkBox) - { - float fWdU[3], fAWdU[3], fDdU[3], fADdU[3], fAWxDdU[3], fRhs; - - Fvector3 kDiff; - kDiff.sub (origin,rkBox.m_translate); - - fWdU[0] = direction.dotproduct(rkBox.m_rotate.i); - fAWdU[0] = _abs(fWdU[0]); - fDdU[0] = kDiff.dotproduct(rkBox.m_rotate.i); - fADdU[0] = _abs(fDdU[0]); - if ( fADdU[0] > rkBox.m_halfsize[0] && fDdU[0]*fWdU[0] >= (float)0.0 ) - return false; - - fWdU[1] = direction.dotproduct(rkBox.m_rotate.j); - fAWdU[1] = _abs(fWdU[1]); - fDdU[1] = kDiff.dotproduct(rkBox.m_rotate.j); - fADdU[1] = _abs(fDdU[1]); - if ( fADdU[1] > rkBox.m_halfsize[1] && fDdU[1]*fWdU[1] >= (float)0.0 ) - return false; - - fWdU[2] = direction.dotproduct(rkBox.m_rotate.k); - fAWdU[2] = _abs(fWdU[2]); - fDdU[2] = kDiff.dotproduct(rkBox.m_rotate.k); - fADdU[2] = _abs(fDdU[2]); - if ( fADdU[2] > rkBox.m_halfsize[2] && fDdU[2]*fWdU[2] >= (float)0.0 ) - return false; - - Fvector3 kWxD; - kWxD.crossproduct(direction,kDiff); - - fAWxDdU[0] = _abs(kWxD.dotproduct(rkBox.m_rotate.i)); - fRhs = rkBox.m_halfsize[1]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[1]; - if ( fAWxDdU[0] > fRhs ) - return false; - - fAWxDdU[1] = _abs(kWxD.dotproduct(rkBox.m_rotate.j)); - fRhs = rkBox.m_halfsize[0]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[0]; - if ( fAWxDdU[1] > fRhs ) - return false; - - fAWxDdU[2] = _abs(kWxD.dotproduct(rkBox.m_rotate.k)); - fRhs = rkBox.m_halfsize[0]*fAWdU[1] + rkBox.m_halfsize[1]*fAWdU[0]; - if ( fAWxDdU[2] > fRhs ) - return false; - - return true; - } -//---------------------------------------------------------------------------- -}; - - -#endif diff --git a/src/utils/xrAI/cl_intersect.h b/src/utils/xrAI/cl_intersect.h deleted file mode 100644 index 35a48410ae3..00000000000 --- a/src/utils/xrAI/cl_intersect.h +++ /dev/null @@ -1,747 +0,0 @@ -//--------------------------------------------------------------------------- -#ifndef intersectH -#define intersectH - -namespace CDB -{ - //---------------------------------------------------------------------- - // Name : intersectRaySphere() - // Input : rO - origin of ray in world space - // rV - _vector_ describing direction of ray in world space - // sO - Origin of sphere - // sR - radius of sphere - // Notes : Normalized directional vectors expected - // ----------------------------------------------------------------------- - IC bool IntersectRaySphere(const Fvector& rO, const Fvector& rV, const Fvector& sO, float sR) - { - Fvector Q; - Q.sub(sO,rO); - - float c = Q.magnitude(); - float v = Q.dotproduct(rV); - float d = sR*sR - (c*c - v*v); - - // If there was no intersection, return -1 - return (d > 0.0); - } - - //-- Ray-Triangle : 2nd level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector** p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0 || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0 || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - //-- Ray-Triangle : 1st level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector* p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0f || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0f || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - - //-- Ray-Triangle(always return range) : 1st level of indirection -------------------------------- - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector* p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector** p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - //--------------------------------------------------------------------------- - // macros for fast arithmetic - //--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- - // compare [-r,r] to [NdD+dt*NdW] -#define TESTV0(NdD, R) \ - if (NdD> R) return false;\ - else if (NdD<-R) return false; - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d0,p+d1},max{p,p+d0,p+d1}] -#define TESTV1(p,d0,d1,r){ \ - if ( (p) > (r) ){ \ - if ( (d0) >= 0.0f ){ \ - if ( (d1) >= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - } \ - }else if ( (d1) <= (d0) ){ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) > (r) ) \ - return false; \ - } \ - }else if ( (p) < -(r) ){ \ - if ( (d0) <= 0.0f ){ \ - if ( (d1) <= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - } \ - }else if ( (d1) >= (d0) ){ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) < -(r) ) \ - return false; \ - } \ - } \ - } - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d},max{p,p+d}] -#define TESTV2(p,d,r){ \ - if ( (p) > (r) ){ \ - if ( (d) >= 0.0f ){ return false; \ - }else{ if ( (p)+(d) > (r) ) return false; } \ - }else if ( (p) < -(r) ){ \ - if ( (d) <= 0.0f ){ return false; \ - }else{ if ( (p)+(d) < -(r) ) return false; } \ - } \ - } - //--------------------------------------------------------------------------- - - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector** p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(*p[1],*p[0]); - E[1].sub(*p[2],*p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(*p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector* p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(p[1],p[0]); - E[1].sub(p[2],p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - //---------------------------------------------------------------------------} - - //---------------------------------------------------------------------------- - IC float MgcSqrDistance (const Fvector& rkPoint, const Fvector& orig, const Fvector& e0,const Fvector& e1){ - - Fvector kDiff; - kDiff.sub(orig,rkPoint); - - float fA00 = e0.square_magnitude(); - float fA01 = e0.dotproduct(e1); - float fA11 = e1.square_magnitude(); - float fB0 = kDiff.dotproduct(e0); - float fB1 = kDiff.dotproduct(e1); - float fC = kDiff.square_magnitude(); - float fDet = _abs(fA00*fA11-fA01*fA01); - float fS = fA01*fB1-fA11*fB0; - float fT = fA01*fB0-fA00*fB1; - float fSqrDist; - - if ( fS + fT <= fDet ){ - if ( fS < 0.0f ){ - if ( fT < 0.0f ){ // region 4 - if ( fB0 < 0.0f ){ - fT = 0.0f; - if ( -fB0 >= fA00 ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else{ // region 3 - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0f ){ // region 5 - fT = 0.0f; - if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else if ( -fB0 >= fA00 ){ - fS = 1.0; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ // region 0 - // minimum at interior point - float fInvDet = 1.0f/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - float fTmp0, fTmp1, fNumer, fDenom; - - if ( fS < 0.0f ){ // region 2 - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fS = 0.0f; - if ( fTmp1 <= 0.0f ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0 ){ // region 6 - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fT = 1.0f; - fS = 0.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = fNumer/fDenom; - fS = 1.0f - fT; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fT = 0.0f; - if ( fTmp1 <= 0.0f ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - } - }else{ // region 1 - fNumer = fA11 + fB1 - fA01 - fB0; - if ( fNumer <= 0.0f ){ - fS = 0.0f; - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - } - } - } - - return _abs(fSqrDist); - } - - enum EST_Result{ - stNone = 0, - stIntersect = 1, - stInside = 2, - }; - - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, - const Fvector& orig, const Fvector& e0,const Fvector& e1) - { - - float fRSqr = sphereRadius*sphereRadius; - Fvector kV0mC; - kV0mC.sub(orig, sphereOrigin); - - // count the number of triangle vertices inside the sphere - int iInside = 0; - - // test if v0 is inside the sphere - if ( kV0mC.square_magnitude() <= fRSqr ) - iInside++; - - // test if v1 is inside the sphere - Fvector kDiff; - kDiff.add(kV0mC, e0); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // test if v2 is inside the sphere - kDiff.add(kV0mC, e1); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // triangle does not traversely intersect sphere - if ( iInside == 3 ) return stInside; - - // triangle transversely intersects sphere - if ( iInside > 0 ) return stIntersect; - - // All vertices are outside the sphere, but the triangle might still - // intersect the sphere. This is the case when the distance from the - // sphere center to the triangle is smaller than the radius. - float fSqrDist = MgcSqrDistance(sphereOrigin,orig,e0,e1); - return (fSqrDist < fRSqr)?stIntersect:stNone; - } - //--------------------------------------------------------------------------- - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector* p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(p[1], p[0]); - e1.sub(p[2], p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,p[0],e0,e1); - } - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector** p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(*p[1], *p[0]); - e1.sub(*p[2], *p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,*p[0],e0,e1); - } - IC bool TestSphereOBB(const Fsphere& rkSphere, const Fobb& rkBox) - { - // Test for intersection in the coordinate system of the box by - // transforming the sphere into that coordinate system. - Fvector3 kCDiff; - kCDiff.sub(rkSphere.P,rkBox.m_translate); - - float fAx = _abs(kCDiff.dotproduct(rkBox.m_rotate.i)); - float fAy = _abs(kCDiff.dotproduct(rkBox.m_rotate.j)); - float fAz = _abs(kCDiff.dotproduct(rkBox.m_rotate.k)); - float fDx = fAx - rkBox.m_halfsize[0]; - float fDy = fAy - rkBox.m_halfsize[1]; - float fDz = fAz - rkBox.m_halfsize[2]; - - if ( fAx <= rkBox.m_halfsize[0] ){ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // sphere center inside box - return true; - }else{ - // potential sphere-face intersection with face z - return fDz <= rkSphere.R; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face y - return fDy <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces y and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDy*fDy + fDz*fDz <= fRSqr; - } - } - }else{ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face x - return fDx <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces x and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDz*fDz <= fRSqr; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-edge intersection with edge formed - // by faces x and y - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy <= fRSqr; - }else{ - // potential sphere-vertex intersection at corner formed - // by faces x,y,z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr; - } - } - } - } - //---------------------------------------------------------------------------- - IC bool TestRayOBB (const Fvector3& origin, const Fvector3& direction, const Fobb& rkBox) - { - float fWdU[3], fAWdU[3], fDdU[3], fADdU[3], fAWxDdU[3], fRhs; - - Fvector3 kDiff; - kDiff.sub (origin,rkBox.m_translate); - - fWdU[0] = direction.dotproduct(rkBox.m_rotate.i); - fAWdU[0] = _abs(fWdU[0]); - fDdU[0] = kDiff.dotproduct(rkBox.m_rotate.i); - fADdU[0] = _abs(fDdU[0]); - if ( fADdU[0] > rkBox.m_halfsize[0] && fDdU[0]*fWdU[0] >= (float)0.0 ) - return false; - - fWdU[1] = direction.dotproduct(rkBox.m_rotate.j); - fAWdU[1] = _abs(fWdU[1]); - fDdU[1] = kDiff.dotproduct(rkBox.m_rotate.j); - fADdU[1] = _abs(fDdU[1]); - if ( fADdU[1] > rkBox.m_halfsize[1] && fDdU[1]*fWdU[1] >= (float)0.0 ) - return false; - - fWdU[2] = direction.dotproduct(rkBox.m_rotate.k); - fAWdU[2] = _abs(fWdU[2]); - fDdU[2] = kDiff.dotproduct(rkBox.m_rotate.k); - fADdU[2] = _abs(fDdU[2]); - if ( fADdU[2] > rkBox.m_halfsize[2] && fDdU[2]*fWdU[2] >= (float)0.0 ) - return false; - - Fvector3 kWxD; - kWxD.crossproduct(direction,kDiff); - - fAWxDdU[0] = _abs(kWxD.dotproduct(rkBox.m_rotate.i)); - fRhs = rkBox.m_halfsize[1]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[1]; - if ( fAWxDdU[0] > fRhs ) - return false; - - fAWxDdU[1] = _abs(kWxD.dotproduct(rkBox.m_rotate.j)); - fRhs = rkBox.m_halfsize[0]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[0]; - if ( fAWxDdU[1] > fRhs ) - return false; - - fAWxDdU[2] = _abs(kWxD.dotproduct(rkBox.m_rotate.k)); - fRhs = rkBox.m_halfsize[0]*fAWdU[1] + rkBox.m_halfsize[1]*fAWdU[0]; - if ( fAWxDdU[2] > fRhs ) - return false; - - return true; - } -//---------------------------------------------------------------------------- -}; - - -#endif diff --git a/src/utils/xrAI/compiler.cpp b/src/utils/xrAI/compiler.cpp index 5776bce84ad..50d67273e89 100644 --- a/src/utils/xrAI/compiler.cpp +++ b/src/utils/xrAI/compiler.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "compiler.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" CDB::MODEL Level; CDB::COLLIDER XRC; diff --git a/src/utils/xrAI/compiler_build.cpp b/src/utils/xrAI/compiler_build.cpp index 41f488a1ff6..d42a5b3f859 100644 --- a/src/utils/xrAI/compiler_build.cpp +++ b/src/utils/xrAI/compiler_build.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "compiler.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "motion_simulator.h" diff --git a/src/utils/xrAI/compiler_cover.cpp b/src/utils/xrAI/compiler_cover.cpp index d8bbc91061d..e0a2b725a00 100644 --- a/src/utils/xrAI/compiler_cover.cpp +++ b/src/utils/xrAI/compiler_cover.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "compiler.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "xrThread.h" #include diff --git a/src/utils/xrAI/compiler_light.cpp b/src/utils/xrAI/compiler_light.cpp index 97c136770c6..4f659715206 100644 --- a/src/utils/xrAI/compiler_light.cpp +++ b/src/utils/xrAI/compiler_light.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "compiler.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "xrThread.h" #include diff --git a/src/utils/xrAI/compiler_smooth.cpp b/src/utils/xrAI/compiler_smooth.cpp index f70ba4f6b94..d984e550f4b 100644 --- a/src/utils/xrAI/compiler_smooth.cpp +++ b/src/utils/xrAI/compiler_smooth.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "compiler.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" // MagicFM #pragma warning(disable:4995) diff --git a/src/utils/xrAI/motion_simulator.cpp b/src/utils/xrAI/motion_simulator.cpp index 43c1d6aa7e5..d129fc95f19 100644 --- a/src/utils/xrAI/motion_simulator.cpp +++ b/src/utils/xrAI/motion_simulator.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "motion_simulator.h" #include "compiler.h" diff --git a/src/utils/xrAI/xrAI.vcxproj b/src/utils/xrAI/xrAI.vcxproj index 5de3ffcf89e..4d0e30b82ef 100644 --- a/src/utils/xrAI/xrAI.vcxproj +++ b/src/utils/xrAI/xrAI.vcxproj @@ -371,7 +371,6 @@ - diff --git a/src/utils/xrAI/xrAI.vcxproj.filters b/src/utils/xrAI/xrAI.vcxproj.filters index 4defef81eee..d66ac979911 100644 --- a/src/utils/xrAI/xrAI.vcxproj.filters +++ b/src/utils/xrAI/xrAI.vcxproj.filters @@ -477,9 +477,6 @@ Compiler\Kernel\Generic\CDB - - Compiler\Kernel\Generic\CDB - Compiler\Kernel\Random32 diff --git a/src/utils/xrDO_Light/cl_intersect.h b/src/utils/xrDO_Light/cl_intersect.h deleted file mode 100644 index 35a48410ae3..00000000000 --- a/src/utils/xrDO_Light/cl_intersect.h +++ /dev/null @@ -1,747 +0,0 @@ -//--------------------------------------------------------------------------- -#ifndef intersectH -#define intersectH - -namespace CDB -{ - //---------------------------------------------------------------------- - // Name : intersectRaySphere() - // Input : rO - origin of ray in world space - // rV - _vector_ describing direction of ray in world space - // sO - Origin of sphere - // sR - radius of sphere - // Notes : Normalized directional vectors expected - // ----------------------------------------------------------------------- - IC bool IntersectRaySphere(const Fvector& rO, const Fvector& rV, const Fvector& sO, float sR) - { - Fvector Q; - Q.sub(sO,rO); - - float c = Q.magnitude(); - float v = Q.dotproduct(rV); - float d = sR*sR - (c*c - v*v); - - // If there was no intersection, return -1 - return (d > 0.0); - } - - //-- Ray-Triangle : 2nd level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector** p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0 || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0 || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - //-- Ray-Triangle : 1st level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector* p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0f || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0f || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - - //-- Ray-Triangle(always return range) : 1st level of indirection -------------------------------- - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector* p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector** p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - //--------------------------------------------------------------------------- - // macros for fast arithmetic - //--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- - // compare [-r,r] to [NdD+dt*NdW] -#define TESTV0(NdD, R) \ - if (NdD> R) return false;\ - else if (NdD<-R) return false; - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d0,p+d1},max{p,p+d0,p+d1}] -#define TESTV1(p,d0,d1,r){ \ - if ( (p) > (r) ){ \ - if ( (d0) >= 0.0f ){ \ - if ( (d1) >= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - } \ - }else if ( (d1) <= (d0) ){ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) > (r) ) \ - return false; \ - } \ - }else if ( (p) < -(r) ){ \ - if ( (d0) <= 0.0f ){ \ - if ( (d1) <= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - } \ - }else if ( (d1) >= (d0) ){ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) < -(r) ) \ - return false; \ - } \ - } \ - } - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d},max{p,p+d}] -#define TESTV2(p,d,r){ \ - if ( (p) > (r) ){ \ - if ( (d) >= 0.0f ){ return false; \ - }else{ if ( (p)+(d) > (r) ) return false; } \ - }else if ( (p) < -(r) ){ \ - if ( (d) <= 0.0f ){ return false; \ - }else{ if ( (p)+(d) < -(r) ) return false; } \ - } \ - } - //--------------------------------------------------------------------------- - - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector** p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(*p[1],*p[0]); - E[1].sub(*p[2],*p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(*p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector* p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(p[1],p[0]); - E[1].sub(p[2],p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - //---------------------------------------------------------------------------} - - //---------------------------------------------------------------------------- - IC float MgcSqrDistance (const Fvector& rkPoint, const Fvector& orig, const Fvector& e0,const Fvector& e1){ - - Fvector kDiff; - kDiff.sub(orig,rkPoint); - - float fA00 = e0.square_magnitude(); - float fA01 = e0.dotproduct(e1); - float fA11 = e1.square_magnitude(); - float fB0 = kDiff.dotproduct(e0); - float fB1 = kDiff.dotproduct(e1); - float fC = kDiff.square_magnitude(); - float fDet = _abs(fA00*fA11-fA01*fA01); - float fS = fA01*fB1-fA11*fB0; - float fT = fA01*fB0-fA00*fB1; - float fSqrDist; - - if ( fS + fT <= fDet ){ - if ( fS < 0.0f ){ - if ( fT < 0.0f ){ // region 4 - if ( fB0 < 0.0f ){ - fT = 0.0f; - if ( -fB0 >= fA00 ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else{ // region 3 - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0f ){ // region 5 - fT = 0.0f; - if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else if ( -fB0 >= fA00 ){ - fS = 1.0; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ // region 0 - // minimum at interior point - float fInvDet = 1.0f/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - float fTmp0, fTmp1, fNumer, fDenom; - - if ( fS < 0.0f ){ // region 2 - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fS = 0.0f; - if ( fTmp1 <= 0.0f ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0 ){ // region 6 - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fT = 1.0f; - fS = 0.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = fNumer/fDenom; - fS = 1.0f - fT; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fT = 0.0f; - if ( fTmp1 <= 0.0f ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - } - }else{ // region 1 - fNumer = fA11 + fB1 - fA01 - fB0; - if ( fNumer <= 0.0f ){ - fS = 0.0f; - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - } - } - } - - return _abs(fSqrDist); - } - - enum EST_Result{ - stNone = 0, - stIntersect = 1, - stInside = 2, - }; - - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, - const Fvector& orig, const Fvector& e0,const Fvector& e1) - { - - float fRSqr = sphereRadius*sphereRadius; - Fvector kV0mC; - kV0mC.sub(orig, sphereOrigin); - - // count the number of triangle vertices inside the sphere - int iInside = 0; - - // test if v0 is inside the sphere - if ( kV0mC.square_magnitude() <= fRSqr ) - iInside++; - - // test if v1 is inside the sphere - Fvector kDiff; - kDiff.add(kV0mC, e0); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // test if v2 is inside the sphere - kDiff.add(kV0mC, e1); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // triangle does not traversely intersect sphere - if ( iInside == 3 ) return stInside; - - // triangle transversely intersects sphere - if ( iInside > 0 ) return stIntersect; - - // All vertices are outside the sphere, but the triangle might still - // intersect the sphere. This is the case when the distance from the - // sphere center to the triangle is smaller than the radius. - float fSqrDist = MgcSqrDistance(sphereOrigin,orig,e0,e1); - return (fSqrDist < fRSqr)?stIntersect:stNone; - } - //--------------------------------------------------------------------------- - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector* p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(p[1], p[0]); - e1.sub(p[2], p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,p[0],e0,e1); - } - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector** p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(*p[1], *p[0]); - e1.sub(*p[2], *p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,*p[0],e0,e1); - } - IC bool TestSphereOBB(const Fsphere& rkSphere, const Fobb& rkBox) - { - // Test for intersection in the coordinate system of the box by - // transforming the sphere into that coordinate system. - Fvector3 kCDiff; - kCDiff.sub(rkSphere.P,rkBox.m_translate); - - float fAx = _abs(kCDiff.dotproduct(rkBox.m_rotate.i)); - float fAy = _abs(kCDiff.dotproduct(rkBox.m_rotate.j)); - float fAz = _abs(kCDiff.dotproduct(rkBox.m_rotate.k)); - float fDx = fAx - rkBox.m_halfsize[0]; - float fDy = fAy - rkBox.m_halfsize[1]; - float fDz = fAz - rkBox.m_halfsize[2]; - - if ( fAx <= rkBox.m_halfsize[0] ){ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // sphere center inside box - return true; - }else{ - // potential sphere-face intersection with face z - return fDz <= rkSphere.R; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face y - return fDy <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces y and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDy*fDy + fDz*fDz <= fRSqr; - } - } - }else{ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face x - return fDx <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces x and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDz*fDz <= fRSqr; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-edge intersection with edge formed - // by faces x and y - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy <= fRSqr; - }else{ - // potential sphere-vertex intersection at corner formed - // by faces x,y,z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr; - } - } - } - } - //---------------------------------------------------------------------------- - IC bool TestRayOBB (const Fvector3& origin, const Fvector3& direction, const Fobb& rkBox) - { - float fWdU[3], fAWdU[3], fDdU[3], fADdU[3], fAWxDdU[3], fRhs; - - Fvector3 kDiff; - kDiff.sub (origin,rkBox.m_translate); - - fWdU[0] = direction.dotproduct(rkBox.m_rotate.i); - fAWdU[0] = _abs(fWdU[0]); - fDdU[0] = kDiff.dotproduct(rkBox.m_rotate.i); - fADdU[0] = _abs(fDdU[0]); - if ( fADdU[0] > rkBox.m_halfsize[0] && fDdU[0]*fWdU[0] >= (float)0.0 ) - return false; - - fWdU[1] = direction.dotproduct(rkBox.m_rotate.j); - fAWdU[1] = _abs(fWdU[1]); - fDdU[1] = kDiff.dotproduct(rkBox.m_rotate.j); - fADdU[1] = _abs(fDdU[1]); - if ( fADdU[1] > rkBox.m_halfsize[1] && fDdU[1]*fWdU[1] >= (float)0.0 ) - return false; - - fWdU[2] = direction.dotproduct(rkBox.m_rotate.k); - fAWdU[2] = _abs(fWdU[2]); - fDdU[2] = kDiff.dotproduct(rkBox.m_rotate.k); - fADdU[2] = _abs(fDdU[2]); - if ( fADdU[2] > rkBox.m_halfsize[2] && fDdU[2]*fWdU[2] >= (float)0.0 ) - return false; - - Fvector3 kWxD; - kWxD.crossproduct(direction,kDiff); - - fAWxDdU[0] = _abs(kWxD.dotproduct(rkBox.m_rotate.i)); - fRhs = rkBox.m_halfsize[1]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[1]; - if ( fAWxDdU[0] > fRhs ) - return false; - - fAWxDdU[1] = _abs(kWxD.dotproduct(rkBox.m_rotate.j)); - fRhs = rkBox.m_halfsize[0]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[0]; - if ( fAWxDdU[1] > fRhs ) - return false; - - fAWxDdU[2] = _abs(kWxD.dotproduct(rkBox.m_rotate.k)); - fRhs = rkBox.m_halfsize[0]*fAWdU[1] + rkBox.m_halfsize[1]*fAWdU[0]; - if ( fAWxDdU[2] > fRhs ) - return false; - - return true; - } -//---------------------------------------------------------------------------- -}; - - -#endif diff --git a/src/utils/xrLC/cl_intersect.h b/src/utils/xrLC/cl_intersect.h deleted file mode 100644 index 35a48410ae3..00000000000 --- a/src/utils/xrLC/cl_intersect.h +++ /dev/null @@ -1,747 +0,0 @@ -//--------------------------------------------------------------------------- -#ifndef intersectH -#define intersectH - -namespace CDB -{ - //---------------------------------------------------------------------- - // Name : intersectRaySphere() - // Input : rO - origin of ray in world space - // rV - _vector_ describing direction of ray in world space - // sO - Origin of sphere - // sR - radius of sphere - // Notes : Normalized directional vectors expected - // ----------------------------------------------------------------------- - IC bool IntersectRaySphere(const Fvector& rO, const Fvector& rV, const Fvector& sO, float sR) - { - Fvector Q; - Q.sub(sO,rO); - - float c = Q.magnitude(); - float v = Q.dotproduct(rV); - float d = sR*sR - (c*c - v*v); - - // If there was no intersection, return -1 - return (d > 0.0); - } - - //-- Ray-Triangle : 2nd level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector** p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0 || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0 || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - //-- Ray-Triangle : 1st level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector* p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0f || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0f || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - - //-- Ray-Triangle(always return range) : 1st level of indirection -------------------------------- - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector* p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector** p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - //--------------------------------------------------------------------------- - // macros for fast arithmetic - //--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- - // compare [-r,r] to [NdD+dt*NdW] -#define TESTV0(NdD, R) \ - if (NdD> R) return false;\ - else if (NdD<-R) return false; - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d0,p+d1},max{p,p+d0,p+d1}] -#define TESTV1(p,d0,d1,r){ \ - if ( (p) > (r) ){ \ - if ( (d0) >= 0.0f ){ \ - if ( (d1) >= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - } \ - }else if ( (d1) <= (d0) ){ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) > (r) ) \ - return false; \ - } \ - }else if ( (p) < -(r) ){ \ - if ( (d0) <= 0.0f ){ \ - if ( (d1) <= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - } \ - }else if ( (d1) >= (d0) ){ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) < -(r) ) \ - return false; \ - } \ - } \ - } - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d},max{p,p+d}] -#define TESTV2(p,d,r){ \ - if ( (p) > (r) ){ \ - if ( (d) >= 0.0f ){ return false; \ - }else{ if ( (p)+(d) > (r) ) return false; } \ - }else if ( (p) < -(r) ){ \ - if ( (d) <= 0.0f ){ return false; \ - }else{ if ( (p)+(d) < -(r) ) return false; } \ - } \ - } - //--------------------------------------------------------------------------- - - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector** p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(*p[1],*p[0]); - E[1].sub(*p[2],*p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(*p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector* p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(p[1],p[0]); - E[1].sub(p[2],p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - //---------------------------------------------------------------------------} - - //---------------------------------------------------------------------------- - IC float MgcSqrDistance (const Fvector& rkPoint, const Fvector& orig, const Fvector& e0,const Fvector& e1){ - - Fvector kDiff; - kDiff.sub(orig,rkPoint); - - float fA00 = e0.square_magnitude(); - float fA01 = e0.dotproduct(e1); - float fA11 = e1.square_magnitude(); - float fB0 = kDiff.dotproduct(e0); - float fB1 = kDiff.dotproduct(e1); - float fC = kDiff.square_magnitude(); - float fDet = _abs(fA00*fA11-fA01*fA01); - float fS = fA01*fB1-fA11*fB0; - float fT = fA01*fB0-fA00*fB1; - float fSqrDist; - - if ( fS + fT <= fDet ){ - if ( fS < 0.0f ){ - if ( fT < 0.0f ){ // region 4 - if ( fB0 < 0.0f ){ - fT = 0.0f; - if ( -fB0 >= fA00 ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else{ // region 3 - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0f ){ // region 5 - fT = 0.0f; - if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else if ( -fB0 >= fA00 ){ - fS = 1.0; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ // region 0 - // minimum at interior point - float fInvDet = 1.0f/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - float fTmp0, fTmp1, fNumer, fDenom; - - if ( fS < 0.0f ){ // region 2 - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fS = 0.0f; - if ( fTmp1 <= 0.0f ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0 ){ // region 6 - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fT = 1.0f; - fS = 0.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = fNumer/fDenom; - fS = 1.0f - fT; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fT = 0.0f; - if ( fTmp1 <= 0.0f ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - } - }else{ // region 1 - fNumer = fA11 + fB1 - fA01 - fB0; - if ( fNumer <= 0.0f ){ - fS = 0.0f; - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - } - } - } - - return _abs(fSqrDist); - } - - enum EST_Result{ - stNone = 0, - stIntersect = 1, - stInside = 2, - }; - - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, - const Fvector& orig, const Fvector& e0,const Fvector& e1) - { - - float fRSqr = sphereRadius*sphereRadius; - Fvector kV0mC; - kV0mC.sub(orig, sphereOrigin); - - // count the number of triangle vertices inside the sphere - int iInside = 0; - - // test if v0 is inside the sphere - if ( kV0mC.square_magnitude() <= fRSqr ) - iInside++; - - // test if v1 is inside the sphere - Fvector kDiff; - kDiff.add(kV0mC, e0); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // test if v2 is inside the sphere - kDiff.add(kV0mC, e1); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // triangle does not traversely intersect sphere - if ( iInside == 3 ) return stInside; - - // triangle transversely intersects sphere - if ( iInside > 0 ) return stIntersect; - - // All vertices are outside the sphere, but the triangle might still - // intersect the sphere. This is the case when the distance from the - // sphere center to the triangle is smaller than the radius. - float fSqrDist = MgcSqrDistance(sphereOrigin,orig,e0,e1); - return (fSqrDist < fRSqr)?stIntersect:stNone; - } - //--------------------------------------------------------------------------- - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector* p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(p[1], p[0]); - e1.sub(p[2], p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,p[0],e0,e1); - } - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector** p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(*p[1], *p[0]); - e1.sub(*p[2], *p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,*p[0],e0,e1); - } - IC bool TestSphereOBB(const Fsphere& rkSphere, const Fobb& rkBox) - { - // Test for intersection in the coordinate system of the box by - // transforming the sphere into that coordinate system. - Fvector3 kCDiff; - kCDiff.sub(rkSphere.P,rkBox.m_translate); - - float fAx = _abs(kCDiff.dotproduct(rkBox.m_rotate.i)); - float fAy = _abs(kCDiff.dotproduct(rkBox.m_rotate.j)); - float fAz = _abs(kCDiff.dotproduct(rkBox.m_rotate.k)); - float fDx = fAx - rkBox.m_halfsize[0]; - float fDy = fAy - rkBox.m_halfsize[1]; - float fDz = fAz - rkBox.m_halfsize[2]; - - if ( fAx <= rkBox.m_halfsize[0] ){ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // sphere center inside box - return true; - }else{ - // potential sphere-face intersection with face z - return fDz <= rkSphere.R; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face y - return fDy <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces y and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDy*fDy + fDz*fDz <= fRSqr; - } - } - }else{ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face x - return fDx <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces x and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDz*fDz <= fRSqr; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-edge intersection with edge formed - // by faces x and y - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy <= fRSqr; - }else{ - // potential sphere-vertex intersection at corner formed - // by faces x,y,z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr; - } - } - } - } - //---------------------------------------------------------------------------- - IC bool TestRayOBB (const Fvector3& origin, const Fvector3& direction, const Fobb& rkBox) - { - float fWdU[3], fAWdU[3], fDdU[3], fADdU[3], fAWxDdU[3], fRhs; - - Fvector3 kDiff; - kDiff.sub (origin,rkBox.m_translate); - - fWdU[0] = direction.dotproduct(rkBox.m_rotate.i); - fAWdU[0] = _abs(fWdU[0]); - fDdU[0] = kDiff.dotproduct(rkBox.m_rotate.i); - fADdU[0] = _abs(fDdU[0]); - if ( fADdU[0] > rkBox.m_halfsize[0] && fDdU[0]*fWdU[0] >= (float)0.0 ) - return false; - - fWdU[1] = direction.dotproduct(rkBox.m_rotate.j); - fAWdU[1] = _abs(fWdU[1]); - fDdU[1] = kDiff.dotproduct(rkBox.m_rotate.j); - fADdU[1] = _abs(fDdU[1]); - if ( fADdU[1] > rkBox.m_halfsize[1] && fDdU[1]*fWdU[1] >= (float)0.0 ) - return false; - - fWdU[2] = direction.dotproduct(rkBox.m_rotate.k); - fAWdU[2] = _abs(fWdU[2]); - fDdU[2] = kDiff.dotproduct(rkBox.m_rotate.k); - fADdU[2] = _abs(fDdU[2]); - if ( fADdU[2] > rkBox.m_halfsize[2] && fDdU[2]*fWdU[2] >= (float)0.0 ) - return false; - - Fvector3 kWxD; - kWxD.crossproduct(direction,kDiff); - - fAWxDdU[0] = _abs(kWxD.dotproduct(rkBox.m_rotate.i)); - fRhs = rkBox.m_halfsize[1]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[1]; - if ( fAWxDdU[0] > fRhs ) - return false; - - fAWxDdU[1] = _abs(kWxD.dotproduct(rkBox.m_rotate.j)); - fRhs = rkBox.m_halfsize[0]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[0]; - if ( fAWxDdU[1] > fRhs ) - return false; - - fAWxDdU[2] = _abs(kWxD.dotproduct(rkBox.m_rotate.k)); - fRhs = rkBox.m_halfsize[0]*fAWdU[1] + rkBox.m_halfsize[1]*fAWdU[0]; - if ( fAWxDdU[2] > fRhs ) - return false; - - return true; - } -//---------------------------------------------------------------------------- -}; - - -#endif diff --git a/src/utils/xrLC/xrLC.vcxproj b/src/utils/xrLC/xrLC.vcxproj index cfd975bc8a0..41c31ce2901 100644 --- a/src/utils/xrLC/xrLC.vcxproj +++ b/src/utils/xrLC/xrLC.vcxproj @@ -236,7 +236,6 @@ - diff --git a/src/utils/xrLC/xrLC.vcxproj.filters b/src/utils/xrLC/xrLC.vcxproj.filters index 52e0a3aea24..f405f4f4073 100644 --- a/src/utils/xrLC/xrLC.vcxproj.filters +++ b/src/utils/xrLC/xrLC.vcxproj.filters @@ -69,9 +69,6 @@ Kernel\Log - - CDB - External diff --git a/src/utils/xrLC_Light/cl_intersect.h b/src/utils/xrLC_Light/cl_intersect.h deleted file mode 100644 index 35a48410ae3..00000000000 --- a/src/utils/xrLC_Light/cl_intersect.h +++ /dev/null @@ -1,747 +0,0 @@ -//--------------------------------------------------------------------------- -#ifndef intersectH -#define intersectH - -namespace CDB -{ - //---------------------------------------------------------------------- - // Name : intersectRaySphere() - // Input : rO - origin of ray in world space - // rV - _vector_ describing direction of ray in world space - // sO - Origin of sphere - // sR - radius of sphere - // Notes : Normalized directional vectors expected - // ----------------------------------------------------------------------- - IC bool IntersectRaySphere(const Fvector& rO, const Fvector& rV, const Fvector& sO, float sR) - { - Fvector Q; - Q.sub(sO,rO); - - float c = Q.magnitude(); - float v = Q.dotproduct(rV); - float d = sR*sR - (c*c - v*v); - - // If there was no intersection, return -1 - return (d > 0.0); - } - - //-- Ray-Triangle : 2nd level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector** p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0 || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0 || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - //-- Ray-Triangle : 1st level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector* p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0f || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0f || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - - //-- Ray-Triangle(always return range) : 1st level of indirection -------------------------------- - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector* p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector** p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - //--------------------------------------------------------------------------- - // macros for fast arithmetic - //--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- - // compare [-r,r] to [NdD+dt*NdW] -#define TESTV0(NdD, R) \ - if (NdD> R) return false;\ - else if (NdD<-R) return false; - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d0,p+d1},max{p,p+d0,p+d1}] -#define TESTV1(p,d0,d1,r){ \ - if ( (p) > (r) ){ \ - if ( (d0) >= 0.0f ){ \ - if ( (d1) >= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - } \ - }else if ( (d1) <= (d0) ){ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) > (r) ) \ - return false; \ - } \ - }else if ( (p) < -(r) ){ \ - if ( (d0) <= 0.0f ){ \ - if ( (d1) <= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - } \ - }else if ( (d1) >= (d0) ){ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) < -(r) ) \ - return false; \ - } \ - } \ - } - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d},max{p,p+d}] -#define TESTV2(p,d,r){ \ - if ( (p) > (r) ){ \ - if ( (d) >= 0.0f ){ return false; \ - }else{ if ( (p)+(d) > (r) ) return false; } \ - }else if ( (p) < -(r) ){ \ - if ( (d) <= 0.0f ){ return false; \ - }else{ if ( (p)+(d) < -(r) ) return false; } \ - } \ - } - //--------------------------------------------------------------------------- - - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector** p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(*p[1],*p[0]); - E[1].sub(*p[2],*p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(*p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector* p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(p[1],p[0]); - E[1].sub(p[2],p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - //---------------------------------------------------------------------------} - - //---------------------------------------------------------------------------- - IC float MgcSqrDistance (const Fvector& rkPoint, const Fvector& orig, const Fvector& e0,const Fvector& e1){ - - Fvector kDiff; - kDiff.sub(orig,rkPoint); - - float fA00 = e0.square_magnitude(); - float fA01 = e0.dotproduct(e1); - float fA11 = e1.square_magnitude(); - float fB0 = kDiff.dotproduct(e0); - float fB1 = kDiff.dotproduct(e1); - float fC = kDiff.square_magnitude(); - float fDet = _abs(fA00*fA11-fA01*fA01); - float fS = fA01*fB1-fA11*fB0; - float fT = fA01*fB0-fA00*fB1; - float fSqrDist; - - if ( fS + fT <= fDet ){ - if ( fS < 0.0f ){ - if ( fT < 0.0f ){ // region 4 - if ( fB0 < 0.0f ){ - fT = 0.0f; - if ( -fB0 >= fA00 ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else{ // region 3 - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0f ){ // region 5 - fT = 0.0f; - if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else if ( -fB0 >= fA00 ){ - fS = 1.0; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ // region 0 - // minimum at interior point - float fInvDet = 1.0f/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - float fTmp0, fTmp1, fNumer, fDenom; - - if ( fS < 0.0f ){ // region 2 - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fS = 0.0f; - if ( fTmp1 <= 0.0f ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0 ){ // region 6 - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fT = 1.0f; - fS = 0.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = fNumer/fDenom; - fS = 1.0f - fT; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fT = 0.0f; - if ( fTmp1 <= 0.0f ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - } - }else{ // region 1 - fNumer = fA11 + fB1 - fA01 - fB0; - if ( fNumer <= 0.0f ){ - fS = 0.0f; - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - } - } - } - - return _abs(fSqrDist); - } - - enum EST_Result{ - stNone = 0, - stIntersect = 1, - stInside = 2, - }; - - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, - const Fvector& orig, const Fvector& e0,const Fvector& e1) - { - - float fRSqr = sphereRadius*sphereRadius; - Fvector kV0mC; - kV0mC.sub(orig, sphereOrigin); - - // count the number of triangle vertices inside the sphere - int iInside = 0; - - // test if v0 is inside the sphere - if ( kV0mC.square_magnitude() <= fRSqr ) - iInside++; - - // test if v1 is inside the sphere - Fvector kDiff; - kDiff.add(kV0mC, e0); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // test if v2 is inside the sphere - kDiff.add(kV0mC, e1); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // triangle does not traversely intersect sphere - if ( iInside == 3 ) return stInside; - - // triangle transversely intersects sphere - if ( iInside > 0 ) return stIntersect; - - // All vertices are outside the sphere, but the triangle might still - // intersect the sphere. This is the case when the distance from the - // sphere center to the triangle is smaller than the radius. - float fSqrDist = MgcSqrDistance(sphereOrigin,orig,e0,e1); - return (fSqrDist < fRSqr)?stIntersect:stNone; - } - //--------------------------------------------------------------------------- - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector* p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(p[1], p[0]); - e1.sub(p[2], p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,p[0],e0,e1); - } - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector** p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(*p[1], *p[0]); - e1.sub(*p[2], *p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,*p[0],e0,e1); - } - IC bool TestSphereOBB(const Fsphere& rkSphere, const Fobb& rkBox) - { - // Test for intersection in the coordinate system of the box by - // transforming the sphere into that coordinate system. - Fvector3 kCDiff; - kCDiff.sub(rkSphere.P,rkBox.m_translate); - - float fAx = _abs(kCDiff.dotproduct(rkBox.m_rotate.i)); - float fAy = _abs(kCDiff.dotproduct(rkBox.m_rotate.j)); - float fAz = _abs(kCDiff.dotproduct(rkBox.m_rotate.k)); - float fDx = fAx - rkBox.m_halfsize[0]; - float fDy = fAy - rkBox.m_halfsize[1]; - float fDz = fAz - rkBox.m_halfsize[2]; - - if ( fAx <= rkBox.m_halfsize[0] ){ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // sphere center inside box - return true; - }else{ - // potential sphere-face intersection with face z - return fDz <= rkSphere.R; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face y - return fDy <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces y and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDy*fDy + fDz*fDz <= fRSqr; - } - } - }else{ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face x - return fDx <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces x and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDz*fDz <= fRSqr; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-edge intersection with edge formed - // by faces x and y - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy <= fRSqr; - }else{ - // potential sphere-vertex intersection at corner formed - // by faces x,y,z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr; - } - } - } - } - //---------------------------------------------------------------------------- - IC bool TestRayOBB (const Fvector3& origin, const Fvector3& direction, const Fobb& rkBox) - { - float fWdU[3], fAWdU[3], fDdU[3], fADdU[3], fAWxDdU[3], fRhs; - - Fvector3 kDiff; - kDiff.sub (origin,rkBox.m_translate); - - fWdU[0] = direction.dotproduct(rkBox.m_rotate.i); - fAWdU[0] = _abs(fWdU[0]); - fDdU[0] = kDiff.dotproduct(rkBox.m_rotate.i); - fADdU[0] = _abs(fDdU[0]); - if ( fADdU[0] > rkBox.m_halfsize[0] && fDdU[0]*fWdU[0] >= (float)0.0 ) - return false; - - fWdU[1] = direction.dotproduct(rkBox.m_rotate.j); - fAWdU[1] = _abs(fWdU[1]); - fDdU[1] = kDiff.dotproduct(rkBox.m_rotate.j); - fADdU[1] = _abs(fDdU[1]); - if ( fADdU[1] > rkBox.m_halfsize[1] && fDdU[1]*fWdU[1] >= (float)0.0 ) - return false; - - fWdU[2] = direction.dotproduct(rkBox.m_rotate.k); - fAWdU[2] = _abs(fWdU[2]); - fDdU[2] = kDiff.dotproduct(rkBox.m_rotate.k); - fADdU[2] = _abs(fDdU[2]); - if ( fADdU[2] > rkBox.m_halfsize[2] && fDdU[2]*fWdU[2] >= (float)0.0 ) - return false; - - Fvector3 kWxD; - kWxD.crossproduct(direction,kDiff); - - fAWxDdU[0] = _abs(kWxD.dotproduct(rkBox.m_rotate.i)); - fRhs = rkBox.m_halfsize[1]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[1]; - if ( fAWxDdU[0] > fRhs ) - return false; - - fAWxDdU[1] = _abs(kWxD.dotproduct(rkBox.m_rotate.j)); - fRhs = rkBox.m_halfsize[0]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[0]; - if ( fAWxDdU[1] > fRhs ) - return false; - - fAWxDdU[2] = _abs(kWxD.dotproduct(rkBox.m_rotate.k)); - fRhs = rkBox.m_halfsize[0]*fAWdU[1] + rkBox.m_halfsize[1]*fAWdU[0]; - if ( fAWxDdU[2] > fRhs ) - return false; - - return true; - } -//---------------------------------------------------------------------------- -}; - - -#endif diff --git a/src/utils/xrLC_Light/detail_slot_calculate.cpp b/src/utils/xrLC_Light/detail_slot_calculate.cpp index 4904b2bee24..d0dd0c5ab0d 100644 --- a/src/utils/xrLC_Light/detail_slot_calculate.cpp +++ b/src/utils/xrLC_Light/detail_slot_calculate.cpp @@ -7,7 +7,7 @@ #include "stdafx.h" #include "detail_slot_calculate.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "base_lighting.h" #include "global_calculation_data.h" #include "../shader_xrlc.h" diff --git a/src/utils/xrLC_Light/xrDeflectorLight.cpp b/src/utils/xrLC_Light/xrDeflectorLight.cpp index 3114d5a6347..cd18fa6d7d6 100644 --- a/src/utils/xrLC_Light/xrDeflectorLight.cpp +++ b/src/utils/xrLC_Light/xrDeflectorLight.cpp @@ -2,7 +2,7 @@ #include "xrdeflector.h" //#include "build.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "xrlc_globaldata.h" //#include "std_classes.h" #include "xrImage_Resampler.h" diff --git a/src/xrEngine/cl_intersect.h b/src/xrCDB/Intersect.hpp similarity index 100% rename from src/xrEngine/cl_intersect.h rename to src/xrCDB/Intersect.hpp diff --git a/src/xrCDB/cl_raypick.cpp b/src/xrCDB/cl_raypick.cpp index 3f21366d568..b02a56c84bf 100644 --- a/src/xrCDB/cl_raypick.cpp +++ b/src/xrCDB/cl_raypick.cpp @@ -3,7 +3,7 @@ #include "cl_RAPID.h" #include "cl_defs.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #ifdef ENGINE_BUILD #define R_BEGIN Device.Statistic->clRAY.Begin() diff --git a/src/xrCDB/xrCDB.vcxproj b/src/xrCDB/xrCDB.vcxproj index 948c0165156..276d5dcc220 100644 --- a/src/xrCDB/xrCDB.vcxproj +++ b/src/xrCDB/xrCDB.vcxproj @@ -338,6 +338,7 @@ + diff --git a/src/xrCDB/xrCDB.vcxproj.filters b/src/xrCDB/xrCDB.vcxproj.filters index 3949ff823da..3c30272e75e 100644 --- a/src/xrCDB/xrCDB.vcxproj.filters +++ b/src/xrCDB/xrCDB.vcxproj.filters @@ -272,6 +272,9 @@ engine + + Kernel + diff --git a/src/xrCDB/xr_area_raypick.cpp b/src/xrCDB/xr_area_raypick.cpp index 69d10000e64..3850b6b5810 100644 --- a/src/xrCDB/xr_area_raypick.cpp +++ b/src/xrCDB/xr_area_raypick.cpp @@ -3,7 +3,7 @@ #include "ispatial.h" #include "../xrengine/xr_collide_form.h" #include "../xrengine/xr_object.h" -#include "../xrengine/cl_intersect.h" +#include "Intersect.hpp" #include "d3d9types.h" //#include "igame_level.h" //#include "x_ray.h" diff --git a/src/xrEngine/Feel_Vision.cpp b/src/xrEngine/Feel_Vision.cpp index 69759ed1052..92790c7b095 100644 --- a/src/xrEngine/Feel_Vision.cpp +++ b/src/xrEngine/Feel_Vision.cpp @@ -4,7 +4,7 @@ #include "xr_object.h" #include "xr_collide_form.h" #include "igame_level.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" namespace Feel { diff --git a/src/xrEngine/xrEngine.vcxproj b/src/xrEngine/xrEngine.vcxproj index 0452770014e..627acb14a33 100644 --- a/src/xrEngine/xrEngine.vcxproj +++ b/src/xrEngine/xrEngine.vcxproj @@ -445,7 +445,6 @@ - diff --git a/src/xrEngine/xrEngine.vcxproj.filters b/src/xrEngine/xrEngine.vcxproj.filters index f498a3eaeb6..67872fe90df 100644 --- a/src/xrEngine/xrEngine.vcxproj.filters +++ b/src/xrEngine/xrEngine.vcxproj.filters @@ -100,9 +100,6 @@ {cd9ac8cb-af4e-4084-968c-98b28d708e33} - - {27ef9226-06f1-48a5-adc5-40991aa22c05} - {0f1086cd-e02a-4030-ae77-22e04fa5cf74} @@ -444,9 +441,6 @@ Engine - - Engine\Collision Core - Engine\Console diff --git a/src/xrEngine/xr_efflensflare.cpp b/src/xrEngine/xr_efflensflare.cpp index dda976402f7..34390fb2800 100644 --- a/src/xrEngine/xr_efflensflare.cpp +++ b/src/xrEngine/xr_efflensflare.cpp @@ -9,7 +9,7 @@ // Instead of SkeletonCustom: #include "xrCore/Animation/Bone.hpp" #include "Include/xrRender/Kinematics.h" -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "xrServerEntities/object_broker.h" diff --git a/src/xrGame/Actor.cpp b/src/xrGame/Actor.cpp index 57e39eba454..d577f8d5270 100644 --- a/src/xrGame/Actor.cpp +++ b/src/xrGame/Actor.cpp @@ -46,7 +46,7 @@ #include "xrmessages.h" #include "string_table.h" #include "usablescriptobject.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" //#include "ExtendedGeom.h" #include "alife_registry_wrappers.h" #include "../Include/xrRender/Kinematics.h" diff --git a/src/xrGame/ActorCameras.cpp b/src/xrGame/ActorCameras.cpp index 89ef90af0e5..7fc7de15e7c 100644 --- a/src/xrGame/ActorCameras.cpp +++ b/src/xrGame/ActorCameras.cpp @@ -14,7 +14,7 @@ #include "SleepEffector.h" #include "ActorEffector.h" #include "level.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" //#include "elevatorstate.h" #include "CharacterPhysicsSupport.h" diff --git a/src/xrGame/DynamicHeightMap.cpp b/src/xrGame/DynamicHeightMap.cpp index 62be41b2570..b168e830933 100644 --- a/src/xrGame/DynamicHeightMap.cpp +++ b/src/xrGame/DynamicHeightMap.cpp @@ -4,7 +4,7 @@ #include "stdafx.h" #include "DynamicHeightMap.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" const int tasksPerFrame = 1; const float limit_up = 100.f; diff --git a/src/xrGame/PHMovementControl.cpp b/src/xrGame/PHMovementControl.cpp index fdb0c97d0d9..9d5fa24ac3f 100644 --- a/src/xrGame/PHMovementControl.cpp +++ b/src/xrGame/PHMovementControl.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "phmovementcontrol.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "../xrserverentities/alife_space.h" //#include "entity.h" diff --git a/src/xrGame/ik_foot_collider.cpp b/src/xrGame/ik_foot_collider.cpp index 1a861ec4769..019396602ce 100644 --- a/src/xrGame/ik_foot_collider.cpp +++ b/src/xrGame/ik_foot_collider.cpp @@ -2,7 +2,7 @@ #include "ik_foot_collider.h" #include "xrEngine/GameMtlLib.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "../include/xrrender/Kinematics.h" #include "Level.h" diff --git a/src/xrPhysics/PHAICharacter.cpp b/src/xrPhysics/PHAICharacter.cpp index 07f0cd422c6..4eca3a77990 100644 --- a/src/xrPhysics/PHAICharacter.cpp +++ b/src/xrPhysics/PHAICharacter.cpp @@ -4,7 +4,7 @@ #include "PHDynamicData.h" #include "Physics.h" #include "ExtendedGeom.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "tri-colliderKNoOPC\__aabb_tri.h" #include "phaicharacter.h" diff --git a/src/xrPhysics/PHCharacter.cpp b/src/xrPhysics/PHCharacter.cpp index cd7a1b9f5fe..8503a2acdb1 100644 --- a/src/xrPhysics/PHCharacter.cpp +++ b/src/xrPhysics/PHCharacter.cpp @@ -6,7 +6,7 @@ #include "ExtendedGeom.h" #include "iphysicsshellholder.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "xrEngine/GameMtlLib.h" #include "tri-colliderKNoOPC\__aabb_tri.h" diff --git a/src/xrPhysics/PHSimpleCharacter.cpp b/src/xrPhysics/PHSimpleCharacter.cpp index 541c89be3d8..713a02a3554 100644 --- a/src/xrPhysics/PHSimpleCharacter.cpp +++ b/src/xrPhysics/PHSimpleCharacter.cpp @@ -2,7 +2,7 @@ #include "PHDynamicData.h" #include "ExtendedGeom.h" -#include "../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "../xrEngine/xr_object_list.h" #include "tri-colliderKNoOPC\__aabb_tri.h" #include "PHSimpleCharacter.h" diff --git a/src/xrPhysics/tri-colliderknoopc/dcTriListCollider.cpp b/src/xrPhysics/tri-colliderknoopc/dcTriListCollider.cpp index 10bbbd3a54d..8616ba2166c 100644 --- a/src/xrPhysics/tri-colliderknoopc/dcTriListCollider.cpp +++ b/src/xrPhysics/tri-colliderknoopc/dcTriListCollider.cpp @@ -1,7 +1,7 @@ // Do NOT build this file seperately. It is included in dTriList.cpp automatically. -#include "../../xrEngine/cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "dTriCollideK.h" #include "dSortTriPrimitive.h" #include "../dCylinder/dCylinder.h" diff --git a/src/xrSound/SoundRender_Core_Processor.cpp b/src/xrSound/SoundRender_Core_Processor.cpp index 0320742e90b..3bcb94d3458 100644 --- a/src/xrSound/SoundRender_Core_Processor.cpp +++ b/src/xrSound/SoundRender_Core_Processor.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #pragma hdrstop -#include "cl_intersect.h" +#include "xrCDB/Intersect.hpp" #include "SoundRender_Core.h" #include "SoundRender_Emitter.h" #include "SoundRender_Target.h" diff --git a/src/xrSound/cl_intersect.h b/src/xrSound/cl_intersect.h deleted file mode 100644 index 35a48410ae3..00000000000 --- a/src/xrSound/cl_intersect.h +++ /dev/null @@ -1,747 +0,0 @@ -//--------------------------------------------------------------------------- -#ifndef intersectH -#define intersectH - -namespace CDB -{ - //---------------------------------------------------------------------- - // Name : intersectRaySphere() - // Input : rO - origin of ray in world space - // rV - _vector_ describing direction of ray in world space - // sO - Origin of sphere - // sR - radius of sphere - // Notes : Normalized directional vectors expected - // ----------------------------------------------------------------------- - IC bool IntersectRaySphere(const Fvector& rO, const Fvector& rV, const Fvector& sO, float sR) - { - Fvector Q; - Q.sub(sO,rO); - - float c = Q.magnitude(); - float v = Q.dotproduct(rV); - float d = sR*sR - (c*c - v*v); - - // If there was no intersection, return -1 - return (d > 0.0); - } - - //-- Ray-Triangle : 2nd level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector** p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0 || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0 || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - //-- Ray-Triangle : 1st level of indirection -------------------------------- - IC bool TestRayTri(const Fvector& C, const Fvector& D, Fvector* p, float& u, float& v, float& range, bool bCull) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det; - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - if (bCull){ // define TEST_CULL if culling is desired - if (det < EPS) return false; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec); // calculate U parameter and test bounds - if (u < 0.0f || u > det) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec); // calculate V parameter and test bounds - if (v < 0.0f || u + v > det) return false; - range = edge2.dotproduct(qvec); // calculate t, scale parameters, ray intersects triangle - inv_det = 1.0f / det; - range *= inv_det; - u *= inv_det; - v *= inv_det; - }else{ // the non-culling branch - if (det > -EPS && det < EPS) return false; - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - if (u < 0.0f || u > 1.0f) return false; - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects triangle - } - return true; - } - - //-- Ray-Triangle(always return range) : 1st level of indirection -------------------------------- - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector* p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(p[1], p[0]); - edge2.sub(p[2], p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - IC bool TestRayTri2(const Fvector& C, const Fvector& D, Fvector** p, float& range) - { - Fvector edge1, edge2, tvec, pvec, qvec; - float det,inv_det,u,v; - - // find vectors for two edges sharing vert0 - edge1.sub(*p[1], *p[0]); - edge2.sub(*p[2], *p[0]); - // begin calculating determinant - also used to calculate U parameter - pvec.crossproduct(D, edge2); - // if determinant is near zero, ray lies in plane of triangle - det = edge1.dotproduct(pvec); - - if (_abs(det) < EPS_S) { range=-1; return false; } - inv_det = 1.0f / det; - tvec.sub(C, *p[0]); // calculate distance from vert0 to ray origin - u = tvec.dotproduct(pvec)*inv_det; // calculate U parameter and test bounds - qvec.crossproduct(tvec, edge1); // prepare to test V parameter - range = edge2.dotproduct(qvec)*inv_det;// calculate t, ray intersects plane - if (u < 0.0f || u > 1.0f) return false; - v = D.dotproduct(qvec)*inv_det; // calculate V parameter and test bounds - if (v < 0.0f || u + v > 1.0f) return false; - return true; - } - //--------------------------------------------------------------------------- - // macros for fast arithmetic - //--------------------------------------------------------------------------- - //--------------------------------------------------------------------------- - // compare [-r,r] to [NdD+dt*NdW] -#define TESTV0(NdD, R) \ - if (NdD> R) return false;\ - else if (NdD<-R) return false; - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d0,p+d1},max{p,p+d0,p+d1}] -#define TESTV1(p,d0,d1,r){ \ - if ( (p) > (r) ){ \ - if ( (d0) >= 0.0f ){ \ - if ( (d1) >= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - } \ - }else if ( (d1) <= (d0) ){ \ - if ( (p)+(d1) > (r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) > (r) ) \ - return false; \ - } \ - }else if ( (p) < -(r) ){ \ - if ( (d0) <= 0.0f ){ \ - if ( (d1) <= 0.0f ){ \ - return false; \ - }else{ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - } \ - }else if ( (d1) >= (d0) ){ \ - if ( (p)+(d1) < -(r) ) \ - return false; \ - }else{ \ - if ( (p)+(d0) < -(r) ) \ - return false; \ - } \ - } \ - } - //--------------------------------------------------------------------------- - // compare [-r,r] to [min{p,p+d},max{p,p+d}] -#define TESTV2(p,d,r){ \ - if ( (p) > (r) ){ \ - if ( (d) >= 0.0f ){ return false; \ - }else{ if ( (p)+(d) > (r) ) return false; } \ - }else if ( (p) < -(r) ){ \ - if ( (d) <= 0.0f ){ return false; \ - }else{ if ( (p)+(d) < -(r) ) return false; } \ - } \ - } - //--------------------------------------------------------------------------- - - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector** p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(*p[1],*p[0]); - E[1].sub(*p[2],*p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(*p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - IC bool TestBBoxTri(const Fmatrix33& A, const Fvector& T, const Fvector& extA, Fvector* p, BOOL bCulling){ - // construct triangle normal, difference of center and vertex (18 ops) - Fvector D, E[2], N; - E[0].sub(p[1],p[0]); - E[1].sub(p[2],p[0]); - N.crossproduct(E[0],E[1]); - - if (bCulling&&(A.k.dotproduct(N)>=0)) return false; - - D.sub(p[0],T); - - // axis C+t*N - float A0dN = A.i.dotproduct(N); - float A1dN = A.j.dotproduct(N); - float A2dN = A.k.dotproduct(N); - float R = _abs(extA.x*A0dN)+_abs(extA.y*A1dN)+_abs(extA.z*A2dN); - float NdD = N.dotproduct(D); - TESTV0(NdD,R); //AXIS_N - - // axis C+t*A0 - float A0dD = A.i.dotproduct(D); - float A0dE0 = A.i.dotproduct(E[0]); - float A0dE1 = A.i.dotproduct(E[1]); - TESTV1(A0dD,A0dE0,A0dE1,extA.x); //AXIS_A0 - - // axis C+t*A1 - float A1dD = A.j.dotproduct(D); - float A1dE0 = A.j.dotproduct(E[0]); - float A1dE1 = A.j.dotproduct(E[1]); - TESTV1(A1dD,A1dE0,A1dE1,extA.y); //AXIS_A1 - - // axis C+t*A2 - float A2dD = A.k.dotproduct(D); - float A2dE0 = A.k.dotproduct(E[0]); - float A2dE1 = A.k.dotproduct(E[1]); - TESTV1(A2dD,A2dE0,A2dE1,extA.z); //AXIS_A2 - - // axis C+t*A0xE0 - Fvector A0xE0; - A0xE0.crossproduct(A.i,E[0]); - float A0xE0dD = A0xE0.dotproduct(D); - R = _abs(extA.y*A2dE0)+_abs(extA.z*A1dE0); - TESTV2(A0xE0dD,A0dN,R); //AXIS_A0xE0 - - // axis C+t*A0xE1 - Fvector A0xE1; - A0xE1.crossproduct(A.i,E[1]); - float A0xE1dD = A0xE1.dotproduct(D); - R = _abs(extA.y*A2dE1)+_abs(extA.z*A1dE1); - TESTV2(A0xE1dD,-A0dN,R); //AXIS_A0xE1 - - // axis C+t*A0xE2 - float A1dE2 = A1dE1-A1dE0; - float A2dE2 = A2dE1-A2dE0; - float A0xE2dD = A0xE1dD-A0xE0dD; - R = _abs(extA.y*A2dE2)+_abs(extA.z*A1dE2); - TESTV2(A0xE2dD,-A0dN,R); //AXIS_A0xE2 - - // axis C+t*A1xE0 - Fvector A1xE0; - A1xE0.crossproduct(A.j,E[0]); - float A1xE0dD = A1xE0.dotproduct(D); - R = _abs(extA.x*A2dE0)+_abs(extA.z*A0dE0); - TESTV2(A1xE0dD,A1dN,R); //AXIS_A1xE0 - - // axis C+t*A1xE1 - Fvector A1xE1; - A1xE1.crossproduct(A.j,E[1]); - float A1xE1dD = A1xE1.dotproduct(D); - R = _abs(extA.x*A2dE1)+_abs(extA.z*A0dE1); - TESTV2(A1xE1dD,-A1dN,R); //AXIS_A1xE1 - - // axis C+t*A1xE2 - float A0dE2 = A0dE1-A0dE0; - float A1xE2dD = A1xE1dD-A1xE0dD; - R = _abs(extA.x*A2dE2)+_abs(extA.z*A0dE2); - TESTV2(A1xE2dD,-A1dN,R); //AXIS_A1xE2 - - // axis C+t*A2xE0 - Fvector A2xE0; - A2xE0.crossproduct(A.k,E[0]); - float A2xE0dD = A2xE0.dotproduct(D); - R = _abs(extA.x*A1dE0)+_abs(extA.y*A0dE0); - TESTV2(A2xE0dD,A2dN,R); //AXIS_A2xE0 - - // axis C+t*A2xE1 - Fvector A2xE1; - A2xE1.crossproduct(A.k,E[1]); - float A2xE1dD = A2xE1.dotproduct(D); - R = _abs(extA.x*A1dE1)+_abs(extA.y*A0dE1); - TESTV2(A2xE1dD,-A2dN,R); //AXIS_A2xE1 - - // axis C+t*A2xE2 - float A2xE2dD = A2xE1dD-A2xE0dD; - R = _abs(extA.x*A1dE2)+_abs(extA.y*A0dE2); - TESTV2(A2xE2dD,-A2dN,R); //AXIS_A2xE2 - - // intersection occurs - return true; - } - //---------------------------------------------------------------------------} - - //---------------------------------------------------------------------------- - IC float MgcSqrDistance (const Fvector& rkPoint, const Fvector& orig, const Fvector& e0,const Fvector& e1){ - - Fvector kDiff; - kDiff.sub(orig,rkPoint); - - float fA00 = e0.square_magnitude(); - float fA01 = e0.dotproduct(e1); - float fA11 = e1.square_magnitude(); - float fB0 = kDiff.dotproduct(e0); - float fB1 = kDiff.dotproduct(e1); - float fC = kDiff.square_magnitude(); - float fDet = _abs(fA00*fA11-fA01*fA01); - float fS = fA01*fB1-fA11*fB0; - float fT = fA01*fB0-fA00*fB1; - float fSqrDist; - - if ( fS + fT <= fDet ){ - if ( fS < 0.0f ){ - if ( fT < 0.0f ){ // region 4 - if ( fB0 < 0.0f ){ - fT = 0.0f; - if ( -fB0 >= fA00 ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else{ // region 3 - fS = 0.0f; - if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else if ( -fB1 >= fA11 ){ - fT = 1; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0f ){ // region 5 - fT = 0.0f; - if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else if ( -fB0 >= fA00 ){ - fS = 1.0; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - }else{ // region 0 - // minimum at interior point - float fInvDet = 1.0f/fDet; - fS *= fInvDet; - fT *= fInvDet; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - float fTmp0, fTmp1, fNumer, fDenom; - - if ( fS < 0.0f ){ // region 2 - fTmp0 = fA01 + fB0; - fTmp1 = fA11 + fB1; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fS = 0.0f; - if ( fTmp1 <= 0.0f ){ - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else if ( fB1 >= 0.0f ){ - fT = 0.0f; - fSqrDist = fC; - }else{ - fT = -fB1/fA11; - fSqrDist = fB1*fT+fC; - } - } - }else if ( fT < 0.0 ){ // region 6 - fTmp0 = fA01 + fB1; - fTmp1 = fA00 + fB0; - if ( fTmp1 > fTmp0 ){ - fNumer = fTmp1 - fTmp0; - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fT = 1.0f; - fS = 0.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fT = fNumer/fDenom; - fS = 1.0f - fT; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - }else{ - fT = 0.0f; - if ( fTmp1 <= 0.0f ){ - fS = 1.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else if ( fB0 >= 0.0f ){ - fS = 0.0f; - fSqrDist = fC; - }else{ - fS = -fB0/fA00; - fSqrDist = fB0*fS+fC; - } - } - }else{ // region 1 - fNumer = fA11 + fB1 - fA01 - fB0; - if ( fNumer <= 0.0f ){ - fS = 0.0f; - fT = 1.0f; - fSqrDist = fA11+2.0f*fB1+fC; - }else{ - fDenom = fA00-2.0f*fA01+fA11; - if ( fNumer >= fDenom ){ - fS = 1.0f; - fT = 0.0f; - fSqrDist = fA00+2.0f*fB0+fC; - }else{ - fS = fNumer/fDenom; - fT = 1.0f - fS; - fSqrDist = fS*(fA00*fS+fA01*fT+2.0f*fB0) + - fT*(fA01*fS+fA11*fT+2.0f*fB1)+fC; - } - } - } - } - - return _abs(fSqrDist); - } - - enum EST_Result{ - stNone = 0, - stIntersect = 1, - stInside = 2, - }; - - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, - const Fvector& orig, const Fvector& e0,const Fvector& e1) - { - - float fRSqr = sphereRadius*sphereRadius; - Fvector kV0mC; - kV0mC.sub(orig, sphereOrigin); - - // count the number of triangle vertices inside the sphere - int iInside = 0; - - // test if v0 is inside the sphere - if ( kV0mC.square_magnitude() <= fRSqr ) - iInside++; - - // test if v1 is inside the sphere - Fvector kDiff; - kDiff.add(kV0mC, e0); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // test if v2 is inside the sphere - kDiff.add(kV0mC, e1); - if ( kDiff.square_magnitude() <= fRSqr ) - iInside++; - - // triangle does not traversely intersect sphere - if ( iInside == 3 ) return stInside; - - // triangle transversely intersects sphere - if ( iInside > 0 ) return stIntersect; - - // All vertices are outside the sphere, but the triangle might still - // intersect the sphere. This is the case when the distance from the - // sphere center to the triangle is smaller than the radius. - float fSqrDist = MgcSqrDistance(sphereOrigin,orig,e0,e1); - return (fSqrDist < fRSqr)?stIntersect:stNone; - } - //--------------------------------------------------------------------------- - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector* p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(p[1], p[0]); - e1.sub(p[2], p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,p[0],e0,e1); - } - IC EST_Result TestSphereTri(const Fvector& sphereOrigin, float sphereRadius, Fvector** p) - { - Fvector e0, e1; - // find vectors for two edges sharing vert0 - e0.sub(*p[1], *p[0]); - e1.sub(*p[2], *p[0]); - return TestSphereTri(sphereOrigin,sphereRadius,*p[0],e0,e1); - } - IC bool TestSphereOBB(const Fsphere& rkSphere, const Fobb& rkBox) - { - // Test for intersection in the coordinate system of the box by - // transforming the sphere into that coordinate system. - Fvector3 kCDiff; - kCDiff.sub(rkSphere.P,rkBox.m_translate); - - float fAx = _abs(kCDiff.dotproduct(rkBox.m_rotate.i)); - float fAy = _abs(kCDiff.dotproduct(rkBox.m_rotate.j)); - float fAz = _abs(kCDiff.dotproduct(rkBox.m_rotate.k)); - float fDx = fAx - rkBox.m_halfsize[0]; - float fDy = fAy - rkBox.m_halfsize[1]; - float fDz = fAz - rkBox.m_halfsize[2]; - - if ( fAx <= rkBox.m_halfsize[0] ){ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // sphere center inside box - return true; - }else{ - // potential sphere-face intersection with face z - return fDz <= rkSphere.R; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face y - return fDy <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces y and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDy*fDy + fDz*fDz <= fRSqr; - } - } - }else{ - if ( fAy <= rkBox.m_halfsize[1] ){ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-face intersection with face x - return fDx <= rkSphere.R; - }else{ - // potential sphere-edge intersection with edge formed - // by faces x and z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDz*fDz <= fRSqr; - } - }else{ - if ( fAz <= rkBox.m_halfsize[2] ){ - // potential sphere-edge intersection with edge formed - // by faces x and y - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy <= fRSqr; - }else{ - // potential sphere-vertex intersection at corner formed - // by faces x,y,z - float fRSqr = rkSphere.R*rkSphere.R; - return fDx*fDx + fDy*fDy + fDz*fDz <= fRSqr; - } - } - } - } - //---------------------------------------------------------------------------- - IC bool TestRayOBB (const Fvector3& origin, const Fvector3& direction, const Fobb& rkBox) - { - float fWdU[3], fAWdU[3], fDdU[3], fADdU[3], fAWxDdU[3], fRhs; - - Fvector3 kDiff; - kDiff.sub (origin,rkBox.m_translate); - - fWdU[0] = direction.dotproduct(rkBox.m_rotate.i); - fAWdU[0] = _abs(fWdU[0]); - fDdU[0] = kDiff.dotproduct(rkBox.m_rotate.i); - fADdU[0] = _abs(fDdU[0]); - if ( fADdU[0] > rkBox.m_halfsize[0] && fDdU[0]*fWdU[0] >= (float)0.0 ) - return false; - - fWdU[1] = direction.dotproduct(rkBox.m_rotate.j); - fAWdU[1] = _abs(fWdU[1]); - fDdU[1] = kDiff.dotproduct(rkBox.m_rotate.j); - fADdU[1] = _abs(fDdU[1]); - if ( fADdU[1] > rkBox.m_halfsize[1] && fDdU[1]*fWdU[1] >= (float)0.0 ) - return false; - - fWdU[2] = direction.dotproduct(rkBox.m_rotate.k); - fAWdU[2] = _abs(fWdU[2]); - fDdU[2] = kDiff.dotproduct(rkBox.m_rotate.k); - fADdU[2] = _abs(fDdU[2]); - if ( fADdU[2] > rkBox.m_halfsize[2] && fDdU[2]*fWdU[2] >= (float)0.0 ) - return false; - - Fvector3 kWxD; - kWxD.crossproduct(direction,kDiff); - - fAWxDdU[0] = _abs(kWxD.dotproduct(rkBox.m_rotate.i)); - fRhs = rkBox.m_halfsize[1]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[1]; - if ( fAWxDdU[0] > fRhs ) - return false; - - fAWxDdU[1] = _abs(kWxD.dotproduct(rkBox.m_rotate.j)); - fRhs = rkBox.m_halfsize[0]*fAWdU[2] + rkBox.m_halfsize[2]*fAWdU[0]; - if ( fAWxDdU[1] > fRhs ) - return false; - - fAWxDdU[2] = _abs(kWxD.dotproduct(rkBox.m_rotate.k)); - fRhs = rkBox.m_halfsize[0]*fAWdU[1] + rkBox.m_halfsize[1]*fAWdU[0]; - if ( fAWxDdU[2] > fRhs ) - return false; - - return true; - } -//---------------------------------------------------------------------------- -}; - - -#endif diff --git a/src/xrSound/xrSound.vcxproj b/src/xrSound/xrSound.vcxproj index 4f1110a2544..35cced5e84c 100644 --- a/src/xrSound/xrSound.vcxproj +++ b/src/xrSound/xrSound.vcxproj @@ -79,7 +79,7 @@ false Neither true - $(xrSdkDir)include;$(XRAY_16X_LIBS)libvorbis-1.2.3\include;$(XRAY_16X_LIBS)libogg-1.1.4\include;$(SolutionDir)3rd party\OpenAL\include;%(AdditionalIncludeDirectories) + $(SolutionDir);$(xrSdkDir)include;$(XRAY_16X_LIBS)libvorbis-1.2.3\include;$(XRAY_16X_LIBS)libogg-1.1.4\include;$(SolutionDir)3rd party\OpenAL\include;%(AdditionalIncludeDirectories) WIN32;DEBUG;_WINDOWS;_USRDLL;XRSOUND_EXPORTS;_SECURE_SCL=0;%(PreprocessorDefinitions) false true @@ -120,7 +120,7 @@ true true true - $(xrSdkDir)include;$(XRAY_16X_LIBS)libvorbis-1.2.3\include;$(XRAY_16X_LIBS)libogg-1.1.4\include;$(SolutionDir)3rd party\OpenAL\include;%(AdditionalIncludeDirectories) + $(SolutionDir);$(xrSdkDir)include;$(XRAY_16X_LIBS)libvorbis-1.2.3\include;$(XRAY_16X_LIBS)libogg-1.1.4\include;$(SolutionDir)3rd party\OpenAL\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;XRSOUND_EXPORTS;_SECURE_SCL=0;%(PreprocessorDefinitions) true @@ -158,7 +158,7 @@ Speed false true - $(xrSdkDir)include;$(XRAY_16X_LIBS)libvorbis-1.2.3\include;$(XRAY_16X_LIBS)libogg-1.1.4\include;$(SolutionDir)3rd party\OpenAL\include;%(AdditionalIncludeDirectories) + $(SolutionDir);$(xrSdkDir)include;$(XRAY_16X_LIBS)libvorbis-1.2.3\include;$(XRAY_16X_LIBS)libogg-1.1.4\include;$(SolutionDir)3rd party\OpenAL\include;%(AdditionalIncludeDirectories) MIXED;WIN32;DEBUG;_WINDOWS;_USRDLL;XRSOUND_EXPORTS;_SECURE_SCL=0;%(PreprocessorDefinitions) true MultiThreadedDLL @@ -184,7 +184,6 @@ - diff --git a/src/xrSound/xrSound.vcxproj.filters b/src/xrSound/xrSound.vcxproj.filters index fdf38b54005..e8cd5ce3022 100644 --- a/src/xrSound/xrSound.vcxproj.filters +++ b/src/xrSound/xrSound.vcxproj.filters @@ -30,9 +30,6 @@ - - Kernel - Kernel