kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #27255
Re: FW: Raytracing engine not displaying board from bottom orthogonal projection
Hello all,
Attached is a fix for the issue described by Edward. It also fixes another precision issue (or bug) while rendering on some angles while using the orthogonal projection.
Thanks Edward for using the 3Dviewer, hope you can share any cool renders with the community.
Let me know if you have any (very simple for me) suggestions or ideas that I can improve it more..
Mario Luzeiro
-----Original Message-----
From: Edward Johns [mailto:edwardgjohns3@xxxxxxxxx]
Sent: Sunday, January 15, 2017 3:09 PM
To: kicad-developers@xxxxxxxxxxxxxxxxxxx
Subject: Raytracing engine not displaying board from bottom orthogonal
projection
Hi, all.
I think I found a corner case related to the raytracing engine. When
viewing the board from the bottom using orthogonal projection, the board
disappears and only some components that extend beyond the board outline are
visible. If you manually rotate even by a miniscule amount, the
visualization is fixed.
On a side note, I use the product branch for design, but the development for
modeling. The 3d visualizations are getting to be pretty awesome.
Thanks and have a good one.
-Ed
From efbcdbeb749174eb2080c3a4235285e4b13828ab Mon Sep 17 00:00:00 2001
Message-Id: <efbcdbeb749174eb2080c3a4235285e4b13828ab.1484779217.git.mrluzeiro@xxxxx>
From: Mario Luzeiro <mrluzeiro@xxxxx>
Date: Wed, 18 Jan 2017 23:39:02 +0100
Subject: [PATCH] 3D-Viewer: Fix precision issues (experienced on isometric
mode) in frustum tests
---
.../3d_rendering/3d_render_raytracing/cfrustum.cpp | 26 ++++++----------------
.../3d_rendering/3d_render_raytracing/ray.cpp | 26 ++++++++--------------
3d-viewer/3d_rendering/3d_render_raytracing/ray.h | 6 ++---
.../3d_render_raytracing/shapes3D/cbbox.cpp | 12 +++++-----
4 files changed, 25 insertions(+), 45 deletions(-)
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/cfrustum.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/cfrustum.cpp
index b4f69cc..e50ef43 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/cfrustum.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/cfrustum.cpp
@@ -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@xxxxx>
- * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@xxxxx>
+ * 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++;
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp
index 27d5af5..5a71041 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/ray.cpp
@@ -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@xxxxx>
- * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@xxxxx>
+ * 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
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/ray.h b/3d-viewer/3d_rendering/3d_render_raytracing/ray.h
index 8497df9..d20685e 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/ray.h
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/ray.h
@@ -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@xxxxx>
- * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@xxxxx>
+ * 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;
diff --git a/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp b/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp
index 1101b21..aef633d 100644
--- a/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp
+++ b/3d-viewer/3d_rendering/3d_render_raytracing/shapes3D/cbbox.cpp
@@ -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@xxxxx>
- * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
+ * Copyright (C) 2015-2017 Mario Luzeiro <mrluzeiro@xxxxx>
+ * 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;
--
2.7.4
Follow ups
References