3D-Viewer: Fix precision issues (experienced on isometric mode) in frustum tests
This commit is contained in:
parent
e5fbd0c442
commit
2eb840b2ed
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -49,22 +49,10 @@ void CFRUSTUM::GenerateFrustum( const RAY &topLeft,
|
|||
m_point[2] = bottomLeft.m_Origin;
|
||||
m_point[3] = topLeft.m_Origin;
|
||||
|
||||
if( topRight.m_Dir == topLeft.m_Dir )
|
||||
{
|
||||
// This will be the case if the camera is Ortho projection
|
||||
|
||||
m_normals[0] = glm::normalize( bottomLeft.m_Origin - topLeft.m_Origin ); // TOP
|
||||
m_normals[1] = glm::normalize( topLeft.m_Origin - topRight.m_Origin ); // RIGHT
|
||||
m_normals[2] = -m_normals[0]; // BOTTOM
|
||||
m_normals[3] = -m_normals[1]; // LEFT
|
||||
}
|
||||
else
|
||||
{
|
||||
m_normals[0] = glm::cross( topRight.m_Dir, topLeft.m_Dir ); // TOP
|
||||
m_normals[1] = glm::cross( bottomRight.m_Dir, topRight.m_Dir ); // RIGHT
|
||||
m_normals[2] = glm::cross( bottomLeft.m_Dir, bottomRight.m_Dir ); // BOTTOM
|
||||
m_normals[3] = glm::cross( topLeft.m_Dir, bottomLeft.m_Dir ); // LEFT
|
||||
}
|
||||
m_normals[0] = glm::cross( topRight.m_Dir, topLeft.m_Dir ); // TOP
|
||||
m_normals[1] = glm::cross( bottomRight.m_Dir, topRight.m_Dir ); // RIGHT
|
||||
m_normals[2] = glm::cross( bottomLeft.m_Dir, bottomRight.m_Dir ); // BOTTOM
|
||||
m_normals[3] = glm::cross( topLeft.m_Dir, bottomLeft.m_Dir ); // LEFT
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,7 +87,7 @@ bool CFRUSTUM::Intersect( const CBBOX &aBBox ) const
|
|||
const SFVEC3F OP = pointPlane - box[j];
|
||||
const float dot = glm::dot( OP, normalPlane );
|
||||
|
||||
if( dot < 0.0f )
|
||||
if( dot < FLT_EPSILON )
|
||||
{
|
||||
out_side++;
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -33,7 +33,7 @@
|
|||
#include <stdio.h>
|
||||
#include <wx/debug.h>
|
||||
|
||||
static unsigned int gs_next_rayID = 0;
|
||||
//static unsigned int gs_next_rayID = 0;
|
||||
|
||||
void RAY::Init( const SFVEC3F& o, const SFVEC3F& d )
|
||||
{
|
||||
|
@ -41,25 +41,17 @@ void RAY::Init( const SFVEC3F& o, const SFVEC3F& d )
|
|||
m_Dir = d;
|
||||
m_InvDir = 1.0f / d;
|
||||
|
||||
if( fabs(m_Dir.x) < FLT_EPSILON )
|
||||
m_InvDir.x = NextFloatDown(FLT_MAX);
|
||||
|
||||
if( fabs(m_Dir.y) < FLT_EPSILON )
|
||||
m_InvDir.y = NextFloatDown(FLT_MAX);
|
||||
|
||||
if( fabs(m_Dir.z) < FLT_EPSILON )
|
||||
m_InvDir.z = NextFloatDown(FLT_MAX);
|
||||
|
||||
rayID = gs_next_rayID;
|
||||
gs_next_rayID++;
|
||||
//rayID = gs_next_rayID;
|
||||
//gs_next_rayID++;
|
||||
|
||||
// An Efficient and Robust Ray–Box Intersection Algorithm
|
||||
// Amy Williams Steve Barrus R. Keith Morley Peter Shirley
|
||||
// University of Utah
|
||||
// http://people.csail.mit.edu/amy/papers/box-jgt.pdf
|
||||
m_dirIsNeg[0] = m_Dir.x < 0.0f;
|
||||
m_dirIsNeg[1] = m_Dir.y < 0.0f;
|
||||
m_dirIsNeg[2] = m_Dir.z < 0.0f;
|
||||
m_dirIsNeg[0] = m_Dir.x <= 0.0f;
|
||||
m_dirIsNeg[1] = m_Dir.y <= 0.0f;
|
||||
m_dirIsNeg[2] = m_Dir.z <= 0.0f;
|
||||
|
||||
|
||||
// ray slope
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -43,7 +43,7 @@ enum RAY_CLASSIFICATION
|
|||
struct RAY
|
||||
{
|
||||
SFVEC3F m_Origin;
|
||||
unsigned int rayID; ///< unique ray ID
|
||||
unsigned int rayID; ///< unique ray ID - not used - dummy
|
||||
|
||||
SFVEC3F m_Dir;
|
||||
RAY_CLASSIFICATION m_Classification;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@ua.pt>
|
||||
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -317,10 +317,10 @@ bool CBBOX::Intersect( const RAY &aRay,
|
|||
const SFVEC3F bounds[2] = {m_min, m_max};
|
||||
|
||||
// Check for ray intersection against x and y slabs
|
||||
float tmin = (bounds[ aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x) * aRay.m_InvDir.x;
|
||||
float tmax = (bounds[1 - aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x) * aRay.m_InvDir.x;
|
||||
float tymin = (bounds[ aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
|
||||
float tymax = (bounds[1 - aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
|
||||
float tmin = (bounds[ aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x) * aRay.m_InvDir.x;
|
||||
float tmax = (bounds[1 - aRay.m_dirIsNeg[0]].x - aRay.m_Origin.x) * aRay.m_InvDir.x;
|
||||
const float tymin = (bounds[ aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
|
||||
const float tymax = (bounds[1 - aRay.m_dirIsNeg[1]].y - aRay.m_Origin.y) * aRay.m_InvDir.y;
|
||||
|
||||
if( (tmin > tymax) || (tymin > tmax) )
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue