mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 23:54:35 +00:00
Merge pull request #1021 from ohmtal/development
FreeBSD ready reloaded
This commit is contained in:
commit
b481dc5db9
11 changed files with 459 additions and 263 deletions
|
|
@ -58,7 +58,7 @@ NvRemoveTjunctions.cpp : A code snippet to remove tjunctions from a triangle mes
|
||||||
#pragma warning(disable:4702)
|
#pragma warning(disable:4702)
|
||||||
#pragma warning(disable:4127) //conditional expression is constant (because _HAS_EXCEPTIONS=0)
|
#pragma warning(disable:4127) //conditional expression is constant (because _HAS_EXCEPTIONS=0)
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#ifdef __APPLE__
|
#if defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
#include <ext/hash_map>
|
#include <ext/hash_map>
|
||||||
#elif LINUX
|
#elif LINUX
|
||||||
#include <hash_map>
|
#include <hash_map>
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,16 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
#include <sys/malloc.h>
|
#include <sys/malloc.h>
|
||||||
|
#else
|
||||||
|
#if defined( __FreeBSD__)
|
||||||
|
#include <stdlib.h>
|
||||||
#else
|
#else
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__CELLOS_LV2__) || defined(LINUX)
|
#if defined(__APPLE__) || defined(__CELLOS_LV2__) || defined(LINUX)
|
||||||
|
|
@ -73,7 +78,7 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#if defined(WIN32)
|
||||||
typedef __int64 NxI64;
|
typedef __int64 NxI64;
|
||||||
typedef signed int NxI32;
|
typedef signed int NxI32;
|
||||||
typedef signed short NxI16;
|
typedef signed short NxI16;
|
||||||
|
|
@ -86,7 +91,7 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
|
||||||
|
|
||||||
typedef float NxF32;
|
typedef float NxF32;
|
||||||
typedef double NxF64;
|
typedef double NxF64;
|
||||||
|
|
||||||
#elif defined(LINUX)
|
#elif defined(LINUX)
|
||||||
typedef long long NxI64;
|
typedef long long NxI64;
|
||||||
typedef signed int NxI32;
|
typedef signed int NxI32;
|
||||||
|
|
@ -115,6 +120,20 @@ NvSimpleTypes.h : Defines basic data types for integers and floats.
|
||||||
typedef float NxF32;
|
typedef float NxF32;
|
||||||
typedef double NxF64;
|
typedef double NxF64;
|
||||||
|
|
||||||
|
#elif defined(__FreeBSD__)
|
||||||
|
typedef long long NxI64;
|
||||||
|
typedef signed int NxI32;
|
||||||
|
typedef signed short NxI16;
|
||||||
|
typedef signed char NxI8;
|
||||||
|
|
||||||
|
typedef unsigned long long NxU64;
|
||||||
|
typedef unsigned int NxU32;
|
||||||
|
typedef unsigned short NxU16;
|
||||||
|
typedef unsigned char NxU8;
|
||||||
|
|
||||||
|
typedef float NxF32;
|
||||||
|
typedef double NxF64;
|
||||||
|
|
||||||
#elif defined(__CELLOS_LV2__)
|
#elif defined(__CELLOS_LV2__)
|
||||||
typedef long long NxI64;
|
typedef long long NxI64;
|
||||||
typedef signed int NxI32;
|
typedef signed int NxI32;
|
||||||
|
|
|
||||||
|
|
@ -302,13 +302,13 @@ template <class Type> NxI32 Array<Type>::IndexOf(Type t)
|
||||||
|
|
||||||
|
|
||||||
NxI32 argmin(NxF32 a[],NxI32 n);
|
NxI32 argmin(NxF32 a[],NxI32 n);
|
||||||
NxF32 sqr(NxF32 a);
|
NxF32 sqr(NxF32 a);
|
||||||
NxF32 clampf(NxF32 a) ;
|
NxF32 clampf(NxF32 a) ;
|
||||||
NxF32 Round(NxF32 a,NxF32 precision);
|
NxF32 Round(NxF32 a,NxF32 precision);
|
||||||
NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha) ;
|
NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha) ;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void Swap(T &a,T &b)
|
void Swap(T &a,T &b)
|
||||||
{
|
{
|
||||||
T tmp = a;
|
T tmp = a;
|
||||||
a=b;
|
a=b;
|
||||||
|
|
@ -318,13 +318,13 @@ void Swap(T &a,T &b)
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
T Max(const T &a,const T &b)
|
T Max(const T &a,const T &b)
|
||||||
{
|
{
|
||||||
return (a>b)?a:b;
|
return (a>b)?a:b;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
T Min(const T &a,const T &b)
|
T Min(const T &a,const T &b)
|
||||||
{
|
{
|
||||||
return (a<b)?a:b;
|
return (a<b)?a:b;
|
||||||
}
|
}
|
||||||
|
|
@ -409,7 +409,7 @@ class float3x3 : public Memalloc
|
||||||
const float3& operator[](NxI32 i) const {assert(i>=0&&i<3);return (&x)[i];}
|
const float3& operator[](NxI32 i) const {assert(i>=0&&i<3);return (&x)[i];}
|
||||||
NxF32& operator()(NxI32 r, NxI32 c) {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];}
|
NxF32& operator()(NxI32 r, NxI32 c) {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];}
|
||||||
const NxF32& operator()(NxI32 r, NxI32 c) const {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];}
|
const NxF32& operator()(NxI32 r, NxI32 c) const {assert(r>=0&&r<3&&c>=0&&c<3);return ((&x)[r])[c];}
|
||||||
};
|
};
|
||||||
float3x3 Transpose( const float3x3& m );
|
float3x3 Transpose( const float3x3& m );
|
||||||
float3 operator*( const float3& v , const float3x3& m );
|
float3 operator*( const float3& v , const float3x3& m );
|
||||||
float3 operator*( const float3x3& m , const float3& v );
|
float3 operator*( const float3x3& m , const float3& v );
|
||||||
|
|
@ -442,7 +442,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct D3DXMATRIX;
|
struct D3DXMATRIX;
|
||||||
|
|
||||||
class float4x4 : public Memalloc
|
class float4x4 : public Memalloc
|
||||||
{
|
{
|
||||||
|
|
@ -450,9 +450,9 @@ class float4x4 : public Memalloc
|
||||||
float4 x,y,z,w; // the 4 rows
|
float4 x,y,z,w; // the 4 rows
|
||||||
float4x4(){}
|
float4x4(){}
|
||||||
float4x4(const float4 &_x, const float4 &_y, const float4 &_z, const float4 &_w):x(_x),y(_y),z(_z),w(_w){}
|
float4x4(const float4 &_x, const float4 &_y, const float4 &_z, const float4 &_w):x(_x),y(_y),z(_z),w(_w){}
|
||||||
float4x4(NxF32 m00, NxF32 m01, NxF32 m02, NxF32 m03,
|
float4x4(NxF32 m00, NxF32 m01, NxF32 m02, NxF32 m03,
|
||||||
NxF32 m10, NxF32 m11, NxF32 m12, NxF32 m13,
|
NxF32 m10, NxF32 m11, NxF32 m12, NxF32 m13,
|
||||||
NxF32 m20, NxF32 m21, NxF32 m22, NxF32 m23,
|
NxF32 m20, NxF32 m21, NxF32 m22, NxF32 m23,
|
||||||
NxF32 m30, NxF32 m31, NxF32 m32, NxF32 m33 )
|
NxF32 m30, NxF32 m31, NxF32 m32, NxF32 m33 )
|
||||||
:x(m00,m01,m02,m03),y(m10,m11,m12,m13),z(m20,m21,m22,m23),w(m30,m31,m32,m33){}
|
:x(m00,m01,m02,m03),y(m10,m11,m12,m13),z(m20,m21,m22,m23),w(m30,m31,m32,m33){}
|
||||||
NxF32& operator()(NxI32 r, NxI32 c) {assert(r>=0&&r<4&&c>=0&&c<4);return ((&x)[r])[c];}
|
NxF32& operator()(NxI32 r, NxI32 c) {assert(r>=0&&r<4&&c>=0&&c<4);return ((&x)[r])[c];}
|
||||||
|
|
@ -510,7 +510,7 @@ NxF32 dot( const Quaternion &a, const Quaternion &b );
|
||||||
float3 operator*( const Quaternion& q, const float3& v );
|
float3 operator*( const Quaternion& q, const float3& v );
|
||||||
float3 operator*( const float3& v, const Quaternion& q );
|
float3 operator*( const float3& v, const Quaternion& q );
|
||||||
Quaternion slerp( Quaternion a, const Quaternion& b, NxF32 interp );
|
Quaternion slerp( Quaternion a, const Quaternion& b, NxF32 interp );
|
||||||
Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,NxF32 alpha);
|
Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,NxF32 alpha);
|
||||||
Quaternion RotationArc(float3 v0, float3 v1 ); // returns quat q where q*v0=v1
|
Quaternion RotationArc(float3 v0, float3 v1 ); // returns quat q where q*v0=v1
|
||||||
Quaternion Inverse(const Quaternion &q);
|
Quaternion Inverse(const Quaternion &q);
|
||||||
float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v);
|
float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v);
|
||||||
|
|
@ -528,7 +528,7 @@ NxF32 Pitch( const float3& v );
|
||||||
|
|
||||||
//------- Plane ----------
|
//------- Plane ----------
|
||||||
|
|
||||||
class Plane
|
class Plane
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
float3 normal;
|
float3 normal;
|
||||||
|
|
@ -576,7 +576,7 @@ NxF32 Round(NxF32 a,NxF32 precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha)
|
NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha)
|
||||||
{
|
{
|
||||||
return f0*(1-alpha) + f1*alpha;
|
return f0*(1-alpha) + f1*alpha;
|
||||||
}
|
}
|
||||||
|
|
@ -585,11 +585,11 @@ NxF32 Interpolate(const NxF32 &f0,const NxF32 &f1,NxF32 alpha)
|
||||||
NxI32 argmin(NxF32 a[],NxI32 n)
|
NxI32 argmin(NxF32 a[],NxI32 n)
|
||||||
{
|
{
|
||||||
NxI32 r=0;
|
NxI32 r=0;
|
||||||
for(NxI32 i=1;i<n;i++)
|
for(NxI32 i=1;i<n;i++)
|
||||||
{
|
{
|
||||||
if(a[i]<a[r])
|
if(a[i]<a[r])
|
||||||
{
|
{
|
||||||
r = i;
|
r = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|
@ -601,49 +601,49 @@ NxI32 argmin(NxF32 a[],NxI32 n)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float3 operator+( const float3& a, const float3& b )
|
float3 operator+( const float3& a, const float3& b )
|
||||||
{
|
{
|
||||||
return float3(a.x+b.x, a.y+b.y, a.z+b.z);
|
return float3(a.x+b.x, a.y+b.y, a.z+b.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float3 operator-( const float3& a, const float3& b )
|
float3 operator-( const float3& a, const float3& b )
|
||||||
{
|
{
|
||||||
return float3( a.x-b.x, a.y-b.y, a.z-b.z );
|
return float3( a.x-b.x, a.y-b.y, a.z-b.z );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float3 operator-( const float3& v )
|
float3 operator-( const float3& v )
|
||||||
{
|
{
|
||||||
return float3( -v.x, -v.y, -v.z );
|
return float3( -v.x, -v.y, -v.z );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float3 operator*( const float3& v, NxF32 s )
|
float3 operator*( const float3& v, NxF32 s )
|
||||||
{
|
{
|
||||||
return float3( v.x*s, v.y*s, v.z*s );
|
return float3( v.x*s, v.y*s, v.z*s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float3 operator*( NxF32 s, const float3& v )
|
float3 operator*( NxF32 s, const float3& v )
|
||||||
{
|
{
|
||||||
return float3( v.x*s, v.y*s, v.z*s );
|
return float3( v.x*s, v.y*s, v.z*s );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float3 operator/( const float3& v, NxF32 s )
|
float3 operator/( const float3& v, NxF32 s )
|
||||||
{
|
|
||||||
return v*(1.0f/s);
|
|
||||||
}
|
|
||||||
|
|
||||||
NxF32 dot( const float3& a, const float3& b )
|
|
||||||
{
|
{
|
||||||
return a.x*b.x + a.y*b.y + a.z*b.z;
|
return v*(1.0f/s);
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 cmul( const float3 &v1, const float3 &v2)
|
NxF32 dot( const float3& a, const float3& b )
|
||||||
{
|
{
|
||||||
return float3(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z);
|
return a.x*b.x + a.y*b.y + a.z*b.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
float3 cmul( const float3 &v1, const float3 &v2)
|
||||||
|
{
|
||||||
|
return float3(v1.x*v2.x, v1.y*v2.y, v1.z*v2.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -710,7 +710,7 @@ float3 normalize( const float3 &v )
|
||||||
{
|
{
|
||||||
// this routine, normalize, is ok, provided magnitude works!!
|
// this routine, normalize, is ok, provided magnitude works!!
|
||||||
NxF32 d=magnitude(v);
|
NxF32 d=magnitude(v);
|
||||||
if (d==0)
|
if (d==0)
|
||||||
{
|
{
|
||||||
printf("Cant normalize ZERO vector\n");
|
printf("Cant normalize ZERO vector\n");
|
||||||
assert(0);// yes this could go here
|
assert(0);// yes this could go here
|
||||||
|
|
@ -735,7 +735,7 @@ float3 Round(const float3 &a,NxF32 precision)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float3 Interpolate(const float3 &v0,const float3 &v1,NxF32 alpha)
|
float3 Interpolate(const float3 &v0,const float3 &v1,NxF32 alpha)
|
||||||
{
|
{
|
||||||
return v0*(1-alpha) + v1*alpha;
|
return v0*(1-alpha) + v1*alpha;
|
||||||
}
|
}
|
||||||
|
|
@ -755,7 +755,7 @@ float3 VectorMax(const float3 &a,const float3 &b)
|
||||||
// - dot product
|
// - dot product
|
||||||
// - cross product
|
// - cross product
|
||||||
// Therefore we never declare/implement this function.
|
// Therefore we never declare/implement this function.
|
||||||
// So we will never see: float3 operator*(float3 a,float3 b)
|
// So we will never see: float3 operator*(float3 a,float3 b)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -763,7 +763,7 @@ float3 VectorMax(const float3 &a,const float3 &b)
|
||||||
//------------ float3x3 ---------------
|
//------------ float3x3 ---------------
|
||||||
NxF32 Determinant(const float3x3 &m)
|
NxF32 Determinant(const float3x3 &m)
|
||||||
{
|
{
|
||||||
return m.x.x*m.y.y*m.z.z + m.y.x*m.z.y*m.x.z + m.z.x*m.x.y*m.y.z
|
return m.x.x*m.y.y*m.z.z + m.y.x*m.z.y*m.x.z + m.z.x*m.x.y*m.y.z
|
||||||
-m.x.x*m.z.y*m.y.z - m.y.x*m.x.y*m.z.z - m.z.x*m.y.y*m.x.z ;
|
-m.x.x*m.z.y*m.y.z - m.y.x*m.x.y*m.z.z - m.z.x*m.y.y*m.x.z ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -772,9 +772,9 @@ float3x3 Inverse(const float3x3 &a)
|
||||||
float3x3 b;
|
float3x3 b;
|
||||||
NxF32 d=Determinant(a);
|
NxF32 d=Determinant(a);
|
||||||
assert(d!=0);
|
assert(d!=0);
|
||||||
for(NxI32 i=0;i<3;i++)
|
for(NxI32 i=0;i<3;i++)
|
||||||
{
|
{
|
||||||
for(NxI32 j=0;j<3;j++)
|
for(NxI32 j=0;j<3;j++)
|
||||||
{
|
{
|
||||||
NxI32 i1=(i+1)%3;
|
NxI32 i1=(i+1)%3;
|
||||||
NxI32 i2=(i+2)%3;
|
NxI32 i2=(i+2)%3;
|
||||||
|
|
@ -798,28 +798,28 @@ float3x3 Transpose( const float3x3& m )
|
||||||
|
|
||||||
|
|
||||||
float3 operator*(const float3& v , const float3x3 &m ) {
|
float3 operator*(const float3& v , const float3x3 &m ) {
|
||||||
return float3((m.x.x*v.x + m.y.x*v.y + m.z.x*v.z),
|
return float3((m.x.x*v.x + m.y.x*v.y + m.z.x*v.z),
|
||||||
(m.x.y*v.x + m.y.y*v.y + m.z.y*v.z),
|
(m.x.y*v.x + m.y.y*v.y + m.z.y*v.z),
|
||||||
(m.x.z*v.x + m.y.z*v.y + m.z.z*v.z));
|
(m.x.z*v.x + m.y.z*v.y + m.z.z*v.z));
|
||||||
}
|
}
|
||||||
float3 operator*(const float3x3 &m,const float3& v ) {
|
float3 operator*(const float3x3 &m,const float3& v ) {
|
||||||
return float3(dot(m.x,v),dot(m.y,v),dot(m.z,v));
|
return float3(dot(m.x,v),dot(m.y,v),dot(m.z,v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float3x3 operator*( const float3x3& a, const float3x3& b )
|
float3x3 operator*( const float3x3& a, const float3x3& b )
|
||||||
{
|
{
|
||||||
return float3x3(a.x*b,a.y*b,a.z*b);
|
return float3x3(a.x*b,a.y*b,a.z*b);
|
||||||
}
|
}
|
||||||
|
|
||||||
float3x3 operator*( const float3x3& a, const NxF32& s )
|
float3x3 operator*( const float3x3& a, const NxF32& s )
|
||||||
{
|
{
|
||||||
return float3x3(a.x*s, a.y*s ,a.z*s);
|
return float3x3(a.x*s, a.y*s ,a.z*s);
|
||||||
}
|
}
|
||||||
float3x3 operator/( const float3x3& a, const NxF32& s )
|
float3x3 operator/( const float3x3& a, const NxF32& s )
|
||||||
{
|
{
|
||||||
NxF32 t=1/s;
|
NxF32 t=1/s;
|
||||||
return float3x3(a.x*t, a.y*t ,a.z*t);
|
return float3x3(a.x*t, a.y*t ,a.z*t);
|
||||||
}
|
}
|
||||||
float3x3 operator+( const float3x3& a, const float3x3& b )
|
float3x3 operator+( const float3x3& a, const float3x3& b )
|
||||||
{
|
{
|
||||||
|
|
@ -868,7 +868,7 @@ float4 operator*( const float4& v, const float4x4& m )
|
||||||
return v.x*m.x + v.y*m.y + v.z*m.z + v.w*m.w; // yes this actually works
|
return v.x*m.x + v.y*m.y + v.z*m.z + v.w*m.w; // yes this actually works
|
||||||
}
|
}
|
||||||
|
|
||||||
NxI32 operator==( const float4 &a, const float4 &b )
|
NxI32 operator==( const float4 &a, const float4 &b )
|
||||||
{
|
{
|
||||||
return (a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w);
|
return (a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w);
|
||||||
}
|
}
|
||||||
|
|
@ -883,32 +883,32 @@ NxI32 operator==( const float4 &a, const float4 &b )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float4 cmul( const float4 &a, const float4 &b)
|
float4 cmul( const float4 &a, const float4 &b)
|
||||||
{
|
{
|
||||||
return float4(a.x*b.x,a.y*b.y,a.z*b.z,a.w*b.w);
|
return float4(a.x*b.x,a.y*b.y,a.z*b.z,a.w*b.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float4 operator*( const float4 &v, NxF32 s)
|
float4 operator*( const float4 &v, NxF32 s)
|
||||||
{
|
{
|
||||||
return float4(v.x*s,v.y*s,v.z*s,v.w*s);
|
return float4(v.x*s,v.y*s,v.z*s,v.w*s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float4 operator*( NxF32 s, const float4 &v)
|
float4 operator*( NxF32 s, const float4 &v)
|
||||||
{
|
{
|
||||||
return float4(v.x*s,v.y*s,v.z*s,v.w*s);
|
return float4(v.x*s,v.y*s,v.z*s,v.w*s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float4 operator+( const float4 &a, const float4 &b)
|
float4 operator+( const float4 &a, const float4 &b)
|
||||||
{
|
{
|
||||||
return float4(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);
|
return float4(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float4 operator-( const float4 &a, const float4 &b)
|
float4 operator-( const float4 &a, const float4 &b)
|
||||||
{
|
{
|
||||||
return float4(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);
|
return float4(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w);
|
||||||
}
|
}
|
||||||
|
|
@ -1010,7 +1010,7 @@ float4x4 Inverse(const float4x4 &m)
|
||||||
src[i] = m(i,0) ;
|
src[i] = m(i,0) ;
|
||||||
src[i + 4] = m(i,1);
|
src[i + 4] = m(i,1);
|
||||||
src[i + 8] = m(i,2);
|
src[i + 8] = m(i,2);
|
||||||
src[i + 12] = m(i,3);
|
src[i + 12] = m(i,3);
|
||||||
}
|
}
|
||||||
/* calculate pairs for first 8 elements (cofactors) */
|
/* calculate pairs for first 8 elements (cofactors) */
|
||||||
tmp[0] = src[10] * src[15];
|
tmp[0] = src[10] * src[15];
|
||||||
|
|
@ -1083,14 +1083,14 @@ float4x4 Inverse(const float4x4 &m)
|
||||||
|
|
||||||
|
|
||||||
//--------- Quaternion --------------
|
//--------- Quaternion --------------
|
||||||
|
|
||||||
Quaternion operator*( const Quaternion& a, const Quaternion& b )
|
Quaternion operator*( const Quaternion& a, const Quaternion& b )
|
||||||
{
|
{
|
||||||
Quaternion c;
|
Quaternion c;
|
||||||
c.w = a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z;
|
c.w = a.w*b.w - a.x*b.x - a.y*b.y - a.z*b.z;
|
||||||
c.x = a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y;
|
c.x = a.w*b.x + a.x*b.w + a.y*b.z - a.z*b.y;
|
||||||
c.y = a.w*b.y - a.x*b.z + a.y*b.w + a.z*b.x;
|
c.y = a.w*b.y - a.x*b.z + a.y*b.w + a.z*b.x;
|
||||||
c.z = a.w*b.z + a.x*b.y - a.y*b.x + a.z*b.w;
|
c.z = a.w*b.z + a.x*b.y - a.y*b.x + a.z*b.w;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1126,8 +1126,8 @@ void Quaternion::Normalize()
|
||||||
|
|
||||||
float3 operator*( const Quaternion& q, const float3& v )
|
float3 operator*( const Quaternion& q, const float3& v )
|
||||||
{
|
{
|
||||||
// The following is equivalent to:
|
// The following is equivalent to:
|
||||||
//return (q.getmatrix() * v);
|
//return (q.getmatrix() * v);
|
||||||
NxF32 qx2 = q.x*q.x;
|
NxF32 qx2 = q.x*q.x;
|
||||||
NxF32 qy2 = q.y*q.y;
|
NxF32 qy2 = q.y*q.y;
|
||||||
NxF32 qz2 = q.z*q.z;
|
NxF32 qz2 = q.z*q.z;
|
||||||
|
|
@ -1151,14 +1151,14 @@ Quaternion operator+( const Quaternion& a, const Quaternion& b )
|
||||||
|
|
||||||
NxF32 dot( const Quaternion &a,const Quaternion &b )
|
NxF32 dot( const Quaternion &a,const Quaternion &b )
|
||||||
{
|
{
|
||||||
return (a.w*b.w + a.x*b.x + a.y*b.y + a.z*b.z);
|
return (a.w*b.w + a.x*b.x + a.y*b.y + a.z*b.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion normalize( Quaternion a )
|
Quaternion normalize( Quaternion a )
|
||||||
{
|
{
|
||||||
NxF32 m = sqrtf(sqr(a.w)+sqr(a.x)+sqr(a.y)+sqr(a.z));
|
NxF32 m = sqrtf(sqr(a.w)+sqr(a.x)+sqr(a.y)+sqr(a.z));
|
||||||
if(m<0.000000001)
|
if(m<0.000000001)
|
||||||
{
|
{
|
||||||
a.w=1;
|
a.w=1;
|
||||||
a.x=a.y=a.z=0;
|
a.x=a.y=a.z=0;
|
||||||
return a;
|
return a;
|
||||||
|
|
@ -1168,7 +1168,7 @@ Quaternion normalize( Quaternion a )
|
||||||
|
|
||||||
Quaternion slerp( Quaternion a, const Quaternion& b, NxF32 interp )
|
Quaternion slerp( Quaternion a, const Quaternion& b, NxF32 interp )
|
||||||
{
|
{
|
||||||
if(dot(a,b) <0.0)
|
if(dot(a,b) <0.0)
|
||||||
{
|
{
|
||||||
a.w=-a.w;
|
a.w=-a.w;
|
||||||
a.x=-a.x;
|
a.x=-a.x;
|
||||||
|
|
@ -1190,7 +1190,7 @@ Quaternion Interpolate(const Quaternion &q0,const Quaternion &q1,NxF32 alpha) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Quaternion YawPitchRoll( NxF32 yaw, NxF32 pitch, NxF32 roll )
|
Quaternion YawPitchRoll( NxF32 yaw, NxF32 pitch, NxF32 roll )
|
||||||
{
|
{
|
||||||
roll *= DEG2RAD;
|
roll *= DEG2RAD;
|
||||||
yaw *= DEG2RAD;
|
yaw *= DEG2RAD;
|
||||||
|
|
@ -1234,7 +1234,7 @@ NxF32 Pitch( const float3& v )
|
||||||
|
|
||||||
|
|
||||||
void Plane::Transform(const float3 &position, const Quaternion &orientation) {
|
void Plane::Transform(const float3 &position, const Quaternion &orientation) {
|
||||||
// Transforms the plane to the space defined by the
|
// Transforms the plane to the space defined by the
|
||||||
// given position/orientation.
|
// given position/orientation.
|
||||||
static float3 newnormal;
|
static float3 newnormal;
|
||||||
static float3 origin;
|
static float3 origin;
|
||||||
|
|
@ -1271,9 +1271,9 @@ Quaternion RotationArc(float3 v0,float3 v1){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v)
|
float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v)
|
||||||
{
|
{
|
||||||
// builds a 4x4 transformation matrix based on orientation q and translation v
|
// builds a 4x4 transformation matrix based on orientation q and translation v
|
||||||
NxF32 qx2 = q.x*q.x;
|
NxF32 qx2 = q.x*q.x;
|
||||||
NxF32 qy2 = q.y*q.y;
|
NxF32 qy2 = q.y*q.y;
|
||||||
NxF32 qz2 = q.z*q.z;
|
NxF32 qz2 = q.z*q.z;
|
||||||
|
|
@ -1286,18 +1286,18 @@ float4x4 MatrixFromQuatVec(const Quaternion &q, const float3 &v)
|
||||||
NxF32 qzqw = q.z*q.w;
|
NxF32 qzqw = q.z*q.w;
|
||||||
|
|
||||||
return float4x4(
|
return float4x4(
|
||||||
1-2*(qy2+qz2),
|
1-2*(qy2+qz2),
|
||||||
2*(qxqy+qzqw),
|
2*(qxqy+qzqw),
|
||||||
2*(qxqz-qyqw),
|
2*(qxqz-qyqw),
|
||||||
0 ,
|
0 ,
|
||||||
2*(qxqy-qzqw),
|
2*(qxqy-qzqw),
|
||||||
1-2*(qx2+qz2),
|
1-2*(qx2+qz2),
|
||||||
2*(qyqz+qxqw),
|
2*(qyqz+qxqw),
|
||||||
0 ,
|
0 ,
|
||||||
2*(qxqz+qyqw),
|
2*(qxqz+qyqw),
|
||||||
2*(qyqz-qxqw),
|
2*(qyqz-qxqw),
|
||||||
1-2*(qx2+qy2),
|
1-2*(qx2+qy2),
|
||||||
0 ,
|
0 ,
|
||||||
v.x ,
|
v.x ,
|
||||||
v.y ,
|
v.y ,
|
||||||
v.z ,
|
v.z ,
|
||||||
|
|
@ -1351,10 +1351,10 @@ float3 TriNormal(const float3 &v0, const float3 &v1, const float3 &v2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NxI32 BoxInside(const float3 &p, const float3 &bmin, const float3 &bmax)
|
NxI32 BoxInside(const float3 &p, const float3 &bmin, const float3 &bmax)
|
||||||
{
|
{
|
||||||
return (p.x >= bmin.x && p.x <=bmax.x &&
|
return (p.x >= bmin.x && p.x <=bmax.x &&
|
||||||
p.y >= bmin.y && p.y <=bmax.y &&
|
p.y >= bmin.y && p.y <=bmax.y &&
|
||||||
p.z >= bmin.z && p.z <=bmax.z );
|
p.z >= bmin.z && p.z <=bmax.z );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1366,13 +1366,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
|
||||||
*impact=v0;
|
*impact=v0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(v0.x<=bmin.x && v1.x>=bmin.x)
|
if(v0.x<=bmin.x && v1.x>=bmin.x)
|
||||||
{
|
{
|
||||||
NxF32 a = (bmin.x-v0.x)/(v1.x-v0.x);
|
NxF32 a = (bmin.x-v0.x)/(v1.x-v0.x);
|
||||||
//v.x = bmin.x;
|
//v.x = bmin.x;
|
||||||
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
||||||
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
||||||
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
|
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
|
||||||
{
|
{
|
||||||
impact->x = bmin.x;
|
impact->x = bmin.x;
|
||||||
impact->y = vy;
|
impact->y = vy;
|
||||||
|
|
@ -1380,13 +1380,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(v0.x >= bmax.x && v1.x <= bmax.x)
|
else if(v0.x >= bmax.x && v1.x <= bmax.x)
|
||||||
{
|
{
|
||||||
NxF32 a = (bmax.x-v0.x)/(v1.x-v0.x);
|
NxF32 a = (bmax.x-v0.x)/(v1.x-v0.x);
|
||||||
//v.x = bmax.x;
|
//v.x = bmax.x;
|
||||||
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
||||||
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
||||||
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
|
if(vy>=bmin.y && vy<=bmax.y && vz>=bmin.z && vz<=bmax.z)
|
||||||
{
|
{
|
||||||
impact->x = bmax.x;
|
impact->x = bmax.x;
|
||||||
impact->y = vy;
|
impact->y = vy;
|
||||||
|
|
@ -1394,13 +1394,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(v0.y<=bmin.y && v1.y>=bmin.y)
|
if(v0.y<=bmin.y && v1.y>=bmin.y)
|
||||||
{
|
{
|
||||||
NxF32 a = (bmin.y-v0.y)/(v1.y-v0.y);
|
NxF32 a = (bmin.y-v0.y)/(v1.y-v0.y);
|
||||||
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
||||||
//v.y = bmin.y;
|
//v.y = bmin.y;
|
||||||
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
||||||
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
|
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
|
||||||
{
|
{
|
||||||
impact->x = vx;
|
impact->x = vx;
|
||||||
impact->y = bmin.y;
|
impact->y = bmin.y;
|
||||||
|
|
@ -1408,13 +1408,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(v0.y >= bmax.y && v1.y <= bmax.y)
|
else if(v0.y >= bmax.y && v1.y <= bmax.y)
|
||||||
{
|
{
|
||||||
NxF32 a = (bmax.y-v0.y)/(v1.y-v0.y);
|
NxF32 a = (bmax.y-v0.y)/(v1.y-v0.y);
|
||||||
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
||||||
// vy = bmax.y;
|
// vy = bmax.y;
|
||||||
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
NxF32 vz = (1-a) *v0.z + a*v1.z;
|
||||||
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
|
if(vx>=bmin.x && vx<=bmax.x && vz>=bmin.z && vz<=bmax.z)
|
||||||
{
|
{
|
||||||
impact->x = vx;
|
impact->x = vx;
|
||||||
impact->y = bmax.y;
|
impact->y = bmax.y;
|
||||||
|
|
@ -1422,13 +1422,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(v0.z<=bmin.z && v1.z>=bmin.z)
|
if(v0.z<=bmin.z && v1.z>=bmin.z)
|
||||||
{
|
{
|
||||||
NxF32 a = (bmin.z-v0.z)/(v1.z-v0.z);
|
NxF32 a = (bmin.z-v0.z)/(v1.z-v0.z);
|
||||||
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
||||||
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
||||||
// v.z = bmin.z;
|
// v.z = bmin.z;
|
||||||
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
|
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
|
||||||
{
|
{
|
||||||
impact->x = vx;
|
impact->x = vx;
|
||||||
impact->y = vy;
|
impact->y = vy;
|
||||||
|
|
@ -1436,13 +1436,13 @@ NxI32 BoxIntersect(const float3 &v0, const float3 &v1, const float3 &bmin, const
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(v0.z >= bmax.z && v1.z <= bmax.z)
|
else if(v0.z >= bmax.z && v1.z <= bmax.z)
|
||||||
{
|
{
|
||||||
NxF32 a = (bmax.z-v0.z)/(v1.z-v0.z);
|
NxF32 a = (bmax.z-v0.z)/(v1.z-v0.z);
|
||||||
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
NxF32 vx = (1-a) *v0.x + a*v1.x;
|
||||||
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
NxF32 vy = (1-a) *v0.y + a*v1.y;
|
||||||
// v.z = bmax.z;
|
// v.z = bmax.z;
|
||||||
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
|
if(vy>=bmin.y && vy<=bmax.y && vx>=bmin.x && vx<=bmax.x)
|
||||||
{
|
{
|
||||||
impact->x = vx;
|
impact->x = vx;
|
||||||
impact->y = vy;
|
impact->y = vy;
|
||||||
|
|
@ -1462,14 +1462,14 @@ NxF32 DistanceBetweenLines(const float3 &ustart, const float3 &udir, const float
|
||||||
NxF32 distu = -dot(cp,ustart);
|
NxF32 distu = -dot(cp,ustart);
|
||||||
NxF32 distv = -dot(cp,vstart);
|
NxF32 distv = -dot(cp,vstart);
|
||||||
NxF32 dist = (NxF32)fabs(distu-distv);
|
NxF32 dist = (NxF32)fabs(distu-distv);
|
||||||
if(upoint)
|
if(upoint)
|
||||||
{
|
{
|
||||||
Plane plane;
|
Plane plane;
|
||||||
plane.normal = normalize(cross(vdir,cp));
|
plane.normal = normalize(cross(vdir,cp));
|
||||||
plane.dist = -dot(plane.normal,vstart);
|
plane.dist = -dot(plane.normal,vstart);
|
||||||
*upoint = PlaneLineIntersection(plane,ustart,ustart+udir);
|
*upoint = PlaneLineIntersection(plane,ustart,ustart+udir);
|
||||||
}
|
}
|
||||||
if(vpoint)
|
if(vpoint)
|
||||||
{
|
{
|
||||||
Plane plane;
|
Plane plane;
|
||||||
plane.normal = normalize(cross(udir,cp));
|
plane.normal = normalize(cross(udir,cp));
|
||||||
|
|
@ -1480,19 +1480,19 @@ NxF32 DistanceBetweenLines(const float3 &ustart, const float3 &udir, const float
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &dir1, const float3 &dir2)
|
Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &dir1, const float3 &dir2)
|
||||||
{
|
{
|
||||||
// routine taken from game programming gems.
|
// routine taken from game programming gems.
|
||||||
// Implement track ball functionality to spin stuf on the screen
|
// Implement track ball functionality to spin stuf on the screen
|
||||||
// cop center of projection
|
// cop center of projection
|
||||||
// cor center of rotation
|
// cor center of rotation
|
||||||
// dir1 old mouse direction
|
// dir1 old mouse direction
|
||||||
// dir2 new mouse direction
|
// dir2 new mouse direction
|
||||||
// pretend there is a sphere around cor. Then find the points
|
// pretend there is a sphere around cor. Then find the points
|
||||||
// where dir1 and dir2 intersect that sphere. Find the
|
// where dir1 and dir2 intersect that sphere. Find the
|
||||||
// rotation that takes the first point to the second.
|
// rotation that takes the first point to the second.
|
||||||
NxF32 m;
|
NxF32 m;
|
||||||
// compute plane
|
// compute plane
|
||||||
float3 nrml = cor - cop;
|
float3 nrml = cor - cop;
|
||||||
NxF32 fudgefactor = 1.0f/(magnitude(nrml) * 0.25f); // since trackball proportional to distance from cop
|
NxF32 fudgefactor = 1.0f/(magnitude(nrml) * 0.25f); // since trackball proportional to distance from cop
|
||||||
nrml = normalize(nrml);
|
nrml = normalize(nrml);
|
||||||
|
|
@ -1501,11 +1501,11 @@ Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &
|
||||||
u=u-cor;
|
u=u-cor;
|
||||||
u=u*fudgefactor;
|
u=u*fudgefactor;
|
||||||
m= magnitude(u);
|
m= magnitude(u);
|
||||||
if(m>1)
|
if(m>1)
|
||||||
{
|
{
|
||||||
u/=m;
|
u/=m;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
u=u - (nrml * sqrtf(1-m*m));
|
u=u - (nrml * sqrtf(1-m*m));
|
||||||
}
|
}
|
||||||
|
|
@ -1513,7 +1513,7 @@ Quaternion VirtualTrackBall(const float3 &cop, const float3 &cor, const float3 &
|
||||||
v=v-cor;
|
v=v-cor;
|
||||||
v=v*fudgefactor;
|
v=v*fudgefactor;
|
||||||
m= magnitude(v);
|
m= magnitude(v);
|
||||||
if(m>1)
|
if(m>1)
|
||||||
{
|
{
|
||||||
v/=m;
|
v/=m;
|
||||||
}
|
}
|
||||||
|
|
@ -1531,7 +1531,7 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
|
||||||
countpolyhit++;
|
countpolyhit++;
|
||||||
NxI32 i;
|
NxI32 i;
|
||||||
float3 nrml(0,0,0);
|
float3 nrml(0,0,0);
|
||||||
for(i=0;i<n;i++)
|
for(i=0;i<n;i++)
|
||||||
{
|
{
|
||||||
NxI32 i1=(i+1)%n;
|
NxI32 i1=(i+1)%n;
|
||||||
NxI32 i2=(i+2)%n;
|
NxI32 i2=(i+2)%n;
|
||||||
|
|
@ -1546,12 +1546,12 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
|
||||||
nrml = nrml * (1.0f/m);
|
nrml = nrml * (1.0f/m);
|
||||||
NxF32 dist = -dot(nrml,vert[0]);
|
NxF32 dist = -dot(nrml,vert[0]);
|
||||||
NxF32 d0,d1;
|
NxF32 d0,d1;
|
||||||
if((d0=dot(v0,nrml)+dist) <0 || (d1=dot(v1,nrml)+dist) >0)
|
if((d0=dot(v0,nrml)+dist) <0 || (d1=dot(v1,nrml)+dist) >0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float3 the_point;
|
static float3 the_point;
|
||||||
// By using the cached plane distances d0 and d1
|
// By using the cached plane distances d0 and d1
|
||||||
// we can optimize the following:
|
// we can optimize the following:
|
||||||
// the_point = planelineintersection(nrml,dist,v0,v1);
|
// the_point = planelineintersection(nrml,dist,v0,v1);
|
||||||
|
|
@ -1560,7 +1560,7 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
|
||||||
|
|
||||||
|
|
||||||
NxI32 inside=1;
|
NxI32 inside=1;
|
||||||
for(NxI32 j=0;inside && j<n;j++)
|
for(NxI32 j=0;inside && j<n;j++)
|
||||||
{
|
{
|
||||||
// let inside = 0 if outside
|
// let inside = 0 if outside
|
||||||
float3 pp1,pp2,side;
|
float3 pp1,pp2,side;
|
||||||
|
|
@ -1569,7 +1569,7 @@ NxI32 PolyHit(const float3 *vert, const NxI32 n, const float3 &v0, const float3
|
||||||
side = cross((pp2-pp1),(the_point-pp1));
|
side = cross((pp2-pp1),(the_point-pp1));
|
||||||
inside = (dot(nrml,side) >= 0.0);
|
inside = (dot(nrml,side) >= 0.0);
|
||||||
}
|
}
|
||||||
if(inside)
|
if(inside)
|
||||||
{
|
{
|
||||||
if(normal){*normal=nrml;}
|
if(normal){*normal=nrml;}
|
||||||
if(impact){*impact=the_point;}
|
if(impact){*impact=the_point;}
|
||||||
|
|
@ -1675,7 +1675,7 @@ NxI32 SplitTest(ConvexH &convex,const Plane &plane) {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
class VertFlag
|
class VertFlag
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NxU8 planetest;
|
NxU8 planetest;
|
||||||
|
|
@ -1683,7 +1683,7 @@ public:
|
||||||
NxU8 undermap;
|
NxU8 undermap;
|
||||||
NxU8 overmap;
|
NxU8 overmap;
|
||||||
};
|
};
|
||||||
class EdgeFlag
|
class EdgeFlag
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NxU8 planetest;
|
NxU8 planetest;
|
||||||
|
|
@ -1691,7 +1691,7 @@ public:
|
||||||
short undermap;
|
short undermap;
|
||||||
short overmap;
|
short overmap;
|
||||||
};
|
};
|
||||||
class PlaneFlag
|
class PlaneFlag
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NxU8 undermap;
|
NxU8 undermap;
|
||||||
|
|
@ -1821,7 +1821,7 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
}
|
}
|
||||||
else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == UNDER) {
|
else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == UNDER) {
|
||||||
// at least one endpoint under, the other coplanar or under
|
// at least one endpoint under, the other coplanar or under
|
||||||
|
|
||||||
edgeflag[e0].undermap = (short)under_edge_count;
|
edgeflag[e0].undermap = (short)under_edge_count;
|
||||||
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
|
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
|
||||||
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
||||||
|
|
@ -1834,16 +1834,16 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
under_edge_count++;
|
under_edge_count++;
|
||||||
}
|
}
|
||||||
else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == COPLANAR) {
|
else if((vertflag[edge0.v].planetest | vertflag[edge1.v].planetest) == COPLANAR) {
|
||||||
// both endpoints coplanar
|
// both endpoints coplanar
|
||||||
// must check a 3rd point to see if UNDER
|
// must check a 3rd point to see if UNDER
|
||||||
NxI32 e2 = e1+1;
|
NxI32 e2 = e1+1;
|
||||||
if(e2>=convex.edges.count || convex.edges[e2].p!=currentplane) {
|
if(e2>=convex.edges.count || convex.edges[e2].p!=currentplane) {
|
||||||
e2 = estart;
|
e2 = estart;
|
||||||
}
|
}
|
||||||
assert(convex.edges[e2].p==currentplane);
|
assert(convex.edges[e2].p==currentplane);
|
||||||
HalfEdge &edge2 = convex.edges[e2];
|
HalfEdge &edge2 = convex.edges[e2];
|
||||||
if(vertflag[edge2.v].planetest==UNDER) {
|
if(vertflag[edge2.v].planetest==UNDER) {
|
||||||
|
|
||||||
edgeflag[e0].undermap = (short)under_edge_count;
|
edgeflag[e0].undermap = (short)under_edge_count;
|
||||||
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
|
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
|
||||||
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
||||||
|
|
@ -1859,8 +1859,8 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(vertflag[edge0.v].planetest == UNDER && vertflag[edge1.v].planetest == OVER) {
|
else if(vertflag[edge0.v].planetest == UNDER && vertflag[edge1.v].planetest == OVER) {
|
||||||
// first is under 2nd is over
|
// first is under 2nd is over
|
||||||
|
|
||||||
edgeflag[e0].undermap = (short) under_edge_count;
|
edgeflag[e0].undermap = (short) under_edge_count;
|
||||||
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
|
tmpunderedges[under_edge_count].v = (NxU8)vertflag[edge0.v].undermap;
|
||||||
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
||||||
|
|
@ -1880,7 +1880,7 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
vout = vertcountunder++;
|
vout = vertcountunder++;
|
||||||
}
|
}
|
||||||
under_edge_count++;
|
under_edge_count++;
|
||||||
/// hmmm something to think about: i might be able to output this edge regarless of
|
/// hmmm something to think about: i might be able to output this edge regarless of
|
||||||
// wheter or not we know v-in yet. ok i;ll try this now:
|
// wheter or not we know v-in yet. ok i;ll try this now:
|
||||||
tmpunderedges[under_edge_count].v = (NxU8)vout;
|
tmpunderedges[under_edge_count].v = (NxU8)vout;
|
||||||
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
tmpunderedges[under_edge_count].p = (NxU8)underplanescount;
|
||||||
|
|
@ -1897,8 +1897,8 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(vertflag[edge0.v].planetest == COPLANAR && vertflag[edge1.v].planetest == OVER) {
|
else if(vertflag[edge0.v].planetest == COPLANAR && vertflag[edge1.v].planetest == OVER) {
|
||||||
// first is coplanar 2nd is over
|
// first is coplanar 2nd is over
|
||||||
|
|
||||||
edgeflag[e0].undermap = -1;
|
edgeflag[e0].undermap = -1;
|
||||||
vout = vertflag[edge0.v].undermap;
|
vout = vertflag[edge0.v].undermap;
|
||||||
// I hate this but i have to make sure part of this face is UNDER before ouputting this vert
|
// I hate this but i have to make sure part of this face is UNDER before ouputting this vert
|
||||||
|
|
@ -1914,11 +1914,11 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
tmpunderedges[under_edge_count].ea = -1;
|
tmpunderedges[under_edge_count].ea = -1;
|
||||||
coplanaredge = under_edge_count; // hmmm should make a note of the edge # for later on
|
coplanaredge = under_edge_count; // hmmm should make a note of the edge # for later on
|
||||||
under_edge_count++;
|
under_edge_count++;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == UNDER) {
|
else if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == UNDER) {
|
||||||
// first is over next is under
|
// first is over next is under
|
||||||
// new vertex!!!
|
// new vertex!!!
|
||||||
if (vin!=-1) return NULL;
|
if (vin!=-1) return NULL;
|
||||||
if(e0<edge0.ea) {
|
if(e0<edge0.ea) {
|
||||||
|
|
@ -1955,8 +1955,8 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
under_edge_count++;
|
under_edge_count++;
|
||||||
}
|
}
|
||||||
else if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == COPLANAR) {
|
else if(vertflag[edge0.v].planetest == OVER && vertflag[edge1.v].planetest == COPLANAR) {
|
||||||
// first is over next is coplanar
|
// first is over next is coplanar
|
||||||
|
|
||||||
edgeflag[e0].undermap = -1;
|
edgeflag[e0].undermap = -1;
|
||||||
vin = vertflag[edge1.v].undermap;
|
vin = vertflag[edge1.v].undermap;
|
||||||
if (vin==-1) return NULL;
|
if (vin==-1) return NULL;
|
||||||
|
|
@ -1970,7 +1970,7 @@ ConvexH *ConvexHCrop(ConvexH &convex,const Plane &slice)
|
||||||
else {
|
else {
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
e0=e1;
|
e0=e1;
|
||||||
e1++; // do the modulo at the beginning of the loop
|
e1++; // do the modulo at the beginning of the loop
|
||||||
|
|
@ -2069,7 +2069,7 @@ static NxI32 candidateplane(Plane *planes,NxI32 planes_count,ConvexH *convex,NxF
|
||||||
if(d<=md) continue;
|
if(d<=md) continue;
|
||||||
for(j=0;j<convex->facets.count;j++)
|
for(j=0;j<convex->facets.count;j++)
|
||||||
{
|
{
|
||||||
if(planes[i]==convex->facets[j])
|
if(planes[i]==convex->facets[j])
|
||||||
{
|
{
|
||||||
d=0;continue;
|
d=0;continue;
|
||||||
}
|
}
|
||||||
|
|
@ -2121,7 +2121,7 @@ NxI32 maxdirfiltered(const T *p,NxI32 count,const T &dir,Array<NxI32> &allow)
|
||||||
}
|
}
|
||||||
assert(m!=-1);
|
assert(m!=-1);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 orth(const float3 &v)
|
float3 orth(const float3 &v)
|
||||||
{
|
{
|
||||||
|
|
@ -2175,21 +2175,21 @@ NxI32 maxdirsterid(const T *p,NxI32 count,const T &dir,Array<NxI32> &allow)
|
||||||
}
|
}
|
||||||
assert(0);
|
assert(0);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NxI32 operator ==(const int3 &a,const int3 &b)
|
NxI32 operator ==(const int3 &a,const int3 &b)
|
||||||
{
|
{
|
||||||
for(NxI32 i=0;i<3;i++)
|
for(NxI32 i=0;i<3;i++)
|
||||||
{
|
{
|
||||||
if(a[i]!=b[i]) return 0;
|
if(a[i]!=b[i]) return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int3 roll3(int3 a)
|
int3 roll3(int3 a)
|
||||||
{
|
{
|
||||||
NxI32 tmp=a[0];
|
NxI32 tmp=a[0];
|
||||||
a[0]=a[1];
|
a[0]=a[1];
|
||||||
|
|
@ -2197,15 +2197,15 @@ int3 roll3(int3 a)
|
||||||
a[2]=tmp;
|
a[2]=tmp;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
NxI32 isa(const int3 &a,const int3 &b)
|
NxI32 isa(const int3 &a,const int3 &b)
|
||||||
{
|
{
|
||||||
return ( a==b || roll3(a)==b || a==roll3(b) );
|
return ( a==b || roll3(a)==b || a==roll3(b) );
|
||||||
}
|
}
|
||||||
NxI32 b2b(const int3 &a,const int3 &b)
|
NxI32 b2b(const int3 &a,const int3 &b)
|
||||||
{
|
{
|
||||||
return isa(a,int3(b[2],b[1],b[0]));
|
return isa(a,int3(b[2],b[1],b[0]));
|
||||||
}
|
}
|
||||||
NxI32 above(float3* vertices,const int3& t, const float3 &p, NxF32 epsilon)
|
NxI32 above(float3* vertices,const int3& t, const float3 &p, NxF32 epsilon)
|
||||||
{
|
{
|
||||||
float3 n=TriNormal(vertices[t[0]],vertices[t[1]],vertices[t[2]]);
|
float3 n=TriNormal(vertices[t[0]],vertices[t[1]],vertices[t[2]]);
|
||||||
return (dot(n,p-vertices[t[0]]) > epsilon); // EPSILON???
|
return (dot(n,p-vertices[t[0]]) > epsilon); // EPSILON???
|
||||||
|
|
@ -2265,7 +2265,7 @@ NxI32 &Tri::neib(NxI32 a,NxI32 b)
|
||||||
{
|
{
|
||||||
static NxI32 er=-1;
|
static NxI32 er=-1;
|
||||||
NxI32 i;
|
NxI32 i;
|
||||||
for(i=0;i<3;i++)
|
for(i=0;i<3;i++)
|
||||||
{
|
{
|
||||||
NxI32 i1=(i+1)%3;
|
NxI32 i1=(i+1)%3;
|
||||||
NxI32 i2=(i+2)%3;
|
NxI32 i2=(i+2)%3;
|
||||||
|
|
@ -2278,7 +2278,7 @@ NxI32 &Tri::neib(NxI32 a,NxI32 b)
|
||||||
void b2bfix(Tri* s,Tri*t)
|
void b2bfix(Tri* s,Tri*t)
|
||||||
{
|
{
|
||||||
NxI32 i;
|
NxI32 i;
|
||||||
for(i=0;i<3;i++)
|
for(i=0;i<3;i++)
|
||||||
{
|
{
|
||||||
NxI32 i1=(i+1)%3;
|
NxI32 i1=(i+1)%3;
|
||||||
NxI32 i2=(i+2)%3;
|
NxI32 i2=(i+2)%3;
|
||||||
|
|
@ -2356,11 +2356,11 @@ bool hasVolume(float3 *verts, NxI32 p0, NxI32 p1, NxI32 p2, NxI32 p3)
|
||||||
int4 FindSimplex(float3 *verts,NxI32 verts_count,Array<NxI32> &allow)
|
int4 FindSimplex(float3 *verts,NxI32 verts_count,Array<NxI32> &allow)
|
||||||
{
|
{
|
||||||
float3 basis[3];
|
float3 basis[3];
|
||||||
basis[0] = float3( 0.01f, 0.02f, 1.0f );
|
basis[0] = float3( 0.01f, 0.02f, 1.0f );
|
||||||
NxI32 p0 = maxdirsterid(verts,verts_count, basis[0],allow);
|
NxI32 p0 = maxdirsterid(verts,verts_count, basis[0],allow);
|
||||||
NxI32 p1 = maxdirsterid(verts,verts_count,-basis[0],allow);
|
NxI32 p1 = maxdirsterid(verts,verts_count,-basis[0],allow);
|
||||||
basis[0] = verts[p0]-verts[p1];
|
basis[0] = verts[p0]-verts[p1];
|
||||||
if(p0==p1 || basis[0]==float3(0,0,0))
|
if(p0==p1 || basis[0]==float3(0,0,0))
|
||||||
return int4(-1,-1,-1,-1);
|
return int4(-1,-1,-1,-1);
|
||||||
basis[1] = cross(float3( 1, 0.02f, 0),basis[0]);
|
basis[1] = cross(float3( 1, 0.02f, 0),basis[0]);
|
||||||
basis[2] = cross(float3(-0.02f, 1, 0),basis[0]);
|
basis[2] = cross(float3(-0.02f, 1, 0),basis[0]);
|
||||||
|
|
@ -2370,13 +2370,13 @@ int4 FindSimplex(float3 *verts,NxI32 verts_count,Array<NxI32> &allow)
|
||||||
{
|
{
|
||||||
p2 = maxdirsterid(verts,verts_count,-basis[1],allow);
|
p2 = maxdirsterid(verts,verts_count,-basis[1],allow);
|
||||||
}
|
}
|
||||||
if(p2 == p0 || p2 == p1)
|
if(p2 == p0 || p2 == p1)
|
||||||
return int4(-1,-1,-1,-1);
|
return int4(-1,-1,-1,-1);
|
||||||
basis[1] = verts[p2] - verts[p0];
|
basis[1] = verts[p2] - verts[p0];
|
||||||
basis[2] = normalize(cross(basis[1],basis[0]));
|
basis[2] = normalize(cross(basis[1],basis[0]));
|
||||||
NxI32 p3 = maxdirsterid(verts,verts_count,basis[2],allow);
|
NxI32 p3 = maxdirsterid(verts,verts_count,basis[2],allow);
|
||||||
if(p3==p0||p3==p1||p3==p2||!hasVolume(verts, p0, p1, p2, p3)) p3 = maxdirsterid(verts,verts_count,-basis[2],allow);
|
if(p3==p0||p3==p1||p3==p2||!hasVolume(verts, p0, p1, p2, p3)) p3 = maxdirsterid(verts,verts_count,-basis[2],allow);
|
||||||
if(p3==p0||p3==p1||p3==p2)
|
if(p3==p0||p3==p1||p3==p2)
|
||||||
return int4(-1,-1,-1,-1);
|
return int4(-1,-1,-1,-1);
|
||||||
assert(!(p0==p1||p0==p2||p0==p3||p1==p2||p1==p3||p2==p3));
|
assert(!(p0==p1||p0==p2||p0==p3||p1==p2||p1==p3||p2==p3));
|
||||||
if(dot(verts[p3]-verts[p0],cross(verts[p1]-verts[p0],verts[p2]-verts[p0])) <0) {Swap(p2,p3);}
|
if(dot(verts[p3]-verts[p0],cross(verts[p1]-verts[p0],verts[p2]-verts[p0])) <0) {Swap(p2,p3);}
|
||||||
|
|
@ -2384,7 +2384,7 @@ int4 FindSimplex(float3 *verts,NxI32 verts_count,Array<NxI32> &allow)
|
||||||
}
|
}
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4706)
|
#pragma warning(disable:4706)
|
||||||
NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
|
NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
|
||||||
{
|
{
|
||||||
if(verts_count <4) return 0;
|
if(verts_count <4) return 0;
|
||||||
if(vlimit==0) vlimit=1000000000;
|
if(vlimit==0) vlimit=1000000000;
|
||||||
|
|
@ -2392,7 +2392,7 @@ NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
|
||||||
float3 bmin(*verts),bmax(*verts);
|
float3 bmin(*verts),bmax(*verts);
|
||||||
Array<NxI32> isextreme(verts_count);
|
Array<NxI32> isextreme(verts_count);
|
||||||
Array<NxI32> allow(verts_count);
|
Array<NxI32> allow(verts_count);
|
||||||
for(j=0;j<verts_count;j++)
|
for(j=0;j<verts_count;j++)
|
||||||
{
|
{
|
||||||
allow.Add(1);
|
allow.Add(1);
|
||||||
isextreme.Add(0);
|
isextreme.Add(0);
|
||||||
|
|
@ -2464,7 +2464,7 @@ NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
|
||||||
if(t->vmax>=0) break;
|
if(t->vmax>=0) break;
|
||||||
float3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]);
|
float3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]);
|
||||||
t->vmax = maxdirsterid(verts,verts_count,n,allow);
|
t->vmax = maxdirsterid(verts,verts_count,n,allow);
|
||||||
if(isextreme[t->vmax])
|
if(isextreme[t->vmax])
|
||||||
{
|
{
|
||||||
t->vmax=-1; // already done that vertex - algorithm needs to be able to terminate.
|
t->vmax=-1; // already done that vertex - algorithm needs to be able to terminate.
|
||||||
}
|
}
|
||||||
|
|
@ -2479,7 +2479,7 @@ NxI32 calchullgen(float3 *verts,NxI32 verts_count, NxI32 vlimit)
|
||||||
}
|
}
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
NxI32 calchull(float3 *verts,NxI32 verts_count, NxI32 *&tris_out, NxI32 &tris_count,NxI32 vlimit)
|
NxI32 calchull(float3 *verts,NxI32 verts_count, NxI32 *&tris_out, NxI32 &tris_count,NxI32 vlimit)
|
||||||
{
|
{
|
||||||
NxI32 rc=calchullgen(verts,verts_count, vlimit) ;
|
NxI32 rc=calchullgen(verts,verts_count, vlimit) ;
|
||||||
if(!rc) return 0;
|
if(!rc) return 0;
|
||||||
|
|
@ -2502,7 +2502,7 @@ static NxF32 area2(const float3 &v0,const float3 &v1,const float3 &v2)
|
||||||
float3 cp = cross(v0-v1,v2-v0);
|
float3 cp = cross(v0-v1,v2-v0);
|
||||||
return dot(cp,cp);
|
return dot(cp,cp);
|
||||||
}
|
}
|
||||||
NxI32 calchullpbev(float3 *verts,NxI32 verts_count,NxI32 vlimit, Array<Plane> &planes,NxF32 bevangle)
|
NxI32 calchullpbev(float3 *verts,NxI32 verts_count,NxI32 vlimit, Array<Plane> &planes,NxF32 bevangle)
|
||||||
{
|
{
|
||||||
NxI32 i,j;
|
NxI32 i,j;
|
||||||
Array<Plane> bplanes;
|
Array<Plane> bplanes;
|
||||||
|
|
@ -2526,7 +2526,7 @@ NxI32 calchullpbev(float3 *verts,NxI32 verts_count,NxI32 vlimit, Array<Plane> &p
|
||||||
REAL3 e = verts[(*t)[(j+2)%3]] - verts[(*t)[(j+1)%3]];
|
REAL3 e = verts[(*t)[(j+2)%3]] - verts[(*t)[(j+1)%3]];
|
||||||
REAL3 n = (e!=REAL3(0,0,0))? cross(snormal,e)+cross(e,p.normal) : snormal+p.normal;
|
REAL3 n = (e!=REAL3(0,0,0))? cross(snormal,e)+cross(e,p.normal) : snormal+p.normal;
|
||||||
assert(n!=REAL3(0,0,0));
|
assert(n!=REAL3(0,0,0));
|
||||||
if(n==REAL3(0,0,0)) return 0;
|
if(n==REAL3(0,0,0)) return 0;
|
||||||
n=normalize(n);
|
n=normalize(n);
|
||||||
bplanes.Add(Plane(n,-dot(n,verts[maxdir(verts,verts_count,n)])));
|
bplanes.Add(Plane(n,-dot(n,verts[maxdir(verts,verts_count,n)])));
|
||||||
}
|
}
|
||||||
|
|
@ -2656,7 +2656,7 @@ static NxI32 overhull(Plane *planes,NxI32 planes_count,float3 *verts, NxI32 vert
|
||||||
float3 *&verts_out, NxI32 &verts_count_out, NxI32 *&faces_out, NxI32 &faces_count_out ,NxF32 inflate)
|
float3 *&verts_out, NxI32 &verts_count_out, NxI32 *&faces_out, NxI32 &faces_count_out ,NxF32 inflate)
|
||||||
{
|
{
|
||||||
NxI32 i,j;
|
NxI32 i,j;
|
||||||
if(verts_count <4) return NULL;
|
if (verts_count < 4) return 0;
|
||||||
maxplanes = Min(maxplanes,planes_count);
|
maxplanes = Min(maxplanes,planes_count);
|
||||||
float3 bmin(verts[0]),bmax(verts[0]);
|
float3 bmin(verts[0]),bmax(verts[0]);
|
||||||
for(i=0;i<verts_count;i++)
|
for(i=0;i<verts_count;i++)
|
||||||
|
|
@ -2862,7 +2862,7 @@ HullError HullLibrary::CreateConvexHull(const HullDesc &desc, //
|
||||||
}
|
}
|
||||||
|
|
||||||
NxF32 skinwidth = 0;
|
NxF32 skinwidth = 0;
|
||||||
if ( desc.HasHullFlag(QF_SKIN_WIDTH) )
|
if ( desc.HasHullFlag(QF_SKIN_WIDTH) )
|
||||||
skinwidth = desc.mSkinWidth;
|
skinwidth = desc.mSkinWidth;
|
||||||
|
|
||||||
ok = ComputeHull(ovcount,vsource,hr,desc.mMaxVertices,skinwidth);
|
ok = ComputeHull(ovcount,vsource,hr,desc.mMaxVertices,skinwidth);
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ NvThreadConfig.cpp : A simple wrapper class to define threading and mutex locks.
|
||||||
#include <xtl.h>
|
#include <xtl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__linux__) || defined( __APPLE__ )
|
#if defined(__linux__) || defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
//#include <sys/time.h>
|
//#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -79,15 +79,18 @@ NvThreadConfig.cpp : A simple wrapper class to define threading and mutex locks.
|
||||||
#define __stdcall
|
#define __stdcall
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( __APPLE__ )
|
#if defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__linux__)
|
#if defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( __APPLE__ )
|
#if defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
|
|
||||||
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -107,7 +110,8 @@ NxU32 tc_timeGetTime(void)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
|
||||||
#elif defined( __APPLE__ )
|
#elif defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
|
|
||||||
struct timeval tp;
|
struct timeval tp;
|
||||||
gettimeofday(&tp, (struct timezone *)0);
|
gettimeofday(&tp, (struct timezone *)0);
|
||||||
return tp.tv_sec * 1000 + tp.tv_usec / 1000;
|
return tp.tv_sec * 1000 + tp.tv_usec / 1000;
|
||||||
|
|
@ -120,7 +124,7 @@ NxU32 tc_timeGetTime(void)
|
||||||
|
|
||||||
void tc_sleep(NxU32 ms)
|
void tc_sleep(NxU32 ms)
|
||||||
{
|
{
|
||||||
#if defined(__linux__) || defined( __APPLE__ )
|
#if defined(__linux__) || defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
usleep(ms * 1000);
|
usleep(ms * 1000);
|
||||||
#else
|
#else
|
||||||
Sleep(ms);
|
Sleep(ms);
|
||||||
|
|
@ -129,26 +133,28 @@ void tc_sleep(NxU32 ms)
|
||||||
|
|
||||||
void tc_spinloop()
|
void tc_spinloop()
|
||||||
{
|
{
|
||||||
#if defined( _XBOX )
|
|
||||||
// Pause would do nothing on the Xbox. Threads are not scheduled.
|
#if defined( _XBOX )
|
||||||
#elif defined( _WIN64 )
|
// Pause would do nothing on the Xbox. Threads are not scheduled.
|
||||||
YieldProcessor( );
|
#elif defined( _WIN64 )
|
||||||
#elif defined( __APPLE__ )
|
YieldProcessor( );
|
||||||
pthread_yield_np();
|
#elif defined( __APPLE__ )
|
||||||
#elif defined(__linux__)
|
pthread_yield_np();
|
||||||
#if defined(_POSIX_PRIORITY_SCHEDULING)
|
#elif defined(__linux__) || defined(__FreeBSD__)
|
||||||
sched_yield();
|
#if defined(_POSIX_PRIORITY_SCHEDULING)
|
||||||
#else
|
sched_yield();
|
||||||
asm("pause");
|
#else
|
||||||
|
asm("pause");
|
||||||
|
#endif
|
||||||
|
#elif
|
||||||
|
__asm { pause };
|
||||||
#endif
|
#endif
|
||||||
#elif
|
|
||||||
__asm { pause };
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tc_interlockedExchange(void *dest, const int64_t exchange)
|
void tc_interlockedExchange(void *dest, const int64_t exchange)
|
||||||
{
|
{
|
||||||
#if defined( __linux__ ) || defined( __APPLE__ )
|
#if defined( __linux__ ) || defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
|
|
||||||
// not working
|
// not working
|
||||||
assert(false);
|
assert(false);
|
||||||
//__sync_lock_test_and_set((int64_t*)dest, exchange);
|
//__sync_lock_test_and_set((int64_t*)dest, exchange);
|
||||||
|
|
@ -174,7 +180,8 @@ void tc_interlockedExchange(void *dest, const int64_t exchange)
|
||||||
|
|
||||||
NxI32 tc_interlockedCompareExchange(void *dest, NxI32 exchange, NxI32 compare)
|
NxI32 tc_interlockedCompareExchange(void *dest, NxI32 exchange, NxI32 compare)
|
||||||
{
|
{
|
||||||
#if defined( __linux__ ) || defined( __APPLE__ )
|
#if defined( __linux__ ) || defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
|
|
||||||
// not working
|
// not working
|
||||||
assert(false);
|
assert(false);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -203,7 +210,7 @@ NxI32 tc_interlockedCompareExchange(void *dest, NxI32 exchange, NxI32 compare)
|
||||||
|
|
||||||
NxI32 tc_interlockedCompareExchange(void *dest, const NxI32 exchange1, const NxI32 exchange2, const NxI32 compare1, const NxI32 compare2)
|
NxI32 tc_interlockedCompareExchange(void *dest, const NxI32 exchange1, const NxI32 exchange2, const NxI32 compare1, const NxI32 compare2)
|
||||||
{
|
{
|
||||||
#if defined( __linux__ ) || defined( __APPLE__ )
|
#if defined( __linux__ ) || defined( __APPLE__ ) || defined( __FreeBSD__)
|
||||||
// not working
|
// not working
|
||||||
assert(false);
|
assert(false);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -239,7 +246,8 @@ public:
|
||||||
{
|
{
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
InitializeCriticalSection(&m_Mutex);
|
InitializeCriticalSection(&m_Mutex);
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
pthread_mutexattr_t mutexAttr; // Mutex Attribute
|
pthread_mutexattr_t mutexAttr; // Mutex Attribute
|
||||||
VERIFY( pthread_mutexattr_init(&mutexAttr) == 0 );
|
VERIFY( pthread_mutexattr_init(&mutexAttr) == 0 );
|
||||||
VERIFY( pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0 );
|
VERIFY( pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0 );
|
||||||
|
|
@ -252,7 +260,8 @@ public:
|
||||||
{
|
{
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
DeleteCriticalSection(&m_Mutex);
|
DeleteCriticalSection(&m_Mutex);
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
VERIFY( pthread_mutex_destroy(&m_Mutex) == 0 );
|
VERIFY( pthread_mutex_destroy(&m_Mutex) == 0 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -261,7 +270,8 @@ public:
|
||||||
{
|
{
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
EnterCriticalSection(&m_Mutex);
|
EnterCriticalSection(&m_Mutex);
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
VERIFY( pthread_mutex_lock(&m_Mutex) == 0 );
|
VERIFY( pthread_mutex_lock(&m_Mutex) == 0 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -273,7 +283,8 @@ public:
|
||||||
//assert(("TryEnterCriticalSection seems to not work on XP???", 0));
|
//assert(("TryEnterCriticalSection seems to not work on XP???", 0));
|
||||||
bRet = TryEnterCriticalSection(&m_Mutex) ? true : false;
|
bRet = TryEnterCriticalSection(&m_Mutex) ? true : false;
|
||||||
return bRet;
|
return bRet;
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
NxI32 result = pthread_mutex_trylock(&m_Mutex);
|
NxI32 result = pthread_mutex_trylock(&m_Mutex);
|
||||||
return (result == 0);
|
return (result == 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -283,7 +294,8 @@ public:
|
||||||
{
|
{
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
LeaveCriticalSection(&m_Mutex);
|
LeaveCriticalSection(&m_Mutex);
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
VERIFY( pthread_mutex_unlock(&m_Mutex) == 0 );
|
VERIFY( pthread_mutex_unlock(&m_Mutex) == 0 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -291,7 +303,8 @@ public:
|
||||||
private:
|
private:
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
CRITICAL_SECTION m_Mutex;
|
CRITICAL_SECTION m_Mutex;
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
pthread_mutex_t m_Mutex;
|
pthread_mutex_t m_Mutex;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
@ -310,7 +323,8 @@ void tc_releaseThreadMutex(ThreadMutex *tm)
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
static unsigned long __stdcall _ThreadWorkerFunc(LPVOID arg);
|
static unsigned long __stdcall _ThreadWorkerFunc(LPVOID arg);
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
static void* _ThreadWorkerFunc(void* arg);
|
static void* _ThreadWorkerFunc(void* arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -322,7 +336,8 @@ public:
|
||||||
mInterface = iface;
|
mInterface = iface;
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
mThread = CreateThread(0, 0, _ThreadWorkerFunc, this, 0, 0);
|
mThread = CreateThread(0, 0, _ThreadWorkerFunc, this, 0, 0);
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
VERIFY( pthread_create(&mThread, NULL, _ThreadWorkerFunc, this) == 0 );
|
VERIFY( pthread_create(&mThread, NULL, _ThreadWorkerFunc, this) == 0 );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -347,7 +362,8 @@ private:
|
||||||
ThreadInterface *mInterface;
|
ThreadInterface *mInterface;
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
HANDLE mThread;
|
HANDLE mThread;
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
pthread_t mThread;
|
pthread_t mThread;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
@ -367,7 +383,8 @@ void tc_releaseThread(Thread *t)
|
||||||
|
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
static unsigned long __stdcall _ThreadWorkerFunc(LPVOID arg)
|
static unsigned long __stdcall _ThreadWorkerFunc(LPVOID arg)
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
static void* _ThreadWorkerFunc(void* arg)
|
static void* _ThreadWorkerFunc(void* arg)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
@ -384,7 +401,8 @@ public:
|
||||||
{
|
{
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
mEvent = ::CreateEventA(NULL,TRUE,TRUE,"ThreadEvent");
|
mEvent = ::CreateEventA(NULL,TRUE,TRUE,"ThreadEvent");
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
pthread_mutexattr_t mutexAttr; // Mutex Attribute
|
pthread_mutexattr_t mutexAttr; // Mutex Attribute
|
||||||
VERIFY( pthread_mutexattr_init(&mutexAttr) == 0 );
|
VERIFY( pthread_mutexattr_init(&mutexAttr) == 0 );
|
||||||
VERIFY( pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0 );
|
VERIFY( pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0 );
|
||||||
|
|
@ -401,7 +419,8 @@ public:
|
||||||
{
|
{
|
||||||
::CloseHandle(mEvent);
|
::CloseHandle(mEvent);
|
||||||
}
|
}
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
VERIFY( pthread_cond_destroy(&mEvent) == 0 );
|
VERIFY( pthread_cond_destroy(&mEvent) == 0 );
|
||||||
VERIFY( pthread_mutex_destroy(&mEventMutex) == 0 );
|
VERIFY( pthread_mutex_destroy(&mEventMutex) == 0 );
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -414,7 +433,8 @@ public:
|
||||||
{
|
{
|
||||||
::SetEvent(mEvent);
|
::SetEvent(mEvent);
|
||||||
}
|
}
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
VERIFY( pthread_mutex_lock(&mEventMutex) == 0 );
|
VERIFY( pthread_mutex_lock(&mEventMutex) == 0 );
|
||||||
VERIFY( pthread_cond_signal(&mEvent) == 0 );
|
VERIFY( pthread_cond_signal(&mEvent) == 0 );
|
||||||
VERIFY( pthread_mutex_unlock(&mEventMutex) == 0 );
|
VERIFY( pthread_mutex_unlock(&mEventMutex) == 0 );
|
||||||
|
|
@ -438,7 +458,8 @@ public:
|
||||||
{
|
{
|
||||||
::WaitForSingleObject(mEvent,ms);
|
::WaitForSingleObject(mEvent,ms);
|
||||||
}
|
}
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
VERIFY( pthread_mutex_lock(&mEventMutex) == 0 );
|
VERIFY( pthread_mutex_lock(&mEventMutex) == 0 );
|
||||||
if (ms == 0xffffffff)
|
if (ms == 0xffffffff)
|
||||||
{
|
{
|
||||||
|
|
@ -468,7 +489,8 @@ public:
|
||||||
private:
|
private:
|
||||||
#if defined(WIN32) || defined(_XBOX)
|
#if defined(WIN32) || defined(_XBOX)
|
||||||
HANDLE mEvent;
|
HANDLE mEvent;
|
||||||
#elif defined(__APPLE__) || defined(__linux__)
|
#elif defined(__APPLE__) || defined(__linux__) || defined( __FreeBSD__)
|
||||||
|
|
||||||
pthread_mutex_t mEventMutex;
|
pthread_mutex_t mEventMutex;
|
||||||
pthread_cond_t mEvent;
|
pthread_cond_t mEvent;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
#include <iosfwd> // for ostream forward-declaration
|
#include <iosfwd> // for ostream forward-declaration
|
||||||
|
|
||||||
// Don't use bits/type_traits.h on Linux - Andrew Galante, GG 8/2/2009
|
// Don't use bits/type_traits.h on Linux - Andrew Galante, GG 8/2/2009
|
||||||
#if !defined(_MSC_VER) && !defined(__CELLOS_LV2__) && !defined(__APPLE__) && !defined(__linux__)
|
#if !defined(_MSC_VER) && !defined(__CELLOS_LV2__) && !defined(__APPLE__) && !defined(__linux__) && !defined( __FreeBSD__)
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
#define HAVE_TYPE_TRAITS
|
#define HAVE_TYPE_TRAITS
|
||||||
#include <bits/type_traits.h>
|
#include <bits/type_traits.h>
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@ GFXGLTextureObject::GFXGLTextureObject(GFXDevice * aDevice, GFXTextureProfile *p
|
||||||
glGenBuffers(1, &mBuffer);
|
glGenBuffers(1, &mBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
GFXGLTextureObject::~GFXGLTextureObject()
|
GFXGLTextureObject::~GFXGLTextureObject()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &mHandle);
|
glDeleteTextures(1, &mHandle);
|
||||||
glDeleteBuffers(1, &mBuffer);
|
glDeleteBuffers(1, &mBuffer);
|
||||||
delete[] mZombieCache;
|
delete[] mZombieCache;
|
||||||
|
|
@ -81,7 +81,7 @@ GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel, RectI *inRect)
|
||||||
{
|
{
|
||||||
mLockedRectRect = RectI(0, 0, width, height);
|
mLockedRectRect = RectI(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
mLockedRect.pitch = mLockedRectRect.extent.x * mBytesPerTexel;
|
mLockedRect.pitch = mLockedRectRect.extent.x * mBytesPerTexel;
|
||||||
|
|
||||||
// CodeReview [ags 12/19/07] This one texel boundary is necessary to keep the clipmap code from crashing. Figure out why.
|
// CodeReview [ags 12/19/07] This one texel boundary is necessary to keep the clipmap code from crashing. Figure out why.
|
||||||
|
|
@ -93,7 +93,7 @@ GFXLockedRect* GFXGLTextureObject::lock(U32 mipLevel, RectI *inRect)
|
||||||
#ifdef TORQUE_DEBUG
|
#ifdef TORQUE_DEBUG
|
||||||
mFrameAllocatorMarkGuard = FrameAllocator::getWaterMark();
|
mFrameAllocatorMarkGuard = FrameAllocator::getWaterMark();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( !mLockedRect.bits )
|
if( !mLockedRect.bits )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
@ -117,12 +117,12 @@ void GFXGLTextureObject::unlock(U32 mipLevel)
|
||||||
glTexSubImage3D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, z,
|
glTexSubImage3D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y, z,
|
||||||
mLockedRectRect.extent.x, mLockedRectRect.extent.y, z, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
|
mLockedRectRect.extent.x, mLockedRectRect.extent.y, z, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
|
||||||
else if(mBinding == GL_TEXTURE_2D)
|
else if(mBinding == GL_TEXTURE_2D)
|
||||||
glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y,
|
glTexSubImage2D(mBinding, mipLevel, mLockedRectRect.point.x, mLockedRectRect.point.y,
|
||||||
mLockedRectRect.extent.x, mLockedRectRect.extent.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
|
mLockedRectRect.extent.x, mLockedRectRect.extent.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
|
||||||
else if(mBinding == GL_TEXTURE_1D)
|
else if(mBinding == GL_TEXTURE_1D)
|
||||||
glTexSubImage1D(mBinding, mipLevel, (mLockedRectRect.point.x > 1 ? mLockedRectRect.point.x : mLockedRectRect.point.y),
|
glTexSubImage1D(mBinding, mipLevel, (mLockedRectRect.point.x > 1 ? mLockedRectRect.point.x : mLockedRectRect.point.y),
|
||||||
(mLockedRectRect.extent.x > 1 ? mLockedRectRect.extent.x : mLockedRectRect.extent.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
|
(mLockedRectRect.extent.x > 1 ? mLockedRectRect.extent.x : mLockedRectRect.extent.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], NULL);
|
||||||
|
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
|
|
||||||
mLockedRect.bits = NULL;
|
mLockedRect.bits = NULL;
|
||||||
|
|
@ -138,7 +138,7 @@ void GFXGLTextureObject::release()
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &mHandle);
|
glDeleteTextures(1, &mHandle);
|
||||||
glDeleteBuffers(1, &mBuffer);
|
glDeleteBuffers(1, &mBuffer);
|
||||||
|
|
||||||
mHandle = 0;
|
mHandle = 0;
|
||||||
mBuffer = 0;
|
mBuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -174,7 +174,7 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
|
||||||
U8 srcBytesPerPixel = GFXFormat_getByteSize( mFormat );
|
U8 srcBytesPerPixel = GFXFormat_getByteSize( mFormat );
|
||||||
|
|
||||||
FrameAllocatorMarker mem;
|
FrameAllocatorMarker mem;
|
||||||
|
|
||||||
|
|
||||||
U32 mipLevels = getMipLevels();
|
U32 mipLevels = getMipLevels();
|
||||||
for (U32 mip = 0; mip < mipLevels; mip++)
|
for (U32 mip = 0; mip < mipLevels; mip++)
|
||||||
|
|
@ -204,7 +204,7 @@ bool GFXGLTextureObject::copyToBmp(GBitmap * bmp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glBindTexture(mBinding, NULL);
|
glBindTexture(mBinding, 0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -236,8 +236,8 @@ U8* GFXGLTextureObject::getTextureData( U32 mip )
|
||||||
AssertFatal( mMipLevels, "");
|
AssertFatal( mMipLevels, "");
|
||||||
mip = (mip < mMipLevels) ? mip : 0;
|
mip = (mip < mMipLevels) ? mip : 0;
|
||||||
|
|
||||||
const U32 dataSize = ImageUtil::isCompressedFormat(mFormat)
|
const U32 dataSize = ImageUtil::isCompressedFormat(mFormat)
|
||||||
? getCompressedSurfaceSize( mFormat, mTextureSize.x, mTextureSize.y, mip )
|
? getCompressedSurfaceSize( mFormat, mTextureSize.x, mTextureSize.y, mip )
|
||||||
: (mTextureSize.x >> mip) * (mTextureSize.y >> mip) * mBytesPerTexel;
|
: (mTextureSize.x >> mip) * (mTextureSize.y >> mip) * mBytesPerTexel;
|
||||||
|
|
||||||
U8* data = new U8[dataSize];
|
U8* data = new U8[dataSize];
|
||||||
|
|
@ -258,10 +258,10 @@ void GFXGLTextureObject::copyIntoCache()
|
||||||
U32 cacheSize = mTextureSize.x * mTextureSize.y;
|
U32 cacheSize = mTextureSize.x * mTextureSize.y;
|
||||||
if(mBinding == GL_TEXTURE_3D)
|
if(mBinding == GL_TEXTURE_3D)
|
||||||
cacheSize *= mTextureSize.z;
|
cacheSize *= mTextureSize.z;
|
||||||
|
|
||||||
cacheSize *= mBytesPerTexel;
|
cacheSize *= mBytesPerTexel;
|
||||||
mZombieCache = new U8[cacheSize];
|
mZombieCache = new U8[cacheSize];
|
||||||
|
|
||||||
glGetTexImage(mBinding, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
|
glGetTexImage(mBinding, 0, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -269,7 +269,7 @@ void GFXGLTextureObject::reloadFromCache()
|
||||||
{
|
{
|
||||||
if(!mZombieCache)
|
if(!mZombieCache)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(mBinding == GL_TEXTURE_3D)
|
if(mBinding == GL_TEXTURE_3D)
|
||||||
{
|
{
|
||||||
static_cast<GFXGLTextureManager*>(TEXMGR)->_loadTexture(this, mZombieCache);
|
static_cast<GFXGLTextureManager*>(TEXMGR)->_loadTexture(this, mZombieCache);
|
||||||
|
|
@ -277,7 +277,7 @@ void GFXGLTextureObject::reloadFromCache()
|
||||||
mZombieCache = NULL;
|
mZombieCache = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRESERVE_TEXTURE(mBinding);
|
PRESERVE_TEXTURE(mBinding);
|
||||||
glBindTexture(mBinding, mHandle);
|
glBindTexture(mBinding, mHandle);
|
||||||
|
|
||||||
|
|
@ -285,10 +285,10 @@ void GFXGLTextureObject::reloadFromCache()
|
||||||
glTexSubImage2D(mBinding, 0, 0, 0, mTextureSize.x, mTextureSize.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
|
glTexSubImage2D(mBinding, 0, 0, 0, mTextureSize.x, mTextureSize.y, GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
|
||||||
else if(mBinding == GL_TEXTURE_1D)
|
else if(mBinding == GL_TEXTURE_1D)
|
||||||
glTexSubImage1D(mBinding, 0, 0, (mTextureSize.x > 1 ? mTextureSize.x : mTextureSize.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
|
glTexSubImage1D(mBinding, 0, 0, (mTextureSize.x > 1 ? mTextureSize.x : mTextureSize.y), GFXGLTextureFormat[mFormat], GFXGLTextureType[mFormat], mZombieCache);
|
||||||
|
|
||||||
if(mMipLevels != 1)
|
if(mMipLevels != 1)
|
||||||
glGenerateMipmap(mBinding);
|
glGenerateMipmap(mBinding);
|
||||||
|
|
||||||
delete[] mZombieCache;
|
delete[] mZombieCache;
|
||||||
mZombieCache = NULL;
|
mZombieCache = NULL;
|
||||||
mIsZombie = false;
|
mIsZombie = false;
|
||||||
|
|
@ -298,11 +298,11 @@ void GFXGLTextureObject::zombify()
|
||||||
{
|
{
|
||||||
if(mIsZombie)
|
if(mIsZombie)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mIsZombie = true;
|
mIsZombie = true;
|
||||||
if(!mProfile->doStoreBitmap() && !mProfile->isRenderTarget() && !mProfile->isDynamic() && !mProfile->isZTarget())
|
if(!mProfile->doStoreBitmap() && !mProfile->isRenderTarget() && !mProfile->isDynamic() && !mProfile->isZTarget())
|
||||||
copyIntoCache();
|
copyIntoCache();
|
||||||
|
|
||||||
release();
|
release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,7 +310,7 @@ void GFXGLTextureObject::resurrect()
|
||||||
{
|
{
|
||||||
if(!mIsZombie)
|
if(!mIsZombie)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glGenTextures(1, &mHandle);
|
glGenTextures(1, &mHandle);
|
||||||
glGenBuffers(1, &mBuffer);
|
glGenBuffers(1, &mBuffer);
|
||||||
}
|
}
|
||||||
|
|
@ -329,6 +329,6 @@ const String GFXGLTextureObject::describeSelf() const
|
||||||
{
|
{
|
||||||
String ret = Parent::describeSelf();
|
String ret = Parent::describeSelf();
|
||||||
ret += String::ToString(" GL Handle: %i", mHandle);
|
ret += String::ToString(" GL Handle: %i", mHandle);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ bool PopupMenu::smSelectionEventHandled = false;
|
||||||
|
|
||||||
/// Event class used to remove popup menus from the event notification in a safe way
|
/// Event class used to remove popup menus from the event notification in a safe way
|
||||||
class PopUpNotifyRemoveEvent : public SimEvent
|
class PopUpNotifyRemoveEvent : public SimEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void process(SimObject *object)
|
void process(SimObject *object)
|
||||||
{
|
{
|
||||||
|
|
@ -46,7 +46,7 @@ public:
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
PopupMenu::PopupMenu()
|
PopupMenu::PopupMenu()
|
||||||
{
|
{
|
||||||
mMenuItems = NULL;
|
mMenuItems = 0;
|
||||||
mMenuBarCtrl = nullptr;
|
mMenuBarCtrl = nullptr;
|
||||||
|
|
||||||
mBarTitle = StringTable->EmptyString();
|
mBarTitle = StringTable->EmptyString();
|
||||||
|
|
@ -115,7 +115,7 @@ void PopupMenu::onMenuSelect()
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void PopupMenu::handleSelectEvent(U32 popID, U32 command)
|
void PopupMenu::handleSelectEvent(U32 popID, U32 command)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -199,7 +199,7 @@ bool PopupMenu::setItem(S32 pos, const char *title, const char* accelerator, con
|
||||||
{
|
{
|
||||||
mMenuItems[i].mID = pos;
|
mMenuItems[i].mID = pos;
|
||||||
mMenuItems[i].mCMD = cmd;
|
mMenuItems[i].mCMD = cmd;
|
||||||
|
|
||||||
if (accelerator && accelerator[0])
|
if (accelerator && accelerator[0])
|
||||||
mMenuItems[i].mAccelerator = dStrdup(accelerator);
|
mMenuItems[i].mAccelerator = dStrdup(accelerator);
|
||||||
else
|
else
|
||||||
|
|
@ -207,7 +207,7 @@ bool PopupMenu::setItem(S32 pos, const char *title, const char* accelerator, con
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
// IN THE SOFTWARE.
|
// IN THE SOFTWARE.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#if !defined( __APPLE__ ) && !defined( __FreeBSD__ )
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
@ -38,14 +38,18 @@
|
||||||
|
|
||||||
Platform::SystemInfo_struct Platform::SystemInfo;
|
Platform::SystemInfo_struct Platform::SystemInfo;
|
||||||
|
|
||||||
static inline void rtrim(std::string &s)
|
// trim from start (in place)
|
||||||
{
|
static inline void ltrim(std::string &s) {
|
||||||
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||||
|
return !std::isspace(ch);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ltrim(std::string &s)
|
// trim from end (in place)
|
||||||
{
|
static inline void rtrim(std::string &s) {
|
||||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
|
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||||
|
return !std::isspace(ch);
|
||||||
|
}).base(), s.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getCPUInformation()
|
static void getCPUInformation()
|
||||||
|
|
@ -183,7 +187,7 @@ static void getCPUInformation()
|
||||||
SetProcessorInfo(Platform::SystemInfo.processor, vendorString.c_str(), brandString.c_str());
|
SetProcessorInfo(Platform::SystemInfo.processor, vendorString.c_str(), brandString.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Processor::init()
|
void Processor::init()
|
||||||
{
|
{
|
||||||
getCPUInformation();
|
getCPUInformation();
|
||||||
|
|
||||||
|
|
@ -244,11 +248,11 @@ namespace CPUInfo
|
||||||
}
|
}
|
||||||
else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
|
else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
|
||||||
{
|
{
|
||||||
return CONFIG_SingleCoreAndHTNotCapable;
|
return CONFIG_SingleCoreAndHTNotCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CONFIG_MultiCoreAndHTEnabled;
|
return CONFIG_MultiCoreAndHTEnabled;
|
||||||
}
|
}
|
||||||
}; // namespace CPUInfo
|
}; // namespace CPUInfo
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
|
#include "core/util/journal/process.h"
|
||||||
#ifndef TORQUE_DEDICATED
|
#ifndef TORQUE_DEDICATED
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -48,7 +49,7 @@ static void CheckExitCode(S64 exitCode)
|
||||||
{
|
{
|
||||||
if (exitCode != 0)
|
if (exitCode != 0)
|
||||||
{
|
{
|
||||||
Con::errorf(ConsoleLogEntry::General,
|
Con::errorf(ConsoleLogEntry::General,
|
||||||
"Nonzero exit code: %d, triggering SIGSEGV for core dump",
|
"Nonzero exit code: %d, triggering SIGSEGV for core dump",
|
||||||
exitCode);
|
exitCode);
|
||||||
kill(getpid(), SIGSEGV);
|
kill(getpid(), SIGSEGV);
|
||||||
|
|
@ -62,7 +63,7 @@ static void SignalHandler(int sigtype)
|
||||||
{
|
{
|
||||||
signal(SIGSEGV, SIG_DFL);
|
signal(SIGSEGV, SIG_DFL);
|
||||||
signal(SIGTRAP, SIG_DFL);
|
signal(SIGTRAP, SIG_DFL);
|
||||||
// restore the signal handling to default so that we don't get into
|
// restore the signal handling to default so that we don't get into
|
||||||
// a crash loop with ImmediateShutdown
|
// a crash loop with ImmediateShutdown
|
||||||
ImmediateShutdown(-sigtype, sigtype);
|
ImmediateShutdown(-sigtype, sigtype);
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +86,7 @@ void Cleanup(bool minimal)
|
||||||
|
|
||||||
StdConsole::destroy();
|
StdConsole::destroy();
|
||||||
|
|
||||||
#ifndef TORQUE_DEDICATED
|
#ifndef TORQUE_DEDICATED
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +106,7 @@ void ImmediateShutdown(S32 exitCode, S32 signalNum)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// there is a problem in kernel 2.4.17 which causes a hang when a segfault
|
// there is a problem in kernel 2.4.17 which causes a hang when a segfault
|
||||||
// occurs. also subsequent runs of "ps" will hang and the machine has to be
|
// occurs. also subsequent runs of "ps" will hang and the machine has to be
|
||||||
// hard reset to clear up the problem
|
// hard reset to clear up the problem
|
||||||
// JMQ: this bug appears to be fixed in 2.4.18
|
// JMQ: this bug appears to be fixed in 2.4.18
|
||||||
|
|
@ -130,7 +131,7 @@ void ProcessControlInit()
|
||||||
signal(SIGTTIN, SIG_IGN);
|
signal(SIGTTIN, SIG_IGN);
|
||||||
signal(SIGTTOU, SIG_IGN);
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
|
||||||
// we're not interested in the exit status of child processes, so this
|
// we're not interested in the exit status of child processes, so this
|
||||||
// prevents zombies from accumulating.
|
// prevents zombies from accumulating.
|
||||||
#if defined(__FreeBSD__) || defined(__APPLE__)
|
#if defined(__FreeBSD__) || defined(__APPLE__)
|
||||||
signal(SIGCHLD, SIG_IGN);
|
signal(SIGCHLD, SIG_IGN);
|
||||||
|
|
@ -147,6 +148,7 @@ void ProcessControlInit()
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Platform::postQuitMessage(const S32 in_quitVal)
|
void Platform::postQuitMessage(const S32 in_quitVal)
|
||||||
{
|
{
|
||||||
|
|
||||||
// if we have a window send a quit event, otherwise just force shutdown
|
// if we have a window send a quit event, otherwise just force shutdown
|
||||||
#if 0
|
#if 0
|
||||||
if (x86UNIXState->windowCreated())
|
if (x86UNIXState->windowCreated())
|
||||||
|
|
@ -155,18 +157,19 @@ void Platform::postQuitMessage(const S32 in_quitVal)
|
||||||
SendQuitEvent();
|
SendQuitEvent();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
forceShutdown(in_quitVal);
|
forceShutdown(in_quitVal);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
Process::requestShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void Platform::debugBreak()
|
void Platform::debugBreak()
|
||||||
{
|
{
|
||||||
// in windows, "Calling DebugBreak causes the program to display
|
// in windows, "Calling DebugBreak causes the program to display
|
||||||
// a dialog box as if it had crashed." So we segfault.
|
// a dialog box as if it had crashed." So we segfault.
|
||||||
Con::errorf(ConsoleLogEntry::General,
|
Con::errorf(ConsoleLogEntry::General,
|
||||||
"Platform::debugBreak: triggering SIGSEGV for core dump");
|
"Platform::debugBreak: triggering SIGSEGV for core dump");
|
||||||
//kill(getpid(), SIGSEGV);
|
//kill(getpid(), SIGSEGV);
|
||||||
|
|
||||||
|
|
@ -197,20 +200,20 @@ void Platform::forceShutdown(S32 returnValue)
|
||||||
void Platform::outputDebugString(const char *string, ...)
|
void Platform::outputDebugString(const char *string, ...)
|
||||||
{
|
{
|
||||||
char buffer[2048];
|
char buffer[2048];
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start( args, string );
|
va_start( args, string );
|
||||||
|
|
||||||
dVsprintf( buffer, sizeof(buffer), string, args );
|
dVsprintf( buffer, sizeof(buffer), string, args );
|
||||||
va_end( args );
|
va_end( args );
|
||||||
|
|
||||||
U32 length = dStrlen(buffer);
|
U32 length = dStrlen(buffer);
|
||||||
if( length == (sizeof(buffer) - 1 ) )
|
if( length == (sizeof(buffer) - 1 ) )
|
||||||
length--;
|
length--;
|
||||||
|
|
||||||
buffer[length++] = '\n';
|
buffer[length++] = '\n';
|
||||||
buffer[length] = '\0';
|
buffer[length] = '\0';
|
||||||
|
|
||||||
fwrite(buffer, sizeof(char), length, stderr);
|
fwrite(buffer, sizeof(char), length, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,4 +237,4 @@ void Platform::restartInstance()
|
||||||
*/
|
*/
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
148
Engine/source/platformSDL/sdlCPUInfo.cpp
Normal file
148
Engine/source/platformSDL/sdlCPUInfo.cpp
Normal file
|
|
@ -0,0 +1,148 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Copyright (c) 2012 GarageGames, LLC
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to
|
||||||
|
// deal in the Software without restriction, including without limitation the
|
||||||
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
// sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in
|
||||||
|
// all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
|
// IN THE SOFTWARE.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// XXTH used for FreeBSD
|
||||||
|
// Note: SDL_cpuinfo have not all information, but better than using
|
||||||
|
// "sysctl hw"
|
||||||
|
//
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
#if defined( __FreeBSD__ )
|
||||||
|
#include "SDL.h"
|
||||||
|
|
||||||
|
#include "platform/platformCPUCount.h"
|
||||||
|
#include "console/console.h"
|
||||||
|
#include <math/mMathFn.h>
|
||||||
|
|
||||||
|
Platform::SystemInfo_struct Platform::SystemInfo;
|
||||||
|
|
||||||
|
void Processor::init()
|
||||||
|
{
|
||||||
|
|
||||||
|
S32 lCpuCount = SDL_GetCPUCount();
|
||||||
|
Platform::SystemInfo.processor.numLogicalProcessors = lCpuCount;
|
||||||
|
//sdl dont have logical/physical CPU count so ... time to guess
|
||||||
|
if (lCpuCount > 1)
|
||||||
|
{
|
||||||
|
Platform::SystemInfo.processor.numPhysicalProcessors = mFloor(lCpuCount / 2); // guessing ;
|
||||||
|
Platform::SystemInfo.processor.isMultiCore = true;
|
||||||
|
//modern CPU should have isHyperThreaded
|
||||||
|
Platform::SystemInfo.processor.isHyperThreaded = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Platform::SystemInfo.processor.numPhysicalProcessors = lCpuCount; // guessing ;
|
||||||
|
Platform::SystemInfo.processor.isMultiCore = false;
|
||||||
|
Platform::SystemInfo.processor.isHyperThreaded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//hackfest
|
||||||
|
Platform::SystemInfo.processor.mhz = 2666;
|
||||||
|
#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_X32)
|
||||||
|
// Set sane default information
|
||||||
|
Platform::SystemInfo.processor.name = StringTable->insert("Unknown Processor");
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_C | CPU_PROP_FPU | CPU_PROP_LE ;
|
||||||
|
Platform::SystemInfo.processor.type = CPU_X86Compatible;
|
||||||
|
|
||||||
|
#elif defined(TORQUE_CPU_ARM32) || defined(TORQUE_CPU_ARM64)
|
||||||
|
Platform::SystemInfo.processor.type = CPU_ArmCompatible;
|
||||||
|
Platform::SystemInfo.processor.name = StringTable->insert("Unknown ARM Processor");
|
||||||
|
Platform::SystemInfo.processor.properties = CPU_PROP_C;
|
||||||
|
#else
|
||||||
|
#warning Unsupported CPU
|
||||||
|
#endif
|
||||||
|
// Set 64bit flag
|
||||||
|
#if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_64bit;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
Con::printf("Processor Init:");
|
||||||
|
Con::printf(" CPU count: %d", lCpuCount);
|
||||||
|
Con::printf(" CacheLine size: %d", SDL_GetCPUCacheLineSize());
|
||||||
|
if (lCpuCount > 1) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_MP;
|
||||||
|
Con::printf(" MultiCore CPU detected" );
|
||||||
|
}
|
||||||
|
Con::printf(" RAM: %d MB", SDL_GetSystemRAM());
|
||||||
|
if (SDL_HasMMX()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_MMX;
|
||||||
|
Con::printf(" MMX detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasSSE()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE;
|
||||||
|
Con::printf(" SSE detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasSSE2()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE2;
|
||||||
|
Con::printf(" SSE2 detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasSSE3()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE3;
|
||||||
|
Con::printf(" SSE3 detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasSSE41()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_1;
|
||||||
|
Con::printf(" SSE4.1 detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasSSE42()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
|
||||||
|
Con::printf(" SSE4.2 detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasSSE42()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
|
||||||
|
Con::printf(" SSE4.2 detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasAVX() || SDL_HasAVX2()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_AVX;
|
||||||
|
Con::printf(" AVX detected" );
|
||||||
|
}
|
||||||
|
if (SDL_HasNEON()) {
|
||||||
|
Platform::SystemInfo.processor.properties |= CPU_PROP_NEON;
|
||||||
|
Con::printf(" NEON detected" );
|
||||||
|
}
|
||||||
|
|
||||||
|
Con::printf(" ");
|
||||||
|
|
||||||
|
SetProcessorInfo(Platform::SystemInfo.processor, "Unknown", "Unknown");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace CPUInfo
|
||||||
|
{
|
||||||
|
EConfig CPUCount(U32 &logical, U32 &physical)
|
||||||
|
{
|
||||||
|
// We don't set logical or physical here because it's already been determined by this point
|
||||||
|
if (Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
|
||||||
|
{
|
||||||
|
return CONFIG_SingleCoreHTEnabled;
|
||||||
|
}
|
||||||
|
else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors > 1)
|
||||||
|
{
|
||||||
|
return CONFIG_MultiCoreAndHTNotCapable;
|
||||||
|
}
|
||||||
|
else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
|
||||||
|
{
|
||||||
|
return CONFIG_SingleCoreAndHTNotCapable;
|
||||||
|
}
|
||||||
|
|
||||||
|
return CONFIG_MultiCoreAndHTEnabled;
|
||||||
|
}
|
||||||
|
}; // namespace CPUInfo
|
||||||
|
|
||||||
|
#endif // defined( __FreeBSD__ )
|
||||||
|
|
@ -65,7 +65,7 @@ class TSCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~TSCallback() {}
|
virtual ~TSCallback() {}
|
||||||
|
|
||||||
virtual void setNodeTransform(TSShapeInstance * si, S32 nodeIndex, MatrixF & localTransform) = 0;
|
virtual void setNodeTransform(TSShapeInstance * si, S32 nodeIndex, MatrixF & localTransform) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -114,13 +114,13 @@ class TSShapeInstance
|
||||||
struct ObjectInstance
|
struct ObjectInstance
|
||||||
{
|
{
|
||||||
virtual ~ObjectInstance() {}
|
virtual ~ObjectInstance() {}
|
||||||
|
|
||||||
/// this needs to be set before using an objectInstance...tells us where to
|
/// this needs to be set before using an objectInstance...tells us where to
|
||||||
/// look for the transforms...gets set be shape instance 'setStatics' method
|
/// look for the transforms...gets set be shape instance 'setStatics' method
|
||||||
const Vector<MatrixF> *mTransforms;
|
const Vector<MatrixF> *mTransforms;
|
||||||
|
|
||||||
S32 nodeIndex;
|
S32 nodeIndex;
|
||||||
|
|
||||||
/// Gets the transform of this object
|
/// Gets the transform of this object
|
||||||
inline const MatrixF& getTransform() const
|
inline const MatrixF& getTransform() const
|
||||||
{
|
{
|
||||||
|
|
@ -166,8 +166,8 @@ class TSShapeInstance
|
||||||
/// If true this mesh is forced to be hidden
|
/// If true this mesh is forced to be hidden
|
||||||
/// regardless of the animation state.
|
/// regardless of the animation state.
|
||||||
bool forceHidden;
|
bool forceHidden;
|
||||||
|
|
||||||
/// The time at which this mesh
|
/// The time at which this mesh
|
||||||
/// was last rendered.
|
/// was last rendered.
|
||||||
U32 mLastTime;
|
U32 mLastTime;
|
||||||
|
|
||||||
|
|
@ -248,7 +248,7 @@ class TSShapeInstance
|
||||||
static Vector<TSThread*> smTranslationThreads;
|
static Vector<TSThread*> smTranslationThreads;
|
||||||
static Vector<TSThread*> smScaleThreads;
|
static Vector<TSThread*> smScaleThreads;
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
TSMaterialList* mMaterialList; ///< by default, points to hShape material list
|
TSMaterialList* mMaterialList; ///< by default, points to hShape material list
|
||||||
//-------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------
|
||||||
// Misc.
|
// Misc.
|
||||||
|
|
@ -333,17 +333,17 @@ protected:
|
||||||
TSShape* getShape() const { return mShape; }
|
TSShape* getShape() const { return mShape; }
|
||||||
|
|
||||||
TSMaterialList* getMaterialList() const { return mMaterialList; }
|
TSMaterialList* getMaterialList() const { return mMaterialList; }
|
||||||
|
|
||||||
/// Set the material list without taking ownership.
|
/// Set the material list without taking ownership.
|
||||||
/// @see cloneMaterialList
|
/// @see cloneMaterialList
|
||||||
void setMaterialList( TSMaterialList *matList );
|
void setMaterialList( TSMaterialList *matList );
|
||||||
|
|
||||||
/// Call this to own the material list -- i.e., we'll make a copy of the
|
/// Call this to own the material list -- i.e., we'll make a copy of the
|
||||||
/// currently set material list and be responsible for deleting it. You
|
/// currently set material list and be responsible for deleting it. You
|
||||||
/// can pass an optional feature set for initializing the cloned materials.
|
/// can pass an optional feature set for initializing the cloned materials.
|
||||||
void cloneMaterialList( const FeatureSet *features = NULL );
|
void cloneMaterialList( const FeatureSet *features = NULL );
|
||||||
|
|
||||||
/// Initializes or re-initializes the material list with
|
/// Initializes or re-initializes the material list with
|
||||||
/// an optional feature set.
|
/// an optional feature set.
|
||||||
void initMaterialList( const FeatureSet *features = NULL );
|
void initMaterialList( const FeatureSet *features = NULL );
|
||||||
|
|
||||||
|
|
@ -469,7 +469,7 @@ protected:
|
||||||
static F32 smDetailAdjust;
|
static F32 smDetailAdjust;
|
||||||
|
|
||||||
/// If this is set to a positive pixel value shapes
|
/// If this is set to a positive pixel value shapes
|
||||||
/// with a smaller pixel size than this will skip
|
/// with a smaller pixel size than this will skip
|
||||||
/// rendering entirely.
|
/// rendering entirely.
|
||||||
static F32 smSmallestVisiblePixelSize;
|
static F32 smSmallestVisiblePixelSize;
|
||||||
|
|
||||||
|
|
@ -490,7 +490,7 @@ protected:
|
||||||
void renderDebugNormals( F32 normalScalar, S32 dl );
|
void renderDebugNormals( F32 normalScalar, S32 dl );
|
||||||
|
|
||||||
/// Render all node transforms as small axis gizmos. It is recommended
|
/// Render all node transforms as small axis gizmos. It is recommended
|
||||||
/// that prior to calling this, shapeInstance::animate is called so that
|
/// that prior to calling this, shapeInstance::animate is called so that
|
||||||
/// nodes are in object space and that the GFX state is setup for
|
/// nodes are in object space and that the GFX state is setup for
|
||||||
/// rendering in model space.
|
/// rendering in model space.
|
||||||
void renderDebugNodes();
|
void renderDebugNodes();
|
||||||
|
|
@ -518,7 +518,7 @@ protected:
|
||||||
/// Sets the 'forceHidden' state on the named mesh.
|
/// Sets the 'forceHidden' state on the named mesh.
|
||||||
/// @see MeshObjectInstance::forceHidden
|
/// @see MeshObjectInstance::forceHidden
|
||||||
void setMeshForceHidden( const char *meshName, bool hidden );
|
void setMeshForceHidden( const char *meshName, bool hidden );
|
||||||
|
|
||||||
/// Sets the 'forceHidden' state on a mesh.
|
/// Sets the 'forceHidden' state on a mesh.
|
||||||
/// @see MeshObjectInstance::forceHidden
|
/// @see MeshObjectInstance::forceHidden
|
||||||
void setMeshForceHidden( S32 meshIndex, bool hidden );
|
void setMeshForceHidden( S32 meshIndex, bool hidden );
|
||||||
|
|
@ -558,8 +558,8 @@ protected:
|
||||||
void setCurrentDetail( S32 dl, F32 intraDL = 1.0f );
|
void setCurrentDetail( S32 dl, F32 intraDL = 1.0f );
|
||||||
|
|
||||||
/// Helper function which internally calls setDetailFromDistance.
|
/// Helper function which internally calls setDetailFromDistance.
|
||||||
S32 setDetailFromPosAndScale( const SceneRenderState *state,
|
S32 setDetailFromPosAndScale( const SceneRenderState *state,
|
||||||
const Point3F &pos,
|
const Point3F &pos,
|
||||||
const Point3F &scale );
|
const Point3F &scale );
|
||||||
|
|
||||||
/// Selects the current detail level using the scaled
|
/// Selects the current detail level using the scaled
|
||||||
|
|
@ -788,7 +788,7 @@ class TSThread
|
||||||
keyPos = 0;
|
keyPos = 0;
|
||||||
mSeqPos = 0;
|
mSeqPos = 0;
|
||||||
mShapeInstance = NULL;
|
mShapeInstance = NULL;
|
||||||
makePath = NULL;
|
makePath = false;
|
||||||
priority = 0;
|
priority = 0;
|
||||||
sequence = 0;
|
sequence = 0;
|
||||||
timeScale = 1.0f;
|
timeScale = 1.0f;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue