forked from bartvdbraak/blender
12966aed05
As mentioned earlier on bf-commiters mailing list, there is no current *nix make file only an msvc60 project file. I only have a linux box at work and to be honest I want to avoid doing any commits from there! So if some kind soul could sort it out that would be great. Dependencies: This code only depends on other stuff in the intern library, moto and memutils the CSG lib needs to have their include paths to compile. Other than that its completely self contained. Acknowledgements: To speed up the polygon-polygon intersection queries I've used some code (under the GPL) from freesolid2.0 this clearly marked in the appropriate files and Gino van den Bergen still owns the copyright to that material. The algorithm I used in based on one from Paul Nettle described on flipcode (www.flipcode.com) and I think his work was a derivative of the "Laidlaw algorithm" There is also some basic 'ear clipping' triangulation code that unfortunately remains unatributable. I have no right to publish this code under the GPL nor BPL for that matter as I have no idea who the original authors are. Its just one of those random bits of internet code. Warning! The stuff used a lot of C++ template features, which on one hand makes it very generic but on the other means that some work will need to be done to get working with other compilters. The msvc60 compiler is not very compliant to the C++ standards with respect to templates so its very difficult to say if this code will compile out of the box on other platforms. I still haven't committed modifications to booleanops.c in the blender code as without a working library to link to it will break the current build. This needs to be done first! Improvements This code is much simpler than the previous bsp implementation see intern/bsp and this old code should be deprectated/removed. However, whilst this implementation produces less triangles in the output than the bps algo, its still not an optimal solution. This is just hard to do and beyond my humble skills. License: Just to make it clear this stuff for the reasons mentioned above and for the fact I'm to mean to give the copyright away to BF is licensed under the GPL only. Cheers, Laurence.
207 lines
3.6 KiB
C++
207 lines
3.6 KiB
C++
/*
|
|
The following BBox class is a lightly modfied version of what
|
|
is found in Free Solid 2.0
|
|
*/
|
|
|
|
/*
|
|
SOLID - Software Library for Interference Detection
|
|
Copyright (C) 1997-1998 Gino van den Bergen
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with this library; if not, write to the Free
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
Please send remarks, questions and bug reports to gino@win.tue.nl,
|
|
or write to:
|
|
Gino van den Bergen
|
|
Department of Mathematics and Computing Science
|
|
Eindhoven University of Technology
|
|
P.O. Box 513, 5600 MB Eindhoven, The Netherlands
|
|
*/
|
|
|
|
#ifndef _BBOX_H_
|
|
#define _BBOX_H_
|
|
|
|
#include "MT_Point3.h"
|
|
#include "MT_Vector3.h"
|
|
#include "MT_MinMax.h"
|
|
|
|
class BBox {
|
|
public:
|
|
BBox() {}
|
|
|
|
BBox(
|
|
const MT_Point3& mini,
|
|
const MT_Point3& maxi
|
|
) { SetValue(mini,maxi); }
|
|
|
|
const MT_Point3&
|
|
Center(
|
|
) const {
|
|
return m_center;
|
|
}
|
|
|
|
const MT_Vector3&
|
|
Extent(
|
|
) const {
|
|
return m_extent;
|
|
}
|
|
|
|
MT_Point3&
|
|
Center(
|
|
) {
|
|
return m_center;
|
|
}
|
|
|
|
MT_Vector3&
|
|
Extent(
|
|
) {
|
|
return m_extent;
|
|
}
|
|
|
|
void
|
|
SetValue(
|
|
const MT_Point3& mini,
|
|
const MT_Point3& maxi
|
|
) {
|
|
m_extent = (maxi-mini)/2;
|
|
m_center = mini+m_extent;
|
|
}
|
|
|
|
void
|
|
Enclose(
|
|
const BBox& a,
|
|
const BBox& b
|
|
) {
|
|
MT_Point3 lower(
|
|
MT_min(a.Lower(0), b.Lower(0)),
|
|
MT_min(a.Lower(1), b.Lower(1)),
|
|
MT_min(a.Lower(2), b.Lower(2))
|
|
);
|
|
MT_Point3 upper(
|
|
MT_max(a.Upper(0), b.Upper(0)),
|
|
MT_max(a.Upper(1), b.Upper(1)),
|
|
MT_max(a.Upper(2), b.Upper(2))
|
|
);
|
|
SetValue(lower, upper);
|
|
}
|
|
|
|
void
|
|
SetEmpty() {
|
|
m_center.setValue(0, 0, 0);
|
|
m_extent.setValue(-MT_INFINITY,-MT_INFINITY,-MT_INFINITY);
|
|
}
|
|
|
|
void
|
|
Include (
|
|
const MT_Point3& p
|
|
) {
|
|
MT_Point3 lower(
|
|
MT_min(Lower(0), p[0]),
|
|
MT_min(Lower(1), p[1]),
|
|
MT_min(Lower(2), p[2])
|
|
);
|
|
MT_Point3 upper(
|
|
MT_max(Upper(0), p[0]),
|
|
MT_max(Upper(1), p[1]),
|
|
MT_max(Upper(2), p[2])
|
|
);
|
|
SetValue(lower, upper);
|
|
}
|
|
|
|
void
|
|
Include (
|
|
const BBox& b
|
|
) {
|
|
Enclose(*this, b);
|
|
}
|
|
|
|
MT_Scalar
|
|
Lower(
|
|
int i
|
|
) const {
|
|
return m_center[i] - m_extent[i];
|
|
}
|
|
MT_Scalar
|
|
Upper(
|
|
int i
|
|
) const {
|
|
return m_center[i] + m_extent[i];
|
|
}
|
|
|
|
MT_Point3
|
|
Lower(
|
|
) const {
|
|
return m_center - m_extent;
|
|
}
|
|
MT_Point3
|
|
Upper(
|
|
) const {
|
|
return m_center + m_extent;
|
|
}
|
|
|
|
MT_Scalar
|
|
Size(
|
|
) const {
|
|
return MT_max(MT_max(m_extent[0], m_extent[1]), m_extent[2]);
|
|
}
|
|
|
|
int
|
|
LongestAxis(
|
|
) const {
|
|
return m_extent.closestAxis();
|
|
}
|
|
|
|
bool
|
|
IntersectXRay(
|
|
const MT_Point3& xBase
|
|
) const {
|
|
if (xBase[0] <= Upper(0))
|
|
{
|
|
if (xBase[1] <= Upper(1) && xBase[1] >= Lower(1))
|
|
{
|
|
if (xBase[2] <= Upper(2) && xBase[2] >= Lower(2))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
|
|
friend bool intersect(const BBox& a, const BBox& b);
|
|
|
|
private:
|
|
MT_Point3 m_center;
|
|
MT_Vector3 m_extent;
|
|
};
|
|
|
|
inline
|
|
bool
|
|
intersect(
|
|
const BBox& a,
|
|
const BBox& b
|
|
) {
|
|
return
|
|
MT_abs(a.m_center[0] - b.m_center[0]) <= a.m_extent[0] + b.m_extent[0] &&
|
|
MT_abs(a.m_center[1] - b.m_center[1]) <= a.m_extent[1] + b.m_extent[1] &&
|
|
MT_abs(a.m_center[2] - b.m_center[2]) <= a.m_extent[2] + b.m_extent[2];
|
|
}
|
|
|
|
#endif
|
|
|
|
|