Add PhysicsEffects to Extras. The build is only tested on Windows and Android.

The Android/NEON optimized version of Physics Effects is thanks to Graham Rhodes and Anthony Hamilton, See Issue 587
This commit is contained in:
erwin.coumans
2012-03-05 04:59:58 +00:00
parent 6cf8dfc202
commit a93a661b94
462 changed files with 86626 additions and 0 deletions

View File

@@ -0,0 +1,181 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_COMMON_H
#define _SCE_PFX_COMMON_H
// Include common headers
#ifdef _WIN32
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#else
#include <stdio.h>
#include <stdint.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <math.h>
#if defined(_WIN32)
#include "pfx_vectormath_include.win32.h"
#else
#include "pfx_vectormath_include.h"
#endif
namespace sce {
namespace PhysicsEffects {
// Basic Types
#if defined(_WIN32)
typedef char PfxInt8;
typedef unsigned char PfxUInt8;
typedef short PfxInt16;
typedef unsigned short PfxUInt16;
typedef int PfxInt32;
typedef unsigned int PfxUInt32;
typedef long long PfxInt64;
typedef unsigned long long PfxUInt64;
#else
typedef int8_t PfxInt8;
typedef uint8_t PfxUInt8;
typedef int16_t PfxInt16;
typedef uint16_t PfxUInt16;
typedef int32_t PfxInt32;
typedef uint32_t PfxUInt32;
typedef int64_t PfxInt64;
typedef uint64_t PfxUInt64;
#endif
typedef bool PfxBool;
typedef float PfxFloat;
} //namespace PhysicsEffects
} //namespace sce
// Debug Print
#ifdef _WIN32
static void pfxOutputDebugString(const char *str, ...)
{
char strDebug[1024]={0};
va_list argList;
va_start(argList, str);
vsprintf_s(strDebug,str,argList);
OutputDebugStringA(strDebug);
va_end(argList);
}
#endif
#if defined(_DEBUG)
#if defined(_WIN32)
#define SCE_PFX_DPRINT pfxOutputDebugString
#else
#define SCE_PFX_DPRINT(...) printf(__VA_ARGS__)
#endif
#else
#ifdef _WIN32
#define SCE_PFX_DPRINT
#else
#define SCE_PFX_DPRINT(...)
#endif
#endif
// Printf
#if defined(_WIN32)
#define SCE_PFX_PRINTF pfxOutputDebugString
#else
// ARA begin insert new code
#ifdef __ANDROID__
#include <android/log.h>
#define SCE_PFX_PRINTF(...) __android_log_print(ANDROID_LOG_VERBOSE, "SCE_PFX_PRINTF", __VA_ARGS__)
#else
#define SCE_PFX_PRINTF(...) printf(__VA_ARGS__)
#endif
// ARA end, old baseline code block was:
// #define SCE_PFX_PRINTF(...) printf(__VA_ARGS__)
//
#endif
#define SCE_PFX_UNLIKELY(a) (a)
#define SCE_PFX_LIKELY(a) (a)
// Inline
#if defined(_MSC_VER)
#define SCE_PFX_FORCE_INLINE __forceinline
#elif defined(__SNC__) || defined(__GNUC__)
#define SCE_PFX_FORCE_INLINE inline __attribute__((always_inline))
#endif
// Assert
#define SCE_PFX_HALT() abort()
#ifdef _DEBUG
#define SCE_PFX_ASSERT(test) {if(!(test)){SCE_PFX_PRINTF("Assert "__FILE__ ":%u ("#test")\n", __LINE__);SCE_PFX_HALT();}}
#define SCE_PFX_ASSERT_MSG(test,msg) {if(!(test)){SCE_PFX_PRINTF("Assert " msg " " __FILE__ ":%u ("#test")\n",__LINE__);SCE_PFX_HALT();}}
#else
#define SCE_PFX_ASSERT(test)
#define SCE_PFX_ASSERT_MSG(test,msg)
#endif
#define SCE_PFX_ALWAYS_ASSERT(test) {if(!(test)){SCE_PFX_PRINTF("Assert "__FILE__ ":%u ("#test")\n", __LINE__);SCE_PFX_HALT();}}
#define SCE_PFX_ALWAYS_ASSERT_MSG(test,msg) {if(!(test)){SCE_PFX_PRINTF("Assert:" msg " " __FILE__ ":%u ("#test")\n",__LINE__);SCE_PFX_HALT();}}
// Aligned
#if defined(_MSC_VER)
#define SCE_PFX_ALIGNED(alignment) __declspec(align(alignment))
#elif defined(__SNC__) || defined(__GNUC__)
#define SCE_PFX_ALIGNED(alignment) __attribute__((__aligned__((alignment))))
#endif
// Etc
#define SCE_PFX_MIN(a,b) (((a)<(b))?(a):(b))
#define SCE_PFX_MAX(a,b) (((a)>(b))?(a):(b))
#define SCE_PFX_CLAMP(v,a,b) SCE_PFX_MAX(a,SCE_PFX_MIN(v,b))
#define SCE_PFX_SWAP(type, x, y) do {type t; t=x; x=y; y=t; } while (0)
#define SCE_PFX_SQR(a) ((a)*(a))
#define SCE_PFX_ALIGN16(count,size) ((((((count) * (size)) + 15) & (~15)) + (size)-1) / (size))
#define SCE_PFX_ALIGN128(count,size) ((((((count) * (size)) + 127) & (~127)) + (size)-1) / (size))
#define SCE_PFX_AVAILABLE_BYTES_ALIGN16(ptr,bytes) (bytes-((uintptr_t)(ptr)&0x0f))
#define SCE_PFX_AVAILABLE_BYTES_ALIGN128(ptr,bytes) (bytes-((uintptr_t)(ptr)&0x7f))
#define SCE_PFX_BYTES_ALIGN16(bytes) (((bytes)+15)&(~15))
#define SCE_PFX_BYTES_ALIGN128(bytes) (((bytes)+127)&(~127))
#define SCE_PFX_PTR_ALIGN16(ptr) (((uintptr_t)(ptr)+15)&(~15))
#define SCE_PFX_PTR_ALIGN128(ptr) (((uintptr_t)(ptr)+127)&(~127))
#define SCE_PFX_PTR_IS_ALIGNED16(ptr) (((uintptr_t)(ptr)&0x0f)==0)
#define SCE_PFX_PTR_IS_ALIGNED128(ptr) (((uintptr_t)(ptr)&0x7f)==0)
#define SCE_PFX_GET_POINTER(offset,stride,id) ((uintptr_t)(offset)+(stride)*(id))
#define SCE_PFX_FLT_MAX 1e+38f
#define SCE_PFX_PI 3.14159265358979f
#define SCE_PFX_RANGE_CHECK(val,minVal,maxVal) (((val)>=(minVal))&&((val)<=(maxVal)))
#define SCE_PFX_IS_RUNNING_ON_64BIT_ENV() ( ( sizeof(void*)==8 )? true : false )
#if defined(__SNC__) || defined(__GNUC__)
#define SCE_PFX_PADDING(count,bytes) PfxUInt8 padding##count[bytes];
#else
#define SCE_PFX_PADDING(count,bytes)
#endif
#include "pfx_error_code.h"
#endif // _SCE_PFX_COMMON_H

View File

@@ -0,0 +1,30 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_ERROR_CODE_H
#define _SCE_PFX_ERROR_CODE_H
#define SCE_PFX_OK 0
#define SCE_PFX_ERR_INVALID_VALUE 0x80880001
#define SCE_PFX_ERR_INVALID_ALIGN 0x80880002
#define SCE_PFX_ERR_OUT_OF_BUFFER 0x80880003
#define SCE_PFX_ERR_OUT_OF_MAX_PAIRS 0x80880004
#define SCE_PFX_ERR_OUT_OF_RANGE 0x80880005
#define SCE_PFX_ERR_OUT_OF_WORLD 0x80880006
#define SCE_PFX_ERR_INVALID_FLAG 0x80880007
#endif // _SCE_PFX_ERROR_CODE_H

View File

@@ -0,0 +1,141 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_HEAP_MANAGER_H
#define _SCE_PFX_HEAP_MANAGER_H
#include "pfx_common.h"
//J プールされたメモリを管理するスタックのサイズ
//E Size of a stack which used to manage pool memory
#define SCE_PFX_HEAP_STACK_SIZE 64
#define SCE_PFX_MIN_ALLOC_SIZE 16
#define SCE_PFX_ALLOC_BYTES_ALIGN16(bytes) SCE_PFX_MAX(16,SCE_PFX_BYTES_ALIGN16(bytes))
#define SCE_PFX_ALLOC_BYTES_ALIGN128(bytes) SCE_PFX_MAX(128,SCE_PFX_BYTES_ALIGN128(bytes))
#if defined (_WIN64) || defined (__LP64__)
#define SCE_PFX_ALIGN_MASK_16 0xfffffffffffffff0
#define SCE_PFX_ALIGN_MASK_128 0xffffffffffffff80
#else
#define SCE_PFX_ALIGN_MASK_16 0xfffffff0
#define SCE_PFX_ALIGN_MASK_128 0xffffff80
#endif
///////////////////////////////////////////////////////////////////////////////
// PfxHeapManager
//J <補足>
//J メモリはスタックで管理されています。取得した順と逆に開放する必要があります。
//J メモリを一気に開放したい場合はclear()を呼び出してください。
//J 最小割り当てサイズはSCE_PFX_MIN_ALLOC_SIZEで定義されます。
//E <Notes>
//E Memory is managed as a stack, so deallocate() needs to be called in reverse order.
//E Use clear() to deallocate all allocated memory at once.
//E SCE_PFX_MIN_ALLOC_SIZE defines the smallest amount of buffer.
namespace sce {
namespace PhysicsEffects {
class PfxHeapManager
{
private:
PfxUInt8 *m_heap;
PfxUInt8 *m_poolStack[SCE_PFX_HEAP_STACK_SIZE];
PfxInt32 m_heapBytes;
PfxInt32 m_curStack;
PfxInt32 m_rest;
public:
enum {ALIGN16=16,ALIGN128=128};
PfxHeapManager(PfxUInt8 *buf,PfxInt32 bytes)
{
m_heap = buf;
m_heapBytes = bytes;
clear();
}
~PfxHeapManager()
{
}
PfxInt32 getAllocated()
{
return (PfxInt32)(m_poolStack[m_curStack]-m_heap);
}
PfxInt32 getRest()
{
return m_heapBytes-getAllocated();
}
void *allocate(size_t bytes,PfxInt32 alignment = ALIGN16)
{
SCE_PFX_ALWAYS_ASSERT(m_curStack<SCE_PFX_HEAP_STACK_SIZE);
bytes = SCE_PFX_MAX(bytes,SCE_PFX_MIN_ALLOC_SIZE);
uintptr_t p = (uintptr_t)m_poolStack[m_curStack];
if(alignment == ALIGN128) {
p = (p+127) & SCE_PFX_ALIGN_MASK_128;
bytes = (bytes+127) & SCE_PFX_ALIGN_MASK_128;
}
else {
p = (p+15) & SCE_PFX_ALIGN_MASK_16;
bytes = (bytes+15) & SCE_PFX_ALIGN_MASK_16;
}
SCE_PFX_ALWAYS_ASSERT_MSG(bytes <= (m_heapBytes-(p-(uintptr_t)m_heap)),"Memory overflow");
m_poolStack[++m_curStack] = (PfxUInt8 *)(p + bytes);
m_rest = getRest();
return (void*)p;
}
void deallocate(void *p)
{
#if 0
m_curStack--;
PfxInt32 addr = (PfxInt32)m_poolStack[m_curStack];
SCE_PFX_ALWAYS_ASSERT_MSG(addr == (PfxInt32)p || ((addr+127) & 0xffffff80) == (PfxInt32)p,"Stack overflow");
#else
(void) p;
m_curStack--;
#endif
}
void clear()
{
m_poolStack[0] = m_heap;
m_curStack = 0;
m_rest = 0;
}
void printStack()
{
SCE_PFX_PRINTF("memStack %d/%d\n",m_curStack,SCE_PFX_HEAP_STACK_SIZE);
}
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_HEAP_MANAGER_H

View File

@@ -0,0 +1,168 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_PERF_COUNTER_H
#define _SCE_PFX_PERF_COUNTER_H
#include "pfx_common.h"
// ARA begin insert new code
#ifndef _WIN32
#include <time.h>
#endif
// ARA end
//J パフォーマンス測定する場合はPFX_USE_PERFCOUNTERを定義
//J ブックマークを使用する場合はPFX_USE_BOOKMARKを定義
//E Define SCE_PFX_USE_PERFCOUNTER to check performance
//E Define SCE_PFX_USE_BOOKMARK to use bookmark
#define SCE_PFX_MAX_PERF_STR 32
#define SCE_PFX_MAX_PERF_COUNT 20
//#define SCE_PFX_USE_PERFCOUNTER
//#define SCE_PFX_USE_BOOKMARK
namespace sce {
namespace PhysicsEffects {
#ifdef SCE_PFX_USE_PERFCOUNTER
class PfxPerfCounter
{
private:
int m_count,m_strCount;
char m_str[SCE_PFX_MAX_PERF_COUNT][SCE_PFX_MAX_PERF_STR];
float m_freq;
SCE_PFX_PADDING(1,4)
#ifdef _WIN32
LONGLONG m_cnt[SCE_PFX_MAX_PERF_COUNT*2];
#else
// ARA begin insert new code
timespec m_cnt[SCE_PFX_MAX_PERF_COUNT*2];
// ARA end
#endif
void count(int i)
{
#ifdef _WIN32
QueryPerformanceCounter( (LARGE_INTEGER *)&m_cnt[i] );
#else
// ARA begin insert new code
clock_gettime(CLOCK_MONOTONIC, &m_cnt[i]);
// ARA end
#endif
}
public:
PfxPerfCounter()
{
#ifdef _WIN32
LARGE_INTEGER sPerfCountFreq;
QueryPerformanceFrequency(&sPerfCountFreq);
m_freq = (float)sPerfCountFreq.QuadPart;
#else
// ARA begin insert new code
m_freq = 1000000000.0f; // clock_gettime reports time in nanoseconds (though accuracy is platform dependent)
// ARA end
#endif
resetCount();
}
~PfxPerfCounter()
{
//printCount();
}
void countBegin(const char *name)
{
SCE_PFX_ASSERT(m_strCount < SCE_PFX_MAX_PERF_COUNT);
strncpy(m_str[m_strCount],name,SCE_PFX_MAX_PERF_STR-1);
m_str[m_strCount][SCE_PFX_MAX_PERF_STR-1] = 0x00;
m_strCount++;
count(m_count++);
}
void countEnd()
{
count(m_count++);
}
void resetCount()
{
m_strCount = 0;
m_count = 0;
}
float getCountTime(int i)
{
#if _WIN32
return (float)(m_cnt[i+1]-m_cnt[i]) / m_freq * 1000.0f;
#else
// ARA begin insert new code
return float(m_cnt[i+1].tv_sec - m_cnt[i].tv_sec) +
(float(m_cnt[i+1].tv_nsec - m_cnt[i].tv_nsec) / m_freq);
// ARA end
#endif
}
void printCount()
{
if(m_count%2 != 0) countEnd();
SCE_PFX_PRINTF("*** PfxPerfCounter results ***\n");
float total = 0.0f;
for(int i=0;i+1<m_count;i+=2) {
total += getCountTime(i);
}
for(int i=0;i+1<m_count;i+=2) {
SCE_PFX_PRINTF(" -- %s %fms(%.2f%%)\n",m_str[i>>1],getCountTime(i),getCountTime(i)/total*100.0f);
}
SCE_PFX_PRINTF(" -- Total %fms\n",total);
}
};
#else /* SCE_PFX_USE_PERFCOUNTER */
class PfxPerfCounter
{
public:
PfxPerfCounter() {}
~PfxPerfCounter() {}
void countBegin(const char *name) {(void) name;}
void countEnd() {}
void resetCount() {}
float getCountTime(int i) {(void)i;return 0.0f;}
void printCount() {}
};
#endif /* SCE_PFX_USE_PERFCOUNTER */
#define pfxInsertBookmark(bookmark)
#ifdef SCE_PFX_USE_BOOKMARK
#define SCE_PFX_PUSH_MARKER(name)
#define SCE_PFX_POP_MARKER()
#else
#define SCE_PFX_PUSH_MARKER(name)
#define SCE_PFX_POP_MARKER()
#endif
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_PERF_COUNTER_H

View File

@@ -0,0 +1,166 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_VEC_INT3_H
#define _SCE_PFX_VEC_INT3_H
#include "pfx_common.h"
namespace sce {
namespace PhysicsEffects {
class SCE_PFX_ALIGNED(16) PfxVecInt3
{
private:
PfxInt32 m_x,m_y,m_z,m_w;
public:
PfxVecInt3() {m_x=m_y=m_z=m_w=0;}
PfxVecInt3(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG vec) {m_x=(PfxInt32)vec[0];m_y=(PfxInt32)vec[1];m_z=(PfxInt32)vec[2];m_w=0;}
PfxVecInt3(PfxFloat fx,PfxFloat fy,PfxFloat fz) {m_x=(PfxInt32)fx;m_y=(PfxInt32)fy;m_z=(PfxInt32)fz;m_w=0;}
PfxVecInt3(PfxInt32 iv) {m_x=m_y=m_z=iv;m_w=0;}
PfxVecInt3(PfxInt32 ix,PfxInt32 iy,PfxInt32 iz) {m_x=ix;m_y=iy;m_z=iz;m_w=0;}
inline PfxVecInt3 &operator =( const PfxVecInt3 &vec);
inline PfxInt32 get(PfxInt32 i) const {return *(&m_x+i);}
inline PfxInt32 getX() const {return m_x;}
inline PfxInt32 getY() const {return m_y;}
inline PfxInt32 getZ() const {return m_z;}
inline void set(PfxInt32 i,PfxInt32 v) {*(&m_x+i) = v;}
inline void setX(PfxInt32 v) {m_x = v;}
inline void setY(PfxInt32 v) {m_y = v;}
inline void setZ(PfxInt32 v) {m_z = v;}
inline const PfxVecInt3 operator +( const PfxVecInt3 & vec ) const;
inline const PfxVecInt3 operator -( const PfxVecInt3 & vec ) const;
inline const PfxVecInt3 operator *( PfxInt32 scalar ) const;
inline const PfxVecInt3 operator /( PfxInt32 scalar ) const;
inline PfxVecInt3 & operator +=( const PfxVecInt3 & vec );
inline PfxVecInt3 & operator -=( const PfxVecInt3 & vec );
inline PfxVecInt3 & operator *=( PfxInt32 scalar );
inline PfxVecInt3 & operator /=( PfxInt32 scalar );
inline const PfxVecInt3 operator -() const;
operator PfxVector3() const
{
return PfxVector3((PfxFloat)m_x,(PfxFloat)m_y,(PfxFloat)m_z);
}
};
inline PfxVecInt3 &PfxVecInt3::operator =( const PfxVecInt3 &vec)
{
m_x = vec.m_x;
m_y = vec.m_y;
m_z = vec.m_z;
return *this;
}
inline const PfxVecInt3 PfxVecInt3::operator +( const PfxVecInt3 & vec ) const
{
return PfxVecInt3(m_x+vec.m_x, m_y+vec.m_y, m_z+vec.m_z);
}
inline const PfxVecInt3 PfxVecInt3::operator -( const PfxVecInt3 & vec ) const
{
return PfxVecInt3(m_x-vec.m_x, m_y-vec.m_y, m_z-vec.m_z);
}
inline const PfxVecInt3 PfxVecInt3::operator *( PfxInt32 scalar ) const
{
return PfxVecInt3(m_x*scalar, m_y*scalar, m_z*scalar);
}
inline const PfxVecInt3 PfxVecInt3::operator /( PfxInt32 scalar ) const
{
return PfxVecInt3(m_x/scalar, m_y/scalar, m_z/scalar);
}
inline PfxVecInt3 &PfxVecInt3::operator +=( const PfxVecInt3 & vec )
{
*this = *this + vec;
return *this;
}
inline PfxVecInt3 &PfxVecInt3::operator -=( const PfxVecInt3 & vec )
{
*this = *this - vec;
return *this;
}
inline PfxVecInt3 &PfxVecInt3::operator *=( PfxInt32 scalar )
{
*this = *this * scalar;
return *this;
}
inline PfxVecInt3 &PfxVecInt3::operator /=( PfxInt32 scalar )
{
*this = *this / scalar;
return *this;
}
inline const PfxVecInt3 PfxVecInt3::operator -() const
{
return PfxVecInt3(-m_x,-m_y,-m_z);
}
inline const PfxVecInt3 operator *( PfxInt32 scalar, const PfxVecInt3 & vec )
{
return vec * scalar;
}
inline const PfxVecInt3 mulPerElem( const PfxVecInt3 & vec0, const PfxVecInt3 & vec1 )
{
return PfxVecInt3(vec0.getX()*vec1.getX(), vec0.getY()*vec1.getY(), vec0.getZ()*vec1.getZ());
}
inline const PfxVecInt3 divPerElem( const PfxVecInt3 & vec0, const PfxVecInt3 & vec1 )
{
return PfxVecInt3(vec0.getX()/vec1.getX(), vec0.getY()/vec1.getY(), vec0.getZ()/vec1.getZ());
}
inline const PfxVecInt3 absPerElem( const PfxVecInt3 & vec )
{
return PfxVecInt3(abs(vec.getX()), abs(vec.getY()), abs(vec.getZ()));
}
inline const PfxVecInt3 maxPerElem( const PfxVecInt3 & vec0, const PfxVecInt3 & vec1 )
{
return PfxVecInt3(
(vec0.getX() > vec1.getX())? vec0.getX() : vec1.getX(),
(vec0.getY() > vec1.getY())? vec0.getY() : vec1.getY(),
(vec0.getZ() > vec1.getZ())? vec0.getZ() : vec1.getZ()
);
}
inline const PfxVecInt3 minPerElem( const PfxVecInt3 & vec0, const PfxVecInt3 & vec1 )
{
return PfxVecInt3(
(vec0.getX() < vec1.getX())? vec0.getX() : vec1.getX(),
(vec0.getY() < vec1.getY())? vec0.getY() : vec1.getY(),
(vec0.getZ() < vec1.getZ())? vec0.getZ() : vec1.getZ()
);
}
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_VEC_INT3_H

View File

@@ -0,0 +1,181 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_VEC_UTILS_H
#define _SCE_PFX_VEC_UTILS_H
#include "pfx_common.h"
#include "pfx_vec_int3.h"
namespace sce {
namespace PhysicsEffects {
static SCE_PFX_FORCE_INLINE PfxVector3 pfxReadVector3(const PfxFloat* fptr)
{
PfxVector3 v;
loadXYZ(v, fptr);
return v;
}
static SCE_PFX_FORCE_INLINE PfxPoint3 pfxReadPoint3(const PfxFloat* fptr)
{
PfxPoint3 v;
loadXYZ(v, fptr);
return v;
}
static SCE_PFX_FORCE_INLINE PfxQuat pfxReadQuat(const PfxFloat* fptr)
{
PfxQuat vq;
loadXYZW(vq, fptr);
return vq;
}
static SCE_PFX_FORCE_INLINE void pfxStoreVector3(const PfxVector3 &src, PfxFloat* fptr)
{
storeXYZ(src, fptr);
}
static SCE_PFX_FORCE_INLINE void pfxStorePoint3(const PfxPoint3 &src, PfxFloat* fptr)
{
storeXYZ(src, fptr);
}
static SCE_PFX_FORCE_INLINE void pfxStoreQuat(const PfxQuat &src, PfxFloat* fptr)
{
storeXYZW(src, fptr);
}
} // namespace PhysicsEffects
} // namespace sce
namespace sce {
namespace PhysicsEffects {
static SCE_PFX_FORCE_INLINE
void pfxGetPlaneSpace(const PfxVector3& n, PfxVector3& fptr, PfxVector3& q)
{
if(fabsf(n[2]) > 0.707f) {
// choose fptr in y-z plane
PfxFloat a = n[1]*n[1] + n[2]*n[2];
PfxFloat k = 1.0f/sqrtf(a);
fptr[0] = 0;
fptr[1] = -n[2]*k;
fptr[2] = n[1]*k;
// set q = n x fptr
q[0] = a*k;
q[1] = -n[0]*fptr[2];
q[2] = n[0]*fptr[1];
}
else {
// choose fptr in x-y plane
PfxFloat a = n[0]*n[0] + n[1]*n[1];
PfxFloat k = 1.0f/sqrtf(a);
fptr[0] = -n[1]*k;
fptr[1] = n[0]*k;
fptr[2] = 0;
// set q = n x fptr
q[0] = -n[2]*fptr[1];
q[1] = n[2]*fptr[0];
q[2] = a*k;
}
}
static SCE_PFX_FORCE_INLINE
void pfxGetRotationAngleAndAxis(const PfxQuat &unitQuat,PfxFloat &angle,PfxVector3 &axis)
{
const PfxFloat epsilon=0.00001f;
if(fabsf(unitQuat.getW()) < 1.0f-epsilon && lengthSqr(unitQuat.getXYZ()) > epsilon) {
PfxFloat angleHalf = acosf(unitQuat.getW());
PfxFloat sinAngleHalf = sinf(angleHalf);
if(fabsf(sinAngleHalf) > 1.0e-10f) {
axis = unitQuat.getXYZ()/sinAngleHalf;
} else {
axis = unitQuat.getXYZ();
}
angle = 2.0f*angleHalf;
} else {
angle = 0.0f;
axis = PfxVector3(1.0f, 0.0f, 0.0f);
}
}
static SCE_PFX_FORCE_INLINE
PfxFloat pfxSafeAtan2(PfxFloat y,PfxFloat x)
{
if(SCE_PFX_SQR(x) < 0.000001f || SCE_PFX_SQR(y) < 0.000001f) {
return 0.0f;
}
return atan2f(y,x);
}
static SCE_PFX_FORCE_INLINE
PfxVector3 pfxSafeNormalize(const PfxVector3 &vec)
{
float lenSqr = lengthSqr( vec );
if( lenSqr > 0.000001f ) {
return normalize(vec);
}else {
return PfxVector3( 1.0f, 0.0f, 0.0f );
}
}
static SCE_PFX_FORCE_INLINE
PfxVecInt3 pfxConvertCoordWorldToLocal(const PfxVector3 &coord,const PfxVector3 &center,const PfxVector3 &half)
{
const PfxVector3 sz(65535.0f);
PfxVector3 q = divPerElem(coord - center + half,2.0f*half);
q = minPerElem(maxPerElem(q,PfxVector3(0.0f)),PfxVector3(1.0f)); // clamp 0.0 - 1.0
q = mulPerElem(q,sz);
return PfxVecInt3(q);
}
static SCE_PFX_FORCE_INLINE
void pfxConvertCoordWorldToLocal(
const PfxVector3 &center,const PfxVector3 &half,
const PfxVector3 &coordMin,const PfxVector3 &coordMax,
PfxVecInt3 &localMin,PfxVecInt3 &localMax)
{
const PfxVector3 sz(65535.0f);
PfxVector3 qmin = divPerElem(coordMin - center + half,2.0f*half);
qmin = minPerElem(maxPerElem(qmin,PfxVector3(0.0f)),PfxVector3(1.0f)); // clamp 0.0 - 1.0
qmin = mulPerElem(qmin,sz);
PfxVector3 qmax = divPerElem(coordMax - center + half,2.0f*half);
qmax = minPerElem(maxPerElem(qmax,PfxVector3(0.0f)),PfxVector3(1.0f)); // clamp 0.0 - 1.0
qmax = mulPerElem(qmax,sz);
localMin = PfxVecInt3(floorf(qmin[0]),floorf(qmin[1]),floorf(qmin[2]));
localMax = PfxVecInt3(ceilf(qmax[0]),ceilf(qmax[1]),ceilf(qmax[2]));
}
static SCE_PFX_FORCE_INLINE
PfxVector3 pfxConvertCoordLocalToWorld(const PfxVecInt3 &coord,const PfxVector3 &center,const PfxVector3 &half)
{
PfxVector3 sz(65535.0f),vcoord(coord);
PfxVector3 q = divPerElem(vcoord,sz);
return mulPerElem(q,2.0f*half) + center - half;
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_VEC_UTILS_H

View File

@@ -0,0 +1,101 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_VECTORMATH_INCLUDE_H
#define _SCE_PFX_VECTORMATH_INCLUDE_H
// If you want to use the free/open sourced vectormath, you need to
// put codes in the include/vecmath folder and set following define.
#define SCE_PFX_USE_FREE_VECTORMATH
// If you want to use vectomath with SIMD,
// following define is needed.
//#define SCE_PFX_USE_SIMD_VECTORMATH
// This option enables to replace original implementation with
// vector geometry library.
//#define SCE_PFX_USE_GEOMETRY
// vectormath include
#ifdef SCE_PFX_USE_FREE_VECTORMATH
// ARA begin insert new code
#if defined(SCE_PFX_USE_SIMD_VECTORMATH) && defined(__ANDROID__) && defined(__ARM_NEON__)
// For Android targets supporting NEON instructions,
// use NEON-optimized vector math library
#include "../../../vecmath/neon/vectormath_aos.h"
#include "../../../vecmath/neon/floatInVec.h"
#else
// ARA end
// use standard free vector math library
#include "../../../vecmath/std/vectormath_aos.h"
#include "../../../vecmath/std/floatInVec.h"
// ARA begin insert new code
#endif
// ARA end
#define SCE_VECTORMATH_AOS_VECTOR_ARG
#define SCE_VECTORMATH_AOS_MATRIX_ARG
namespace sce {
namespace PhysicsEffects {
typedef Vectormath::Aos::Point3 PfxPoint3;
typedef Vectormath::Aos::Vector3 PfxVector3;
typedef Vectormath::Aos::Vector4 PfxVector4;
typedef Vectormath::Aos::Quat PfxQuat;
typedef Vectormath::Aos::Matrix3 PfxMatrix3;
typedef Vectormath::Aos::Matrix4 PfxMatrix4;
typedef Vectormath::Aos::Transform3 PfxTransform3;
typedef Vectormath::floatInVec PfxFloatInVec;
typedef Vectormath::boolInVec PfxBoolInVec;
} //namespace PhysicsEffects
} //namespace sce
#else
#include <vectormath.h>
#define SCE_GEOMETRY_USE_SCALAR_MATH
#define SCE_VECTORMATH_AOS_VECTOR_ARG SCE_VECTORMATH_SCALAR_AOS_VECTOR_ARG
#define SCE_VECTORMATH_AOS_MATRIX_ARG SCE_VECTORMATH_SCALAR_AOS_MATRIX_ARG
namespace sce {
namespace PhysicsEffects {
typedef sce::Vectormath::Scalar::Aos::Point3 PfxPoint3;
typedef sce::Vectormath::Scalar::Aos::Vector3 PfxVector3;
typedef sce::Vectormath::Scalar::Aos::Vector4 PfxVector4;
typedef sce::Vectormath::Scalar::Aos::Quat PfxQuat;
typedef sce::Vectormath::Scalar::Aos::Matrix3 PfxMatrix3;
typedef sce::Vectormath::Scalar::Aos::Matrix4 PfxMatrix4;
typedef sce::Vectormath::Scalar::Aos::Transform3 PfxTransform3;
typedef sce::Vectormath::Scalar::floatInVec PfxFloatInVec;
typedef sce::Vectormath::Scalar::boolInVec PfxBoolInVec;
} //namespace PhysicsEffects
} //namespace sce
#ifdef SCE_PFX_USE_GEOMETRY
#include <sce_geometry.h>
namespace sce {
namespace PhysicsEffects {
typedef sce::Geometry::Aos::Line PfxGeomLine;
typedef sce::Geometry::Aos::Segment PfxGeomSegment;
typedef sce::Geometry::Aos::Plane PfxGeomPlane;
typedef sce::Geometry::Aos::Sphere PfxGeomSphere;
typedef sce::Geometry::Aos::Capsule PfxGeomCapsule;
typedef sce::Geometry::Aos::Bounds PfxGeomBounds;
typedef sce::Geometry::Aos::Aabb PfxGeomAabb;
typedef sce::Geometry::Aos::Obb PfxGeomObb;
} //namespace PhysicsEffects
} //namespace sce
#endif
#endif
#endif // _SCE_PFX_VECTORMATH_INCLUDE_H

View File

@@ -0,0 +1,116 @@
/*
Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.
All rights reserved.
Physics Effects is open software; you can redistribute it and/or
modify it under the terms of the BSD License.
Physics Effects is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the BSD License for more details.
A copy of the BSD License is distributed with
Physics Effects under the filename: physics_effects_license.txt
*/
#ifndef _SCE_PFX_VECTORMATH_INCLUDE_WIN32_H
#define _SCE_PFX_VECTORMATH_INCLUDE_WIN32_H
// If you want to use the free/open sourced vectormath, you need to
// put codes in the include/vecmath folder and set following define.
#define SCE_PFX_USE_FREE_VECTORMATH
// If you want to use vectomath with SIMD,
// following define is needed.
// #define SCE_PFX_USE_SIMD_VECTORMATH
// This option enables to replace original implementation with
// vector geometry library.
//#define SCE_PFX_USE_GEOMETRY
// vectormath include
#ifdef SCE_PFX_USE_FREE_VECTORMATH
#ifdef SCE_PFX_USE_SIMD_VECTORMATH
#include "../../../vecmath/sse/vectormath_aos.h"
#include "../../../vecmath/sse/floatInVec.h"
#define SCE_VECTORMATH_AOS_VECTOR_ARG &
#define SCE_VECTORMATH_AOS_MATRIX_ARG &
#else
#include "../../../vecmath/std/vectormath_aos.h"
#include "../../../vecmath/std/floatInVec.h"
#define SCE_VECTORMATH_AOS_VECTOR_ARG
#define SCE_VECTORMATH_AOS_MATRIX_ARG
#endif
namespace sce {
namespace PhysicsEffects {
typedef Vectormath::Aos::Point3 PfxPoint3;
typedef Vectormath::Aos::Vector3 PfxVector3;
typedef Vectormath::Aos::Vector4 PfxVector4;
typedef Vectormath::Aos::Quat PfxQuat;
typedef Vectormath::Aos::Matrix3 PfxMatrix3;
typedef Vectormath::Aos::Matrix4 PfxMatrix4;
typedef Vectormath::Aos::Transform3 PfxTransform3;
typedef Vectormath::floatInVec PfxFloatInVec;
typedef Vectormath::boolInVec PfxBoolInVec;
} //namespace PhysicsEffects
} //namespace sce
#else
#include <vectormath.h>
#ifdef SCE_PFX_USE_SIMD_VECTORMATH
#define SCE_VECTORMATH_AOS_VECTOR_ARG SCE_VECTORMATH_SIMD_AOS_VECTOR_ARG
#define SCE_VECTORMATH_AOS_MATRIX_ARG SCE_VECTORMATH_SIMD_AOS_MATRIX_ARG
namespace sce {
namespace PhysicsEffects {
typedef sce::Vectormath::Simd::Aos::Point3 PfxPoint3;
typedef sce::Vectormath::Simd::Aos::Vector3 PfxVector3;
typedef sce::Vectormath::Simd::Aos::Vector4 PfxVector4;
typedef sce::Vectormath::Simd::Aos::Quat PfxQuat;
typedef sce::Vectormath::Simd::Aos::Matrix3 PfxMatrix3;
typedef sce::Vectormath::Simd::Aos::Matrix4 PfxMatrix4;
typedef sce::Vectormath::Simd::Aos::Transform3 PfxTransform3;
typedef sce::Vectormath::Simd::floatInVec PfxFloatInVec;
typedef sce::Vectormath::Simd::boolInVec PfxBoolInVec;
} //namespace PhysicsEffects
} //namespace sce
#else
#define SCE_GEOMETRY_USE_SCALAR_MATH
#define SCE_VECTORMATH_AOS_VECTOR_ARG SCE_VECTORMATH_SCALAR_AOS_VECTOR_ARG
#define SCE_VECTORMATH_AOS_MATRIX_ARG SCE_VECTORMATH_SCALAR_AOS_MATRIX_ARG
namespace sce {
namespace PhysicsEffects {
typedef sce::Vectormath::Scalar::Aos::Point3 PfxPoint3;
typedef sce::Vectormath::Scalar::Aos::Vector3 PfxVector3;
typedef sce::Vectormath::Scalar::Aos::Vector4 PfxVector4;
typedef sce::Vectormath::Scalar::Aos::Quat PfxQuat;
typedef sce::Vectormath::Scalar::Aos::Matrix3 PfxMatrix3;
typedef sce::Vectormath::Scalar::Aos::Matrix4 PfxMatrix4;
typedef sce::Vectormath::Scalar::Aos::Transform3 PfxTransform3;
typedef sce::Vectormath::Scalar::floatInVec PfxFloatInVec;
typedef sce::Vectormath::Scalar::boolInVec PfxBoolInVec;
} //namespace PhysicsEffects
} //namespace sce
#endif
#endif
#ifdef SCE_PFX_USE_GEOMETRY
#include <sce_geometry.h>
namespace sce {
namespace PhysicsEffects {
typedef sce::Geometry::Aos::Line PfxGeomLine;
typedef sce::Geometry::Aos::Segment PfxGeomSegment;
typedef sce::Geometry::Aos::Plane PfxGeomPlane;
typedef sce::Geometry::Aos::Sphere PfxGeomSphere;
typedef sce::Geometry::Aos::Capsule PfxGeomCapsule;
typedef sce::Geometry::Aos::Bounds PfxGeomBounds;
typedef sce::Geometry::Aos::Aabb PfxGeomAabb;
typedef sce::Geometry::Aos::Obb PfxGeomObb;
} //namespace PhysicsEffects
} //namespace sce
#endif
#endif // _SCE_PFX_VECTORMATH_INCLUDE_WIN32_H