initial
This commit is contained in:
40
thirdparty/quickhull/_vpc_/manifest_quickhull/win32/manifest.txt
vendored
Normal file
40
thirdparty/quickhull/_vpc_/manifest_quickhull/win32/manifest.txt
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// ----------------------------------------- //
|
||||
// File generated by VPC //
|
||||
// ----------------------------------------- //
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\common\debug_lib_check.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhConvex.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhConvex.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhConvex.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhHalfEdge.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhHalfEdge.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhHalfEdge.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMass.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMass.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMass.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMath.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMath.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMath.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
Source file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMemory.cpp
|
||||
Debug output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMemory.cpp
|
||||
Release output file: F:\csgo_64\cstrike15_src\thirdparty\quickhull\qhMemory.cpp
|
||||
Containing unity file:
|
||||
PCH file:
|
||||
|
||||
72
thirdparty/quickhull/qhArray.h
vendored
Normal file
72
thirdparty/quickhull/qhArray.h
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhArray.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 03/12/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include "qhTypes.h"
|
||||
#include "qhMemory.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhArray
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T >
|
||||
class qhArray
|
||||
{
|
||||
public:
|
||||
qhArray( void );
|
||||
~qhArray( void );
|
||||
|
||||
int Capacity( void ) const;
|
||||
int Size( void ) const;
|
||||
bool Empty( void ) const;
|
||||
|
||||
void Clear( void );
|
||||
void Reserve( int Count );
|
||||
void Resize( int Count );
|
||||
|
||||
T& Expand( void );
|
||||
void PushBack( const T& Other );
|
||||
void PopBack( void );
|
||||
|
||||
int IndexOf( const T& Element ) const;
|
||||
|
||||
T& operator[]( int Offset );
|
||||
const T& operator[]( int Offset ) const;
|
||||
|
||||
T& Front( void );
|
||||
const T& Front( void ) const;
|
||||
T& Back( void );
|
||||
const T& Back( void ) const;
|
||||
|
||||
T* Begin( void );
|
||||
const T* Begin( void ) const;
|
||||
T* End( void );
|
||||
const T* End( void ) const;
|
||||
|
||||
void Swap( qhArray< T >& Other );
|
||||
|
||||
private:
|
||||
T* mBegin;
|
||||
T* mEnd;
|
||||
T* mCapacity;
|
||||
|
||||
// Non-copyable
|
||||
qhArray( const qhArray& );
|
||||
qhArray& operator=( const qhArray& );
|
||||
};
|
||||
|
||||
|
||||
template < typename T >
|
||||
void qhSwap( qhArray< T >& Lhs, qhArray< T >& Rhs );
|
||||
|
||||
|
||||
#include "qhArray.inl"
|
||||
246
thirdparty/quickhull/qhArray.inl
vendored
Normal file
246
thirdparty/quickhull/qhArray.inl
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhArray.inl
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhArray
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
qhArray< T >::qhArray( void )
|
||||
: mBegin( NULL )
|
||||
, mEnd( NULL )
|
||||
, mCapacity( NULL )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
qhArray< T >::~qhArray( void )
|
||||
{
|
||||
qhDestroy( mBegin, Size() );
|
||||
qhFree( mBegin );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
int qhArray< T >::Capacity( void ) const
|
||||
{
|
||||
return int( mCapacity - mBegin );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
int qhArray< T >::Size( void ) const
|
||||
{
|
||||
return int( mEnd - mBegin );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
bool qhArray< T >::Empty( void ) const
|
||||
{
|
||||
return mEnd == mBegin;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhArray< T >::Clear( void )
|
||||
{
|
||||
qhDestroy( mBegin, Size() );
|
||||
mEnd = mBegin;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhArray< T >::Reserve( int Count )
|
||||
{
|
||||
if ( Count > Capacity() )
|
||||
{
|
||||
T* Begin = (T*)qhAlloc( Count * sizeof( T ) );
|
||||
qhMove( Begin, mBegin, mEnd );
|
||||
qhFree( mBegin );
|
||||
|
||||
mCapacity = Begin + Count;
|
||||
mEnd = Begin + Size();
|
||||
mBegin = Begin;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhArray< T >::Resize( int Count )
|
||||
{
|
||||
Reserve( Count );
|
||||
|
||||
qhDestroy( mBegin + Count, Size() - Count );
|
||||
qhConstruct( mEnd, Count - Size() );
|
||||
mEnd = mBegin + Count;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T& qhArray< T >::Expand( void )
|
||||
{
|
||||
if ( mEnd == mCapacity )
|
||||
{
|
||||
Reserve( 2 * Capacity() + 1 );
|
||||
}
|
||||
|
||||
qhConstruct( mEnd );
|
||||
return *mEnd++;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhArray< T >::PushBack( const T& Other )
|
||||
{
|
||||
if ( mEnd == mCapacity )
|
||||
{
|
||||
Reserve( 2 * Capacity() + 1 );
|
||||
}
|
||||
|
||||
qhCopyConstruct( mEnd++, Other );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhArray< T >::PopBack( void )
|
||||
{
|
||||
qhDestroy( --mEnd );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
int qhArray< T >::IndexOf( const T& Element ) const
|
||||
{
|
||||
for ( int i = 0; i < Size(); ++i )
|
||||
{
|
||||
if ( mBegin[ i ] == Element )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T& qhArray< T >::operator[]( int Offset )
|
||||
{
|
||||
QH_ASSERT( 0 <= Offset && Offset < Size() );
|
||||
return *( mBegin + Offset );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
const T& qhArray< T >::operator[]( int Offset ) const
|
||||
{
|
||||
QH_ASSERT( 0 <= Offset && Offset < Size() );
|
||||
return *( mBegin + Offset );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T& qhArray< T >::Front( void )
|
||||
{
|
||||
QH_ASSERT( !Empty() );
|
||||
return *mBegin;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
const T& qhArray< T >::Front( void ) const
|
||||
{
|
||||
QH_ASSERT( !Empty() );
|
||||
return *mBegin;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T& qhArray< T >::Back( void )
|
||||
{
|
||||
QH_ASSERT( !Empty() );
|
||||
return *( mEnd - 1 );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T* qhArray< T >::Begin( void )
|
||||
{
|
||||
return mBegin;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
const T* qhArray< T >::Begin( void ) const
|
||||
{
|
||||
return mBegin;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T* qhArray< T >::End( void )
|
||||
{
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
const T* qhArray< T >::End( void ) const
|
||||
{
|
||||
return mEnd;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
const T& qhArray< T >::Back( void ) const
|
||||
{
|
||||
QH_ASSERT( !Empty() );
|
||||
return *( mEnd - 1 );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhArray< T >::Swap( qhArray< T >& Other )
|
||||
{
|
||||
qhSwap( mBegin, Other.mBegin );
|
||||
qhSwap( mEnd, Other.mEnd );
|
||||
qhSwap( mCapacity, Other.mCapacity );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T >
|
||||
void qhSwap( qhArray< T >& Lhs, qhArray< T >& Rhs )
|
||||
{
|
||||
Lhs.Swap( Rhs );
|
||||
}
|
||||
|
||||
|
||||
1631
thirdparty/quickhull/qhConvex.cpp
vendored
Normal file
1631
thirdparty/quickhull/qhConvex.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
130
thirdparty/quickhull/qhConvex.h
vendored
Normal file
130
thirdparty/quickhull/qhConvex.h
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhConvex.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 30/11/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include "qhTypes.h"
|
||||
#include "qhMath.h"
|
||||
#include "qhArray.h"
|
||||
#include "qhList.h"
|
||||
#include "qhHalfEdge.h"
|
||||
#include "qhMass.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMesh
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
struct qhMesh
|
||||
{
|
||||
qhArray< qhVector3 > Vertices; // Vertices
|
||||
qhArray< qhVector3 > Normals; // *Face* normals
|
||||
qhArray< int > Faces; // Index count for each face
|
||||
qhArray< int > Indices; // Face indices into vertex array
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhIteration
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
struct qhIteration
|
||||
{
|
||||
qhVector3 Apex;
|
||||
qhArray< qhVector3 > Horizon;
|
||||
qhArray< qhVector3 > Vertices;
|
||||
qhArray< int > Faces;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhConvex
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhConvex
|
||||
{
|
||||
public:
|
||||
// Construction / Destruction
|
||||
qhConvex( void );
|
||||
~qhConvex( void );
|
||||
|
||||
void Construct( int VertexCount, const qhVector3* VertexBase, qhReal RelativeWeldTolerance );
|
||||
void Construct( int PlaneCount, const qhPlane* PlaneBase, qhReal RelativeWeldTolerance, const qhVector3& InternalPoint = QH_VEC3_ZERO );
|
||||
bool IsConsistent( void ) const;
|
||||
|
||||
void Simplify( qhConvex& Convex, qhReal MaxAngle ) const;
|
||||
|
||||
// Accessors / Mutators
|
||||
qhVector3 GetCentroid( void ) const;
|
||||
|
||||
int GetVertexCount( void ) const;
|
||||
int GetEdgeCount( void ) const;
|
||||
int GetFaceCount( void ) const;
|
||||
|
||||
const qhList< qhVertex >& GetVertexList( void ) const;
|
||||
const qhList< qhFace >& GetFaceList( void ) const;
|
||||
|
||||
// Polygonal mesh for rendering
|
||||
void GetMesh( qhMesh& Mesh ) const;
|
||||
|
||||
// Mass properties (relative to origin)
|
||||
qhMass ComputeMass( qhReal Density = qhReal( 1 ) ) const;
|
||||
|
||||
// Debug information
|
||||
int GetIterationCount( void ) const;
|
||||
const qhIteration& GetIteration( int Index ) const;
|
||||
|
||||
private:
|
||||
// Memory management
|
||||
qhVertex* CreateVertex( const qhVector3& Position );
|
||||
void DestroyVertex( qhVertex* Vertex );
|
||||
qhFace* CreateFace( qhVertex* Vertex1, qhVertex* Vertex2, qhVertex* Vertex3 );
|
||||
void DestroyFace( qhFace* Face );
|
||||
|
||||
// Implementation
|
||||
void ComputeTolerance( qhArray< qhVector3 >& Vertices );
|
||||
bool BuildInitialHull( int VertexCount, const qhVector3* VertexBase );
|
||||
qhVertex* NextConflictVertex( void );
|
||||
void AddVertexToHull( qhVertex* Vertex );
|
||||
void AddIteration( qhVertex* Apex, const qhArray< qhHalfEdge* >& Horizon, const qhList< qhFace >& FaceList );
|
||||
|
||||
void CleanHull( void );
|
||||
void ShiftHull( const qhVector3& Translation );
|
||||
|
||||
void BuildHorizon( qhArray< qhHalfEdge* >& Horizon, qhVertex* Apex, qhFace* Seed, qhHalfEdge* Edge1 = NULL );
|
||||
void BuildCone( qhArray< qhFace* >& Cone, const qhArray< qhHalfEdge* >& Horizon, qhVertex* Apex );
|
||||
void MergeFaces( qhArray< qhFace* >& Cone );
|
||||
void ResolveVertices( qhArray< qhFace* >& Cone );
|
||||
void ResolveFaces( qhArray< qhFace* >& Cone );
|
||||
|
||||
bool FirstPass( qhFace* Face );
|
||||
bool SecondPass( qhFace* Face );
|
||||
void ConnectFaces( qhHalfEdge* Edge );
|
||||
void ConnectEdges( qhHalfEdge* Prev, qhHalfEdge* Next, qhArray< qhFace* >& MergedFaces );
|
||||
void DestroyEdges( qhHalfEdge* Begin, qhHalfEdge* End );
|
||||
void AbsorbFaces( qhFace* Face, qhArray< qhFace* >& MergedFaces );
|
||||
|
||||
// Data members
|
||||
qhReal mTolerance;
|
||||
qhReal mMinRadius;
|
||||
qhReal mMinOutside;
|
||||
|
||||
qhVector3 mInteriorPoint;
|
||||
qhList< qhVertex > mOrphanedList;
|
||||
qhList< qhVertex > mVertexList;
|
||||
qhList< qhFace > mFaceList;
|
||||
|
||||
qhArray< qhIteration > mIterations;
|
||||
|
||||
// Non-copyable
|
||||
qhConvex( const qhConvex& );
|
||||
qhConvex& operator=( const qhConvex& );
|
||||
};
|
||||
|
||||
|
||||
#include "qhConvex.inl"
|
||||
92
thirdparty/quickhull/qhConvex.inl
vendored
Normal file
92
thirdparty/quickhull/qhConvex.inl
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhConvex.inl
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhConvex
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline qhVector3 qhConvex::GetCentroid( void ) const
|
||||
{
|
||||
qhVector3 Centroid = QH_VEC3_ZERO;
|
||||
if ( !mVertexList.Empty() )
|
||||
{
|
||||
int VertexCount = 0;
|
||||
for ( const qhVertex* Vertex = mVertexList.Begin(); Vertex != mVertexList.End(); Vertex = Vertex->Next )
|
||||
{
|
||||
Centroid += Vertex->Position;
|
||||
VertexCount++;
|
||||
}
|
||||
|
||||
Centroid /= qhReal( VertexCount );
|
||||
}
|
||||
|
||||
return Centroid;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline int qhConvex::GetVertexCount( void ) const
|
||||
{
|
||||
return mVertexList.Size();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline int qhConvex::GetEdgeCount( void ) const
|
||||
{
|
||||
int Count = 0;
|
||||
for ( const qhFace* Face = mFaceList.Begin(); Face != mFaceList.End(); Face = Face->Next )
|
||||
{
|
||||
qhHalfEdge* Edge = Face->Edge;
|
||||
QH_ASSERT( Edge != NULL );
|
||||
|
||||
do
|
||||
{
|
||||
Count += 1;
|
||||
Edge = Edge->Next;
|
||||
}
|
||||
while ( Edge != Face->Edge );
|
||||
}
|
||||
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline int qhConvex::GetFaceCount( void ) const
|
||||
{
|
||||
return mFaceList.Size();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline const qhList< qhVertex >& qhConvex::GetVertexList( void ) const
|
||||
{
|
||||
return mVertexList;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline const qhList< qhFace >& qhConvex::GetFaceList( void ) const
|
||||
{
|
||||
return mFaceList;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline int qhConvex::GetIterationCount( void ) const
|
||||
{
|
||||
return mIterations.Size();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline const qhIteration& qhConvex::GetIteration( int i ) const
|
||||
{
|
||||
return mIterations[ i ];
|
||||
}
|
||||
|
||||
|
||||
222
thirdparty/quickhull/qhHalfEdge.cpp
vendored
Normal file
222
thirdparty/quickhull/qhHalfEdge.cpp
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhHalfEdge.cpp
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include "qhHalfEdge.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Utilities
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool qhHalfEdge::IsConvex( qhReal Tolerance ) const
|
||||
{
|
||||
return Face->Plane.Distance( Twin->Face->Centroid ) < -Tolerance;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhLinkFace( qhFace* Face, int Index, qhHalfEdge* Twin )
|
||||
{
|
||||
qhHalfEdge* Edge = Face->Edge;
|
||||
while ( Index-- > 0 )
|
||||
{
|
||||
Edge = Edge->Next;
|
||||
}
|
||||
|
||||
QH_ASSERT( Edge != Twin );
|
||||
Edge->Twin = Twin;
|
||||
Twin->Twin = Edge;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhLinkFaces( qhFace* Face1, int Index1, qhFace* Face2, int Index2 )
|
||||
{
|
||||
qhHalfEdge* Edge1 = Face1->Edge;
|
||||
while ( Index1-- > 0 )
|
||||
{
|
||||
Edge1 = Edge1->Next;
|
||||
}
|
||||
|
||||
qhHalfEdge* Edge2 = Face2->Edge;
|
||||
while ( Index2-- > 0 )
|
||||
{
|
||||
Edge2 = Edge2->Next;
|
||||
}
|
||||
|
||||
QH_ASSERT( Edge1 != Edge2 );
|
||||
Edge1->Twin = Edge2;
|
||||
Edge2->Twin = Edge1;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhNewellPlane( qhFace* Face )
|
||||
{
|
||||
int Count = 0;
|
||||
qhVector3 Centroid = QH_VEC3_ZERO;
|
||||
qhVector3 Normal = QH_VEC3_ZERO;
|
||||
|
||||
qhHalfEdge* Edge = Face->Edge;
|
||||
QH_ASSERT( Edge->Face == Face );
|
||||
|
||||
do
|
||||
{
|
||||
qhHalfEdge* Twin = Edge->Twin;
|
||||
QH_ASSERT( Twin->Twin == Edge );
|
||||
|
||||
const qhVector3& V1 = Edge->Origin->Position;
|
||||
const qhVector3& V2 = Twin->Origin->Position;
|
||||
|
||||
Count++;
|
||||
Centroid += V1;
|
||||
|
||||
// This seems to be more robust than N += Cross( V1, V2 )
|
||||
Normal.X += ( V1.Y - V2.Y ) * ( V1.Z + V2.Z );
|
||||
Normal.Y += ( V1.Z - V2.Z ) * ( V1.X + V2.X );
|
||||
Normal.Z += ( V1.X - V2.X ) * ( V1.Y + V2.Y );
|
||||
|
||||
Edge = Edge->Next;
|
||||
}
|
||||
while ( Edge != Face->Edge );
|
||||
|
||||
QH_ASSERT( Count > 2 );
|
||||
Centroid /= qhReal( Count );
|
||||
Face->Centroid = Centroid;
|
||||
|
||||
qhReal Area = qhLength( Normal );
|
||||
QH_ASSERT( Area > qhReal( 0.0 ) );
|
||||
Normal /= Area;
|
||||
|
||||
Face->Plane = qhPlane( Normal, Centroid );
|
||||
Face->Area = Area;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool qhIsConvex( const qhFace* Face, qhReal Tolerance )
|
||||
{
|
||||
const qhHalfEdge* Edge = Face->Edge;
|
||||
|
||||
do
|
||||
{
|
||||
qhVector3 Tail = Edge->Origin->Position;
|
||||
qhVector3 Head = Edge->Twin->Origin->Position;
|
||||
|
||||
qhVector3 Offset = Head - Tail;
|
||||
qhVector3 Normal = qhCross( Offset, Face->Plane.Normal );
|
||||
|
||||
qhPlane Plane( Normal, Head );
|
||||
Plane.Normalize();
|
||||
|
||||
qhReal Distance = Plane.Distance( Edge->Next->Twin->Origin->Position );
|
||||
if ( Distance > -Tolerance )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Edge = Edge->Next;
|
||||
}
|
||||
while ( Edge != Face->Edge );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int qhVertexCount( const qhFace* Face )
|
||||
{
|
||||
int VertexCount = 0;
|
||||
|
||||
const qhHalfEdge* Edge = Face->Edge;
|
||||
do
|
||||
{
|
||||
VertexCount++;
|
||||
Edge = Edge->Next;
|
||||
}
|
||||
while ( Edge != Face->Edge );
|
||||
|
||||
return VertexCount;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool qhCheckConsistency( const qhFace* Face )
|
||||
{
|
||||
if ( Face->Mark == QH_MARK_DELETE )
|
||||
{
|
||||
// Face is not on the hull
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( qhVertexCount( Face ) < 3 )
|
||||
{
|
||||
// Invalid geometry
|
||||
return false;
|
||||
}
|
||||
|
||||
const qhHalfEdge* Edge = Face->Edge;
|
||||
|
||||
do
|
||||
{
|
||||
const qhHalfEdge* Twin = Edge->Twin;
|
||||
|
||||
if ( Twin == NULL )
|
||||
{
|
||||
// Unreflected edge
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Twin->Face == NULL )
|
||||
{
|
||||
// Missing face
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Twin->Face == Face )
|
||||
{
|
||||
// Edge is connecting the same face
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Twin->Face->Mark == QH_MARK_DELETE )
|
||||
{
|
||||
// Face is not on hull
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Twin->Twin != Edge )
|
||||
{
|
||||
// Edge reflected incorrectly
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Edge->Origin != Twin->Next->Origin )
|
||||
{
|
||||
// Topology error
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Twin->Origin != Edge->Next->Origin )
|
||||
{
|
||||
// Topology error
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Edge->Face != Face )
|
||||
{
|
||||
// Topology error
|
||||
return false;
|
||||
}
|
||||
|
||||
Edge = Edge->Next;
|
||||
}
|
||||
while ( Edge != Face->Edge );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
93
thirdparty/quickhull/qhHalfEdge.h
vendored
Normal file
93
thirdparty/quickhull/qhHalfEdge.h
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhHalfEdge.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 30/11/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include "qhTypes.h"
|
||||
#include "qhMath.h"
|
||||
#include "qhList.h"
|
||||
|
||||
struct qhVertex;
|
||||
struct qhHalfEdge;
|
||||
struct qhFace;
|
||||
|
||||
#define QH_MARK_VISIBLE 0
|
||||
#define QH_MARK_DELETE 1
|
||||
#define QH_MARK_CONCAVE 2
|
||||
#define QH_MARK_CONFIRM 3
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhVertex
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
struct qhVertex
|
||||
{
|
||||
qhVertex* Prev;
|
||||
qhVertex* Next;
|
||||
|
||||
int Mark;
|
||||
qhVector3 Position;
|
||||
qhHalfEdge* Edge;
|
||||
qhFace* ConflictFace;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhHalfEdge
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
struct qhHalfEdge
|
||||
{
|
||||
qhHalfEdge* Prev;
|
||||
qhHalfEdge* Next;
|
||||
|
||||
qhVertex* Origin;
|
||||
qhFace* Face;
|
||||
qhHalfEdge* Twin;
|
||||
|
||||
bool IsConvex( qhReal Tolerance ) const;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhFace
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
struct qhFace
|
||||
{
|
||||
qhFace* Prev;
|
||||
qhFace* Next;
|
||||
|
||||
qhHalfEdge* Edge;
|
||||
|
||||
int Mark;
|
||||
qhReal Area;
|
||||
qhVector3 Centroid;
|
||||
qhPlane Plane;
|
||||
bool Flipped;
|
||||
|
||||
qhList< qhVertex > ConflictList;
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Utilities
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhLinkFace( qhFace* Face, int Index, qhHalfEdge* Twin );
|
||||
void qhLinkFaces( qhFace* Face1, int Index1, qhFace* Face2, int Index2 );
|
||||
void qhNewellPlane( qhFace* Face );
|
||||
|
||||
int qhVertexCount( const qhFace* Face );
|
||||
bool qhIsConvex( const qhFace* Face, qhReal Tolerance );
|
||||
bool qhCheckConsistency( const qhFace* Face );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
65
thirdparty/quickhull/qhList.h
vendored
Normal file
65
thirdparty/quickhull/qhList.h
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhList.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 30/11/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhListNode
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T >
|
||||
void qhInsert( T* Node, T* Where );
|
||||
|
||||
template < typename T >
|
||||
void qhRemove( T* Node );
|
||||
|
||||
template < typename T >
|
||||
bool qhInList( T* Node );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhList
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T >
|
||||
class qhList
|
||||
{
|
||||
public:
|
||||
qhList( void );
|
||||
|
||||
int Size( void ) const;
|
||||
bool Empty( void ) const;
|
||||
|
||||
void Clear( void );
|
||||
void PushFront( T* Node );
|
||||
void PopFront( void );
|
||||
void PushBack( T* Node );
|
||||
void PopBack( void );
|
||||
|
||||
void Insert( T* Node, T* Where );
|
||||
void Remove( T* Node );
|
||||
int IndexOf( const T* Node ) const;
|
||||
|
||||
T* Begin( void );
|
||||
const T* Begin( void ) const;
|
||||
T* End( void );
|
||||
const T* End( void ) const;
|
||||
|
||||
private:
|
||||
T mHead;
|
||||
|
||||
// Non-copyable
|
||||
qhList( const qhList< T >& );
|
||||
qhList< T >& operator=( const qhList< T >& );
|
||||
};
|
||||
|
||||
|
||||
|
||||
#include "qhList.inl"
|
||||
200
thirdparty/quickhull/qhList.inl
vendored
Normal file
200
thirdparty/quickhull/qhList.inl
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhList.inl
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhListNode
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhInsert( T* Node, T* Where )
|
||||
{
|
||||
QH_ASSERT( !qhInList( Node ) && qhInList( Where ) );
|
||||
|
||||
Node->Prev = Where->Prev;
|
||||
Node->Next = Where;
|
||||
|
||||
Node->Prev->Next = Node;
|
||||
Node->Next->Prev = Node;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhRemove( T* Node )
|
||||
{
|
||||
QH_ASSERT( qhInList( Node ) );
|
||||
|
||||
Node->Prev->Next = Node->Next;
|
||||
Node->Next->Prev = Node->Prev;
|
||||
|
||||
Node->Prev = NULL;
|
||||
Node->Next = NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
bool qhInList( T* Node )
|
||||
{
|
||||
return Node->Prev != NULL && Node->Next != NULL;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhList
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
qhList< T >::qhList( void )
|
||||
{
|
||||
mHead.Prev = &mHead;
|
||||
mHead.Next = &mHead;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
int qhList< T >::Size( void ) const
|
||||
{
|
||||
int Count = 0;
|
||||
for ( const T* Node = Begin(); Node != End(); Node = Node->Next )
|
||||
{
|
||||
Count++;
|
||||
}
|
||||
|
||||
return Count;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
bool qhList< T >::Empty( void ) const
|
||||
{
|
||||
return mHead.Next == &mHead;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhList< T >::Clear( void )
|
||||
{
|
||||
mHead.Prev = &mHead;
|
||||
mHead.Next = &mHead;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhList< T >::PushFront( T* Node )
|
||||
{
|
||||
qhInsert( Node, mHead.Next );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhList< T >::PopFront( void )
|
||||
{
|
||||
QH_ASSERT( !Empty() );
|
||||
|
||||
T* Node = mHead.Next;
|
||||
qhRemove( Node );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhList< T >::PushBack( T* Node )
|
||||
{
|
||||
qhInsert( Node, mHead.Prev );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhList< T >::PopBack( void )
|
||||
{
|
||||
QH_ASSERT( !Empty() );
|
||||
|
||||
T* Node = mHead.Prev;
|
||||
qhRemove( Node );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhList< T >::Insert( T* Node, T* Where )
|
||||
{
|
||||
qhInsert( Node, Where );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhList< T >::Remove( T* Node )
|
||||
{
|
||||
qhRemove( Node );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
int qhList< T >::IndexOf( const T* Node ) const
|
||||
{
|
||||
int Index = 0;
|
||||
for ( const T* First = Begin(); First != End(); First = First->Next )
|
||||
{
|
||||
if ( First == Node )
|
||||
{
|
||||
return Index;
|
||||
}
|
||||
|
||||
Index++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T* qhList< T >::Begin( void )
|
||||
{
|
||||
return mHead.Next;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
const T* qhList< T >::Begin( void ) const
|
||||
{
|
||||
return mHead.Next;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T* qhList< T >::End( void )
|
||||
{
|
||||
return &mHead;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
const T* qhList< T >::End( void ) const
|
||||
{
|
||||
return &mHead;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
123
thirdparty/quickhull/qhMass.cpp
vendored
Normal file
123
thirdparty/quickhull/qhMass.cpp
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMass.cpp
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include "qhMass.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Local utilities
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline qhMatrix3 qhSteiner( qhReal Weight, const qhVector3& Center )
|
||||
{
|
||||
// Usage: Io = Ic + Is and Ic = Io - Is
|
||||
qhReal Ixx = Weight * ( Center.Y * Center.Y + Center.Z * Center.Z );
|
||||
qhReal Iyy = Weight * ( Center.X * Center.X + Center.Z * Center.Z );
|
||||
qhReal Izz = Weight * ( Center.X * Center.X + Center.Y * Center.Y );
|
||||
qhReal Ixy = -Weight * Center.X * Center.Y;
|
||||
qhReal Ixz = -Weight * Center.X * Center.Z;
|
||||
qhReal Iyz = -Weight * Center.Y * Center.Z;
|
||||
|
||||
// Write
|
||||
qhMatrix3 Out;
|
||||
Out.C1.X = Ixx; Out.C2.X = Ixy; Out.C3.X = Ixz;
|
||||
Out.C1.Y = Ixy; Out.C2.Y = Iyy; Out.C3.Y = Iyz;
|
||||
Out.C1.Z = Ixz; Out.C2.Z = Iyz; Out.C3.Z = Izz;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMass
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
qhMass::qhMass( void )
|
||||
: Weight( 0 )
|
||||
, Center( QH_VEC3_ZERO )
|
||||
, Inertia( QH_MAT3_ZERO )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
qhMass& qhMass::operator+=( const qhMass& Other )
|
||||
{
|
||||
Inertia += Other.Inertia;
|
||||
Center = ( Weight * Center + Other.Weight * Other.Center ) / ( Weight + Other.Weight );
|
||||
Weight += Other.Weight;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhMass::ShiftToOrigin( void )
|
||||
{
|
||||
Inertia += qhSteiner( Weight, Center );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhMass::ShiftToCenter( void )
|
||||
{
|
||||
Inertia -= qhSteiner( Weight, Center );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
qhMass qhSphereMass( const qhVector3& Center, qhReal Radius, qhReal Density )
|
||||
{
|
||||
qhReal Volume = qhReal( 0.4 ) * QH_PI * Radius * Radius * Radius;
|
||||
qhReal Weight = Volume * Density;
|
||||
|
||||
qhReal I = qhReal( 0.4 ) * Weight * Radius * Radius;
|
||||
|
||||
qhMass Mass;
|
||||
Mass.Weight = Weight;
|
||||
Mass.Center = Center;
|
||||
Mass.Inertia = qhMatrix3( I, I, I ) + qhSteiner( Weight, Center );
|
||||
|
||||
return Mass;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
qhMass qhCapsuleMass( const qhVector3& Center1, const qhVector3& Center2, qhReal Radius, qhReal Density )
|
||||
{
|
||||
// Compute height and check if we degenerate into a sphere
|
||||
qhReal Height = qhDistance( Center1, Center2 );
|
||||
if ( Height < qhReal( 100 ) * QH_REAL_EPSILON )
|
||||
{
|
||||
return qhSphereMass( qhReal( 0.5 ) * ( Center1 + Center2 ), Radius, Density );
|
||||
}
|
||||
|
||||
// Cylinder
|
||||
qhReal CylinderVolume = ( QH_PI * Radius * Radius ) * Height;
|
||||
qhReal CylinderWeight = CylinderVolume * Density;
|
||||
|
||||
// Sphere
|
||||
qhReal SphereVolume = qhReal( 4.0 / 3.0 ) * QH_PI * Radius * Radius * Radius;
|
||||
qhReal SphereWeight = SphereVolume * Density;
|
||||
|
||||
// Parallel Axis Theorem (Steiner)
|
||||
qhReal Offset = qhReal( 0.5 ) * Height + qhReal( 3.0 / 8.0 ) * Radius;
|
||||
|
||||
qhReal Ix = qhReal( 1.0 / 12.0 ) * CylinderWeight * ( qhReal( 3 ) * Radius * Radius + Height * Height ) + qhReal( 83.0 / 320.0 ) * SphereWeight * Radius * Radius + SphereWeight * Offset * Offset;
|
||||
qhReal Iy = qhReal( 0.5 ) * CylinderWeight * Radius * Radius + qhReal( 0.4 ) * SphereWeight * Radius * Radius;
|
||||
|
||||
// Align capsule axis with chosen up-axis
|
||||
qhReal Weight = SphereWeight + CylinderWeight;
|
||||
qhVector3 Center = qhReal( 0.5 ) * ( Center1 + Center2 );
|
||||
qhVector3 Direction = qhNormalize( Center2 - Center1 );
|
||||
qhQuaternion Q = qhRotation( QH_VEC3_AXIS_Y, Direction );
|
||||
qhMatrix3 R = qhConvert( Q );
|
||||
|
||||
qhMass Mass;
|
||||
Mass.Weight = Weight;
|
||||
Mass.Center = Center;
|
||||
Mass.Inertia = R * qhMatrix3( Ix, Iy, Ix ) * qhTranspose( R ) + qhSteiner( Weight, Center );
|
||||
|
||||
return Mass;
|
||||
}
|
||||
37
thirdparty/quickhull/qhMass.h
vendored
Normal file
37
thirdparty/quickhull/qhMass.h
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhMass.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 03/12/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include "qhTypes.h"
|
||||
#include "qhMath.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMass
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
struct qhMass
|
||||
{
|
||||
qhMass( void );
|
||||
|
||||
qhReal Weight;
|
||||
qhVector3 Center;
|
||||
qhMatrix3 Inertia;
|
||||
|
||||
qhMass& operator+=( const qhMass& Other );
|
||||
|
||||
void ShiftToOrigin( void );
|
||||
void ShiftToCenter( void );
|
||||
};
|
||||
|
||||
|
||||
qhMass qhSphereMass( const qhVector3& Center, qhReal Radius, qhReal Density = qhReal( 1 ) );
|
||||
qhMass qhCapsuleMass( const qhVector3& Center1, const qhVector3& Center2, qhReal Radius, qhReal Density = qhReal( 1 ) );
|
||||
125
thirdparty/quickhull/qhMath.cpp
vendored
Normal file
125
thirdparty/quickhull/qhMath.cpp
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMath.cpp
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include "qhMath.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Local utilities
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static inline qhBounds3 qhComputeBounds( const qhArray< qhVector3 >& Vertices, const qhTransform& Transform )
|
||||
{
|
||||
qhBounds3 Bounds = QH_BOUNDS3_EMPTY;
|
||||
for ( int Index = 0; Index < Vertices.Size(); ++Index )
|
||||
{
|
||||
Bounds += qhTMul( Transform, Vertices[ Index ] );
|
||||
}
|
||||
|
||||
return Bounds;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhBox
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhBox::GetVertices( qhVector3 Vertices[ 8 ] ) const
|
||||
{
|
||||
Vertices[ 0 ] = Orientation * qhVector3( Extent.X, -Extent.Y, Extent.Z ) + Center;
|
||||
Vertices[ 1 ] = Orientation * qhVector3( -Extent.X, -Extent.Y, Extent.Z ) + Center;
|
||||
Vertices[ 2 ] = Orientation * qhVector3( -Extent.X, -Extent.Y, -Extent.Z ) + Center;
|
||||
Vertices[ 3 ] = Orientation * qhVector3( Extent.X, -Extent.Y, -Extent.Z ) + Center;
|
||||
Vertices[ 4 ] = Orientation * qhVector3( Extent.X, Extent.Y, Extent.Z ) + Center;
|
||||
Vertices[ 5 ] = Orientation * qhVector3( -Extent.X, Extent.Y, Extent.Z ) + Center;
|
||||
Vertices[ 6 ] = Orientation * qhVector3( -Extent.X, Extent.Y, -Extent.Z ) + Center;
|
||||
Vertices[ 7 ] = Orientation * qhVector3( Extent.X, Extent.Y, -Extent.Z ) + Center;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
qhBox qhBestFit( const qhArray< qhVector3 >& Vertices, qhReal Threshold )
|
||||
{
|
||||
qhVector3 Center( 0, 0, 0 );
|
||||
for ( int Index = 0; Index < Vertices.Size(); ++Index )
|
||||
{
|
||||
Center += Vertices[ Index ];
|
||||
}
|
||||
Center = Center / float( Vertices.Size() );
|
||||
|
||||
qhBox BestBox;
|
||||
qhReal BestVolume = QH_REAL_MAX;
|
||||
|
||||
qhReal Sweep = qhReal( 45 );
|
||||
qhVector3 SweepCenter( 0, 0, 0 );
|
||||
|
||||
while ( Sweep >= Threshold )
|
||||
{
|
||||
bool Improved = false;
|
||||
qhVector3 BestAngles;
|
||||
|
||||
static const qhReal kSteps = 7.0;
|
||||
qhReal StepSize = Sweep / kSteps;
|
||||
|
||||
for ( qhReal X = SweepCenter.X - Sweep; X <= SweepCenter.X + Sweep; X += StepSize )
|
||||
{
|
||||
for ( qhReal Y = SweepCenter.Y - Sweep; Y <= SweepCenter.Y + Sweep; Y += StepSize )
|
||||
{
|
||||
for ( qhReal Z = SweepCenter.Z - Sweep; Z <= SweepCenter.Z + Sweep; Z += StepSize )
|
||||
{
|
||||
qhQuaternion Rx = qhRotationX( X * QH_DEG2RAD );
|
||||
qhQuaternion Ry = qhRotationY( Y * QH_DEG2RAD );
|
||||
qhQuaternion Rz = qhRotationZ( Z * QH_DEG2RAD );
|
||||
qhQuaternion R = Rz * Ry * Rx;
|
||||
|
||||
qhTransform Transform;
|
||||
Transform.Rotation = qhConvert( R );
|
||||
Transform.Translation = Center;
|
||||
|
||||
qhBounds3 Bounds = qhComputeBounds( Vertices, Transform );
|
||||
|
||||
float Volume = Bounds.GetVolume();
|
||||
if ( Volume < BestVolume )
|
||||
{
|
||||
BestBox.Center = Transform * Bounds.GetCenter();
|
||||
BestBox.Orientation = R;
|
||||
BestBox.Extent = Bounds.GetExtent();
|
||||
|
||||
BestVolume = Volume;
|
||||
BestAngles = qhVector3( X, Y, Z );
|
||||
|
||||
Improved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( Improved )
|
||||
{
|
||||
SweepCenter = BestAngles;
|
||||
Sweep *= 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return BestBox;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
qhBox qhBestFit( int VertexCount, const void* VertexBase, int VertexStride, qhReal Threshold )
|
||||
{
|
||||
qhArray< qhVector3 > Vertices;
|
||||
Vertices.Resize( VertexCount );
|
||||
|
||||
for ( int Index = 0; Index < VertexCount; ++Index )
|
||||
{
|
||||
Vertices[ Index ] = qhVector3( reinterpret_cast< const qhReal* >( VertexBase ) );
|
||||
VertexBase = qhAddByteOffset( VertexBase, VertexStride );
|
||||
}
|
||||
|
||||
return qhBestFit( Vertices, Threshold );
|
||||
}
|
||||
346
thirdparty/quickhull/qhMath.h
vendored
Normal file
346
thirdparty/quickhull/qhMath.h
vendored
Normal file
@@ -0,0 +1,346 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhMath.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 30/11/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include "qhTypes.h"
|
||||
#include "qhArray.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <limits>
|
||||
|
||||
class qhVector3;
|
||||
class qhMatrix3;
|
||||
class qhQuaternion;
|
||||
class qhTransform;
|
||||
class qhPlane;
|
||||
class qhBounds3;
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4201 ) // nameless structs/unions
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhConstants
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#define QH_PI qhReal( 3.14159265358 )
|
||||
#define QH_2PI qhReal( 6.28318530717 )
|
||||
#define QH_SQRT2 qhReal( 1.41421356237 )
|
||||
#define QH_SQRT3 qhReal( 1.73205080757 )
|
||||
|
||||
#define QH_DEG2RAD ( QH_PI / qhReal( 180 ) )
|
||||
#define QH_RAD2DEG ( qhReal( 180 ) / QH_PI )
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMath
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
qhReal qhSin( qhReal Rad );
|
||||
qhReal qhCos( qhReal Rad );
|
||||
qhReal qhTan( qhReal Rad );
|
||||
|
||||
qhReal qhArcSin( qhReal X );
|
||||
qhReal qhArcCos( qhReal X );
|
||||
qhReal qhArcTan( qhReal X );
|
||||
qhReal qhArcTan2( qhReal Y, qhReal X );
|
||||
|
||||
qhReal qhAbs( qhReal X );
|
||||
qhReal qhSqrt( qhReal X );
|
||||
|
||||
template< typename T > T qhMin( T X, T Y );
|
||||
template< typename T > T qhMax( T X, T Y );
|
||||
template< typename T > T qhClamp( T X, T Min, T Max );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhVector3
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhVector3
|
||||
{
|
||||
public:
|
||||
// Attributes
|
||||
qhReal X, Y, Z;
|
||||
|
||||
// Construction
|
||||
qhVector3( void );
|
||||
qhVector3( qhReal X, qhReal Y, qhReal Z );
|
||||
qhVector3( const qhReal* V );
|
||||
|
||||
// Conversion
|
||||
operator qhReal*( void );
|
||||
operator const qhReal*( void ) const;
|
||||
|
||||
// Assignment
|
||||
qhVector3& operator*=( const qhVector3& V );
|
||||
qhVector3& operator+=( const qhVector3& V );
|
||||
qhVector3& operator-=( const qhVector3& V );
|
||||
qhVector3& operator*=( qhReal S );
|
||||
qhVector3& operator/=( qhReal S );
|
||||
|
||||
// Unary operators
|
||||
qhVector3 operator+( void ) const;
|
||||
qhVector3 operator-( void ) const;
|
||||
};
|
||||
|
||||
// Binary operators
|
||||
qhVector3 operator*( const qhMatrix3& M, const qhVector3& V );
|
||||
qhVector3 operator*( const qhQuaternion& Q, const qhVector3& V );
|
||||
qhVector3 operator*( const qhTransform& T, const qhVector3& V );
|
||||
|
||||
qhVector3 operator*( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 operator+( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 operator-( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 operator*( qhReal S, const qhVector3& V );
|
||||
qhVector3 operator*( const qhVector3& V, qhReal S );
|
||||
qhVector3 operator/( const qhVector3& V, qhReal S );
|
||||
|
||||
bool operator==( const qhVector3& V1, const qhVector3& V2 );
|
||||
bool operator!=( const qhVector3& V1, const qhVector3& V2 );
|
||||
|
||||
// Standard vector operations
|
||||
void qhStore( qhReal Dst[ 3 ], const qhVector3& V );
|
||||
|
||||
qhVector3 qhMul( const qhMatrix3& M, const qhVector3& V );
|
||||
qhVector3 qhTMul( const qhMatrix3& M, const qhVector3& V );
|
||||
qhVector3 qhMul( const qhQuaternion& Q, const qhVector3& V );
|
||||
qhVector3 qhTMul( const qhQuaternion& Q, const qhVector3& V );
|
||||
qhVector3 qhMul( const qhTransform& T, const qhVector3& V );
|
||||
qhVector3 qhTMul( const qhTransform& T, const qhVector3& V );
|
||||
|
||||
qhVector3 qhMul( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 qhAdd( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 qhSub( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 qhCross( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 qhScale( const qhVector3& V, qhReal S );
|
||||
qhVector3 qhNormalize( const qhVector3& V );
|
||||
qhVector3 qhNegate( const qhVector3& V );
|
||||
|
||||
qhVector3 qhAbs( const qhVector3& V );
|
||||
qhVector3 qhMin( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 qhMax( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhVector3 qhClamp( const qhVector3& V, const qhVector3& Min, const qhVector3& Max );
|
||||
|
||||
qhReal qhDot( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhReal qhLength( const qhVector3& V );
|
||||
qhReal qhLengthSq( const qhVector3& V );
|
||||
qhReal qhDistance( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhReal qhDistanceSq( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhReal qhDet( const qhVector3& V1, const qhVector3& V2, const qhVector3& V3 );
|
||||
|
||||
int qhMinElement( const qhVector3& V );
|
||||
int qhMaxElement( const qhVector3& V );
|
||||
|
||||
// Constants
|
||||
QH_GLOBAL_CONSTANT const qhVector3 QH_VEC3_ZERO = qhVector3( 0, 0, 0 );
|
||||
QH_GLOBAL_CONSTANT const qhVector3 QH_VEC3_AXIS_X = qhVector3( 1, 0, 0 );
|
||||
QH_GLOBAL_CONSTANT const qhVector3 QH_VEC3_AXIS_Y = qhVector3( 0, 1, 0 );
|
||||
QH_GLOBAL_CONSTANT const qhVector3 QH_VEC3_AXIS_Z = qhVector3( 0, 0, 1 );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMatrix3
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhMatrix3
|
||||
{
|
||||
public:
|
||||
// Attributes
|
||||
qhVector3 C1, C2, C3;
|
||||
|
||||
// Construction
|
||||
qhMatrix3( void );
|
||||
qhMatrix3( qhReal A11, qhReal A22, qhReal A33 );
|
||||
qhMatrix3( const qhVector3& C1, const qhVector3& C2, const qhVector3& C3 );
|
||||
|
||||
// Assignment
|
||||
qhMatrix3& operator*=( const qhMatrix3& M );
|
||||
qhMatrix3& operator+=( const qhMatrix3& M );
|
||||
qhMatrix3& operator-=( const qhMatrix3& M );
|
||||
qhMatrix3& operator*=( qhReal F );
|
||||
qhMatrix3& operator/=( qhReal F );
|
||||
|
||||
// Unary operators
|
||||
qhMatrix3 operator+( void ) const;
|
||||
qhMatrix3 operator-( void ) const;
|
||||
};
|
||||
|
||||
// Binary arithmetic operators
|
||||
qhMatrix3 operator*( const qhMatrix3& M1, const qhMatrix3& M2 );
|
||||
qhMatrix3 operator+( const qhMatrix3& M1, const qhMatrix3& M2 );
|
||||
qhMatrix3 operator-( const qhMatrix3& M1, const qhMatrix3& M2 );
|
||||
qhMatrix3 operator*( qhReal F, const qhMatrix3& M );
|
||||
qhMatrix3 operator*( const qhMatrix3& M, qhReal F );
|
||||
qhMatrix3 operator/( const qhMatrix3& M, qhReal F );
|
||||
|
||||
// Comparison operators
|
||||
bool operator==( const qhMatrix3& M1, const qhMatrix3& M2 );
|
||||
bool operator!=( const qhMatrix3& M1, const qhMatrix3& M2 );
|
||||
|
||||
// Standard matrix operations
|
||||
qhMatrix3 qhMul( const qhMatrix3& M1, const qhMatrix3& M2 );
|
||||
qhMatrix3 qhTMul( const qhMatrix3& M1, const qhMatrix3& M2 );
|
||||
qhMatrix3 qhTranspose( const qhMatrix3& M );
|
||||
qhMatrix3 qhAdjoint( const qhMatrix3& M );
|
||||
qhMatrix3 qhInvert( const qhMatrix3& M );
|
||||
qhMatrix3 qhInvertT( const qhMatrix3& M );
|
||||
qhMatrix3 qhConvert( const qhQuaternion& Q );
|
||||
qhMatrix3 qhSkew( const qhVector3& V );
|
||||
|
||||
qhReal qhTrace( const qhMatrix3& M );
|
||||
qhReal qhDet( const qhMatrix3& M );
|
||||
|
||||
// Constants
|
||||
QH_GLOBAL_CONSTANT const qhMatrix3 QH_MAT3_ZERO = qhMatrix3( qhVector3( 0, 0, 0 ), qhVector3( 0, 0, 0 ), qhVector3( 0, 0, 0 ) );
|
||||
QH_GLOBAL_CONSTANT const qhMatrix3 QH_MAT3_IDENTITY = qhMatrix3( qhVector3( 1, 0, 0 ), qhVector3( 0, 1, 0 ), qhVector3( 0, 0, 1 ) );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhQuaternion
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhQuaternion
|
||||
{
|
||||
public:
|
||||
// Attributes
|
||||
qhReal X, Y, Z, W;
|
||||
|
||||
// Construction
|
||||
qhQuaternion( void );
|
||||
qhQuaternion( qhReal X, qhReal Y, qhReal Z, qhReal W );
|
||||
qhQuaternion( const qhVector3& V, qhReal S );
|
||||
qhQuaternion( const qhReal* Q );
|
||||
|
||||
qhVector3 V( void ) const { return qhVector3( X, Y, Z ); }
|
||||
qhReal S( void ) const { return W; }
|
||||
|
||||
};
|
||||
|
||||
qhQuaternion operator*( const qhQuaternion& Q1, const qhQuaternion& Q2 );
|
||||
|
||||
qhQuaternion qhRotation( const qhVector3& V1, const qhVector3& V2 );
|
||||
qhQuaternion qhRotationX( qhReal Rad );
|
||||
qhQuaternion qhRotationY( qhReal Rad );
|
||||
qhQuaternion qhRotationZ( qhReal Rad );
|
||||
|
||||
qhQuaternion qhConjugate( const qhQuaternion& Q );
|
||||
qhQuaternion qhNormalize( const qhQuaternion& Q );
|
||||
|
||||
qhReal qhDot( const qhQuaternion& Q1, const qhQuaternion& Q2 );
|
||||
qhReal qhLength( const qhQuaternion& Q );
|
||||
qhReal qhLengthSq( const qhQuaternion& Q );
|
||||
|
||||
// Constants
|
||||
QH_GLOBAL_CONSTANT const qhQuaternion QH_QUAT_ZERO = qhQuaternion( 0, 0, 0, 0 );
|
||||
QH_GLOBAL_CONSTANT const qhQuaternion QH_QUAT_IDENTITY = qhQuaternion( 0, 0, 0, 1 );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhTranform
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhTransform
|
||||
{
|
||||
public:
|
||||
// Attributes
|
||||
qhMatrix3 Rotation;
|
||||
qhVector3 Translation;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhPlane
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhPlane
|
||||
{
|
||||
public:
|
||||
// Attributes
|
||||
qhVector3 Normal;
|
||||
qhReal Offset;
|
||||
|
||||
// Construction
|
||||
qhPlane( void );
|
||||
qhPlane( const qhVector3& Normal, qhReal Offset );
|
||||
qhPlane( const qhVector3& Normal, const qhVector3& Point );
|
||||
qhPlane( const qhVector3& Point1, const qhVector3& Point2, const qhVector3& Point3 );
|
||||
|
||||
void Negate( void );
|
||||
void Normalize( void );
|
||||
void Translate( const qhVector3& Translation );
|
||||
|
||||
qhReal Distance( const qhVector3& Point ) const;
|
||||
};
|
||||
|
||||
// Standard plane operations
|
||||
void qhStore( qhReal Dst[ 4 ], const qhPlane& Plane );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhPlane
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhBounds3
|
||||
{
|
||||
public:
|
||||
// Attributes
|
||||
qhVector3 Min, Max;
|
||||
|
||||
// Construction
|
||||
qhBounds3( void );
|
||||
qhBounds3( const qhVector3& Min, const qhVector3& Max );
|
||||
|
||||
// Assignment
|
||||
qhBounds3& operator+=( const qhVector3& Point );
|
||||
qhBounds3& operator+=( const qhBounds3& Bounds );
|
||||
|
||||
// Standard bounds operations
|
||||
qhVector3 GetCenter( void ) const;
|
||||
qhVector3 GetExtent( void ) const;
|
||||
|
||||
qhReal GetVolume( void ) const;
|
||||
};
|
||||
|
||||
// Binary arithmetic operators
|
||||
qhBounds3 operator+( const qhBounds3& Bounds1, const qhBounds3& Bounds2 );
|
||||
|
||||
// Comparison operators
|
||||
bool operator==( const qhBounds3& Bounds1, const qhBounds3& Bounds2 );
|
||||
bool operator!=( const qhBounds3& Bounds1, const qhBounds3& Bounds2 );
|
||||
|
||||
QH_GLOBAL_CONSTANT const qhBounds3 QH_BOUNDS3_EMPTY = qhBounds3( qhVector3( QH_REAL_MAX, QH_REAL_MAX, QH_REAL_MAX ), qhVector3( -QH_REAL_MAX, -QH_REAL_MAX, -QH_REAL_MAX ) );
|
||||
QH_GLOBAL_CONSTANT const qhBounds3 QH_BOUNDS3_INFINITE = qhBounds3( qhVector3( -QH_REAL_MAX, -QH_REAL_MAX, -QH_REAL_MAX ), qhVector3( QH_REAL_MAX, QH_REAL_MAX, QH_REAL_MAX ) );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhBox
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class qhBox
|
||||
{
|
||||
public:
|
||||
qhVector3 Center;
|
||||
qhQuaternion Orientation;
|
||||
qhVector3 Extent;
|
||||
|
||||
void GetVertices( qhVector3 Vertices[ 8 ] ) const;
|
||||
};
|
||||
|
||||
qhBox qhBestFit( const qhArray< qhVector3 >& Vertices, qhReal Threshold = qhReal( 1 ) );
|
||||
qhBox qhBestFit( int VertexCount, const void* VertexBase, int VertexStride = 3 * sizeof( qhReal ), qhReal Threshold = qhReal( 1 ) );
|
||||
|
||||
|
||||
|
||||
#include "qhMath.inl"
|
||||
|
||||
#pragma warning( pop )
|
||||
1141
thirdparty/quickhull/qhMath.inl
vendored
Normal file
1141
thirdparty/quickhull/qhMath.inl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
49
thirdparty/quickhull/qhMemory.cpp
vendored
Normal file
49
thirdparty/quickhull/qhMemory.cpp
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMemory.cpp
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#include "qhMemory.h"
|
||||
#include "qhTypes.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Local utilities
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static void* qhDefaultAlloc( size_t Bytes )
|
||||
{
|
||||
return malloc( Bytes );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static void qhDefaultFree( void* Address )
|
||||
{
|
||||
return free( Address );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMemory
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void* (*qhAllocHook)( size_t ) = qhDefaultAlloc;
|
||||
void (*qhFreeHook)( void* ) = qhDefaultFree;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void* qhAlloc( size_t Bytes )
|
||||
{
|
||||
QH_ASSERT( qhAllocHook != NULL );
|
||||
return qhAllocHook( Bytes );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void qhFree( void* Address )
|
||||
{
|
||||
QH_ASSERT( qhFreeHook != NULL );
|
||||
qhFreeHook( Address );
|
||||
}
|
||||
|
||||
79
thirdparty/quickhull/qhMemory.h
vendored
Normal file
79
thirdparty/quickhull/qhMemory.h
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhMemory.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 30/11/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include <new>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMemory
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
extern void* (*qhAllocHook)( std::size_t );
|
||||
extern void (*qhFreeHook)( void* );
|
||||
|
||||
void* qhAlloc( std::size_t Bytes );
|
||||
void qhFree( void* Address );
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhPool
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T >
|
||||
class qhPool
|
||||
{
|
||||
public:
|
||||
qhPool( void );
|
||||
~qhPool( void );
|
||||
|
||||
void Clear( void );
|
||||
void Resize( int Size );
|
||||
T* Allocate( void );
|
||||
void Free( T* Address );
|
||||
|
||||
private:
|
||||
int mSize;
|
||||
T* mPool;
|
||||
int mFree;
|
||||
|
||||
// Non-copyable
|
||||
qhPool( const qhPool& );
|
||||
qhPool& operator=( const qhPool& );
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Memory utilities
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T >
|
||||
void qhConstruct( T* Address );
|
||||
|
||||
template < typename T >
|
||||
void qhConstruct( T* Address, int N );
|
||||
|
||||
template < typename T >
|
||||
void qhCopyConstruct( T* Address, const T& Other );
|
||||
|
||||
template < typename T >
|
||||
void qhDestroy( T* Address );
|
||||
|
||||
template < typename T >
|
||||
void qhDestroy( T* Address, int N );
|
||||
|
||||
template < typename T >
|
||||
void qhMove( T* address, T* Begin, T* End );
|
||||
|
||||
template < typename T >
|
||||
void qhSwap( T& Lhs, T& Rhs );
|
||||
|
||||
const void* qhAddByteOffset( const void* Address, std::size_t Bytes );
|
||||
|
||||
|
||||
#include "qhMemory.inl"
|
||||
175
thirdparty/quickhull/qhMemory.inl
vendored
Normal file
175
thirdparty/quickhull/qhMemory.inl
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhMemory.inl
|
||||
//
|
||||
// Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
#include "qhTypes.h"
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhPool
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
qhPool< T >::qhPool( void )
|
||||
: mSize( 0 )
|
||||
, mPool( NULL )
|
||||
, mFree( -1 )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
qhPool< T >::~qhPool( void )
|
||||
{
|
||||
qhFree( mPool );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhPool< T >::Clear( void )
|
||||
{
|
||||
mSize = 0;
|
||||
qhFree( mPool );
|
||||
mPool = NULL;
|
||||
mFree = -1;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhPool< T >::Resize( int Size )
|
||||
{
|
||||
QH_ASSERT( mSize == 0 && mPool == NULL );
|
||||
|
||||
mSize = Size;
|
||||
mPool = (T*)qhAlloc( Size * sizeof( T ) );
|
||||
mFree = 0;
|
||||
|
||||
for ( int i = 0; i < mSize - 1; ++i )
|
||||
{
|
||||
int* Next = (int*)( mPool + i );
|
||||
*Next = i + 1;
|
||||
}
|
||||
|
||||
int* Next = (int*)( mPool + mSize - 1 );
|
||||
*Next = -1;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
T* qhPool< T >::Allocate( void )
|
||||
{
|
||||
QH_ASSERT( mFree >= 0 );
|
||||
int Next = mFree;
|
||||
mFree = *(int*)( mPool + mFree );
|
||||
|
||||
#ifdef QH_DEBUG
|
||||
memset( mPool + Next, 0xcd, sizeof( T ) );
|
||||
#endif
|
||||
|
||||
return mPool + Next;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhPool< T >::Free( T* Address )
|
||||
{
|
||||
#ifdef QH_DEBUG
|
||||
QH_ASSERT( Address != NULL );
|
||||
memset( Address, 0xdb, sizeof( T ) );
|
||||
#endif
|
||||
|
||||
QH_ASSERT( mPool <= Address && Address < mPool + mSize );
|
||||
int* Next = (int*)Address;
|
||||
*Next = mFree;
|
||||
|
||||
mFree = int( Address - mPool );
|
||||
QH_ASSERT( 0 <= mFree && mFree < mSize );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// Memory utilities
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhConstruct( T* Address )
|
||||
{
|
||||
new ( Address ) T;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhConstruct( T* Address, int N )
|
||||
{
|
||||
// If n < 0 no objects are constructed (e.g. if shrinking an array)
|
||||
for ( int i = 0; i < N; ++i )
|
||||
{
|
||||
new ( Address + i ) T;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhCopyConstruct( T* Address, const T& Other )
|
||||
{
|
||||
new ( Address ) T( Other );
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhDestroy( T* Address )
|
||||
{
|
||||
( Address )->~T();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template < typename T > inline
|
||||
void qhDestroy( T* Address, int N )
|
||||
{
|
||||
// If n < 0 no objects are destroyed (e.g. if growing an array)
|
||||
for ( int i = 0; i < N; ++i )
|
||||
{
|
||||
( Address + i )->~T();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
template < typename T >
|
||||
void qhMove( T* Address, T* Begin, T* End )
|
||||
{
|
||||
while ( Begin != End )
|
||||
{
|
||||
new ( Address ) T;
|
||||
qhSwap( *Address++, *Begin++ );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
template <typename T> inline
|
||||
void qhSwap( T& Lhs, T& Rhs )
|
||||
{
|
||||
T Temp = Lhs;
|
||||
Lhs = Rhs;
|
||||
Rhs = Temp;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
inline const void* qhAddByteOffset( const void* Address, size_t Bytes )
|
||||
{
|
||||
return reinterpret_cast< const unsigned char* >( Address ) + Bytes;
|
||||
}
|
||||
38
thirdparty/quickhull/qhTypes.h
vendored
Normal file
38
thirdparty/quickhull/qhTypes.h
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
@file qhTypes.h
|
||||
|
||||
@author Dirk Gregorius
|
||||
@version 0.1
|
||||
@date 30/11/2011
|
||||
|
||||
Copyright(C) 2011 by D. Gregorius. All rights reserved.
|
||||
*/
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#pragma once
|
||||
|
||||
#include "tier0/dbg.h"
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhTypes
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
typedef float qhReal;
|
||||
typedef unsigned int qhIndex;
|
||||
|
||||
#define QH_REAL_MIN std::numeric_limits< qhReal >::min()
|
||||
#define QH_REAL_MAX std::numeric_limits< qhReal >::max()
|
||||
#define QH_REAL_EPSILON std::numeric_limits< qhReal >::epsilon()
|
||||
|
||||
#ifndef _MSC_VER
|
||||
# define QH_GLOBAL_CONSTANT static
|
||||
#else
|
||||
# define QH_GLOBAL_CONSTANT extern __declspec( selectany )
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// qhAssert
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#define QH_ASSERT( Cond ) Assert( Cond )
|
||||
49
thirdparty/quickhull/quickhull.vpc
vendored
Normal file
49
thirdparty/quickhull/quickhull.vpc
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// quickhull.vpc
|
||||
//
|
||||
// Project Script
|
||||
//-----------------------------------------------------------------------------
|
||||
$macro SRCDIR "..\.."
|
||||
//$macro OUTLIBDIR "$SRCDIR\lib\public"
|
||||
|
||||
$include "$SRCDIR\vpc_scripts\source_lib_base.vpc"
|
||||
|
||||
|
||||
$Configuration
|
||||
{
|
||||
$Compiler
|
||||
{
|
||||
$AdditionalIncludeDirectories "$BASE;$SRCDIR\public;$SRCDIR\common;$SRCDIR\public\quickhull"
|
||||
$DisableSpecificWarnings "$BASE;4127;4239" [$WINDOWS]
|
||||
$EnableRunTimeTypeInfo "No (/GR-)"
|
||||
}
|
||||
$Compiler [$WINDOWS]
|
||||
{
|
||||
$EnableEnhancedInstructionSet "Streaming SIMD Extensions (/arch:SSE)"
|
||||
}
|
||||
}
|
||||
|
||||
$Project "quickhull"
|
||||
{
|
||||
$Folder "Source Files"
|
||||
{
|
||||
$File "qhTypes.h"
|
||||
$File "qhMath.h"
|
||||
$File "qhMath.inl"
|
||||
$File "qhMath.cpp"
|
||||
$File "qhMemory.h"
|
||||
$File "qhMemory.inl"
|
||||
$File "qhMemory.cpp"
|
||||
$File "qhArray.h"
|
||||
$File "qhArray.inl"
|
||||
$File "qhList.h"
|
||||
$File "qhList.inl"
|
||||
$File "qhHalfEdge.h"
|
||||
$File "qhHalfEdge.cpp"
|
||||
$File "qhConvex.h"
|
||||
$File "qhConvex.inl"
|
||||
$File "qhConvex.cpp"
|
||||
$File "qhMass.h"
|
||||
$File "qhMass.cpp"
|
||||
}
|
||||
}
|
||||
13
thirdparty/quickhull/quickhull.vpc.vpc_cache
vendored
Normal file
13
thirdparty/quickhull/quickhull.vpc.vpc_cache
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"vpc_cache"
|
||||
{
|
||||
"CacheVersion" "1"
|
||||
"win32"
|
||||
{
|
||||
"CRCFile" "quickhull.vcxproj.vpc_crc"
|
||||
"OutputFiles"
|
||||
{
|
||||
"0" "quickhull.vcxproj"
|
||||
"1" "quickhull.vcxproj.filters"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user