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

View File

@@ -0,0 +1,46 @@
/*
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_BROADPHASE_PAIR_H
#define _SCE_PFX_BROADPHASE_PAIR_H
#include "../sort/pfx_sort_data.h"
namespace sce {
namespace PhysicsEffects {
typedef PfxSortData16 PfxBroadphasePair;
SCE_PFX_FORCE_INLINE void pfxSetObjectIdA(PfxBroadphasePair &pair,PfxUInt16 i) {pair.set16(0,i);}
SCE_PFX_FORCE_INLINE void pfxSetObjectIdB(PfxBroadphasePair &pair,PfxUInt16 i) {pair.set16(1,i);}
SCE_PFX_FORCE_INLINE void pfxSetMotionMaskA(PfxBroadphasePair &pair,PfxUInt8 i) {pair.set8(4,i);}
SCE_PFX_FORCE_INLINE void pfxSetMotionMaskB(PfxBroadphasePair &pair,PfxUInt8 i) {pair.set8(5,i);}
SCE_PFX_FORCE_INLINE void pfxSetBroadphaseFlag(PfxBroadphasePair &pair,PfxUInt8 f) {pair.set8(6,(pair.get8(6)&0xf0)|(f&0x0f));}
SCE_PFX_FORCE_INLINE void pfxSetActive(PfxBroadphasePair &pair,PfxBool b) {pair.set8(6,(pair.get8(6)&0x0f)|((b?1:0)<<4));}
SCE_PFX_FORCE_INLINE void pfxSetContactId(PfxBroadphasePair &pair,PfxUInt32 i) {pair.set32(2,i);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetObjectIdA(const PfxBroadphasePair &pair) {return pair.get16(0);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetObjectIdB(const PfxBroadphasePair &pair) {return pair.get16(1);}
SCE_PFX_FORCE_INLINE PfxUInt8 pfxGetMotionMaskA(const PfxBroadphasePair &pair) {return pair.get8(4);}
SCE_PFX_FORCE_INLINE PfxUInt8 pfxGetMotionMaskB(const PfxBroadphasePair &pair) {return pair.get8(5);}
SCE_PFX_FORCE_INLINE PfxUInt8 pfxGetBroadphaseFlag(const PfxBroadphasePair &pair) {return pair.get8(6)&0x0f;}
SCE_PFX_FORCE_INLINE PfxBool pfxGetActive(const PfxBroadphasePair &pair) {return (pair.get8(6)>>4)!=0;}
SCE_PFX_FORCE_INLINE PfxUInt32 pfxGetContactId(const PfxBroadphasePair &pair) {return pair.get32(2);}
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_BROADPHASE_PAIR_H

View File

@@ -0,0 +1,42 @@
/*
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_BROADPHASE_PROXY_H
#define _SCE_PFX_BROADPHASE_PROXY_H
namespace sce {
namespace PhysicsEffects {
typedef PfxSortData32 PfxBroadphaseProxy;
//J AABBパラメータはPfxAabbと共通
//E PfxBroadphaseProxy shares AABB parameters with PfxAabb32
SCE_PFX_FORCE_INLINE void pfxSetObjectId(PfxBroadphaseProxy &proxy,PfxUInt16 i) {proxy.set16(6,i);}
SCE_PFX_FORCE_INLINE void pfxSetMotionMask(PfxBroadphaseProxy &proxy,PfxUInt8 i) {proxy.set8(14,i);}
SCE_PFX_FORCE_INLINE void pfxSetProxyFlag(PfxBroadphaseProxy &proxy,PfxUInt8 i) {proxy.set8(15,i);}
SCE_PFX_FORCE_INLINE void pfxSetSelf(PfxBroadphaseProxy &proxy,PfxUInt32 i) {proxy.set32(5,i);}
SCE_PFX_FORCE_INLINE void pfxSetTarget(PfxBroadphaseProxy &proxy,PfxUInt32 i) {proxy.set32(6,i);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetObjectId(const PfxBroadphaseProxy &proxy) {return proxy.get16(6);}
SCE_PFX_FORCE_INLINE PfxUInt8 pfxGetMotionMask(const PfxBroadphaseProxy &proxy) {return proxy.get8(14);}
SCE_PFX_FORCE_INLINE PfxUInt8 pfxGetProxyFlag(const PfxBroadphaseProxy &proxy) {return proxy.get8(15);}
SCE_PFX_FORCE_INLINE PfxUInt32 pfxGetSelf(const PfxBroadphaseProxy &proxy) {return proxy.get32(5);}
SCE_PFX_FORCE_INLINE PfxUInt32 pfxGetTarget(const PfxBroadphaseProxy &proxy) {return proxy.get32(6);}
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_BROADPHASE_PROXY_H

View File

@@ -0,0 +1,80 @@
/*
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_UPDATE_BROADPHASE_PROXY_H
#define _SCE_PFX_UPDATE_BROADPHASE_PROXY_H
#include "pfx_broadphase_pair.h"
#include "pfx_broadphase_proxy.h"
#include "../rigidbody/pfx_rigid_state.h"
#include "../collision/pfx_collidable.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Update Broadphase Proxy
//E For single axis
//J 単一軸に対して作成
PfxInt32 pfxUpdateBroadphaseProxy(
PfxBroadphaseProxy &proxy,
const PfxRigidState &state,
const PfxCollidable &coll,
const PfxVector3 &worldCenter,
const PfxVector3 &worldExtent,
PfxUInt32 axis);
PfxInt32 pfxUpdateBroadphaseProxy(
PfxBroadphaseProxy &proxy,
const PfxRigidState &state,
const PfxVector3 &objectCenter,
const PfxVector3 &objectHalf,
const PfxVector3 &worldCenter,
const PfxVector3 &worldExtent,
PfxUInt32 axis);
//E For all axes
//J 全軸に対して作成
PfxInt32 pfxUpdateBroadphaseProxy(
PfxBroadphaseProxy &proxyX,
PfxBroadphaseProxy &proxyY,
PfxBroadphaseProxy &proxyZ,
PfxBroadphaseProxy &proxyXb,
PfxBroadphaseProxy &proxyYb,
PfxBroadphaseProxy &proxyZb,
const PfxRigidState &state,
const PfxCollidable &coll,
const PfxVector3 &worldCenter,
const PfxVector3 &worldExtent);
PfxInt32 pfxUpdateBroadphaseProxy(
PfxBroadphaseProxy &proxyX,
PfxBroadphaseProxy &proxyY,
PfxBroadphaseProxy &proxyZ,
PfxBroadphaseProxy &proxyXb,
PfxBroadphaseProxy &proxyYb,
PfxBroadphaseProxy &proxyZb,
const PfxRigidState &state,
const PfxVector3 &objectCenter,
const PfxVector3 &objectHalf,
const PfxVector3 &worldCenter,
const PfxVector3 &worldExtent);
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_UPDATE_BROADPHASE_PROXY_H

View File

@@ -0,0 +1,124 @@
/*
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_AABB_H
#define _SCE_PFX_AABB_H
#include "../sort/pfx_sort_data.h"
namespace sce {
namespace PhysicsEffects {
typedef PfxSortData16 PfxAabb16;
typedef PfxSortData32 PfxAabb32;
SCE_PFX_FORCE_INLINE void pfxSetXMin(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(0,i);}
SCE_PFX_FORCE_INLINE void pfxSetXMax(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(1,i);}
SCE_PFX_FORCE_INLINE void pfxSetYMin(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(2,i);}
SCE_PFX_FORCE_INLINE void pfxSetYMax(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(3,i);}
SCE_PFX_FORCE_INLINE void pfxSetZMin(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(4,i);}
SCE_PFX_FORCE_INLINE void pfxSetZMax(PfxAabb16& aabb,PfxUInt16 i) {aabb.set16(5,i);}
SCE_PFX_FORCE_INLINE void pfxSetXYZMin(PfxAabb16 &aabb,PfxUInt16 i,int axis) {aabb.set16(axis<<1,i);}
SCE_PFX_FORCE_INLINE void pfxSetXYZMax(PfxAabb16 &aabb,PfxUInt16 i,int axis) {aabb.set16((axis<<1)+1,i);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMin(const PfxAabb16& aabb) {return aabb.get16(0);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMax(const PfxAabb16& aabb) {return aabb.get16(1);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMin(const PfxAabb16& aabb) {return aabb.get16(2);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMax(const PfxAabb16& aabb) {return aabb.get16(3);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMin(const PfxAabb16& aabb) {return aabb.get16(4);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMax(const PfxAabb16& aabb) {return aabb.get16(5);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMin(const PfxAabb16 &aabb,int axis) {return aabb.get16(axis<<1);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMax(const PfxAabb16 &aabb,int axis) {return aabb.get16((axis<<1)+1);}
SCE_PFX_FORCE_INLINE void pfxSetXMin(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(0,i);}
SCE_PFX_FORCE_INLINE void pfxSetXMax(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(1,i);}
SCE_PFX_FORCE_INLINE void pfxSetYMin(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(2,i);}
SCE_PFX_FORCE_INLINE void pfxSetYMax(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(3,i);}
SCE_PFX_FORCE_INLINE void pfxSetZMin(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(4,i);}
SCE_PFX_FORCE_INLINE void pfxSetZMax(PfxAabb32& aabb,PfxUInt16 i) {aabb.set16(5,i);}
SCE_PFX_FORCE_INLINE void pfxSetXYZMin(PfxAabb32 &aabb,PfxUInt16 i,int axis) {aabb.set16(axis<<1,i);}
SCE_PFX_FORCE_INLINE void pfxSetXYZMax(PfxAabb32 &aabb,PfxUInt16 i,int axis) {aabb.set16((axis<<1)+1,i);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMin(const PfxAabb32& aabb) {return aabb.get16(0);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXMax(const PfxAabb32& aabb) {return aabb.get16(1);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMin(const PfxAabb32& aabb) {return aabb.get16(2);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetYMax(const PfxAabb32& aabb) {return aabb.get16(3);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMin(const PfxAabb32& aabb) {return aabb.get16(4);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetZMax(const PfxAabb32& aabb) {return aabb.get16(5);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMin(const PfxAabb32 &aabb,int axis) {return aabb.get16(axis<<1);}
SCE_PFX_FORCE_INLINE PfxUInt16 pfxGetXYZMax(const PfxAabb32 &aabb,int axis) {return aabb.get16((axis<<1)+1);}
#define SCE_PFX_TEST_AABB(aabbA,aabbB) \
if(pfxGetXMax(aabbA) < pfxGetXMin(aabbB) || pfxGetXMin(aabbA) > pfxGetXMax(aabbB)) return false;\
if(pfxGetYMax(aabbA) < pfxGetYMin(aabbB) || pfxGetYMin(aabbA) > pfxGetYMax(aabbB)) return false;\
if(pfxGetZMax(aabbA) < pfxGetZMin(aabbB) || pfxGetZMin(aabbA) > pfxGetZMax(aabbB)) return false;\
return true;
SCE_PFX_FORCE_INLINE
bool pfxTestAabb(const PfxAabb16 &aabbA,const PfxAabb16 &aabbB)
{
SCE_PFX_TEST_AABB(aabbA,aabbB)
}
SCE_PFX_FORCE_INLINE
bool pfxTestAabb(const PfxAabb32 &aabbA,const PfxAabb32 &aabbB)
{
SCE_PFX_TEST_AABB(aabbA,aabbB)
}
SCE_PFX_FORCE_INLINE
bool pfxTestAabb(const PfxAabb32 &aabbA,const PfxAabb16 &aabbB)
{
SCE_PFX_TEST_AABB(aabbA,aabbB)
}
SCE_PFX_FORCE_INLINE
bool pfxTestAabb(const PfxAabb16 &aabbA,const PfxAabb32 &aabbB)
{
SCE_PFX_TEST_AABB(aabbA,aabbB)
}
SCE_PFX_FORCE_INLINE
PfxAabb16 pfxMergeAabb(const PfxAabb16 &aabbA,const PfxAabb16 &aabbB)
{
PfxAabb16 aabb = aabbA;
pfxSetXMin(aabb,SCE_PFX_MIN(pfxGetXMin(aabbA),pfxGetXMin(aabbB)));
pfxSetXMax(aabb,SCE_PFX_MAX(pfxGetXMax(aabbA),pfxGetXMax(aabbB)));
pfxSetYMin(aabb,SCE_PFX_MIN(pfxGetYMin(aabbA),pfxGetYMin(aabbB)));
pfxSetYMax(aabb,SCE_PFX_MAX(pfxGetYMax(aabbA),pfxGetYMax(aabbB)));
pfxSetZMin(aabb,SCE_PFX_MIN(pfxGetZMin(aabbA),pfxGetZMin(aabbB)));
pfxSetZMax(aabb,SCE_PFX_MAX(pfxGetZMax(aabbA),pfxGetZMax(aabbB)));
return aabb;
}
SCE_PFX_FORCE_INLINE
PfxAabb32 pfxMergeAabb(const PfxAabb32 &aabbA,const PfxAabb32 &aabbB)
{
PfxAabb32 aabb = aabbA;
pfxSetXMin(aabb,SCE_PFX_MIN(pfxGetXMin(aabbA),pfxGetXMin(aabbB)));
pfxSetXMax(aabb,SCE_PFX_MAX(pfxGetXMax(aabbA),pfxGetXMax(aabbB)));
pfxSetYMin(aabb,SCE_PFX_MIN(pfxGetYMin(aabbA),pfxGetYMin(aabbB)));
pfxSetYMax(aabb,SCE_PFX_MAX(pfxGetYMax(aabbA),pfxGetYMax(aabbB)));
pfxSetZMin(aabb,SCE_PFX_MIN(pfxGetZMin(aabbA),pfxGetZMin(aabbB)));
pfxSetZMax(aabb,SCE_PFX_MAX(pfxGetZMax(aabbA),pfxGetZMax(aabbB)));
return aabb;
}
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_AABB_H

View File

@@ -0,0 +1,61 @@
/*
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_BOX_H
#define _SCE_PFX_BOX_H
#include "../base/pfx_common.h"
namespace sce{
namespace PhysicsEffects{
struct PfxBox {
PfxVector3 m_half;
inline PfxBox() {}
inline PfxBox(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half);
inline PfxBox(PfxFloat hx, PfxFloat hy, PfxFloat hz);
inline void set(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half);
inline void set(PfxFloat hx, PfxFloat hy, PfxFloat hz);
};
inline
PfxBox::PfxBox(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half)
{
set(half);
}
inline
PfxBox::PfxBox(PfxFloat hx, PfxFloat hy, PfxFloat hz)
{
set(hx, hy, hz);
}
inline
void PfxBox::set(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG half)
{
m_half = half;
}
inline
void PfxBox::set(PfxFloat hx, PfxFloat hy, PfxFloat hz)
{
m_half = PfxVector3(hx, hy, hz);
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_BOX_H

View File

@@ -0,0 +1,53 @@
/*
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_CAPSULE_H
#define _SCE_PFX_CAPSULE_H
#include "../base/pfx_common.h"
namespace sce {
namespace PhysicsEffects {
struct PfxCapsule
{
PfxFloat m_halfLen;
PfxFloat m_radius;
PfxCapsule() {}
PfxCapsule(PfxFloat halfLength, PfxFloat radius);
void set(PfxFloat halfLength, PfxFloat radius);
};
inline
PfxCapsule::PfxCapsule(PfxFloat halfLength, PfxFloat radius)
{
m_halfLen = halfLength;
m_radius = radius;
}
inline
void PfxCapsule::set(PfxFloat halfLength, PfxFloat radius)
{
m_halfLen = halfLength;
m_radius = radius;
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_CAPSULE_H

View File

@@ -0,0 +1,74 @@
/*
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_COLLIDABLE_H
#define _SCE_PFX_COLLIDABLE_H
#include "pfx_shape.h"
namespace sce {
namespace PhysicsEffects {
#define SCE_PFX_NUMPRIMS 64
///////////////////////////////////////////////////////////////////////////////
// Collidable Object
class SCE_PFX_ALIGNED(128) PfxCollidable
{
friend class PfxShapeIterator;
private:
PfxShape *m_shapeBase;
PfxUInt16 m_shapeIds[SCE_PFX_NUMPRIMS];
PfxUInt8 m_numShapes;
PfxUInt8 m_maxShapes;
SCE_PFX_PADDING(1,2)
PfxFloat m_center[3]; // AABB center (Local)
PfxFloat m_half[3]; // AABB half (Local)
PfxShape m_defShape;
SCE_PFX_PADDING(2,32)
inline PfxShape &getNewShape();
public:
inline void reset();
inline void reset(PfxShape *base,PfxUInt16 *ids,int n=1);
void finish();
void addShape(const PfxShape &shape);
inline PfxUInt32 getNumShapes() const;
const PfxShape& getDefShape() const {return m_defShape;}
PfxShape& getDefShape() {return m_defShape;}
inline PfxUInt16 getShapeId(int i) const;
inline const PfxShape& getShape(int i) const;
inline PfxShape& getShape(int i);
inline PfxVector3 getHalf() const;
inline PfxVector3 getCenter() const;
};
#include "pfx_collidable_implementation.h"
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_COLLIDABLE_H

View File

@@ -0,0 +1,114 @@
/*
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_COLLIDABLE_IMPLEMENTATION_H
#define _SCE_PFX_COLLIDABLE_IMPLEMENTATION_H
inline
void PfxCollidable::reset()
{
m_shapeBase = NULL;
m_numShapes = 0;
m_maxShapes = 1;
m_center[0] = 0.0f;
m_center[1] = 0.0f;
m_center[2] = 0.0f;
m_half[0] = 0.0f;
m_half[1] = 0.0f;
m_half[2] = 0.0f;
}
inline
void PfxCollidable::reset(PfxShape *base,PfxUInt16 *ids,int n)
{
m_shapeBase = base;
m_numShapes = 0;
m_maxShapes = n;
for(int i=0;i<n;i++) {
m_shapeIds[i] = ids[i];
}
m_center[0] = 0.0f;
m_center[1] = 0.0f;
m_center[2] = 0.0f;
m_half[0] = 0.0f;
m_half[1] = 0.0f;
m_half[2] = 0.0f;
}
inline
PfxUInt32 PfxCollidable::getNumShapes() const
{
return m_numShapes;
}
inline
PfxUInt16 PfxCollidable::getShapeId(int i) const
{
SCE_PFX_ASSERT(i>0);
return m_shapeIds[i-1];
}
inline
const PfxShape& PfxCollidable::getShape(int i) const
{
SCE_PFX_ASSERT(i<m_numShapes);
if(i>0) {
return m_shapeBase[m_shapeIds[i-1]];
}
else {
return m_defShape;
}
}
inline
PfxShape& PfxCollidable::getShape(int i)
{
SCE_PFX_ASSERT(i<m_numShapes);
if(i>0) {
return m_shapeBase[m_shapeIds[i-1]];
}
else {
return m_defShape;
}
}
inline
PfxShape &PfxCollidable::getNewShape()
{
SCE_PFX_ASSERT(m_numShapes<=m_maxShapes);
if(m_numShapes == 0) {
m_numShapes++;
return m_defShape;
}
else {
m_numShapes++;
return m_shapeBase[m_shapeIds[m_numShapes-2]];
}
}
inline
PfxVector3 PfxCollidable::getHalf() const
{
return pfxReadVector3(m_half);
}
inline
PfxVector3 PfxCollidable::getCenter() const
{
return pfxReadVector3(m_center);
}
#endif // _SCE_PFX_COLLIDABLE_IMPLEMENTATION_H

View File

@@ -0,0 +1,135 @@
/*
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_CONTACT_MANIFOLD_H
#define _SCE_PFX_CONTACT_MANIFOLD_H
#include "../base/pfx_common.h"
#include "../base/pfx_vec_utils.h"
#include "pfx_sub_data.h"
#include "../solver/pfx_constraint_row.h"
namespace sce {
namespace PhysicsEffects {
#define SCE_PFX_NUMCONTACTS_PER_BODIES 4
///////////////////////////////////////////////////////////////////////////////
// Contact Point
struct PfxContactPoint
{
PfxUInt8 m_duration;
PfxUInt8 m_shapeIdA;
PfxUInt8 m_shapeIdB;
SCE_PFX_PADDING(1,1)
PfxSubData m_subData;
PfxFloat m_distance;
PfxFloat m_localPointA[3];
PfxFloat m_localPointB[3];
SCE_PFX_PADDING(2,8)
PfxConstraintRow m_constraintRow[3];
void reset()
{
m_duration = 0;
m_shapeIdA = m_shapeIdB = 0;
m_subData = PfxSubData();
m_distance = SCE_PFX_FLT_MAX;
m_constraintRow[0].m_accumImpulse = 0.0f;
m_constraintRow[1].m_accumImpulse = 0.0f;
m_constraintRow[2].m_accumImpulse = 0.0f;
}
};
///////////////////////////////////////////////////////////////////////////////
// Contact Manifold
//J 同一ペアの衝突が続く限り保持されるコンタクト情報
//E PfxContactManifold keeps contact information until two rigid bodies are separated.
class SCE_PFX_ALIGNED(128) PfxContactManifold
{
private:
PfxUInt16 m_rigidBodyIdA,m_rigidBodyIdB;
PfxUInt16 m_duration;
PfxUInt16 m_numContacts;
PfxFloat m_compositeFriction;
PfxUInt32 m_internalFlag;
PfxContactPoint m_contactPoints[SCE_PFX_NUMCONTACTS_PER_BODIES];
void *m_userData;
PfxUInt32 m_userParam[4];
SCE_PFX_PADDING(1,28)
int findNearestContactPoint(const PfxPoint3 &newPoint,const PfxVector3 &newNormal);
int sort4ContactPoints(const PfxPoint3 &newPoint,PfxFloat newDistance);
public:
// Internal method
PfxFloat getCompositeFriction() const {return m_compositeFriction;}
void setCompositeFriction(PfxFloat f) {m_compositeFriction = f;}
PfxUInt32 getInternalFlag() const {return m_internalFlag;}
void setInternalFlag(PfxUInt32 f) {m_internalFlag = f;}
public:
void reset(PfxUInt16 rigidBodyIdA,PfxUInt16 rigidBodyIdB)
{
m_userData = 0;
m_userParam[0] = m_userParam[1] = m_userParam[2] = m_userParam[3] = 0;
m_numContacts = 0;
m_duration = 0;
m_rigidBodyIdA = rigidBodyIdA;
m_rigidBodyIdB = rigidBodyIdB;
}
void addContactPoint(
PfxFloat newDistance,
const PfxVector3 &newNormal, // world coords
const PfxPoint3 &newPointA, // local coords to the objectA
const PfxPoint3 &newPointB, // local coords to the objectB
PfxSubData subData);
void addContactPoint(const PfxContactPoint &cp);
void removeContactPoint(int i)
{
SCE_PFX_ASSERT(i>=0&&i<m_numContacts);
m_contactPoints[i] = m_contactPoints[m_numContacts-1];
m_numContacts--;
}
int getNumContacts() const {return (int)m_numContacts;}
PfxContactPoint &getContactPoint(int i) {return m_contactPoints[i];}
const PfxContactPoint &getContactPoint(int i) const {return m_contactPoints[i];}
void refresh(const PfxVector3 &pA,const PfxQuat &qA,const PfxVector3 &pB,const PfxQuat &qB);
void merge(const PfxContactManifold &contact);
PfxUInt16 getDuration() const {return m_duration;}
PfxUInt16 getRigidBodyIdA() const {return m_rigidBodyIdA;}
PfxUInt16 getRigidBodyIdB() const {return m_rigidBodyIdB;}
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_CONTACT_MANIFOLD_H

View File

@@ -0,0 +1,53 @@
/*
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_CYLINDER_H
#define _SCE_PFX_CYLINDER_H
#include "../base/pfx_common.h"
namespace sce {
namespace PhysicsEffects {
struct PfxCylinder
{
PfxFloat m_halfLen;
PfxFloat m_radius;
PfxCylinder() {}
PfxCylinder(PfxFloat halfLength, PfxFloat radius);
void set(PfxFloat halfLength, PfxFloat radius);
};
inline
PfxCylinder::PfxCylinder(PfxFloat halfLength, PfxFloat radius)
{
m_halfLen = halfLength;
m_radius = radius;
}
inline
void PfxCylinder::set(PfxFloat halfLength, PfxFloat radius)
{
m_halfLen = halfLength;
m_radius = radius;
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_CYLINDER_H

View File

@@ -0,0 +1,122 @@
/*
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_LARGE_TRI_MESH_H
#define _SCE_PFX_LARGE_TRI_MESH_H
#include "pfx_tri_mesh.h"
namespace sce {
namespace PhysicsEffects {
#define SCE_PFX_MAX_LARGETRIMESH_ISLANDS 256
///////////////////////////////////////////////////////////////////////////////
// Large Mesh
class SCE_PFX_ALIGNED(16) PfxLargeTriMesh
{
public:
//J ラージメッシュのサイズ
//E Size of a large mesh
PfxVector3 m_half;
//J 含まれるメッシュの総数
//E Number of mesh groups
PfxUInt16 m_numIslands;
//J アイランドAABB配列ソート済み
//E Array of island AABB (Sorted)
PfxUInt8 m_axis; // 0 = X , 1 = Y , 2 = Z
SCE_PFX_PADDING(1,1)
PfxAabb16 *m_aabbList;
SCE_PFX_PADDING(2,4)
//J アイランド配列
//E Array of island
PfxTriMesh *m_islands;
PfxLargeTriMesh()
{
m_numIslands = 0;
m_islands = NULL;
m_aabbList = NULL;
}
inline bool testAABB(int islandId,const PfxVector3 &center,const PfxVector3 &half) const;
//J ワールド座標値をラージメッシュローカルに変換する
//E Convert a position in the world coordinate into a position in the local coordinate
inline PfxVecInt3 getLocalPosition(const PfxVector3 &worldPosition) const;
inline void getLocalPosition(
const PfxVector3 &worldMinPosition,const PfxVector3 &worldMaxPosition,
PfxVecInt3 &localMinPosition,PfxVecInt3 &localMaxPosition) const;
//J ラージメッシュローカル座標値をワールドに変換する
//E Convert a position in the local coordinate into a position in the world coordinate
inline PfxVector3 getWorldPosition(const PfxVecInt3 &localPosition) const;
};
inline
bool PfxLargeTriMesh::testAABB(int islandId,const PfxVector3 &center,const PfxVector3 &half) const
{
PfxVecInt3 aabbMinL = getLocalPosition(center-half);
PfxVecInt3 aabbMaxL = getLocalPosition(center+half);
if(aabbMaxL.getX() < pfxGetXMin(m_aabbList[islandId]) || aabbMinL.getX() > pfxGetXMax(m_aabbList[islandId])) return false;
if(aabbMaxL.getY() < pfxGetYMin(m_aabbList[islandId]) || aabbMinL.getY() > pfxGetYMax(m_aabbList[islandId])) return false;
if(aabbMaxL.getZ() < pfxGetZMin(m_aabbList[islandId]) || aabbMinL.getZ() > pfxGetZMax(m_aabbList[islandId])) return false;
return true;
}
inline
PfxVecInt3 PfxLargeTriMesh::getLocalPosition(const PfxVector3 &worldPosition) const
{
const PfxVector3 sz(65535.0f);
PfxVector3 tmp = divPerElem(worldPosition+m_half,2.0f*m_half);
tmp = mulPerElem(sz,minPerElem(maxPerElem(tmp,PfxVector3(0.0f)),PfxVector3(1.0f))); // clamp 0.0 - 1.0
return PfxVecInt3(tmp);
}
inline
void PfxLargeTriMesh::getLocalPosition(
const PfxVector3 &worldMinPosition,const PfxVector3 &worldMaxPosition,
PfxVecInt3 &localMinPosition,PfxVecInt3 &localMaxPosition) const
{
const PfxVector3 sz(65535.0f);
PfxVector3 qmin = divPerElem(worldMinPosition+m_half,2.0f*m_half);
qmin = mulPerElem(sz,minPerElem(maxPerElem(qmin,PfxVector3(0.0f)),PfxVector3(1.0f))); // clamp 0.0 - 1.0
PfxVector3 qmax = divPerElem(worldMaxPosition+m_half,2.0f*m_half);
qmax = mulPerElem(sz,minPerElem(maxPerElem(qmax,PfxVector3(0.0f)),PfxVector3(1.0f))); // clamp 0.0 - 1.0
localMinPosition = PfxVecInt3(floorf(qmin[0]),floorf(qmin[1]),floorf(qmin[2]));
localMaxPosition = PfxVecInt3(ceilf(qmax[0]),ceilf(qmax[1]),ceilf(qmax[2]));
}
inline
PfxVector3 PfxLargeTriMesh::getWorldPosition(const PfxVecInt3 &localPosition) const
{
PfxVector3 sz(65535.0f),lp(localPosition);
PfxVector3 tmp = divPerElem(lp,sz);
return mulPerElem(tmp,2.0f*m_half) - m_half;
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_LARGE_TRI_MESH_H

View File

@@ -0,0 +1,59 @@
/*
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_RAY_H
#define _SCE_PFX_RAY_H
#include "../base/pfx_common.h"
#include "pfx_sub_data.h"
namespace sce {
namespace PhysicsEffects {
#define SCE_PFX_RAY_FACET_MODE_FRONT_ONLY 0
#define SCE_PFX_RAY_FACET_MODE_BACK_ONLY 1
#define SCE_PFX_RAY_FACET_MODE_FRONT_AND_BACK 2
struct SCE_PFX_ALIGNED(16) PfxRayInput
{
PfxVector3 m_startPosition;
PfxVector3 m_direction;
PfxUInt32 m_contactFilterSelf;
PfxUInt32 m_contactFilterTarget;
PfxUInt8 m_facetMode;
SCE_PFX_PADDING(1,7)
void reset()
{
m_contactFilterSelf = m_contactFilterTarget = 0xffffffff;
m_facetMode = SCE_PFX_RAY_FACET_MODE_FRONT_ONLY;
}
};
struct SCE_PFX_ALIGNED(16) PfxRayOutput
{
PfxVector3 m_contactPoint;
PfxVector3 m_contactNormal;
PfxFloat m_variable;
PfxUInt16 m_objectId;
PfxUInt8 m_shapeId;
PfxBool m_contactFlag : 1;
PfxSubData m_subData;
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_RAY_H

View File

@@ -0,0 +1,118 @@
/*
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_SHAPE_H
#define _SCE_PFX_SHAPE_H
#include "../base/pfx_common.h"
#include "../base/pfx_vec_utils.h"
#include "pfx_box.h"
#include "pfx_sphere.h"
#include "pfx_capsule.h"
#include "pfx_cylinder.h"
#include "pfx_tri_mesh.h"
#include "pfx_large_tri_mesh.h"
namespace sce {
namespace PhysicsEffects {
enum ePfxShapeType
{
kPfxShapeSphere = 0,
kPfxShapeBox,
kPfxShapeCapsule,
kPfxShapeCylinder,
kPfxShapeConvexMesh,
kPfxShapeLargeTriMesh,
kPfxShapeReserved0,
kPfxShapeReserved1,
kPfxShapeReserved2,
kPfxShapeUser0,
kPfxShapeUser1,
kPfxShapeUser2,
kPfxShapeCount // =12
};
class SCE_PFX_ALIGNED(16) PfxShape
{
friend class PfxCollidable;
private:
union {
PfxFloat m_vecDataF[3];
PfxUInt32 m_vecDataI[3];
void *m_vecDataPtr[2];
};
PfxUInt8 m_type;
SCE_PFX_PADDING(1,3)
PfxFloat m_offsetPosition[3];
PfxFloat m_offsetOrientation[4];
PfxUInt32 m_contactFilterSelf;
PfxUInt32 m_contactFilterTarget;
SCE_PFX_PADDING(2,12)
public:
inline void reset();
// Shape
inline void setBox(PfxBox SCE_VECTORMATH_AOS_VECTOR_ARG box);
inline void setCapsule(PfxCapsule capsule);
inline void setCylinder(PfxCylinder cylinder);
inline void setSphere(PfxSphere sphere);
inline void setConvexMesh(const PfxConvexMesh *convexMesh);
inline void setLargeTriMesh(const PfxLargeTriMesh *largeMesh);
inline PfxUInt8 getType() const;
inline PfxBox getBox()const ;
inline PfxCapsule getCapsule() const;
inline PfxCylinder getCylinder() const;
inline PfxSphere getSphere() const;
inline const PfxConvexMesh* getConvexMesh() const;
inline const PfxLargeTriMesh* getLargeTriMesh() const;
// Offset
inline void setOffsetTransform(const PfxTransform3 & xfrm);
inline void setOffsetOrientation(const PfxQuat SCE_VECTORMATH_AOS_VECTOR_ARG rot) {return pfxStoreQuat(rot,m_offsetOrientation);}
inline void setOffsetPosition(const PfxVector3 SCE_VECTORMATH_AOS_VECTOR_ARG pos) {return pfxStoreVector3(pos,m_offsetPosition);}
inline PfxTransform3 getOffsetTransform() const;
inline PfxVector3 getOffsetPosition() const {return pfxReadVector3(m_offsetPosition);}
inline PfxQuat getOffsetOrientation() const {return pfxReadQuat(m_offsetOrientation);}
// Raw data access
inline void setDataFloat(int i,PfxFloat v) {m_vecDataF[i]=v;}
inline void setDataInteger(int i,PfxUInt32 v) {m_vecDataI[i]=v;}
inline PfxFloat getDataFloat(int i) const {return m_vecDataF[i];}
inline PfxUInt32 getDataInteger(int i) const {return m_vecDataI[i];}
// Contact Filter
PfxUInt32 getContactFilterSelf() const {return m_contactFilterSelf;}
void setContactFilterSelf(PfxUInt32 filter) {m_contactFilterSelf = filter;}
PfxUInt32 getContactFilterTarget() const {return m_contactFilterTarget;}
void setContactFilterTarget(PfxUInt32 filter) {m_contactFilterTarget = filter;}
// Bouding Volume
void getAabb(PfxVector3 &aabbMin,PfxVector3 &aabbMax) const;
};
#include "pfx_shape_implementation.h"
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_SHAPE_H

View File

@@ -0,0 +1,145 @@
/*
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_SHAPE_IMPLEMENTATION_H
#define _SCE_PFX_SHAPE_IMPLEMENTATION_H
inline
void PfxShape::reset()
{
m_type = kPfxShapeSphere;
m_offsetPosition[0] = m_offsetPosition[1] = m_offsetPosition[2]= 0.0f;
m_offsetOrientation[0] = m_offsetOrientation[1] = m_offsetOrientation[2]= 0.0f;
m_offsetOrientation[3] = 1.0f;
m_contactFilterSelf = m_contactFilterTarget = 0xffffffff;
}
inline
void PfxShape::setBox(PfxBox SCE_VECTORMATH_AOS_VECTOR_ARG box)
{
m_vecDataF[0] = box.m_half[0];
m_vecDataF[1] = box.m_half[1];
m_vecDataF[2] = box.m_half[2];
m_type = kPfxShapeBox;
}
inline
void PfxShape::setCapsule(PfxCapsule capsule)
{
m_vecDataF[0] = capsule.m_halfLen;
m_vecDataF[1] = capsule.m_radius;
m_vecDataF[2] = 0.0f;
m_type = kPfxShapeCapsule;
}
inline
void PfxShape::setCylinder(PfxCylinder cylinder)
{
m_vecDataF[0] = cylinder.m_halfLen;
m_vecDataF[1] = cylinder.m_radius;
m_vecDataF[2] = 0.0f;
m_type = kPfxShapeCylinder;
}
inline
void PfxShape::setSphere(PfxSphere sphere)
{
m_vecDataF[0] = sphere.m_radius;
m_vecDataF[1] = 0.0f;
m_vecDataF[2] = 0.0f;
m_type = kPfxShapeSphere;
}
inline
void PfxShape::setConvexMesh(const PfxConvexMesh *convexMesh)
{
m_vecDataPtr[0] = (void*)convexMesh;
m_vecDataPtr[1] = NULL;
m_type = kPfxShapeConvexMesh;
}
inline
void PfxShape::setLargeTriMesh(const PfxLargeTriMesh *largeMesh)
{
m_vecDataPtr[0] = (void*)largeMesh;
m_vecDataPtr[1] = NULL;
m_type = kPfxShapeLargeTriMesh;
}
inline
void PfxShape::setOffsetTransform(const PfxTransform3 & xfrm)
{
setOffsetOrientation(PfxQuat(xfrm.getUpper3x3()));
setOffsetPosition(xfrm.getTranslation());
}
inline
PfxUInt8 PfxShape::getType() const
{
return m_type;
}
inline
PfxBox PfxShape::getBox() const
{
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeBox);
return PfxBox(m_vecDataF[0],m_vecDataF[1],m_vecDataF[2]);
}
inline
PfxCapsule PfxShape::getCapsule() const
{
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeCapsule);
return PfxCapsule(m_vecDataF[0], m_vecDataF[1]);
}
inline
PfxCylinder PfxShape::getCylinder() const
{
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeCylinder);
return PfxCylinder(m_vecDataF[0], m_vecDataF[1]);
}
inline
PfxSphere PfxShape::getSphere() const
{
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeSphere);
return PfxSphere(m_vecDataF[0]);
}
inline
const PfxConvexMesh *PfxShape::getConvexMesh() const
{
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeConvexMesh);
SCE_PFX_ALWAYS_ASSERT(m_vecDataPtr[0]!=NULL);
return (PfxConvexMesh*)m_vecDataPtr[0];
}
inline
const PfxLargeTriMesh *PfxShape::getLargeTriMesh() const
{
SCE_PFX_ALWAYS_ASSERT(m_type==kPfxShapeLargeTriMesh);
SCE_PFX_ALWAYS_ASSERT(m_vecDataPtr[0]!=NULL);
return (PfxLargeTriMesh*)m_vecDataPtr[0];
}
inline
PfxTransform3 PfxShape::getOffsetTransform() const
{
return PfxTransform3(getOffsetOrientation(),getOffsetPosition());
}
#endif // _SCE_PFX_SHAPE_IMPLEMENTATION_H

View File

@@ -0,0 +1,58 @@
/*
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_SHAPE_ITERATOR_H
#define _SCE_PFX_SHAPE_ITERATOR_H
#include "pfx_collidable.h"
namespace sce {
namespace PhysicsEffects {
class PfxShapeIterator
{
private:
PfxUInt32 m_numShapes;
PfxShape *m_shapeBase;
const PfxUInt16 *m_shapeIds;
const PfxShape *m_curShape;
PfxUInt32 m_index;
public:
PfxShapeIterator(const PfxCollidable &coll) : m_shapeIds(coll.m_shapeIds)
{
m_numShapes = coll.m_numShapes;
m_shapeBase = coll.m_shapeBase;
m_index = 0;
m_curShape = &coll.m_defShape;
}
~PfxShapeIterator() {}
inline PfxShapeIterator& operator++()
{
m_curShape = &m_shapeBase[m_shapeIds[m_index++]];
return *this;
}
const PfxShape& operator*() const {return *m_curShape;}
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_SHAPE_ITERATOR_H

View File

@@ -0,0 +1,49 @@
/*
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_SPHERE_H
#define _SCE_PFX_SPHERE_H
#include "../base/pfx_common.h"
namespace sce {
namespace PhysicsEffects {
struct PfxSphere {
PfxFloat m_radius;
PfxSphere() {}
PfxSphere( PfxFloat radius );
void set( PfxFloat radius );
};
inline
PfxSphere::PfxSphere( PfxFloat radius )
{
m_radius = radius;
}
inline
void PfxSphere::set( PfxFloat radius )
{
m_radius = radius;
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_SPHERE_H

View File

@@ -0,0 +1,63 @@
/*
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_SUB_DATA_H
#define _SCE_PFX_SUB_DATA_H
namespace sce {
namespace PhysicsEffects {
struct PfxSubData {
enum {
NONE = 0,
MESH_INFO
};
union {
struct {
PfxUInt8 m_type;
SCE_PFX_PADDING(1,1)
struct {
PfxUInt8 islandId;
PfxUInt8 facetId;
PfxUInt16 s;
PfxUInt16 t;
} m_facetLocal;
};
PfxUInt32 param[2];
};
PfxSubData()
{
param[0] = param[1] = 0;
}
void setIslandId(PfxUInt8 i) {m_facetLocal.islandId = i;}
void setFacetId(PfxUInt8 i) {m_facetLocal.facetId = i;}
void setFacetLocalS(PfxFloat s) {m_facetLocal.s = (PfxUInt16)(s * 65535.0f);}
void setFacetLocalT(PfxFloat t) {m_facetLocal.t = (PfxUInt16)(t * 65535.0f);}
PfxUInt8 getIslandId() {return m_facetLocal.islandId;}
PfxUInt8 getFacetId() {return m_facetLocal.facetId;}
PfxFloat getFacetLocalS() {return m_facetLocal.s / 65535.0f;}
PfxFloat getFacetLocalT() {return m_facetLocal.t / 65535.0f;}
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_SUB_DATA_H

View File

@@ -0,0 +1,154 @@
/*
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_TRI_MESH_H
#define _SCE_PFX_TRI_MESH_H
#include "../base/pfx_common.h"
#include "../base/pfx_vec_utils.h"
#include "pfx_aabb.h"
namespace sce {
namespace PhysicsEffects {
//J メッシュのリソース制限
//E Define some limitations of a triangle mesh
#define SCE_PFX_NUMMESHFACETS 64
#define SCE_PFX_NUMMESHEDGES 192
#define SCE_PFX_NUMMESHVERTICES 128
//J エッジの角
//E Edge types
#define SCE_PFX_EDGE_FLAT 0
#define SCE_PFX_EDGE_CONVEX 1
#define SCE_PFX_EDGE_CONCAVE 2
///////////////////////////////////////////////////////////////////////////////
// Edge
struct PfxEdge
{
PfxUInt8 m_vertId[2];
PfxUInt8 m_angleType;
PfxUInt8 m_tilt;
};
inline
bool operator ==(const PfxEdge &e1,const PfxEdge &e2)
{
return (e1.m_vertId[0] == e2.m_vertId[0] && e1.m_vertId[1] == e2.m_vertId[1]) ||
(e1.m_vertId[1] == e2.m_vertId[0] && e1.m_vertId[0] == e2.m_vertId[1]);
}
///////////////////////////////////////////////////////////////////////////////
// Facet
struct PfxFacet
{
PfxFloat m_normal[3];
PfxFloat m_thickness;
PfxUInt8 m_group;
PfxUInt8 m_vertIds[3];
PfxUInt8 m_edgeIds[3];
PfxUInt8 m_userData;
PfxFloat m_half[3];
PfxFloat m_center[3];
};
///////////////////////////////////////////////////////////////////////////////
// Mesh
struct SCE_PFX_ALIGNED(16) PfxTriMesh
{
PfxUInt8 m_numVerts;
PfxUInt8 m_numEdges;
PfxUInt8 m_numFacets;
PfxUInt8 m_reserved;
PfxFacet m_facets[SCE_PFX_NUMMESHFACETS];
PfxEdge m_edges[SCE_PFX_NUMMESHEDGES];
SCE_PFX_PADDING(1,12)
PfxVector3 m_verts[SCE_PFX_NUMMESHVERTICES];
PfxVector3 m_half;
PfxTriMesh()
{
m_numVerts = m_numEdges = m_numFacets = 0;
}
inline void updateAABB();
};
inline
void PfxTriMesh::updateAABB()
{
PfxVector3 halfMax(0);
for(PfxUInt8 i=0;i<m_numFacets;i++) {
PfxVector3 pnts[6] = {
m_verts[m_facets[i].m_vertIds[0]],
m_verts[m_facets[i].m_vertIds[1]],
m_verts[m_facets[i].m_vertIds[2]],
m_verts[m_facets[i].m_vertIds[0]] - m_facets[i].m_thickness * pfxReadVector3(m_facets[i].m_normal),
m_verts[m_facets[i].m_vertIds[1]] - m_facets[i].m_thickness * pfxReadVector3(m_facets[i].m_normal),
m_verts[m_facets[i].m_vertIds[2]] - m_facets[i].m_thickness * pfxReadVector3(m_facets[i].m_normal)
};
PfxVector3 facetAABBmin,facetAABBmax,facetHalf,facetCenter;
facetAABBmin = minPerElem(pnts[5],minPerElem(pnts[4],minPerElem(pnts[3],minPerElem(pnts[2],minPerElem(pnts[0],pnts[1])))));
facetAABBmax = maxPerElem(pnts[5],maxPerElem(pnts[4],maxPerElem(pnts[3],maxPerElem(pnts[2],maxPerElem(pnts[0],pnts[1])))));
facetHalf = 0.5f * (facetAABBmax - facetAABBmin) + PfxVector3(0.00001f); // Slightly stretch to avoid collision hole
facetCenter = 0.5f * (facetAABBmax + facetAABBmin);
pfxStoreVector3(facetHalf,m_facets[i].m_half);
pfxStoreVector3(facetCenter,m_facets[i].m_center);
halfMax = maxPerElem(absPerElem(facetAABBmax),halfMax);
}
m_half = halfMax;
}
///////////////////////////////////////////////////////////////////////////////
// Convex Mesh
struct SCE_PFX_ALIGNED(16) PfxConvexMesh
{
PfxUInt8 m_numVerts;
PfxUInt8 m_numIndices;
PfxUInt16 m_indices[SCE_PFX_NUMMESHFACETS*3];
SCE_PFX_PADDING(1,14)
PfxVector3 m_verts[SCE_PFX_NUMMESHVERTICES];
PfxVector3 m_half;
SCE_PFX_PADDING(2,16)
PfxConvexMesh()
{
m_numVerts = m_numIndices = 0;
}
inline void updateAABB();
};
inline
void PfxConvexMesh::updateAABB()
{
PfxVector3 halfMax(0);
for(int i=0;i<m_numVerts;i++) {
halfMax = maxPerElem(absPerElem(m_verts[i]),halfMax);
}
m_half = halfMax;
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_TRI_MESH_H

View File

@@ -0,0 +1,50 @@
/*
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_BASE_LEVEL_INCLUDE_H
#define _SCE_PFX_BASE_LEVEL_INCLUDE_H
///////////////////////////////////////////////////////////////////////////////
// Physics Effects Base Level Headers
#include "base/pfx_common.h"
#include "base/pfx_perf_counter.h"
#include "rigidbody/pfx_rigid_state.h"
#include "rigidbody/pfx_rigid_body.h"
#include "broadphase/pfx_broadphase_pair.h"
#include "broadphase/pfx_broadphase_proxy.h"
#include "broadphase/pfx_update_broadphase_proxy.h"
#include "collision/pfx_collidable.h"
#include "collision/pfx_shape_iterator.h"
#include "collision/pfx_contact_manifold.h"
#include "solver/pfx_constraint_pair.h"
#include "solver/pfx_contact_constraint.h"
#include "solver/pfx_joint_ball.h"
#include "solver/pfx_joint_swing_twist.h"
#include "solver/pfx_joint_hinge.h"
#include "solver/pfx_joint_slider.h"
#include "solver/pfx_joint_fix.h"
#include "solver/pfx_joint_universal.h"
#include "solver/pfx_integrate.h"
#include "sort/pfx_sort.h"
#endif // _SCE_PFX_BASE_LEVEL_INCLUDE_H

View File

@@ -0,0 +1,71 @@
/*
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_RIGID_BODY_H
#define _SCE_PFX_RIGID_BODY_H
#include "../base/pfx_common.h"
namespace sce {
namespace PhysicsEffects {
class SCE_PFX_ALIGNED(128) PfxRigidBody
{
private:
// Rigid Body constants
PfxMatrix3 m_inertia; // Inertia matrix in body's coords
PfxMatrix3 m_inertiaInv; // Inertia matrix inverse in body's coords
PfxFloat m_mass; // Rigid Body mass
PfxFloat m_massInv; // Inverse of mass
PfxFloat m_restitution; // Coefficient of restitution
PfxFloat m_friction; // Coefficient of friction
SCE_PFX_PADDING(1,16)
public:
PfxFloat getMassInv() const {return m_massInv;}
void setMassInv(PfxFloat massInv) {m_massInv=massInv;}
const PfxMatrix3& getInertiaInv() const {return m_inertiaInv;}
void setInertiaInv(const PfxMatrix3 SCE_VECTORMATH_AOS_MATRIX_ARG inertiaInv) {m_inertiaInv = inertiaInv;}
public:
inline void reset();
PfxFloat getMass() const {return m_mass;};
void setMass(PfxFloat mass) {m_mass=mass;m_massInv=mass>0.0f?1.0f/mass:0.0f;}
const PfxMatrix3& getInertia() const {return m_inertia;}
void setInertia(const PfxMatrix3 SCE_VECTORMATH_AOS_MATRIX_ARG inertia) {m_inertia = inertia;m_inertiaInv = inverse(inertia);}
PfxFloat getRestitution() const {return m_restitution;}
void setRestitution(PfxFloat restitution) {m_restitution = restitution;}
PfxFloat getFriction() const {return m_friction;}
void setFriction(PfxFloat friction) {m_friction = friction;}
};
inline
void PfxRigidBody::reset()
{
m_mass = 0.0f;
m_restitution = 0.2f;
m_friction = 0.6f;
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_RIGID_BODY_H

View File

@@ -0,0 +1,196 @@
/*
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_RIGID_STATE_H
#define _SCE_PFX_RIGID_STATE_H
#include "../base/pfx_common.h"
#include "../base/pfx_vec_utils.h"
namespace sce {
namespace PhysicsEffects {
// Motion Type
enum ePfxMotionType {
kPfxMotionTypeFixed = 0,
kPfxMotionTypeActive,
kPfxMotionTypeKeyframe,
kPfxMotionTypeOneWay,
kPfxMotionTypeTrigger,
kPfxMotionTypeCount
};
#define SCE_PFX_MOTION_MASK_DYNAMIC(motion) ((1<<(motion))&0x0a) // Active,OneWay
#define SCE_PFX_MOTION_MASK_STATIC(motion) ((1<<(motion))&0x95) // Fixed,Keyframe
#define SCE_PFX_MOTION_MASK_CAN_SLEEP(motion) ((1<<(motion))&0x0e) // Can sleep
#define SCE_PFX_MOTION_MASK_SLEEPING 0x80 // Is sleeping
#define SCE_PFX_MOTION_MASK_TYPE 0x7f // Motion Type
class SCE_PFX_ALIGNED(128) PfxRigidState
{
private:
union {
struct {
PfxUInt8 m_useSleep : 1;
PfxUInt8 m_sleeping : 1;
PfxUInt8 m_reserved1 : 1;
PfxUInt8 m_reserved2 : 1;
PfxUInt8 m_reserved3 : 1;
PfxUInt8 m_reserved4 : 1;
PfxUInt8 m_reserved5 : 1;
PfxUInt8 m_reserved6 : 1;
};
PfxUInt8 m_flags;
};
PfxUInt8 m_motionType;
PfxUInt16 m_sleepCount;
PfxUInt16 m_rigidBodyId;
SCE_PFX_PADDING(1,2)
PfxUInt32 m_contactFilterSelf;
PfxUInt32 m_contactFilterTarget;
PfxFloat m_linearDamping;
PfxFloat m_angularDamping;
PfxFloat m_maxLinearVelocity;
PfxFloat m_maxAngularVelocity;
PfxVector3 m_position;
PfxQuat m_orientation;
PfxVector3 m_linearVelocity;
PfxVector3 m_angularVelocity;
void *m_userData;
PfxUInt32 m_userParam[4];
SCE_PFX_PADDING(2,12)
public:
inline void reset();
PfxUInt16 getRigidBodyId() const {return m_rigidBodyId;}
void setRigidBodyId(PfxUInt16 i) {m_rigidBodyId = i;}
PfxUInt32 getContactFilterSelf() const {return m_contactFilterSelf;}
void setContactFilterSelf(PfxUInt32 filter) {m_contactFilterSelf = filter;}
PfxUInt32 getContactFilterTarget() const {return m_contactFilterTarget;}
void setContactFilterTarget(PfxUInt32 filter) {m_contactFilterTarget = filter;}
ePfxMotionType getMotionType() const {return (ePfxMotionType)m_motionType;}
void setMotionType(ePfxMotionType t) {SCE_PFX_ALWAYS_ASSERT(t<kPfxMotionTypeCount);m_motionType = (PfxUInt8)t;wakeup();}
PfxUInt8 getMotionMask() const {return m_motionType|(m_sleeping<<7);}
PfxBool isAsleep() const {return m_sleeping==1;}
PfxBool isAwake() const {return m_sleeping==0;}
void wakeup() {m_sleeping=0;m_sleepCount=0;}
void sleep() {if(m_useSleep) {m_sleeping=1;m_sleepCount=0;}}
PfxUInt8 getUseSleep() const {return m_useSleep;}
void setUseSleep(PfxUInt8 b) {m_useSleep=b;}
void incrementSleepCount() {if(m_sleepCount<0xffff)m_sleepCount++;}
void resetSleepCount() {m_sleepCount=0;}
PfxUInt16 getSleepCount() const {return m_sleepCount;}
PfxFloat getLinearDamping() const {return m_linearDamping;}
PfxFloat getAngularDamping() const {return m_angularDamping;}
PfxFloat getMaxLinearVelocity() const {return m_maxLinearVelocity;}
PfxFloat getMaxAngularVelocity() const {return m_maxAngularVelocity;}
void setLinearDamping(PfxFloat damping) {m_linearDamping=damping;}
void setAngularDamping(PfxFloat damping) {m_angularDamping=damping;}
void setMaxLinearVelocity(PfxFloat maxvelocity){m_maxLinearVelocity = maxvelocity;}
void setMaxAngularVelocity(PfxFloat maxvelocity){m_maxAngularVelocity = maxvelocity;}
PfxVector3 getPosition() const {return m_position;}
PfxQuat getOrientation() const {return m_orientation;}
PfxVector3 getLinearVelocity() const {return m_linearVelocity;}
PfxVector3 getAngularVelocity() const {return m_angularVelocity;}
void setPosition(const PfxVector3 &pos) {m_position = pos;}
void setOrientation(const PfxQuat &rot) {m_orientation = rot;}
void setLinearVelocity(const PfxVector3 &vel) {m_linearVelocity = vel;}
void setAngularVelocity(const PfxVector3 &vel) {m_angularVelocity = vel;}
void *getUserData() const {return m_userData;}
void setUserData(void *d) {m_userData=d;}
inline void movePosition(const PfxVector3 &pos,PfxFloat timeStep);
inline void moveOrientation(const PfxQuat &rot,PfxFloat timeStep);
};
inline
void PfxRigidState::reset()
{
m_sleepCount = 0;
m_motionType = kPfxMotionTypeActive;
m_flags = 0;
m_rigidBodyId = 0;
m_contactFilterSelf = 0xffffffff;
m_contactFilterTarget = 0xffffffff;
m_linearDamping = 1.0f;
m_angularDamping = 0.99f;
m_maxLinearVelocity = 200.0f;
m_maxAngularVelocity = SCE_PFX_PI * 100.0f;
m_position = PfxVector3(0.0f);
m_orientation = PfxQuat::identity();
m_linearVelocity = PfxVector3(0.0f);
m_angularVelocity = PfxVector3(0.0f);
m_userData = NULL;
}
inline
void PfxRigidState::movePosition(const PfxVector3 &pos,PfxFloat timeStep)
{
if(getMotionType()!=kPfxMotionTypeKeyframe) return;
SCE_PFX_ASSERT(timeStep > 0.0f);
setLinearVelocity((pos - getPosition()) / timeStep);
}
inline
void PfxRigidState::moveOrientation(const PfxQuat &rot,PfxFloat timeStep)
{
if(getMotionType()!=kPfxMotionTypeKeyframe) return;
SCE_PFX_ASSERT(timeStep > 0.0f);
PfxQuat ori1 = getOrientation();
PfxQuat ori2 = rot;
if(dot(ori2,ori1) < 0.0f) {
ori2 = -rot;
}
PfxQuat dq = ( ori2 - ori1 ) / timeStep;
dq = dq * 2.0f * conj(ori1);
PfxVector3 omega = dq.getXYZ();
setAngularVelocity(omega);
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_RIGID_STATE_H

View File

@@ -0,0 +1,39 @@
/*
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_CONSTRAINT_PAIR_H
#define _SCE_PFX_CONSTRAINT_PAIR_H
#include "../sort/pfx_sort_data.h"
#include "../broadphase/pfx_broadphase_pair.h"
namespace sce {
namespace PhysicsEffects {
typedef PfxSortData16 PfxConstraintPair;
//J PfxBroadphasePairと共通
//E Same as PfxBroadphasePair
SCE_PFX_FORCE_INLINE void pfxSetConstraintId(PfxConstraintPair &pair,PfxUInt32 i) {pair.set32(2,i);}
SCE_PFX_FORCE_INLINE void pfxSetNumConstraints(PfxConstraintPair &pair,PfxUInt8 n) {pair.set8(7,n);}
SCE_PFX_FORCE_INLINE PfxUInt32 pfxGetConstraintId(const PfxConstraintPair &pair) {return pair.get32(2);}
SCE_PFX_FORCE_INLINE PfxUInt8 pfxGetNumConstraints(const PfxConstraintPair &pair) {return pair.get8(7);}
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_CONSTRAINT_PAIR_H

View File

@@ -0,0 +1,40 @@
/*
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_CONSTRAINT_ROW_H
#define _SCE_PFX_CONSTRAINT_ROW_H
#include "../base/pfx_vec_utils.h"
namespace sce {
namespace PhysicsEffects {
#include "../base/pfx_common.h"
//E Don't change following order of parameters
struct SCE_PFX_ALIGNED(16) PfxConstraintRow {
PfxFloat m_normal[3];
PfxFloat m_rhs;
PfxFloat m_jacDiagInv;
PfxFloat m_lowerLimit;
PfxFloat m_upperLimit;
PfxFloat m_accumImpulse;
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_CONSTRAINT_ROW_H

View File

@@ -0,0 +1,59 @@
/*
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_CONTACT_CONSTRAINT_H
#define _SCE_PFX_CONTACT_CONSTRAINT_H
#include "../rigidbody/pfx_rigid_state.h"
#include "pfx_constraint_row.h"
#include "pfx_solver_body.h"
namespace sce {
namespace PhysicsEffects {
void pfxSetupContactConstraint(
PfxConstraintRow &constraintResponse,
PfxConstraintRow &constraintFriction1,
PfxConstraintRow &constraintFriction2,
PfxFloat penetrationDepth,
PfxFloat restitution,
PfxFloat friction,
const PfxVector3 &contactNormal,
const PfxVector3 &contactPointA,
const PfxVector3 &contactPointB,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB,
PfxFloat separateBias,
PfxFloat timeStep
);
void pfxSolveContactConstraint(
PfxConstraintRow &constraintResponse,
PfxConstraintRow &constraintFriction1,
PfxConstraintRow &constraintFriction2,
const PfxVector3 &contactPointA,
const PfxVector3 &contactPointB,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB,
PfxFloat friction
);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_CONTACT_CONSTRAINT_H

View File

@@ -0,0 +1,121 @@
/*
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_INTEGRATE_H_
#define _SCE_PFX_INTEGRATE_H_
#include "../base/pfx_common.h"
#include "../rigidbody/pfx_rigid_body.h"
#include "../rigidbody/pfx_rigid_state.h"
namespace sce {
namespace PhysicsEffects {
template <typename T>
static SCE_PFX_FORCE_INLINE T pfxRungeKutta(const T &deriv,PfxFloat dt)
{
T k0, k1, k2, k3;
k0 = deriv * dt;
k1 = (deriv + k0 * 0.5f) * dt;
k2 = (deriv + k1 * 0.5f) * dt;
k3 = (deriv + k2) * dt;
return (k0 + k1*2.0f + k2*2.0f + k3) / 6.0f;
}
#define SCE_PFX_MOTION_MASK_INTEGRATE ((1<<kPfxMotionTypeFixed)|(1<<kPfxMotionTypeTrigger))
static SCE_PFX_FORCE_INLINE
void pfxIntegrate(
PfxRigidState &state,
const PfxRigidBody &body,
PfxFloat timeStep
)
{
(void) body;
if(((1<<state.getMotionMask())&SCE_PFX_MOTION_MASK_INTEGRATE) || state.isAsleep()) return;
PfxVector3 position = state.getPosition();
PfxQuat orientation = state.getOrientation();
PfxVector3 linearVelocity = state.getLinearVelocity();
PfxVector3 angularVelocity = state.getAngularVelocity();
PfxVector3 dx = linearVelocity;
PfxQuat dq = PfxQuat(angularVelocity,0) * orientation * 0.5f;
#ifdef SCE_PFX_ODE_EULER
position += dx * timeStep;
orientation += dq * timeStep;
orientation = normalize(orientation);
#else
position += pfxRungeKutta(dx,timeStep);
orientation += pfxRungeKutta(dq,timeStep);
orientation = normalize(orientation);
#endif
state.setPosition(position);
state.setOrientation(orientation);
}
#define SCE_PFX_MOTION_MASK_APPLYFORCE ((1<<kPfxMotionTypeFixed)|(1<<kPfxMotionTypeTrigger)|(1<<kPfxMotionTypeKeyframe))
static SCE_PFX_FORCE_INLINE
void pfxApplyExternalForce(
PfxRigidState &state,
const PfxRigidBody &body,
const PfxVector3 &extForce,
const PfxVector3 &extTorque,
PfxFloat timeStep
)
{
if(((1<<state.getMotionType())&SCE_PFX_MOTION_MASK_APPLYFORCE) || state.isAsleep()) return;
PfxVector3 angularVelocity = state.getAngularVelocity();
PfxMatrix3 m(state.getOrientation());
PfxMatrix3 worldInertia = m * body.getInertia() * transpose(m);
PfxMatrix3 worldInertiaInv = m * body.getInertiaInv() * transpose(m);
PfxVector3 dv = extForce * body.getMassInv();
PfxVector3 dw = worldInertiaInv * (cross(worldInertia * angularVelocity, angularVelocity) + extTorque);
PfxVector3 nv = state.getLinearVelocity();
PfxVector3 nw = state.getAngularVelocity();
#ifdef SCE_PFX_ODE_EULER
nv += dv * timeStep;
nw += dw * timeStep;
#else
nv += pfxRungeKutta(dv,timeStep);
nw += pfxRungeKutta(dw,timeStep);
#endif
nv *= state.getLinearDamping();
nw *= state.getAngularDamping();
if(length(nv) > state.getMaxLinearVelocity())
{
nv = normalize( nv ) * state.getMaxLinearVelocity();
}
if(length(nw) > state.getMaxAngularVelocity())
{
nw = normalize( nw ) * state.getMaxAngularVelocity();
}
state.setLinearVelocity(nv);
state.setAngularVelocity(nw);
}
} //namespace PhysicsEffects
} //namespace sce
#endif /* _SCE_PFX_INTEGRATE_H_ */

View File

@@ -0,0 +1,90 @@
/*
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_JOINT_H
#define _SCE_PFX_JOINT_H
#include "../rigidbody/pfx_rigid_state.h"
#include "pfx_joint_constraint.h"
#include "pfx_constraint_pair.h"
namespace sce {
namespace PhysicsEffects {
// Joint Type
enum ePfxJointType {
kPfxJointBall = 0,
kPfxJointSwingtwist,
kPfxJointHinge,
kPfxJointSlider,
kPfxJointFix,
kPfxJointUniversal,
kPfxJointAnimation,
kPfxJointReserved0,
kPfxJointReserved1,
kPfxJointReserved2,
kPfxJointUser0,
kPfxJointUser1,
kPfxJointUser2,
kPfxJointUser3,
kPfxJointUser4,
kPfxJointCount // = 15
};
// Joint Structure
struct SCE_PFX_ALIGNED(128) PfxJoint {
PfxUInt8 m_active;
PfxUInt8 m_numConstraints;
PfxUInt8 m_type;
SCE_PFX_PADDING(1,1)
PfxUInt16 m_rigidBodyIdA;
PfxUInt16 m_rigidBodyIdB;
SCE_PFX_PADDING(2,8)
PfxJointConstraint m_constraints[6];
void *m_userData;
SCE_PFX_PADDING(3,12)
PfxVector3 m_param[4]; // Used by some joints for specific features
PfxVector3 m_anchorA;
PfxVector3 m_anchorB;
PfxMatrix3 m_frameA;
PfxMatrix3 m_frameB;
SCE_PFX_PADDING(4,32)
};
SCE_PFX_FORCE_INLINE
void pfxUpdateJointPairs(
PfxConstraintPair &pair,
PfxUInt32 jointId,
const PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB
)
{
SCE_PFX_ALWAYS_ASSERT(stateA.getRigidBodyId()==joint.m_rigidBodyIdA);
SCE_PFX_ALWAYS_ASSERT(stateB.getRigidBodyId()==joint.m_rigidBodyIdB);
pfxSetObjectIdA(pair,stateA.getRigidBodyId());
pfxSetObjectIdB(pair,stateB.getRigidBodyId());
pfxSetMotionMaskA(pair,stateA.getMotionMask());
pfxSetMotionMaskB(pair,stateB.getMotionMask());
pfxSetConstraintId(pair,jointId);
pfxSetNumConstraints(pair,joint.m_numConstraints);
pfxSetActive(pair,joint.m_active>0);
}
} //namespace PhysicsEffects
} //namespace sce
#endif // _PFX_JOINT_H

View File

@@ -0,0 +1,62 @@
/*
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_JOINT_BALL_H
#define _SCE_PFX_JOINT_BALL_H
#include "pfx_joint.h"
#include "pfx_solver_body.h"
namespace sce {
namespace PhysicsEffects {
struct PfxBallJointInitParam {
PfxVector3 anchorPoint;
PfxBallJointInitParam()
{
anchorPoint = PfxVector3(0.0f);
}
};
PfxInt32 pfxInitializeBallJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
const PfxBallJointInitParam &param);
void pfxSetupBallJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB,
PfxFloat timeStep);
void pfxWarmStartBallJoint(
PfxJoint &joint,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB);
void pfxSolveBallJoint(
PfxJoint &joint,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_JOINT_BALL_H

View File

@@ -0,0 +1,67 @@
/*
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_JOINT_CONSTRAINT_H
#define _SCE_PFX_JOINT_CONSTRAINT_H
#include "../base/pfx_common.h"
#include "../base/pfx_vec_utils.h"
#include "pfx_constraint_row.h"
namespace sce {
namespace PhysicsEffects {
// Lock type
#define SCE_PFX_JOINT_LOCK_FREE 0
#define SCE_PFX_JOINT_LOCK_LIMIT 1
#define SCE_PFX_JOINT_LOCK_FIX 2
// Slop
#define SCE_PFX_JOINT_LINEAR_SLOP 0.01f
#define SCE_PFX_JOINT_ANGULAR_SLOP 0.01f
///////////////////////////////////////////////////////////////////////////////// Joint Constraint
struct PfxJointConstraint {
PfxInt8 m_lock;
PfxInt8 m_warmStarting;
SCE_PFX_PADDING(1,2)
PfxFloat m_movableLowerLimit;
PfxFloat m_movableUpperLimit;
PfxFloat m_bias;
PfxFloat m_weight;
PfxFloat m_damping;
PfxFloat m_maxImpulse;
SCE_PFX_PADDING(2,4)
PfxConstraintRow m_constraintRow;
void reset()
{
m_lock = SCE_PFX_JOINT_LOCK_FIX;
m_warmStarting = 0;
m_movableLowerLimit = 0.0f;
m_movableUpperLimit = 0.0f;
m_bias = 0.2f;
m_weight = 1.0f;
m_damping = 0.0f;
m_maxImpulse = SCE_PFX_FLT_MAX;
memset(&m_constraintRow,0,sizeof(PfxConstraintRow));
}
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_JOINT_CONSTRAINT_H

View File

@@ -0,0 +1,49 @@
/*
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_JOINT_FIX_H
#define _SCE_PFX_JOINT_FIX_H
#include "pfx_joint.h"
#include "pfx_solver_body.h"
namespace sce {
namespace PhysicsEffects {
struct PfxFixJointInitParam {
PfxVector3 anchorPoint;
PfxFixJointInitParam()
{
anchorPoint = PfxVector3(0.0f);
}
};
PfxInt32 pfxInitializeFixJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
const PfxFixJointInitParam &param);
// pfxSetupFixJoint = pfxSetupSwingTwistJoint
// pfxWarmStartFixJoint = pfxWarmStartSwingTwistJoint
// pfxSolveFixJoint = pfxSolveSwingTwistJoint
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_JOINT_FIX_H

View File

@@ -0,0 +1,56 @@
/*
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_JOINT_HINGE_H_
#define _SCE_PFX_JOINT_HINGE_H_
#include "pfx_joint.h"
#include "pfx_solver_body.h"
namespace sce {
namespace PhysicsEffects {
struct PfxHingeJointInitParam {
PfxVector3 anchorPoint;
PfxVector3 axis;
PfxFloat lowerAngle;
PfxFloat upperAngle;
SCE_PFX_PADDING(1,8)
PfxHingeJointInitParam()
{
anchorPoint = PfxVector3(0.0f);
axis = PfxVector3(1.0f,0.0f,0.0f);
lowerAngle = 0.0f;
upperAngle = 0.0f;
}
};
PfxInt32 pfxInitializeHingeJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
const PfxHingeJointInitParam &param);
// pfxSetupHingeJoint = pfxSetupSwingTwistJoint
// pfxWarmStartHingeJoint = pfxWarmStartSwingTwistJoint
// pfxSolveHingeJoint = pfxSolveSwingTwistJoint
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_JOINT_HINGE_H

View File

@@ -0,0 +1,57 @@
/*
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_JOINT_SLIDER_H
#define _SCE_PFX_JOINT_SLIDER_H
#include "pfx_joint.h"
#include "pfx_solver_body.h"
namespace sce {
namespace PhysicsEffects {
struct PfxSliderJointInitParam {
PfxVector3 anchorPoint;
PfxVector3 direction;
PfxFloat lowerDistance;
PfxFloat upperDistance;
SCE_PFX_PADDING(1,8)
PfxSliderJointInitParam()
{
anchorPoint = PfxVector3(0.0f);
direction = PfxVector3(1.0f,0.0f,0.0f);
lowerDistance = 0.0f;
upperDistance = 0.0f;
}
};
PfxInt32 pfxInitializeSliderJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
const PfxSliderJointInitParam &param);
// pfxSetupSliderJoint = pfxSetupSwingTwistJoint
// pfxWarmStartSliderJoint = pfxWarmStartSwingTwistJoint
// pfxSolveSliderJoint = pfxSolveSwingTwistJoint
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_JOINT_SLIDER_H

View File

@@ -0,0 +1,70 @@
/*
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_JOINT_SWING_TWIST_H
#define _SCE_PFX_JOINT_SWING_TWIST_H
#include "pfx_joint.h"
#include "pfx_solver_body.h"
namespace sce {
namespace PhysicsEffects {
struct PfxSwingTwistJointInitParam {
PfxVector3 anchorPoint;
PfxVector3 twistAxis;
PfxFloat twistLowerAngle;
PfxFloat twistUpperAngle;
PfxFloat swingLowerAngle;
PfxFloat swingUpperAngle;
PfxSwingTwistJointInitParam()
{
anchorPoint = PfxVector3(0.0f);
twistAxis = PfxVector3(1.0f,0.0f,0.0f);
twistLowerAngle = -0.26f;
twistUpperAngle = 0.26f;
swingLowerAngle = 0.0f;
swingUpperAngle = 0.7f;
}
};
PfxInt32 pfxInitializeSwingTwistJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
const PfxSwingTwistJointInitParam &param);
void pfxSetupSwingTwistJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB,
PfxFloat timeStep);
void pfxWarmStartSwingTwistJoint(
PfxJoint &joint,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB);
void pfxSolveSwingTwistJoint(
PfxJoint &joint,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_JOINT_SWING_TWIST_H

View File

@@ -0,0 +1,65 @@
/*
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_JOINT_UNIVERSAL_H
#define _SCE_PFX_JOINT_UNIVERSAL_H
#include "pfx_joint.h"
#include "pfx_solver_body.h"
namespace sce {
namespace PhysicsEffects {
struct PfxUniversalJointInitParam {
PfxVector3 anchorPoint;
PfxVector3 axis;
PfxFloat swing1LowerAngle;
PfxFloat swing1UpperAngle;
PfxFloat swing2LowerAngle;
PfxFloat swing2UpperAngle;
PfxUniversalJointInitParam()
{
anchorPoint = PfxVector3(0.0f);
axis = PfxVector3(1.0f,0.0f,0.0f);
swing1LowerAngle = -0.7f;
swing1UpperAngle = 0.7f;
swing2LowerAngle = -0.7f;
swing2UpperAngle = 0.7f;
}
};
PfxInt32 pfxInitializeUniversalJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
const PfxUniversalJointInitParam &param);
void pfxSetupUniversalJoint(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB,
PfxFloat timeStep);
// pfxWarmStartUniversalJoint = pfxWarmStartSwingTwistJoint
// pfxSolveUniversalJoint = pfxSolveSwingTwistJoint
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_JOINT_UNIVERSAL_H

View File

@@ -0,0 +1,37 @@
/*
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_SOLVER_BODY_H
#define _SCE_PFX_SOLVER_BODY_H
#include "../base/pfx_common.h"
namespace sce {
namespace PhysicsEffects {
struct SCE_PFX_ALIGNED(128) PfxSolverBody {
PfxVector3 m_deltaLinearVelocity;
PfxVector3 m_deltaAngularVelocity;
PfxQuat m_orientation;
PfxMatrix3 m_inertiaInv;
PfxFloat m_massInv;
PfxUInt32 m_motionType;
SCE_PFX_PADDING(1,24)
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_SOLVER_BODY_H

View File

@@ -0,0 +1,33 @@
/*
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_SORT_H
#define _SCE_PFX_SORT_H
#include "pfx_sort_data.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Single Sort
void pfxSort(PfxSortData16 *data,PfxSortData16 *buff,unsigned int n);
void pfxSort(PfxSortData32 *data,PfxSortData32 *buff,unsigned int n);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_SORT_H

View File

@@ -0,0 +1,82 @@
/*
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_SORT_DATA_H
#define _SCE_PFX_SORT_DATA_H
#include "../base/pfx_common.h"
namespace sce {
namespace PhysicsEffects {
#define SCE_PFX_SENTINEL_KEY 0xffffffff
struct SCE_PFX_ALIGNED(16) PfxSortData16 {
union {
PfxUInt8 i8data[16];
PfxUInt16 i16data[8];
PfxUInt32 i32data[4];
};
void set8(int slot,PfxUInt8 data) {i8data[slot] = data;}
void set16(int slot,PfxUInt16 data) {i16data[slot] = data;}
void set32(int slot,PfxUInt32 data) {i32data[slot] = data;}
PfxUInt8 get8(int slot) const {return i8data[slot];}
PfxUInt16 get16(int slot) const {return i16data[slot];}
PfxUInt32 get32(int slot) const {return i32data[slot];}
};
struct SCE_PFX_ALIGNED(16) PfxSortData32 {
union {
PfxUInt8 i8data[32];
PfxUInt16 i16data[16];
PfxUInt32 i32data[8];
};
void set8(int slot,PfxUInt8 data) {i8data[slot] = data;}
void set16(int slot,PfxUInt16 data) {i16data[slot] = data;}
void set32(int slot,PfxUInt32 data) {i32data[slot] = data;}
PfxUInt8 get8(int slot) const {return i8data[slot];}
PfxUInt16 get16(int slot) const {return i16data[slot];}
PfxUInt32 get32(int slot) const {return i32data[slot];}
};
SCE_PFX_FORCE_INLINE
void pfxSetKey(PfxSortData16 &sortData,PfxUInt32 key) {sortData.set32(3,key);}
SCE_PFX_FORCE_INLINE
PfxUInt32 pfxGetKey(const PfxSortData16 &sortData) {return sortData.get32(3);}
SCE_PFX_FORCE_INLINE
void pfxSetKey(PfxSortData32 &sortData,PfxUInt32 key) {sortData.set32(7,key);}
SCE_PFX_FORCE_INLINE
PfxUInt32 pfxGetKey(const PfxSortData32 &sortData) {return sortData.get32(7);}
SCE_PFX_FORCE_INLINE
PfxUInt32 pfxCreateUniqueKey(PfxUInt32 i,PfxUInt32 j)
{
PfxUInt32 minIdx = SCE_PFX_MIN(i,j);
PfxUInt32 maxIdx = SCE_PFX_MAX(i,j);
return (maxIdx<<16)|(minIdx&0xffff);
}
} // namespace PhysicsEffects
} // namespace sce
#endif // _SCE_PFX_SORT_DATA_H

View File

@@ -0,0 +1,124 @@
/*
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_BROADPHASE_H_
#define _SCE_PFX_BROADPHASE_H_
#include "../../base_level/broadphase/pfx_broadphase_pair.h"
#include "../../base_level/broadphase/pfx_broadphase_proxy.h"
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../../base_level/collision/pfx_collidable.h"
#include "../task/pfx_task_manager.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Update Broadphase Proxies
#define SCE_PFX_OUT_OF_WORLD_BEHAVIOR_FIX_MOTION 0x01
#define SCE_PFX_OUT_OF_WORLD_BEHAVIOR_REMOVE_PROXY 0x02
struct PfxUpdateBroadphaseProxiesParam {
void *workBuff;
PfxUInt32 workBytes;
PfxBroadphaseProxy *proxiesX;
PfxBroadphaseProxy *proxiesY;
PfxBroadphaseProxy *proxiesZ;
PfxBroadphaseProxy *proxiesXb;
PfxBroadphaseProxy *proxiesYb;
PfxBroadphaseProxy *proxiesZb;
PfxRigidState *offsetRigidStates;
PfxCollidable *offsetCollidables;
PfxUInt32 numRigidBodies;
PfxUInt32 outOfWorldBehavior;
PfxVector3 worldCenter;
PfxVector3 worldExtent;
PfxUpdateBroadphaseProxiesParam() : outOfWorldBehavior(0) {}
};
struct PfxUpdateBroadphaseProxiesResult {
PfxInt32 numOutOfWorldProxies;
};
PfxUInt32 pfxGetWorkBytesOfUpdateBroadphaseProxies(PfxUInt32 numRigidBodies);
PfxUInt32 pfxGetWorkBytesOfUpdateBroadphaseProxies(PfxUInt32 numRigidBodies,PfxUInt32 maxTasks);
PfxInt32 pfxUpdateBroadphaseProxies(PfxUpdateBroadphaseProxiesParam &param,PfxUpdateBroadphaseProxiesResult &result);
PfxInt32 pfxUpdateBroadphaseProxies(PfxUpdateBroadphaseProxiesParam &param,PfxUpdateBroadphaseProxiesResult &result,PfxTaskManager *taskManager);
///////////////////////////////////////////////////////////////////////////////
// Find Pairs
struct PfxFindPairsParam {
void *workBuff;
PfxUInt32 workBytes;
void *pairBuff;
PfxUInt32 pairBytes;
PfxBroadphaseProxy *proxies;
PfxUInt32 numProxies;
PfxUInt32 maxPairs;
int axis;
};
struct PfxFindPairsResult {
PfxBroadphasePair *pairs;
PfxUInt32 numPairs;
};
PfxUInt32 pfxGetWorkBytesOfFindPairs(PfxUInt32 maxPairs,PfxUInt32 maxTasks=1);
PfxUInt32 pfxGetPairBytesOfFindPairs(PfxUInt32 maxPairs);
PfxInt32 pfxFindPairs(PfxFindPairsParam &param,PfxFindPairsResult &result);
PfxInt32 pfxFindPairs(PfxFindPairsParam &param,PfxFindPairsResult &result,PfxTaskManager *taskManager);
///////////////////////////////////////////////////////////////////////////////
// Decompose Pairs
struct PfxDecomposePairsParam {
void *workBuff;
PfxUInt32 workBytes;
void *pairBuff;
PfxUInt32 pairBytes;
PfxBroadphasePair *previousPairs;
PfxUInt32 numPreviousPairs;
PfxBroadphasePair *currentPairs;
PfxUInt32 numCurrentPairs;
};
struct PfxDecomposePairsResult {
PfxBroadphasePair *outNewPairs;
PfxUInt32 numOutNewPairs;
PfxBroadphasePair *outKeepPairs;
PfxUInt32 numOutKeepPairs;
PfxBroadphasePair *outRemovePairs;
PfxUInt32 numOutRemovePairs;
};
PfxUInt32 pfxGetWorkBytesOfDecomposePairs(PfxUInt32 numPreviousPairs,PfxUInt32 numCurrentPairs,int maxTasks=1);
PfxUInt32 pfxGetPairBytesOfDecomposePairs(PfxUInt32 numPreviousPairs,PfxUInt32 numCurrentPairs);
PfxInt32 pfxDecomposePairs(PfxDecomposePairsParam &param,PfxDecomposePairsResult &result);
PfxInt32 pfxDecomposePairs(PfxDecomposePairsParam &param,PfxDecomposePairsResult &result,PfxTaskManager *taskManager);
} //namespace PhysicsEffects
} //namespace sce
#endif /* _SCE_PFX_BROADPHASE_H_ */

View File

@@ -0,0 +1,38 @@
/*
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_BATCHED_RAY_CAST_H
#define _SCE_PFX_BATCHED_RAY_CAST_H
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../../base_level/collision/pfx_collidable.h"
#include "../../base_level/broadphase/pfx_broadphase_proxy.h"
#include "../task/pfx_task_manager.h"
#include "pfx_ray_cast.h"
///////////////////////////////////////////////////////////////////////////////
// Batched RayCast
namespace sce {
namespace PhysicsEffects {
void pfxCastRays(PfxRayInput *rayInputs,PfxRayOutput *rayOutputs,int numRays,PfxRayCastParam &param);
void pfxCastRays(PfxRayInput *rayInputs,PfxRayOutput *rayOutputs,int numRays,PfxRayCastParam &param,PfxTaskManager *taskManager);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_BATCHED_RAY_CAST_H

View File

@@ -0,0 +1,48 @@
/*
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_COLLISION_DETECTION_H_
#define _SCE_PFX_COLLISION_DETECTION_H_
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../../base_level/collision/pfx_collidable.h"
#include "../../base_level/collision/pfx_contact_manifold.h"
#include "../../base_level/solver/pfx_constraint_pair.h"
#include "../task/pfx_task_manager.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Detect Collision
struct PfxDetectCollisionParam {
PfxConstraintPair *contactPairs;
PfxUInt32 numContactPairs;
PfxContactManifold *offsetContactManifolds;
PfxRigidState *offsetRigidStates;
PfxCollidable *offsetCollidables;
PfxUInt32 numRigidBodies;
};
PfxInt32 pfxDetectCollision(PfxDetectCollisionParam &param);
PfxInt32 pfxDetectCollision(PfxDetectCollisionParam &param,PfxTaskManager *taskManager);
} //namespace PhysicsEffects
} //namespace sce
#endif /* _SCE_PFX_COLLISION_DETECTION_H_ */

View File

@@ -0,0 +1,78 @@
/*
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_ISLAND_GENERATION_H_
#define _SCE_PFX_ISLAND_GENERATION_H_
#include "../../base_level/solver/pfx_constraint_pair.h"
#include "../task/pfx_task_manager.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Island Generation
struct PfxIsland;
struct PfxIslandUnit;
struct PfxGenerateIslandParam {
void *islandBuff;
PfxUInt32 islandBytes;
PfxConstraintPair *pairs;
PfxUInt32 numPairs;
PfxUInt32 numObjects;
};
struct PfxGenerateIslandResult {
PfxIsland *island;
};
//J アイランド情報を使い終わるまでislandBuffを破棄しないでください
//E Keep islandBuff while the island is used
PfxUInt32 pfxGetIslandBytesOfGenerateIsland(PfxUInt32 numObjects);
PfxInt32 pfxGenerateIsland(PfxGenerateIslandParam &param,PfxGenerateIslandResult &result);
//E Access to island information
//J アイランド情報へのアクセス
//E Get the number of islands
//J アイランド数を取得する
PfxUInt32 pfxGetNumIslands(const PfxIsland *islands);
//E Get a island unit in a island
//J 指定したアイランドに含まれるユニット(剛体)にアクセス
PfxIslandUnit *pfxGetFirstUnitInIsland(const PfxIsland *islands,PfxUInt32 islandId);
PfxIslandUnit *pfxGetNextUnitInIsland(const PfxIslandUnit *islandUnit);
PfxUInt32 pfxGetUnitId(const PfxIslandUnit *islandUnit);
//E Get an index of an island which includes a specific unit
//J 指定したユニット(剛体)のアイランドインデックスを取得する
PfxUInt32 pfxGetIslandId(const PfxIsland *islands,PfxUInt32 unitId);
//E Add pairs and construct islands
//J アイランドにペアを追加する
PfxInt32 pfxAppendPairs(PfxIsland *island,PfxConstraintPair *pairs,PfxUInt32 numPairs);
//E Reset islands
//J アイランドリセット
void pfxResetIsland(PfxIsland *island);
} //namespace PhysicsEffects
} //namespace sce
#endif /* _SCE_PFX_ISLAND_GENERATION_H_ */

View File

@@ -0,0 +1,50 @@
/*
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_RAY_CAST_H
#define _SCE_PFX_RAY_CAST_H
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../../base_level/collision/pfx_collidable.h"
#include "../../base_level/collision/pfx_ray.h"
#include "../../base_level/broadphase/pfx_broadphase_proxy.h"
///////////////////////////////////////////////////////////////////////////////
// RayCast
namespace sce {
namespace PhysicsEffects {
struct PfxRayCastParam {
PfxRigidState *offsetRigidStates;
PfxCollidable *offsetCollidables;
PfxBroadphaseProxy *proxiesX;
PfxBroadphaseProxy *proxiesY;
PfxBroadphaseProxy *proxiesZ;
PfxBroadphaseProxy *proxiesXb;
PfxBroadphaseProxy *proxiesYb;
PfxBroadphaseProxy *proxiesZb;
PfxUInt32 numProxies;
SCE_PFX_PADDING(1,12)
PfxVector3 rangeCenter;
PfxVector3 rangeExtent;
};
void pfxCastSingleRay(const PfxRayInput &rayInput,PfxRayOutput &rayOutput,const PfxRayCastParam &param);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_RAY_CAST_H

View File

@@ -0,0 +1,46 @@
/*
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_REFRESH_CONTACTS_H
#define _SCE_PFX_REFRESH_CONTACTS_H
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../../base_level/solver/pfx_constraint_pair.h"
#include "../../base_level/collision/pfx_contact_manifold.h"
#include "../task/pfx_task_manager.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Refresh Contacts
struct PfxRefreshContactsParam {
PfxConstraintPair *contactPairs;
PfxUInt32 numContactPairs;
PfxContactManifold *offsetContactManifolds;
PfxRigidState *offsetRigidStates;
PfxUInt32 numRigidBodies;
};
PfxInt32 pfxRefreshContacts(PfxRefreshContactsParam &param);
PfxInt32 pfxRefreshContacts(PfxRefreshContactsParam &param,PfxTaskManager *taskManager);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_REFRESH_CONTACTS_H

View File

@@ -0,0 +1,46 @@
/*
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_LOW_LEVEL_INCLUDE_H
#define _SCE_PFX_LOW_LEVEL_INCLUDE_H
///////////////////////////////////////////////////////////////////////////////
// Physics Effects Low Level Headers
// Include base level headers
#include "../base_level/pfx_base_level_include.h"
// Include low level headers
#include "broadphase/pfx_broadphase.h"
#include "collision/pfx_collision_detection.h"
#include "collision/pfx_refresh_contacts.h"
#include "collision/pfx_batched_ray_cast.h"
#include "collision/pfx_ray_cast.h"
#include "collision/pfx_island_generation.h"
#include "solver/pfx_constraint_solver.h"
#include "solver/pfx_update_rigid_states.h"
#include "sort/pfx_parallel_sort.h"
// ARA begin insert new code
#ifdef USE_PTHREADS
#include "task/pfx_pthreads.h"
#endif
// ARA end
#endif // _SCE_PFX_LOW_LEVEL_INCLUDE_H

View File

@@ -0,0 +1,123 @@
/*
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_CONSTRAINT_SOLVER_H
#define _SCE_PFX_CONSTRAINT_SOLVER_H
#include "../../base_level/rigidbody/pfx_rigid_body.h"
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../../base_level/solver/pfx_solver_body.h"
#include "../../base_level/solver/pfx_constraint_pair.h"
#include "../../base_level/solver/pfx_joint.h"
#include "../../base_level/collision/pfx_contact_manifold.h"
#include "../task/pfx_task_manager.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Setup Solver Bodies
struct PfxSetupSolverBodiesParam {
PfxRigidState *states;
PfxRigidBody *bodies;
PfxSolverBody *solverBodies;
PfxUInt32 numRigidBodies;
};
PfxInt32 pfxSetupSolverBodies(PfxSetupSolverBodiesParam &param);
PfxInt32 pfxSetupSolverBodies(PfxSetupSolverBodiesParam &param,PfxTaskManager *taskManager);
///////////////////////////////////////////////////////////////////////////////
// Setup Constraints
struct PfxSetupContactConstraintsParam {
PfxConstraintPair *contactPairs;
PfxUInt32 numContactPairs;
PfxContactManifold *offsetContactManifolds;
PfxRigidState *offsetRigidStates;
PfxRigidBody *offsetRigidBodies;
PfxSolverBody *offsetSolverBodies;
PfxUInt32 numRigidBodies;
PfxFloat timeStep;
PfxFloat separateBias;
PfxSetupContactConstraintsParam()
{
timeStep = 0.016f;
separateBias = 0.2f;
}
};
PfxInt32 pfxSetupContactConstraints(PfxSetupContactConstraintsParam &param);
PfxInt32 pfxSetupContactConstraints(PfxSetupContactConstraintsParam &param,PfxTaskManager *taskManager);
struct PfxSetupJointConstraintsParam {
PfxConstraintPair *jointPairs;
PfxUInt32 numJointPairs;
PfxJoint *offsetJoints;
PfxRigidState *offsetRigidStates;
PfxRigidBody *offsetRigidBodies;
PfxSolverBody *offsetSolverBodies;
PfxUInt32 numRigidBodies;
PfxFloat timeStep;
PfxSetupJointConstraintsParam()
{
timeStep = 0.016f;
}
};
PfxInt32 pfxSetupJointConstraints(PfxSetupJointConstraintsParam &param);
PfxInt32 pfxSetupJointConstraints(PfxSetupJointConstraintsParam &param,PfxTaskManager *taskManager);
///////////////////////////////////////////////////////////////////////////////
// Solve Constraints
struct PfxSolveConstraintsParam {
void *workBuff;
PfxUInt32 workBytes;
PfxConstraintPair *contactPairs;
PfxUInt32 numContactPairs;
PfxContactManifold *offsetContactManifolds;
PfxConstraintPair *jointPairs;
PfxUInt32 numJointPairs;
PfxJoint *offsetJoints;
PfxRigidState *offsetRigidStates;
PfxSolverBody *offsetSolverBodies;
PfxUInt32 numRigidBodies;
PfxUInt32 iteration;
PfxSolveConstraintsParam()
{
iteration = 5;
}
};
PfxUInt32 pfxGetWorkBytesOfSolveConstraints(PfxUInt32 numRigidBodies,PfxUInt32 numContactPairs,PfxUInt32 numJointPairs,PfxUInt32 maxTasks=1);
PfxInt32 pfxSolveConstraints(PfxSolveConstraintsParam &param);
PfxInt32 pfxSolveConstraints(PfxSolveConstraintsParam &param,PfxTaskManager *taskManager);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_CONSTRAINT_SOLVER_H

View File

@@ -0,0 +1,69 @@
/*
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_JOINT_CONSTRAINT_FUNC_H_
#define _SCE_PFX_JOINT_CONSTRAINT_FUNC_H_
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../../base_level/solver/pfx_solver_body.h"
#include "../../base_level/solver/pfx_joint.h"
#include "../../base_level/solver/pfx_joint_constraint.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Setup Joint Constraint Func
typedef void (*PfxSetupJointConstraintFunc)(
PfxJoint &joint,
const PfxRigidState &stateA,
const PfxRigidState &stateB,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB,
PfxFloat timeStep);
PfxSetupJointConstraintFunc pfxGetSetupJointConstraintFunc(PfxUInt8 jointType);
int pfxSetSetupJointConstraintFunc(PfxUInt8 jointType,PfxSetupJointConstraintFunc func);
///////////////////////////////////////////////////////////////////////////////
// Warm Start Joint Constraint Func
typedef void (*PfxWarmStartJointConstraintFunc)(
PfxJoint &joint,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB);
PfxWarmStartJointConstraintFunc pfxGetWarmStartJointConstraintFunc(PfxUInt8 jointType);
int pfxSetWarmStartJointConstraintFunc(PfxUInt8 jointType,PfxWarmStartJointConstraintFunc func);
///////////////////////////////////////////////////////////////////////////////
// Solve Joint Constraint Func
typedef void (*PfxSolveJointConstraintFunc)(
PfxJoint &joint,
PfxSolverBody &solverBodyA,
PfxSolverBody &solverBodyB);
PfxSolveJointConstraintFunc pfxGetSolveJointConstraintFunc(PfxUInt8 jointType);
int pfxSetSolveJointConstraintFunc(PfxUInt8 jointType,PfxSolveJointConstraintFunc func);
} //namespace PhysicsEffects
} //namespace sce
#endif /* _PFX_JOINT_CONSTRAINT_FUNC_H_ */

View File

@@ -0,0 +1,45 @@
/*
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_UPDATE_RIGID_STATES_H_
#define _SCE_PFX_UPDATE_RIGID_STATES_H_
#include "../../base_level/rigidbody/pfx_rigid_body.h"
#include "../../base_level/rigidbody/pfx_rigid_state.h"
#include "../task/pfx_task_manager.h"
namespace sce {
namespace PhysicsEffects {
///////////////////////////////////////////////////////////////////////////////
// Update Rigid Body States
struct PfxUpdateRigidStatesParam {
PfxRigidState *states;
PfxRigidBody *bodies;
PfxUInt32 numRigidBodies;
PfxFloat timeStep;
};
PfxInt32 pfxUpdateRigidStates(PfxUpdateRigidStatesParam &param);
PfxInt32 pfxUpdateRigidStates(PfxUpdateRigidStatesParam &param,PfxTaskManager *taskManager);
} //namespace PhysicsEffects
} //namespace sce
#endif /* _SCE_PFX_UPDATE_RIGID_STATES_H_ */

View File

@@ -0,0 +1,40 @@
/*
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_PARALLEL_SORT_H
#define _SCE_PFX_PARALLEL_SORT_H
#include "../../base_level/sort/pfx_sort_data.h"
#include "../task/pfx_task_manager.h"
///////////////////////////////////////////////////////////////////////////////
// Parallel Sort
namespace sce {
namespace PhysicsEffects {
PfxInt32 pfxParallelSort(PfxSortData16 *data,PfxUInt32 numData,void *workBuff,PfxUInt32 workBytes);
PfxInt32 pfxParallelSort(PfxSortData32 *data,PfxUInt32 numData,void *workBuff,PfxUInt32 workBytes);
PfxInt32 pfxParallelSort(PfxSortData16 *data,PfxUInt32 numData,void *workBuff,PfxUInt32 workBytes,
PfxTaskManager *taskManager);
PfxInt32 pfxParallelSort(PfxSortData32 *data,PfxUInt32 numData,void *workBuff,PfxUInt32 workBytes,
PfxTaskManager *taskManager);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_PARALLEL_SORT_H

View File

@@ -0,0 +1,55 @@
/*
Applied Research Associates Inc. (c)2011
Redistribution and use in source and binary forms,
with or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Applied Research Associates Inc nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _SCE_PFX_PTHREADS_H
#define _SCE_PFX_PTHREADS_H
#include "../../base_level/base/pfx_common.h"
#include <errno.h>
namespace sce {
namespace PhysicsEffects {
class PfxBarrier;
class PfxCriticalSection;
class PfxTaskManager;
#define SCE_PFX_CHECK_PTHREADS_OUTCOME(result) \
if(0 != result) \
{ \
SCE_PFX_PRINTF("pthreads problem at line %i in file %s: %i %d\n", __LINE__, __FILE__, result, errno); \
}
PfxBarrier *PfxCreateBarrierPthreads(int n);
PfxCriticalSection *PfxCreateCriticalSectionPthreads();
PfxTaskManager *PfxCreateTaskManagerPthreads(PfxUInt32 numTasks,PfxUInt32 maxTasks,void *workBuff,PfxUInt32 workBytes);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_PTHREADS_H

View File

@@ -0,0 +1,53 @@
/*
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_SYNC_COMPONENTS_H
#define _SCE_PFX_SYNC_COMPONENTS_H
#include "../../base_level/base/pfx_common.h"
//J スレッド間の同期をとるための同期コンポネント
//E Components for threads sychronization
namespace sce {
namespace PhysicsEffects {
class PfxBarrier {
public:
PfxBarrier() {}
virtual ~PfxBarrier() {}
virtual void sync() = 0;
virtual void setMaxCount(int n) = 0;
virtual int getMaxCount() = 0;
};
class PfxCriticalSection {
public:
PfxCriticalSection() {}
virtual ~PfxCriticalSection() {}
PfxUInt32 m_commonBuff[32];
virtual PfxUInt32 getSharedParam(int i) = 0;
virtual void setSharedParam(int i,PfxUInt32 p) = 0;
virtual void lock() = 0;
virtual void unlock() = 0;
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_SYNC_COMPONENTS_H

View File

@@ -0,0 +1,96 @@
/*
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_TASK_MANAGER_H
#define _SCE_PFX_TASK_MANAGER_H
#include "../../base_level/base/pfx_common.h"
#include "../../base_level/base/pfx_heap_manager.h"
#include "pfx_sync_components.h"
#define SCE_PFX_IO_BUFF_BYTES 1048576
namespace sce {
namespace PhysicsEffects {
//J 並列処理するためのタスクマネージャクラス
//E Task manager class for parallel computation
struct PfxTaskArg
{
int taskId;
int maxTasks;
PfxBarrier *barrier;
PfxCriticalSection *criticalSection;
void *io;
PfxUInt32 data[4];
};
typedef void (*PfxTaskEntry)(PfxTaskArg *arg);
class PfxTaskManager
{
protected:
PfxUInt32 m_numTasks;
PfxUInt32 m_maxTasks;
SCE_PFX_PADDING(1,4)
PfxUInt8 SCE_PFX_ALIGNED(16) m_ioBuff[SCE_PFX_IO_BUFF_BYTES];
PfxHeapManager m_pool;
PfxHeapManager m_ioPool;
PfxTaskEntry m_taskEntry;
PfxTaskArg *m_taskArg;
SCE_PFX_PADDING(2,8)
PfxTaskManager() : m_pool(NULL,0),m_ioPool(NULL,0) {}
public:
void *allocate(size_t bytes) {return m_ioPool.allocate(bytes);}
void deallocate(void *p) {m_ioPool.deallocate(p);}
void clearPool() {m_ioPool.clear();}
virtual PfxUInt32 getSharedParam(int i) = 0;
virtual void setSharedParam(int i,PfxUInt32 p) = 0;
virtual void startTask(int taskId,void *io,PfxUInt32 data1,PfxUInt32 data2,PfxUInt32 data3,PfxUInt32 data4) = 0;
virtual void waitTask(int &taskId,PfxUInt32 &data1,PfxUInt32 &data2,PfxUInt32 &data3,PfxUInt32 &data4) = 0;
virtual void setTaskEntry(void *entry) {m_taskEntry = (PfxTaskEntry)entry;}
public:
PfxTaskManager(PfxUInt32 numTasks,PfxUInt32 maxTasks,void *workBuff,PfxUInt32 workBytes)
: m_pool((unsigned char*)workBuff,workBytes),m_ioPool(m_ioBuff,SCE_PFX_IO_BUFF_BYTES)
{
SCE_PFX_ASSERT(numTasks>0);
SCE_PFX_ASSERT(numTasks<=maxTasks);
m_numTasks = numTasks;
m_maxTasks = maxTasks;
m_taskArg = (PfxTaskArg*)m_pool.allocate(sizeof(PfxTaskArg)*m_maxTasks);
}
virtual ~PfxTaskManager()
{
m_pool.clear();
}
virtual PfxUInt32 getNumTasks() const {return m_numTasks;}
virtual void setNumTasks(PfxUInt32 tasks) {m_numTasks = SCE_PFX_MIN(tasks,m_maxTasks);}
virtual void initialize() = 0;
virtual void finalize() = 0;
};
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_TASK_MANAGER_H

View File

@@ -0,0 +1,60 @@
/*
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
*/
///////////////////////////////////////////////////////////////////////////////
//E Mass , Inertia tensor calculation
//J 質量・慣性テンソルの算出
#ifndef _SCE_PFX_MASS_H
#define _SCE_PFX_MASS_H
#include "../base_level/base/pfx_common.h"
namespace sce {
namespace PhysicsEffects {
// Box
PfxFloat pfxCalcMassBox(PfxFloat density,const PfxVector3 &halfExtent);
PfxMatrix3 pfxCalcInertiaBox(const PfxVector3 &halfExtent,PfxFloat mass);
// Sphere
PfxFloat pfxCalcMassSphere(PfxFloat density,PfxFloat radius);
PfxMatrix3 pfxCalcInertiaSphere(PfxFloat radius,PfxFloat mass);
// Cylinder
PfxFloat pfxCalcMassCylinder(PfxFloat density,PfxFloat halfLength,PfxFloat radius);
PfxMatrix3 pfxCalcInertiaCylinderX(PfxFloat halfLength,PfxFloat radius,PfxFloat mass);
PfxMatrix3 pfxCalcInertiaCylinderY(PfxFloat halfLength,PfxFloat radius,PfxFloat mass);
PfxMatrix3 pfxCalcInertiaCylinderZ(PfxFloat halfLength,PfxFloat radius,PfxFloat mass);
///////////////////////////////////////////////////////////////////////////////
//E Mass convertion
//J 質量の移動・回転・合成
// translation
//E returns translated inertia tensor
//J 移動後の慣性テンソルを返します
PfxMatrix3 pfxMassTranslate(PfxFloat mass,const PfxMatrix3 &inertia,const PfxVector3 &translation);
// rotation
//E returns rotated inertia tensor
//J 回転後の慣性テンソルを返します
PfxMatrix3 pfxMassRotate(const PfxMatrix3 &inertia,const PfxMatrix3 &rotate);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_MASS_H

View File

@@ -0,0 +1,96 @@
/*
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_MESH_CREATOR_H
#define _SCE_PFX_MESH_CREATOR_H
#include "../base_level/collision/pfx_large_tri_mesh.h"
namespace sce {
namespace PhysicsEffects {
//J フラグに指定する値
//E Specify these values to a flag parameter
#define SCE_PFX_MESH_FLAG_NORMAL_FLIP 0x01
#define SCE_PFX_MESH_FLAG_16BIT_INDEX 0x02
#define SCE_PFX_MESH_FLAG_32BIT_INDEX 0x04
#define SCE_PFX_MESH_FLAG_AUTO_ELIMINATION 0x08
#define SCE_PFX_MESH_FLAG_AUTO_THICKNESS 0x10
///////////////////////////////////////////////////////////////////////////////
// Convex Mesh
struct PfxCreateConvexMeshParam {
PfxUInt32 flag;
PfxFloat *verts;
PfxUInt32 numVerts;
void *triangles;
PfxUInt32 numTriangles;
PfxUInt32 vertexStrideBytes;
PfxUInt32 triangleStrideBytes;
PfxCreateConvexMeshParam()
{
flag = SCE_PFX_MESH_FLAG_16BIT_INDEX|SCE_PFX_MESH_FLAG_AUTO_ELIMINATION;
verts = NULL;
triangles = NULL;
numVerts = 0;
numTriangles = 0;
vertexStrideBytes = sizeof(PfxFloat)*3;
triangleStrideBytes = sizeof(PfxUInt16)*3;
}
};
PfxInt32 pfxCreateConvexMesh(PfxConvexMesh &convex,const PfxCreateConvexMeshParam &param);
///////////////////////////////////////////////////////////////////////////////
// Large Mesh
struct PfxCreateLargeTriMeshParam {
PfxUInt32 flag;
PfxFloat *verts;
PfxUInt32 numVerts;
void *triangles;
PfxUInt32 numTriangles;
PfxUInt32 vertexStrideBytes;
PfxUInt32 triangleStrideBytes;
PfxUInt32 numFacetsLimit;
PfxFloat islandsRatio;
PfxFloat defaultThickness;
PfxCreateLargeTriMeshParam()
{
flag = SCE_PFX_MESH_FLAG_16BIT_INDEX|SCE_PFX_MESH_FLAG_AUTO_ELIMINATION;
verts = NULL;
triangles = NULL;
numVerts = 0;
numTriangles = 0;
vertexStrideBytes = sizeof(PfxFloat)*3;
triangleStrideBytes = sizeof(PfxUInt16)*3;
numFacetsLimit = 15;
islandsRatio = 0.2f;
defaultThickness = 0.025f;
}
};
PfxInt32 pfxCreateLargeTriMesh(PfxLargeTriMesh &lmesh,const PfxCreateLargeTriMeshParam &param);
void pfxReleaseLargeTriMesh(PfxLargeTriMesh &lmesh);
} //namespace PhysicsEffects
} //namespace sce
#endif // _SCE_PFX_MESH_CREATOR_H

View File

@@ -0,0 +1,26 @@
/*
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_UTIL_INCLUDE_H
#define _SCE_PFX_UTIL_INCLUDE_H
///////////////////////////////////////////////////////////////////////////////
// Physics Effects Utility Headers
#include "pfx_mass.h"
#include "pfx_mesh_creator.h"
#endif // _SCE_PFX_UTIL_INCLUDE_H