aboutsummaryrefslogtreecommitdiff
path: root/APEX_1.4/shared/general/RenderDebug/src
diff options
context:
space:
mode:
authorgit perforce import user <a@b>2016-10-25 12:29:14 -0600
committerSheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees>2016-10-25 18:56:37 -0500
commit3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch)
treefa6485c169e50d7415a651bf838f5bcd0fd3bfbd /APEX_1.4/shared/general/RenderDebug/src
downloadphysx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz
physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip
Initial commit:
PhysX 3.4.0 Update @ 21294896 APEX 1.4.0 Update @ 21275617 [CL 21300167]
Diffstat (limited to 'APEX_1.4/shared/general/RenderDebug/src')
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/ClientServer.cpp1133
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/FileRenderDebug.cpp621
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/Hull2MeshEdges.cpp459
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/InternalRenderDebug.cpp2708
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/ProcessRenderDebug.cpp3342
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/PsCommLayer.cpp567
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/PsCommStream.cpp291
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/RenderDebug.cpp817
-rw-r--r--APEX_1.4/shared/general/RenderDebug/src/RenderDebugDLLMain.cpp37
9 files changed, 9975 insertions, 0 deletions
diff --git a/APEX_1.4/shared/general/RenderDebug/src/ClientServer.cpp b/APEX_1.4/shared/general/RenderDebug/src/ClientServer.cpp
new file mode 100644
index 00000000..f48171b4
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/ClientServer.cpp
@@ -0,0 +1,1133 @@
+#include "ClientServer.h"
+#include "GetArgs.h"
+#include "PsCommLayer.h"
+#include "PsCommStream.h"
+#include "PsArray.h"
+#include "PsUserAllocated.h"
+#include "PxIntrinsics.h"
+#include "PsMutex.h"
+#include "PsThread.h"
+#include "PsString.h"
+#include "PsTime.h"
+#include <stdio.h>
+
+#define MAX_SERVER_COMMAND_STRING 16384
+
+enum PacketType
+{
+ PT_PRIMITIVES = 100,
+ PT_COMMAND,
+ PT_ACK,
+ PT_COMM_VERSION,
+ PT_FINALIZE_FRAME,
+ PT_APPLICATION_NAME,
+ PT_REQUEST_REMOTE_RESOURCE,
+ PT_REMOTE_RESOURCE,
+ PT_INPUT_EVENT
+};
+
+struct NetworkCommmand
+{
+ NetworkCommmand(void)
+ {
+ mPacketType = PT_COMMAND;
+ mCommandLength = 0;
+ mCommand = NULL;
+ }
+ uint32_t mPacketType;
+ uint32_t mCommandLength;
+ char *mCommand;
+};
+
+struct NetworkFrame
+{
+ NetworkFrame(void)
+ {
+ mPacketType = PT_PRIMITIVES;
+ }
+
+ uint32_t getPrefixSize(void) const
+ {
+ return sizeof(NetworkFrame)-(sizeof(void *)*2);
+ }
+
+ uint32_t mPacketType;
+ uint32_t mFrameCount;
+ uint32_t mPrimType;
+ uint32_t mPrimCount;
+ uint32_t mDataLength;
+ void *mData;
+ void *mBaseData;
+};
+
+#define MAX_RESOURCE_STRING 256
+
+class RequestRemoteResource
+{
+public:
+ uint32_t mCommand;
+ char mNameSpace[MAX_RESOURCE_STRING];
+ char mResourceName[MAX_RESOURCE_STRING];
+};
+
+class RemoteResourcePacket
+{
+public:
+ uint32_t mCommand;
+ uint32_t mLength;
+ uint32_t mBigEndian;
+ char mNameSpace[MAX_RESOURCE_STRING];
+ char mResourceName[MAX_RESOURCE_STRING];
+};
+
+class RemoteResource : public RemoteResourcePacket
+{
+public:
+ RemoteResource(void)
+ {
+ mData = NULL;
+ }
+ void *mData;
+};
+
+typedef physx::shdfnd::Array< NetworkFrame > NetworkFrameArray;
+typedef physx::shdfnd::Array< NetworkCommmand > NetworkCommandArray;
+typedef physx::shdfnd::Array< RemoteResource > RemoteResourceArray;
+typedef physx::shdfnd::Array< RENDER_DEBUG::InputEvent > InputEventArray;
+
+
+static PX_INLINE void swap4Bytes(void* _data)
+{
+ char *data = static_cast<char *>(_data);
+ char one_byte;
+ one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
+ one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
+}
+
+static PX_INLINE bool isBigEndian()
+{
+ int32_t i = 1;
+ return *(reinterpret_cast<char*>(&i))==0;
+}
+
+
+struct ServerCommandString
+{
+ ServerCommandString(void)
+ {
+ mCommandString[0] = 0;
+ }
+ char mCommandString[MAX_SERVER_COMMAND_STRING];
+};
+
+class ClientServerImpl : public ClientServer, public physx::shdfnd::UserAllocated
+{
+ PX_NOCOPY(ClientServerImpl)
+public:
+ ClientServerImpl(void)
+ {
+
+ }
+
+ ClientServerImpl(RENDER_DEBUG::RenderDebug::Desc &desc) :
+ mIncomingNetworkFrames(PX_DEBUG_EXP("ClientServer::mIncomingNetworkFrames")),
+ mNetworkFrames(PX_DEBUG_EXP("ClientServer::mNetworkFrames")),
+ mNetworkCommands(PX_DEBUG_EXP("ClientServer::mNetworkCommands")),
+ mRemoteResources(PX_DEBUG_EXP("ClientServer::mRemoteResource"))
+ {
+ mSkipFrame = false;
+ physx::shdfnd::strlcpy(mApplicationName,512,desc.applicationName);
+ mStreamName[0] = 0;
+ mDataSent = false;
+ mServerStallCallback = desc.serverStallCallback;
+ mRenderDebugResource = desc.renderDebugResource;
+ mBadVersion = true; // the version number is presumed bad until we know otherwise
+ mMaxServerWait = desc.maxServerWait;
+ mReceivedAck = true;
+ mCurrentNetworkFrame = 0;
+ mLastProcessNetworkFrame = 0;
+ mCommStream = NULL;
+ mCommLayer = NULL;
+ mCurrentCommLayer = NULL;
+ mLastFrame = 0;
+ mHaveApplicationName = false;
+ mMeshId = 100000; // base mesh id
+ mUsedMeshId = false;
+ mIsServer = desc.runMode == RENDER_DEBUG::RenderDebug::RM_SERVER;
+ mStreamCount = 1;
+ mWasConnected = false;
+ mCommLayer = createCommLayer(desc.hostName,desc.portNumber,mIsServer);
+ setStreamFilename(desc.streamFileName);
+ if ( mCommLayer == NULL )
+ {
+ desc.errorCode = "Failed to create connection";
+ }
+ else if ( !mIsServer )
+ {
+ sendVersionPacket();
+ }
+
+ }
+
+ virtual ~ClientServerImpl(void)
+ {
+ if ( mCommLayer )
+ {
+ mCommLayer->release();
+ }
+ if ( mCommStream )
+ {
+ mCommStream->release();
+ }
+ releaseNetworkFrames();
+ releaseIncomingNetworkFrames();
+ releaseRemoteResources();
+ releaseNetworkCommands();
+ }
+
+ void sendVersionPacket(void)
+ {
+ if ( !mCurrentCommLayer ) return;
+ uint32_t packet[2];
+ packet[0] = PT_COMM_VERSION;
+ packet[1] = RENDER_DEBUG_COMM_VERSION;
+ mCurrentCommLayer->sendMessage(packet,sizeof(packet));
+ }
+
+ void sendApplicationNamePacket(void)
+ {
+ if ( !mCurrentCommLayer ) return;
+ uint32_t packet[(512/4)+1];
+ packet[0] = PT_APPLICATION_NAME;
+ physx::intrinsics::memCopy(&packet[1],mApplicationName,512);
+ mCurrentCommLayer->sendMessage(packet,sizeof(packet));
+ }
+
+ virtual void release(void)
+ {
+ delete this;
+ }
+
+ virtual bool isServer(void) const
+ {
+ return mIsServer;
+ }
+
+ virtual void recordPrimitives(uint32_t frameCount,
+ uint32_t primType,
+ uint32_t primCount,
+ uint32_t dataLength,
+ const void *data)
+ {
+ mLastFrame = frameCount;
+
+ if ( mCurrentCommLayer && !mIsServer )
+ {
+ if ( mCurrentCommLayer->isConnected() ) // if we still have a connection..
+ {
+ // If we haven't caught up in
+ uint32_t sendSize = sizeof(uint32_t)*5+dataLength;
+ void *sendData = PX_ALLOC(sendSize,"sendData");
+ uint32_t *sendDataHeader = static_cast<uint32_t *>(sendData);
+ sendDataHeader[0] = PT_PRIMITIVES;
+ sendDataHeader[1] = frameCount;
+ sendDataHeader[2] = primType;
+ sendDataHeader[3] = primCount;
+ sendDataHeader[4] = dataLength;
+ sendDataHeader+=5;
+ physx::intrinsics::memCopy(sendDataHeader,data,dataLength);
+ mCurrentCommLayer->sendMessage(sendData,sendSize);
+ PX_FREE(sendData);
+ mDataSent = true;
+ }
+ }
+
+ }
+
+ void processNetworkData(void)
+ {
+ bool isBigEndianPacket;
+ uint32_t newDataSize = mCurrentCommLayer->peekMessage(isBigEndianPacket);
+ bool endOfFrame = false;
+ while ( newDataSize && !endOfFrame )
+ {
+ void *readData = PX_ALLOC(newDataSize,"readData");
+ bool freeReadData = true;
+ uint32_t rlen = mCurrentCommLayer->getMessage(readData,newDataSize,isBigEndianPacket);
+
+ if ( rlen == newDataSize )
+ {
+ bool needEndianSwap = false;
+ uint32_t type = *static_cast<uint32_t *>(readData);
+ if ( isBigEndianPacket != isBigEndian() )
+ {
+ needEndianSwap = true;
+ }
+ if ( needEndianSwap )
+ {
+ swap4Bytes(&type);
+ }
+ switch ( type )
+ {
+ case PT_APPLICATION_NAME:
+ {
+ uint32_t *packet = static_cast<uint32_t *>(readData);
+ physx::intrinsics::memCopy(mApplicationName,packet+1,512);
+ mHaveApplicationName = true;
+ }
+ break;
+ case PT_COMM_VERSION:
+ {
+ if ( mIsServer ) // if we are the server, tell the client our version number
+ {
+ sendVersionPacket(); // inform the client that we are of the same version
+ }
+ else
+ {
+ sendApplicationNamePacket(); // if we are the client, tell the server the name of our application
+ }
+ uint32_t *packet = static_cast<uint32_t *>(readData);
+ if ( needEndianSwap )
+ {
+ swap4Bytes(&packet[1]);
+ }
+ if ( packet[1] == RENDER_DEBUG_COMM_VERSION ) // if it is the same version as us, no problems!
+ {
+ mBadVersion = false;
+ }
+ else
+ {
+ mBadVersion = true;
+ }
+ }
+ break;
+ case PT_PRIMITIVES:
+ if ( !mBadVersion ) // if we have agreed upon each other's version number then we can process the data stream, otherwise..not so much
+ {
+ // as expected..
+ NetworkFrame nframe;
+ uint32_t *header = static_cast<uint32_t *>(readData);
+
+ nframe.mFrameCount = header[1];
+ nframe.mPrimType = header[2];
+ nframe.mPrimCount = header[3];
+ nframe.mDataLength = header[4];
+ nframe.mData = &header[5];
+
+ if ( needEndianSwap )
+ {
+ swap4Bytes(&nframe.mFrameCount);
+ swap4Bytes(&nframe.mPrimType);
+ swap4Bytes(&nframe.mPrimCount);
+ swap4Bytes(&nframe.mDataLength);
+ }
+
+ nframe.mBaseData = readData;
+ freeReadData = false;
+
+ if ( nframe.mFrameCount != mCurrentNetworkFrame )
+ {
+ for (uint32_t j=0; j<mIncomingNetworkFrames.size(); j++)
+ {
+ NetworkFrame &nf = mIncomingNetworkFrames[j];
+ uint32_t pcount = nf.mPrimCount;
+ const uint8_t *scan = static_cast<const uint8_t *>(nf.mData);
+ for (uint32_t i=0; i<pcount; i++)
+ {
+ RENDER_DEBUG::DebugPrimitive *prim = const_cast<RENDER_DEBUG::DebugPrimitive *>(reinterpret_cast<const RENDER_DEBUG::DebugPrimitive *>(scan));
+ if ( needEndianSwap )
+ {
+ endianSwap(prim);
+ }
+
+ switch ( uint32_t(prim->mCommand) )
+ {
+ case RENDER_DEBUG::DebugCommand::DEBUG_CREATE_TRIANGLE_MESH:
+ {
+ RENDER_DEBUG::DebugCreateTriangleMesh *d = static_cast< RENDER_DEBUG::DebugCreateTriangleMesh *>(prim);
+ uint32_t *hackMeshId = reinterpret_cast<uint32_t *>(d);
+ hackMeshId[2]+=mMeshId;
+ mUsedMeshId = true;
+ }
+ break;
+ case RENDER_DEBUG::DebugCommand::DEBUG_REFRESH_TRIANGLE_MESH_VERTICES:
+ {
+ RENDER_DEBUG::DebugRefreshTriangleMeshVertices *d = static_cast< RENDER_DEBUG::DebugRefreshTriangleMeshVertices *>(prim);
+ uint32_t *hackMeshId = reinterpret_cast<uint32_t *>(d);
+ hackMeshId[2]+=mMeshId;
+ mUsedMeshId = true;
+ }
+ break;
+ case RENDER_DEBUG::DebugCommand::DEBUG_RENDER_TRIANGLE_MESH_INSTANCES:
+ {
+ RENDER_DEBUG::DebugRenderTriangleMeshInstances *d = static_cast<RENDER_DEBUG::DebugRenderTriangleMeshInstances *>(prim);
+ uint32_t *hackMeshId = reinterpret_cast<uint32_t *>(d);
+ hackMeshId[2]+=mMeshId;
+ mUsedMeshId = true;
+ }
+ break;
+ case RENDER_DEBUG::DebugCommand::DEBUG_RENDER_POINTS:
+ {
+ RENDER_DEBUG::DebugRenderPoints *d = static_cast<RENDER_DEBUG::DebugRenderPoints *>(prim);
+ uint32_t *hackMeshId = reinterpret_cast<uint32_t *>(d);
+ hackMeshId[2]+=mMeshId;
+ mUsedMeshId = true;
+ }
+ break;
+ case RENDER_DEBUG::DebugCommand::DEBUG_CONVEX_HULL:
+ printf("Debug me");
+ break;
+ case RENDER_DEBUG::DebugCommand::DEBUG_RELEASE_TRIANGLE_MESH:
+ {
+ RENDER_DEBUG::DebugReleaseTriangleMesh *d = static_cast<RENDER_DEBUG::DebugReleaseTriangleMesh *>(prim);
+ d->mMeshId+=mMeshId;
+ mUsedMeshId = true;
+ }
+ break;
+ case RENDER_DEBUG::DebugCommand::DEBUG_SKIP_FRAME:
+ mSkipFrame = true;
+ break;
+ }
+ uint32_t plen = RENDER_DEBUG::DebugCommand::getPrimtiveSize(*prim);
+ scan+=plen;
+ }
+ }
+ endOfFrame = true;
+ if ( mSkipFrame )
+ {
+ mSkipFrame = false;
+ releaseIncomingNetworkFrames();
+ }
+ else
+ {
+ releaseNetworkFrames(); // release previous network frames
+ mNetworkFrames = mIncomingNetworkFrames;
+ mIncomingNetworkFrames.clear();
+ }
+ mCurrentNetworkFrame = nframe.mFrameCount;
+ mIncomingNetworkFrames.pushBack(nframe);
+
+ if ( mIsServer )
+ {
+ // if we are the server, we should send an ACK to the client so that they know that we processed their frame of data.
+ uint32_t ack = PT_ACK;
+ mCurrentCommLayer->sendMessage(&ack,sizeof(ack));
+ }
+ }
+ else
+ {
+ mIncomingNetworkFrames.pushBack(nframe);
+ }
+ }
+ break;
+ case PT_COMMAND:
+ if ( !mBadVersion )
+ {
+ NetworkCommmand c;
+ uint32_t *header = static_cast<uint32_t *>(readData);
+ c.mCommandLength = header[1];
+ if ( needEndianSwap )
+ {
+ swap4Bytes(&c.mCommandLength);
+ }
+ c.mCommand = static_cast<char*>(PX_ALLOC(c.mCommandLength+1,"NetworkCommand"));
+ physx::intrinsics::memCopy(c.mCommand,&header[2],c.mCommandLength+1);
+ mNetworkCommandMutex.lock();
+ mNetworkCommands.pushBack(c);
+ mNetworkCommandMutex.unlock();
+ }
+ break;
+ case PT_REMOTE_RESOURCE:
+ if ( !mBadVersion )
+ {
+ RemoteResourcePacket *rr = static_cast<RemoteResourcePacket *>(readData);
+ if ( needEndianSwap )
+ {
+ swap4Bytes(&rr->mLength);
+ swap4Bytes(&rr->mBigEndian);
+ }
+ uint32_t bigEndianPacket = isBigEndianPacket ? uint32_t(1) : uint32_t(0);
+ PX_UNUSED(bigEndianPacket);
+ PX_ASSERT( bigEndianPacket == rr->mBigEndian );
+ RemoteResource sr;
+ RemoteResourcePacket *prr = static_cast< RemoteResource *>(&sr);
+ *prr = *rr;
+ sr.mData = PX_ALLOC(sr.mLength,"RemoteResource");
+ rr++;
+ physx::intrinsics::memCopy(sr.mData,rr,sr.mLength);
+ mRemoteResources.pushBack(sr);
+ }
+ break;
+ case PT_INPUT_EVENT:
+ {
+ RENDER_DEBUG::InputEvent e = *static_cast<const RENDER_DEBUG::InputEvent *>(readData);
+ if ( needEndianSwap )
+ {
+ swap4Bytes(&e.mId);
+ swap4Bytes(&e.mCommunicationsFrame);
+ swap4Bytes(&e.mRenderFrame);
+ swap4Bytes(&e.mEventType);
+ swap4Bytes(&e.mSensitivity);
+ swap4Bytes(&e.mDigitalValue);
+ swap4Bytes(&e.mAnalogValue);
+ swap4Bytes(&e.mMouseX);
+ swap4Bytes(&e.mMouseY);
+ swap4Bytes(&e.mMouseDX);
+ swap4Bytes(&e.mMouseDY);
+ swap4Bytes(&e.mWindowSizeX);
+ swap4Bytes(&e.mWindowSizeY);
+ swap4Bytes(&e.mEyePosition[0]);
+ swap4Bytes(&e.mEyePosition[1]);
+ swap4Bytes(&e.mEyePosition[2]);
+ swap4Bytes(&e.mEyeDirection[0]);
+ swap4Bytes(&e.mEyeDirection[1]);
+ swap4Bytes(&e.mEyeDirection[2]);
+ }
+ mInputEvents.pushBack(e);
+ }
+ break;
+ case PT_REQUEST_REMOTE_RESOURCE:
+ if ( !mBadVersion )
+ {
+ const RequestRemoteResource *rr = static_cast<const RequestRemoteResource *>(readData);
+ if ( mRenderDebugResource )
+ {
+ uint32_t len;
+ const void *data = mRenderDebugResource->requestResource(rr->mNameSpace,rr->mResourceName,len);
+ if ( data )
+ {
+ sendRemoteResource(rr->mNameSpace,rr->mResourceName,data,len);
+ mRenderDebugResource->releaseResource(data,len,rr->mNameSpace,rr->mResourceName);
+ }
+ }
+ }
+ break;
+ case PT_FINALIZE_FRAME:
+ {
+ uint32_t *header = static_cast<uint32_t *>(readData);
+ if ( needEndianSwap )
+ {
+ swap4Bytes(&header[1]);
+ }
+ mCurrentNetworkFrame = header[1];
+ if ( mIsServer )
+ {
+ // if we are the server, we should send an ACK to the client so that they know that we processed their frame of data.
+ uint32_t ack = PT_ACK;
+ mCurrentCommLayer->sendMessage(&ack,sizeof(ack));
+ }
+ }
+ break;
+ case PT_ACK:
+ mReceivedAck = true;
+ break;
+ }
+ }
+ if ( freeReadData )
+ {
+ PX_FREE(readData);
+ }
+ newDataSize = mCurrentCommLayer->peekMessage(isBigEndianPacket);
+ }
+
+ }
+
+ void processFrame(RENDER_DEBUG::ProcessRenderDebug *processRenderDebug,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ if ( !mCurrentCommLayer ) return;
+
+ if ( mIsServer )
+ {
+ if ( mCommStream && !mCommStream->isValid() )
+ {
+ mCommStream->release();
+ mCommStream = NULL;
+ mCurrentCommLayer = mCommLayer;
+ }
+ if ( mCurrentCommLayer->hasClient() )
+ {
+ mWasConnected = true;
+ }
+ else if ( mWasConnected )
+ {
+ if ( mCommStream )
+ {
+ internalSetStreamFilename(mStreamName);
+ }
+ mWasConnected = false;
+ }
+ }
+
+
+ if ( !mCurrentCommLayer->isConnected() ) return;
+
+ processNetworkData();
+
+ if ( !mNetworkFrames.empty() )
+ {
+ uint32_t lastDisplayType = 0;
+
+ for (uint32_t j=0; j<mNetworkFrames.size(); j++)
+ {
+ NetworkFrame &nf = mNetworkFrames[j];
+
+ if ( j == 0 )
+ {
+ lastDisplayType = nf.mPrimType;
+ }
+
+ uint32_t ipcount = nf.mPrimCount;
+ if ( ipcount > MAX_SEND_BUFFER )
+ {
+ ipcount = MAX_SEND_BUFFER;
+ }
+ const uint8_t *scan = static_cast<const uint8_t *>(nf.mData);
+ uint32_t pcount = 0;
+ for (uint32_t i=0; i<ipcount; i++)
+ {
+ RENDER_DEBUG::DebugPrimitive *prim = const_cast<RENDER_DEBUG::DebugPrimitive *>(reinterpret_cast<const RENDER_DEBUG::DebugPrimitive *>(scan));
+ bool includePrimitive = true;
+ if ( mCurrentNetworkFrame == mLastProcessNetworkFrame )
+ {
+ switch ( uint32_t(prim->mCommand) )
+ {
+ case RENDER_DEBUG::DebugCommand::DEBUG_MESSAGE:
+ case RENDER_DEBUG::DebugCommand::DEBUG_CREATE_TRIANGLE_MESH:
+ case RENDER_DEBUG::DebugCommand::DEBUG_REFRESH_TRIANGLE_MESH_VERTICES:
+ case RENDER_DEBUG::DebugCommand::DEBUG_RELEASE_TRIANGLE_MESH:
+ case RENDER_DEBUG::DebugCommand::DEBUG_CREATE_CUSTOM_TEXTURE:
+ case RENDER_DEBUG::DebugCommand::DEBUG_REGISTER_INPUT_EVENT:
+ case RENDER_DEBUG::DebugCommand::DEBUG_RESET_INPUT_EVENTS:
+ case RENDER_DEBUG::DebugCommand::DEBUG_UNREGISTER_INPUT_EVENT:
+ case RENDER_DEBUG::DebugCommand::DEBUG_SKIP_FRAME:
+ includePrimitive = false;
+ break;
+ }
+ }
+ if ( includePrimitive )
+ {
+ mDebugPrimitives[pcount] = prim;
+ pcount++;
+ }
+ uint32_t plen = RENDER_DEBUG::DebugCommand::getPrimtiveSize(*prim);
+ scan+=plen;
+ }
+ if ( lastDisplayType != nf.mPrimType )
+ {
+ processRenderDebug->flush(iface,static_cast<RENDER_DEBUG::ProcessRenderDebug::DisplayType>(lastDisplayType));
+ lastDisplayType = nf.mPrimType;
+ }
+ processRenderDebug->processRenderDebug(const_cast<const RENDER_DEBUG::DebugPrimitive **>(reinterpret_cast<RENDER_DEBUG::DebugPrimitive **>(mDebugPrimitives)),
+ pcount,
+ iface,
+ static_cast<RENDER_DEBUG::ProcessRenderDebug::DisplayType>(nf.mPrimType));
+ }
+ processRenderDebug->flush(iface,static_cast<RENDER_DEBUG::ProcessRenderDebug::DisplayType>(lastDisplayType));
+ processRenderDebug->flushFrame(iface);
+ mLastProcessNetworkFrame = mCurrentNetworkFrame;
+ }
+ }
+
+ void releaseNetworkCommands(void)
+ {
+ for (uint32_t i=0; i<mNetworkCommands.size(); i++)
+ {
+ NetworkCommmand nc = mNetworkCommands[i];
+ PX_FREE(nc.mCommand);
+ }
+ mNetworkCommands.clear();
+ }
+
+ void releaseNetworkFrames(void)
+ {
+ for (uint32_t i=0; i<mNetworkFrames.size(); i++)
+ {
+ NetworkFrame &nf = mNetworkFrames[i];
+ PX_FREE(nf.mBaseData);
+ }
+ mNetworkFrames.clear();
+ }
+
+ void releaseIncomingNetworkFrames(void)
+ {
+ for (uint32_t i=0; i<mIncomingNetworkFrames.size(); i++)
+ {
+ NetworkFrame &nf = mIncomingNetworkFrames[i];
+ PX_FREE(nf.mBaseData);
+ }
+ mIncomingNetworkFrames.clear();
+ }
+
+
+ virtual bool serverWait(void)
+ {
+ bool ret = false;
+
+ // Here we wait up until the maximum wait count to receive an ack from the server.
+ if ( !mIsServer && mCurrentCommLayer && mCurrentCommLayer->isConnected() )
+ {
+ if ( mReceivedAck )
+ {
+ mReceivedAck = false;
+ }
+ else
+ {
+ bool ok = false;
+ for (uint32_t i=0; i<mMaxServerWait; i++)
+ {
+ if ( !isConnected() )
+ {
+ ok = false;
+ break;
+ }
+ processNetworkData();
+ if ( mReceivedAck )
+ {
+ mReceivedAck = false;
+ ok = true;
+ break;
+ }
+ else
+ {
+ mTime.getElapsedSeconds();
+ physx::shdfnd::Time::Second diff = mTime.peekElapsedSeconds();
+ while ( diff < 0.001 )
+ {
+ diff = mTime.peekElapsedSeconds();
+ processNetworkData();
+ if ( mReceivedAck )
+ {
+ mReceivedAck = false;
+ ok = true;
+ break;
+ }
+ physx::shdfnd::Thread::sleep(0); // we are low priority since we are in a wait loop, give up timeslice to other thread if necessary
+ }
+ if ( ok )
+ {
+ break;
+ }
+ if ( mServerStallCallback )
+ {
+ if ( !mServerStallCallback->continueWaitingForServer(i+1) )
+ {
+ ok = false;
+ break;
+ }
+ }
+ }
+ }
+ if ( !ok )
+ {
+ mCurrentCommLayer = NULL;
+ if ( mCommLayer )
+ {
+ mCommLayer->release();
+ mCommLayer = NULL;
+ }
+ if ( mCommStream )
+ {
+ mCommStream->release();
+ mCommStream = NULL;
+ }
+
+ releaseNetworkFrames();
+ }
+ }
+ }
+
+ return ret;
+ }
+
+ virtual const char **getCommand(uint32_t &argc)
+ {
+ const char **ret = NULL;
+ argc = 0;
+
+ mNetworkCommandMutex.lock();
+
+ if ( !mNetworkCommands.empty() )
+ {
+ NetworkCommmand nc = mNetworkCommands[0];
+ mNetworkCommands.remove(0);
+ physx::intrinsics::memCopy(mCurrentCommand,nc.mCommand,nc.mCommandLength+1);
+ PX_FREE(nc.mCommand);
+ ret = mParser.getArgs(mCurrentCommand,argc);
+ }
+
+ mNetworkCommandMutex.unlock();
+
+ return ret;
+ }
+
+ virtual bool sendCommand(const char *cmd)
+ {
+ bool ret = false;
+
+ if ( cmd && mCurrentCommLayer)
+ {
+ uint32_t slen = uint32_t(strlen(cmd));
+ if ( slen < MAX_SERVER_COMMAND_STRING )
+ {
+ uint32_t sendSize = sizeof(uint32_t)*2+slen+1;
+ uint32_t *sendData = static_cast<uint32_t *>(PX_ALLOC(sendSize,"SendCommand"));
+ sendData[0] = PT_COMMAND;
+ sendData[1] = slen;
+ physx::intrinsics::memCopy(&sendData[2],cmd,slen+1);
+ mCurrentCommLayer->sendMessage(sendData,sendSize);
+ PX_FREE(sendData);
+ ret = true;
+ }
+ }
+
+ return ret;
+ }
+
+ virtual bool isConnected(void)
+ {
+ if ( !mCurrentCommLayer ) return false;
+ if ( mIsServer )
+ {
+ bool hasClient = mCurrentCommLayer->hasClient();
+ if ( !hasClient && mUsedMeshId )
+ {
+ mUsedMeshId = false;
+ mMeshId+=10000; // increment the baseline mesh-id for the next time the client runs.
+ mHaveApplicationName = false;
+ }
+ return hasClient;
+ }
+ return mCurrentCommLayer->isConnected();
+ }
+
+ virtual uint32_t getCommunicationsFrame(void) const
+ {
+ if ( mIsServer )
+ {
+ return mCurrentNetworkFrame;
+ }
+ return mLastFrame;
+ }
+
+ virtual void finalizeFrame(uint32_t frameCount)
+ {
+ if ( mDataSent )
+ {
+ mDataSent = false;
+ return;
+ }
+ if ( !mCurrentCommLayer )
+ {
+ return;
+ }
+ if ( mIsServer )
+ {
+ return;
+ }
+
+ if ( !mCurrentCommLayer->isConnected() )
+ {
+ return;
+ }
+ uint32_t packet[2];
+ packet[0] = PT_FINALIZE_FRAME;
+ packet[1] = frameCount;
+ mCurrentCommLayer->sendMessage(packet,sizeof(packet));
+ }
+
+ virtual const char * getRemoteApplicationName(void)
+ {
+ const char *ret = NULL;
+
+ if ( mIsServer && mHaveApplicationName )
+ {
+ ret = mApplicationName;
+ }
+
+ return ret;
+ }
+
+ /**
+ \brief Transmits an arbitrary block of binary data to the remote machine. The block of data can have a command and id associated with it.
+
+ It is important to note that due to the fact the RenderDebug system is synchronized every single frame, it is strongly recommended
+ that you only use this feature for relatively small data items; probably on the order of a few megabytes at most. If you try to do
+ a very large transfer, in theory it would work, but it might take a very long time to complete and look like a hang since it will
+ essentially be blocking.
+
+ \param nameSpace The namespace associated with this data transfer, for example this could indicate a remote file request.
+ \param resourceName The name of the resource associated with this data transfer, for example the id could be the file name of a file transfer request.
+ \param data The block of binary data to transmit, you are responsible for maintaining endian correctness of the internal data if necessary.
+ \param dlen The length of the lock of data to transmit.
+
+ \return Returns true if the data was queued to be transmitted, false if it failed.
+ */
+ virtual bool sendRemoteResource(const char *nameSpace,
+ const char *resourceName,
+ const void *data,
+ uint32_t dlen)
+ {
+ bool ret = false;
+
+ if ( mCurrentCommLayer && mCurrentCommLayer->isConnected() && data && dlen )
+ {
+ uint32_t sendLen = sizeof(RemoteResourcePacket)+dlen;
+ RemoteResourcePacket *sendPacket = static_cast<RemoteResourcePacket*>(PX_ALLOC(sendLen,"RemoteResource"));
+ RemoteResourcePacket &rr = *sendPacket;
+
+ rr.mCommand = PT_REMOTE_RESOURCE;
+ rr.mLength = dlen;
+ rr.mBigEndian = isBigEndian() ? uint32_t( 1) : uint32_t( 0);
+ physx::shdfnd::strlcpy(rr.mNameSpace,MAX_RESOURCE_STRING,nameSpace);
+ physx::shdfnd::strlcpy(rr.mResourceName,MAX_RESOURCE_STRING,resourceName);
+ RemoteResourcePacket *dest = sendPacket;
+ dest++;
+ physx::intrinsics::memCopy(dest,data,dlen);
+ ret = mCurrentCommLayer->sendMessage(sendPacket,sendLen);
+ PX_FREE(sendPacket);
+
+ }
+
+
+ return ret;
+ }
+
+ /**
+ \brief This function allows you to request a file from the remote machine by name. If successful it will be returned via 'getRemoteData'
+
+ \param nameSpace The namespace field associated with this request which will be returned by 'getRemoteData'
+ \param resourceName The resource name being requested from the remote machine.
+
+ \return Returns true if the request was queued to be transmitted, false if it failed.
+ */
+ virtual bool requestRemoteResource(const char *nameSpace,
+ const char *resourceName)
+ {
+ bool ret = false;
+
+ if ( mCurrentCommLayer && mCurrentCommLayer->isConnected() )
+ {
+ RequestRemoteResource rr;
+ rr.mCommand = PT_REQUEST_REMOTE_RESOURCE;
+ physx::shdfnd::strlcpy(rr.mNameSpace,MAX_RESOURCE_STRING,nameSpace);
+ physx::shdfnd::strlcpy(rr.mResourceName,MAX_RESOURCE_STRING,resourceName);
+ ret = mCurrentCommLayer->sendMessage(&rr,sizeof(rr));
+ }
+
+ return ret;
+ }
+
+ /**
+ \brief Retrieves a block of remotely transmitted binary data.
+
+ \param nameSpace A a reference to a pointer which will store the namespace associated with this data transfer, for example this could indicate a remote file request.
+ \param resourceName A reference to a pointer which will store the resource name associated with this data transfer, for example the id could be the file name of a file transfer request.
+ \param dlen A reference that will contain length of the lock of data received.
+ \param remoteIsBigEndian A reference to a boolean which will be set to true if the remote machine that sent this data is big endian format.
+
+ \retrun A pointer to the block of data received.
+ */
+ virtual const void * getRemoteResource(const char *&nameSpace,
+ const char *&resourceName,
+ uint32_t &dlen,
+ bool &remoteIsBigEndian)
+ {
+ const void *ret = NULL;
+
+ nameSpace = NULL;
+ resourceName = NULL;
+ dlen = 0;
+ remoteIsBigEndian = 0;
+ if ( !mRemoteResources.empty() )
+ {
+ if ( mCurrentRemoteResource.mData )
+ {
+ PX_FREE(mCurrentRemoteResource.mData);
+ mCurrentRemoteResource.mData = NULL;
+ }
+ mCurrentRemoteResource = mRemoteResources[0];
+ mRemoteResources.remove(0);
+
+ ret = mCurrentRemoteResource.mData;
+ nameSpace = mCurrentRemoteResource.mNameSpace;
+ resourceName = mCurrentRemoteResource.mResourceName;
+ dlen = mCurrentRemoteResource.mLength;
+ remoteIsBigEndian = mCurrentRemoteResource.mBigEndian ? true : false;
+
+ }
+
+ return ret;
+ }
+
+ void releaseRemoteResources(void)
+ {
+ if ( mCurrentRemoteResource.mData )
+ {
+ PX_FREE(mCurrentRemoteResource.mData);
+ mCurrentRemoteResource.mData = NULL;
+ }
+ for (uint32_t i=0; i<mRemoteResources.size(); i++)
+ {
+ RemoteResource &rr = mRemoteResources[i];
+ PX_FREE(rr.mData);
+ }
+ mRemoteResources.clear();
+ }
+
+ virtual void sendInputEvent(const RENDER_DEBUG::InputEvent &ev)
+ {
+ if ( mCurrentCommLayer )
+ {
+ RENDER_DEBUG::InputEvent e = ev;
+ e.mReserved = PT_INPUT_EVENT;
+ mCurrentCommLayer->sendMessage(&e,sizeof(RENDER_DEBUG::InputEvent));
+ }
+ }
+
+ virtual const RENDER_DEBUG::InputEvent *getInputEvent(bool flush)
+ {
+ const RENDER_DEBUG::InputEvent *ret = NULL;
+
+ if ( !mInputEvents.empty() )
+ {
+ mCurrentInputEvent = mInputEvents[0];
+ ret = &mCurrentInputEvent;
+ if ( flush )
+ {
+ mInputEvents.remove(0);
+ }
+ }
+
+ return ret;
+ }
+
+ /**
+ \brief Set the base file name to record communications stream; or NULL to disable it.
+
+ \param fileName The base name of the file to record the communications channel stream to, or NULL to disable it.
+ */
+ virtual bool setStreamFilename(const char *fileName)
+ {
+ if ( fileName )
+ {
+ physx::shdfnd::strlcpy(mStreamName,256,fileName);
+ }
+ else
+ {
+ mStreamName[0] = 0;
+ if ( mCommStream )
+ {
+ mCommStream->release();
+ mCommStream = NULL;
+ }
+ }
+ return internalSetStreamFilename(mStreamName);
+ }
+
+ bool internalSetStreamFilename(const char *fileName)
+ {
+ bool ret = true;
+
+ mCurrentCommLayer = mCommLayer;
+
+ if ( mIsServer && fileName[0] )
+ {
+ if ( mCommStream )
+ {
+ mCommStream->release();
+ mCommStream = NULL;
+ }
+ if ( fileName )
+ {
+ char scratch[512];
+ sprintf(scratch,"%s%02d.nvcs", fileName, mStreamCount );
+ mCommStream = createCommStream(scratch,true,mCommLayer);
+ if ( mCommStream )
+ {
+ mStreamCount++;
+ mCurrentCommLayer = static_cast< CommLayer *>(mCommStream);
+ }
+ else
+ {
+ ret = false;
+ }
+ }
+ }
+ return ret;
+ }
+
+ /**
+ \brief Begin playing back a communications stream recording
+
+ \param fileName The name of the previously captured communications stream file
+ */
+ virtual bool setStreamPlayback(const char *fileName)
+ {
+ if ( !mIsServer ) return false;
+ if ( mCommLayer->hasClient() ) return false;
+ if ( mCommStream )
+ {
+ mCommStream->release();
+ mCommStream = NULL;
+ }
+ bool ret = false;
+ mCurrentCommLayer = mCommLayer;
+ mCommStream = createCommStream(fileName,false,mCommLayer);
+ if ( mCommStream )
+ {
+ ret = true;
+ mCurrentCommLayer = mCommStream;
+ }
+ return ret;
+ }
+
+ bool mSkipFrame;
+ char mStreamName[256];
+ uint32_t mStreamCount;
+ bool mWasConnected;
+ bool mDataSent; // whether or not any data was sent this frame
+ bool mBadVersion;
+ bool mReceivedAck;
+ uint32_t mMeshId;
+ bool mUsedMeshId;
+ uint32_t mLastFrame;
+ bool mIsServer;
+ RENDER_DEBUG::DebugPrimitive *mDebugPrimitives[MAX_SEND_BUFFER];
+ char mCurrentCommand[MAX_SERVER_COMMAND_STRING];
+ CommLayer *mCommLayer;
+ CommStream *mCommStream;
+ CommLayer *mCurrentCommLayer;
+ uint32_t mLastProcessNetworkFrame;
+ uint32_t mCurrentNetworkFrame;
+ NetworkFrameArray mIncomingNetworkFrames;
+ NetworkFrameArray mNetworkFrames;
+ NetworkCommandArray mNetworkCommands;
+ physx::shdfnd::Mutex mNetworkCommandMutex;
+ uint32_t mMaxServerWait;
+ RENDER_DEBUG::RenderDebug::ServerStallCallback *mServerStallCallback;
+ bool mHaveApplicationName;
+ char mApplicationName[512];
+ GetArgs mParser;
+ RENDER_DEBUG::RenderDebugResource *mRenderDebugResource;
+ RemoteResource mCurrentRemoteResource;
+ RemoteResourceArray mRemoteResources;
+ RENDER_DEBUG::InputEvent mCurrentInputEvent;
+ InputEventArray mInputEvents;
+ physx::shdfnd::Time mTime;
+};
+
+ClientServer *createClientServer(RENDER_DEBUG::RenderDebug::Desc &desc)
+{
+ ClientServer *ret = NULL;
+ desc.errorCode = NULL;
+ ClientServerImpl *c = PX_NEW(ClientServerImpl)(desc);
+ if ( desc.errorCode )
+ {
+ c->release();
+ }
+ else
+ {
+ ret = static_cast< ClientServer *>(c);
+ }
+ return ret;
+}
diff --git a/APEX_1.4/shared/general/RenderDebug/src/FileRenderDebug.cpp b/APEX_1.4/shared/general/RenderDebug/src/FileRenderDebug.cpp
new file mode 100644
index 00000000..52355e90
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/FileRenderDebug.cpp
@@ -0,0 +1,621 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved.
+#include "FileRenderDebug.h"
+#include "PsFileBuffer.h"
+#include "ProcessRenderDebug.h"
+#include "ClientServer.h"
+#include "PsArray.h"
+#include "PsUserAllocated.h"
+
+namespace RENDER_DEBUG
+{
+
+static char magic[4] = { 'D', 'E', 'B', 'G' };
+
+#define DEFAULT_FRAME_BUFFER_SIZE (1024*1024)*128 // default size is 16mb per frame.
+
+static uint32_t isBigEndian(void)
+{
+ int32_t i = 1;
+ bool b = *(reinterpret_cast<char*>(&i))==0;
+ return b ? uint32_t(1) : uint32_t(0);
+}
+
+class DataStream
+{
+public:
+ DataStream(void)
+ {
+ mWriteBufferLoc = 0;
+ mWriteBufferEnd = NULL;
+ mReadBuffer = NULL;
+ mReadBufferLoc = 0;
+ }
+
+ void initWriteBuffer(void *_writeBuffer,uint32_t writeBufferLen)
+ {
+ uint8_t *writeBuffer = reinterpret_cast<uint8_t*>(_writeBuffer);
+ mWriteBufferLoc = mWriteBuffer = writeBuffer;
+ mWriteBufferEnd = writeBuffer+writeBufferLen;
+ mReadBuffer = NULL;
+ }
+
+ void initReadBuffer(const void *readBuffer)
+ {
+ mReadBufferLoc = mReadBuffer = reinterpret_cast<const uint8_t *>(readBuffer);
+ mWriteBufferLoc = NULL;
+ mWriteBufferEnd = NULL;
+ mWriteBuffer = NULL;
+ }
+
+ // store data of this type to the output stream
+ template <class Type > PX_INLINE void operator<<(Type v)
+ {
+ PX_ASSERT(mWriteBuffer);
+ PX_ASSERT(mWriteBufferLoc);
+ if ( (mWriteBufferLoc+sizeof(Type)) < mWriteBufferEnd )
+ {
+ *reinterpret_cast<Type*>(mWriteBufferLoc) = v;
+ mWriteBufferLoc+=sizeof(Type);
+ }
+ else
+ {
+ PX_ASSERT(0);
+ }
+ }
+
+ template <class Type> PX_INLINE void operator>>(Type &v)
+ {
+ v = *reinterpret_cast<const Type*>(mReadBufferLoc);
+ mReadBufferLoc+=sizeof(Type);
+ }
+
+ void readData(void *dest,uint32_t len)
+ {
+ memcpy(dest,mReadBufferLoc,len);
+ mReadBufferLoc+=len;
+ }
+
+ PX_INLINE void writeString(const char *c)
+ {
+ uint32_t len = c ? uint32_t(strlen(c)) : 0;
+ PX_ASSERT(mWriteBuffer);
+ PX_ASSERT(mWriteBufferLoc);
+ if ( (mWriteBufferLoc+len+sizeof(uint32_t) ) < mWriteBufferEnd )
+ {
+ *reinterpret_cast<uint32_t*>(mWriteBufferLoc) = len;
+ mWriteBufferLoc+=sizeof(uint32_t);
+ if ( len )
+ {
+ memcpy(mWriteBufferLoc,c,len);
+ }
+ mWriteBufferLoc+=len;
+ }
+ else
+ {
+ PX_ASSERT(0);
+ }
+ }
+
+ PX_INLINE void readString(char *str,uint32_t maxLen)
+ {
+ uint32_t slen;
+ (*this) >> slen;
+ PX_UNUSED(maxLen);
+ PX_ASSERT( slen < maxLen );
+ memcpy(str,mReadBufferLoc,slen);
+ str[slen] = 0;
+ mReadBufferLoc+=slen;
+ }
+
+ PX_INLINE void writeBuffer(const void *buffer,uint32_t len)
+ {
+ PX_ASSERT(mWriteBufferLoc);
+ if ( (mWriteBufferLoc+len ) < mWriteBufferEnd )
+ {
+ if ( len )
+ {
+ memcpy(mWriteBufferLoc,buffer,len);
+ }
+ mWriteBufferLoc+=len;
+ }
+ else
+ {
+ PX_ASSERT(0);
+ }
+ }
+
+ PX_INLINE uint32_t getWriteBufferLength(void) const
+ {
+ return uint32_t(mWriteBufferLoc-mWriteBuffer);
+ }
+
+ PX_INLINE void * getWriteBufferLoc(void) const
+ {
+ return mWriteBufferLoc;
+ }
+
+ PX_INLINE void * getWriteBuffer(void) const
+ {
+ return mWriteBuffer;
+ }
+
+ PX_INLINE uint32_t getReadBufferLength(void) const
+ {
+ return uint32_t(mReadBufferLoc-mReadBuffer);
+ }
+
+ PX_INLINE const void *getReadBuffer(void) const
+ {
+ return mReadBuffer;
+ }
+
+ PX_INLINE void reset(void)
+ {
+ mWriteBufferLoc = mWriteBuffer;
+ mReadBufferLoc = mReadBuffer;
+ }
+
+ // returns the current read buffer address and advances the read pointer past the length we are consuming.
+ // avoids a memory copy
+ PX_INLINE const void * getAdvanceReadLoc(uint32_t len)
+ {
+ const void *ret = mReadBufferLoc;
+ mReadBufferLoc+=len;
+ return ret;
+ }
+
+private:
+ uint8_t *mWriteBuffer;
+ uint8_t *mWriteBufferLoc;
+ uint8_t *mWriteBufferEnd;
+ const uint8_t *mReadBuffer;
+ const uint8_t *mReadBufferLoc;
+};
+
+
+struct FrameHeader
+{
+ void init(void)
+ {
+ mSeekLocation = 0;
+ mItemCount = 0;
+ mItemSize = 0;
+ }
+ uint32_t mSeekLocation;
+ uint32_t mItemCount;
+ uint32_t mItemSize;
+};
+
+struct PrimitiveBatch
+{
+ uint32_t mPrimitiveType;
+ uint32_t mPrimitiveCount;
+ uint32_t mPrimitiveIndex;
+};
+
+struct TypeHeader
+{
+ TypeHeader(void)
+ {
+ mSeekLocation = 0;
+ mDisplayType = ProcessRenderDebug::DT_LAST;
+ mPrimitiveCount = 0;
+ }
+
+ void init(ProcessRenderDebug::DisplayType type)
+ {
+ mSeekLocation = 0;
+ mDisplayType = type;
+ mPrimitiveCount = 0;
+ }
+
+ uint32_t mSeekLocation;
+ uint32_t mDisplayType;
+ uint32_t mPrimitiveCount;
+};
+
+
+class FileRenderDebugImpl : public FileRenderDebug, public physx::shdfnd::UserAllocated
+{
+public:
+ FileRenderDebugImpl(const char *fileName,bool readAccess,ProcessRenderDebug *echoLocally,ClientServer *cs) :
+ mPrimitiveBatch(PX_DEBUG_EXP("FileRenderDebugImpl::mPrimitiveBatch")),
+ mFrameHeaders(PX_DEBUG_EXP("FileRenderDebugImpl::mFrameHeaders"))
+ {
+ mEndianSwap = false;
+ mClientServer = cs;
+ mLastDisplayType = ProcessRenderDebug::DT_LAST;
+ mData = NULL;
+ mPrimitives = NULL;
+ mPrimitiveCount = 0;
+ mCurrentFrame = 0xFFFFFFFF;
+ mFrameItemCount = 0;
+ mFrameStart = 0;
+ mFrameCount = 1;
+ mReadAccess = readAccess;
+ mEchoLocally = echoLocally;
+ mMaxFrameBufferSize = DEFAULT_FRAME_BUFFER_SIZE;
+ mWriteBufferData = PX_ALLOC(mMaxFrameBufferSize,"FileRenderDebugFrameBuffer");
+ mWriteBuffer.initWriteBuffer(mWriteBufferData,mMaxFrameBufferSize);
+ mFileBuffer = NULL;
+
+ if ( mClientServer == NULL && fileName )
+ {
+ mFileBuffer = PX_NEW(physx::PsFileBuffer)(fileName, readAccess ? physx::PsFileBuffer::OPEN_READ_ONLY : physx::PsFileBuffer::OPEN_WRITE_ONLY);
+ if ( mFileBuffer->isOpen() )
+ {
+ if ( mReadAccess )
+ {
+ char temp[4];
+ uint32_t r = mFileBuffer->read(temp,4);
+ uint32_t version = mFileBuffer->readDword();
+ uint32_t bigEndian = mFileBuffer->readDword();
+
+ if ( r == 4 && magic[0] == temp[0] && magic[1] == temp[1] && magic[2] == temp[2] && magic[3] == temp[3] && version == RENDER_DEBUG_COMM_VERSION )
+ {
+ if ( bigEndian != isBigEndian() )
+ {
+ mEndianSwap = true;
+ }
+ // it's valid!
+ FrameHeader h;
+ while ( readFrameHeader(h,*mFileBuffer ) )
+ {
+ mFrameHeaders.pushBack(h);
+ }
+ mFrameCount = mFrameHeaders.size();
+ }
+ else
+ {
+ delete mFileBuffer;
+ mFileBuffer = NULL;
+ }
+ }
+ else
+ {
+ mFileBuffer->write(magic, 4 );
+ mFileBuffer->storeDword(RENDER_DEBUG_COMM_VERSION);
+ uint32_t bigEndian = isBigEndian();
+ mFileBuffer->storeDword(bigEndian);
+ mFileBuffer->flush();
+ }
+
+ }
+ else
+ {
+ delete mFileBuffer;
+ mFileBuffer = NULL;
+ }
+ }
+ }
+
+ bool readFrameHeader(FrameHeader &h,physx::PsFileBuffer &fph)
+ {
+ bool ret = false;
+
+ h.init();
+ h.mItemCount = fph.readDword();
+ h.mItemSize = fph.readDword();
+ h.mSeekLocation = fph.tellRead();
+ if ( h.mItemCount > 0 && h.mItemSize > 0 )
+ {
+ fph.seekRead(h.mSeekLocation+h.mItemSize);
+ ret = true;
+ }
+ return ret;
+ }
+
+ virtual ~FileRenderDebugImpl(void)
+ {
+ reset();
+ PX_FREE(mWriteBufferData);
+ if(mFileBuffer)
+ {
+ mFileBuffer->close();
+ delete mFileBuffer;
+ }
+ }
+
+ virtual ProcessRenderDebug * getEchoLocal(void) const
+ {
+ return mEchoLocally;
+ }
+
+ bool isOk(void) const
+ {
+ if ( mClientServer ) return true;
+ if ( mReadAccess && getFrameCount() == 0 ) return false;
+ return mFileBuffer ? true : false;
+ }
+
+ virtual void processRenderDebug(const DebugPrimitive **dplist,
+ uint32_t pcount,
+ RENDER_DEBUG::RenderDebugInterface *iface,
+ ProcessRenderDebug::DisplayType type)
+ {
+ if ( !mReadAccess )
+ {
+ PX_ASSERT(pcount);
+ if ( mFrameStart == 0 )
+ {
+ uint32_t pv = 0;
+ if ( mFileBuffer )
+ {
+ mFrameStart = mFileBuffer->tellWrite();
+ mFileBuffer->storeDword(pv);
+ mFileBuffer->storeDword(pv);
+ }
+ }
+ if ( type != mLastDisplayType )
+ {
+ flushDisplayType(mLastDisplayType);
+ beginDisplayType(type);
+ }
+ mTypeHeaders[type].mPrimitiveCount+=pcount;
+ for (uint32_t i=0; i<pcount; i++)
+ {
+ const DebugPrimitive *dp = dplist[i];
+ uint32_t plen = DebugCommand::getPrimtiveSize(*dp);
+ mWriteBuffer.writeBuffer(dp,plen);
+ }
+
+ if ( mFileBuffer )
+ {
+ mFileBuffer->write(mWriteBuffer.getWriteBuffer(),mWriteBuffer.getWriteBufferLength());
+ }
+ else if ( mClientServer )
+ {
+ mClientServer->recordPrimitives(mFrameCount,type,pcount,mWriteBuffer.getWriteBufferLength(),mWriteBuffer.getWriteBuffer());
+ }
+
+ mWriteBuffer.initWriteBuffer(mWriteBufferData,mMaxFrameBufferSize);
+ mFrameItemCount+=pcount;
+ }
+
+ if ( mEchoLocally )
+ {
+ mEchoLocally->processRenderDebug(dplist,pcount,iface,type);
+ }
+ }
+
+ void flushDisplayType(DisplayType type)
+ {
+ if ( type != ProcessRenderDebug::DT_LAST && mTypeHeaders[type].mDisplayType != ProcessRenderDebug::DT_LAST )
+ {
+ if ( mFileBuffer )
+ {
+ uint32_t loc = mFileBuffer->tellWrite();
+ mFileBuffer->seekWrite( mTypeHeaders[type].mSeekLocation );
+ mFileBuffer->storeDword( mTypeHeaders[type].mDisplayType );
+ mFileBuffer->storeDword( mTypeHeaders[type].mPrimitiveCount );
+ mFileBuffer->seekWrite( loc );
+ }
+ mTypeHeaders[type].init(ProcessRenderDebug::DT_LAST);
+ mLastDisplayType = ProcessRenderDebug::DT_LAST;
+ }
+ }
+
+ void beginDisplayType(DisplayType type)
+ {
+ mTypeHeaders[type].init(type);
+ if ( mFileBuffer )
+ {
+ mTypeHeaders[type].mSeekLocation = mFileBuffer->tellWrite();
+ mFileBuffer->storeDword( mTypeHeaders[type].mDisplayType );
+ mFileBuffer->storeDword( mTypeHeaders[type].mPrimitiveCount );
+ }
+ mLastDisplayType = type;
+ }
+
+ virtual void flush(RENDER_DEBUG::RenderDebugInterface *iface,ProcessRenderDebug::DisplayType type)
+ {
+ if ( !mReadAccess )
+ {
+ flushDisplayType(type);
+ }
+ if ( mEchoLocally )
+ {
+ mEchoLocally->flush(iface,type);
+ }
+ }
+
+ virtual void release(void)
+ {
+ delete this;
+ }
+
+ virtual void processReadFrame(RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ if ( mReadAccess && mEchoLocally )
+ {
+ for (uint32_t i=0; i<mPrimitiveBatch.size(); i++)
+ {
+ PrimitiveBatch &b = mPrimitiveBatch[i];
+ mEchoLocally->processRenderDebug(&mPrimitives[b.mPrimitiveIndex],b.mPrimitiveCount,iface,static_cast<ProcessRenderDebug::DisplayType>(b.mPrimitiveType));
+ mEchoLocally->flush(iface,static_cast<ProcessRenderDebug::DisplayType>(b.mPrimitiveType));
+ }
+ }
+
+ }
+
+ virtual void flushFrame(RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ PX_UNUSED(iface);
+ }
+
+ virtual void finalizeFrame(void)
+ {
+ if ( mFileBuffer )
+ {
+ if ( mFrameItemCount )
+ {
+ if ( mFileBuffer )
+ {
+ uint32_t current = mFileBuffer->tellWrite();
+ uint32_t frameLength = (current-mFrameStart)-( sizeof(uint32_t)*2 );
+ mFileBuffer->seekWrite(mFrameStart);
+ mFileBuffer->storeDword(mFrameItemCount);
+ mFileBuffer->storeDword(frameLength);
+ mFileBuffer->seekWrite(current);
+ mFileBuffer->flush();
+ }
+ }
+ }
+ if ( mClientServer )
+ {
+ mClientServer->finalizeFrame(mFrameCount);
+ mClientServer->serverWait(); // wait up to 1 millisecond for the server to catch up with us...
+ }
+ mFrameStart = 0;
+ mFrameItemCount = 0;
+ mFrameCount++;
+ }
+
+ virtual uint32_t getFrameCount(void) const
+ {
+ return mFrameCount;
+ }
+
+ void reset(void)
+ {
+ PX_FREE(mPrimitives);
+ PX_FREE(mData);
+ mData = NULL;
+ mPrimitives = NULL;
+ }
+
+ virtual void setFrame(uint32_t frameNo)
+ {
+ if ( !mFileBuffer )
+ return;
+
+ if ( mReadAccess && frameNo < mFrameCount && frameNo != mCurrentFrame )
+ {
+ mPrimitiveBatch.resize(0);
+
+ FrameHeader &h = mFrameHeaders[frameNo];
+ mCurrentFrame = frameNo;
+ reset();
+ mPrimitiveCount = h.mItemCount;
+ mPrimitives = const_cast<const DebugPrimitive **>(reinterpret_cast<DebugPrimitive **>(PX_ALLOC( sizeof(DebugPrimitive *)*mPrimitiveCount, PX_DEBUG_EXP("DebugPrimitive"))));
+ mData = reinterpret_cast<uint8_t*>(PX_ALLOC(h.mItemSize, PX_DEBUG_EXP("FrameItemSize")));
+ mFileBuffer->seekRead(h.mSeekLocation);
+ uint32_t bcount = mFileBuffer->read(mData,h.mItemSize);
+ if ( bcount == h.mItemSize )
+ {
+
+ uint32_t index = 0;
+
+ const uint8_t *scan = mData;
+
+ while ( index < h.mItemCount )
+ {
+ PrimitiveBatch b;
+
+ uint32_t *uscan = const_cast<uint32_t*>(reinterpret_cast<const uint32_t*>(scan));
+ b.mPrimitiveType = uscan[0];
+ b.mPrimitiveCount = uscan[1];
+ b.mPrimitiveIndex = index;
+
+ mPrimitiveBatch.pushBack(b);
+
+ uscan+=2;
+ scan = reinterpret_cast<uint8_t *>(uscan);
+
+ for (uint32_t i=0; i<b.mPrimitiveCount; i++)
+ {
+ DebugPrimitive *prim = const_cast<DebugPrimitive*>(reinterpret_cast<const DebugPrimitive *>(scan));
+
+ if ( mEndianSwap )
+ {
+ endianSwap(prim);
+ }
+
+ PX_ASSERT( prim->mCommand < DebugCommand::DEBUG_LAST );
+ mPrimitives[i+index] = prim;
+ uint32_t plen = DebugCommand::getPrimtiveSize(*prim);
+ scan+=plen;
+ }
+ index+=b.mPrimitiveCount;
+ }
+ }
+ else
+ {
+ reset();
+ }
+
+
+
+ }
+
+ }
+
+private:
+
+ physx::PsFileBuffer *mFileBuffer;
+
+ bool mReadAccess;
+ ProcessRenderDebug *mEchoLocally;
+ uint32_t mFrameStart;
+ uint32_t mFrameItemCount;
+ uint32_t mFrameCount;
+ uint32_t mCurrentFrame;
+
+ uint32_t mPrimitiveCount;
+ const DebugPrimitive **mPrimitives;
+ uint8_t *mData;
+ physx::shdfnd::Array< PrimitiveBatch > mPrimitiveBatch;
+ physx::shdfnd::Array< FrameHeader > mFrameHeaders;
+
+ ProcessRenderDebug::DisplayType mLastDisplayType;
+ TypeHeader mTypeHeaders[ProcessRenderDebug::DT_LAST];
+
+ uint32_t mMaxFrameBufferSize;
+ void *mWriteBufferData;
+ DataStream mWriteBuffer;
+ ClientServer *mClientServer;
+ bool mEndianSwap;
+};
+
+FileRenderDebug * createFileRenderDebug(const char *fileName,
+ bool readAccess,
+ ProcessRenderDebug *echoLocally,
+ ClientServer *cs)
+{
+ FileRenderDebugImpl *f = PX_NEW(FileRenderDebugImpl)(fileName, readAccess, echoLocally, cs);
+ if (!f->isOk() )
+ {
+ delete f;
+ f = NULL;
+ }
+ return static_cast< FileRenderDebug *>(f);
+}
+
+
+
+} // end of namespace
diff --git a/APEX_1.4/shared/general/RenderDebug/src/Hull2MeshEdges.cpp b/APEX_1.4/shared/general/RenderDebug/src/Hull2MeshEdges.cpp
new file mode 100644
index 00000000..94f60f4e
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/Hull2MeshEdges.cpp
@@ -0,0 +1,459 @@
+#include "Hull2MeshEdges.h"
+#include "PsUserAllocated.h"
+#include "PxVec4.h"
+#include "PxVec3.h"
+#include "PxPlane.h"
+#include "PxMath.h"
+#include "PxTransform.h"
+#include "PsArray.h"
+
+
+#define FLT_EPS 0.000000001f
+
+PX_INLINE bool intersectPlanes(physx::PxVec3& pos, physx::PxVec3& dir, const physx::PxPlane& plane0, const physx::PxPlane& plane1)
+{
+ const physx::PxVec3 n0 = plane0.n;
+ const physx::PxVec3 n1 = plane1.n;
+
+ dir = n0.cross(n1);
+
+ if(dir.normalize() < FLT_EPS)
+ {
+ return false;
+ }
+
+ pos = physx::PxVec3(0.0f);
+
+ for (int iter = 3; iter--;)
+ {
+ // Project onto plane0:
+ pos = plane0.project(pos);
+
+ // Raycast to plane1:
+ const physx::PxVec3 b = dir.cross(n0);
+ //pos = pos - (pos.dot(plane1.n)/b.dot(plane1.n))*b;
+
+ pos = pos - (plane1.distance(pos) / b.dot(plane1.n))*b;
+
+ }
+
+ return true;
+}
+
+void calculatePolygonEdges(physx::shdfnd::Array<HullEdge>& edges,uint32_t planeCount,const physx::PxPlane *planes)
+{
+ for (uint32_t i = 0; i <planeCount; ++i)
+ {
+ const physx::PxPlane& plane_i = planes[i];
+ for (uint32_t j = i+1; j <planeCount; ++j)
+ {
+ const physx::PxPlane& plane_j = planes[j];
+ // Find potential edge from intersection if plane_i and plane_j
+ physx::PxVec3 orig;
+ physx::PxVec3 edgeDir;
+ if (intersectPlanes(orig, edgeDir, plane_i, plane_j))
+ {
+ float minS = -FLT_MAX;
+ float maxS = FLT_MAX;
+ bool intersectionFound = true;
+ for (uint32_t k = 0; k < planeCount; ++k)
+ {
+ if (k == i || k == j)
+ {
+ continue;
+ }
+ const physx::PxPlane& plane_k = planes[k];
+ const float num = -plane_k.distance(orig);
+ const float den = plane_k.n.dot(edgeDir);
+ if (physx::PxAbs(den) > FLT_EPS)
+ {
+ const float s = num/den;
+ if (den > 0.0f)
+ {
+ maxS = physx::PxMin(maxS, s);
+ }
+ else
+ {
+ minS = physx::PxMax(minS, s);
+ }
+ if (maxS <= minS)
+ {
+ intersectionFound = false;
+ break;
+ }
+ }
+ else
+ if (num < -10*FLT_EPS)
+ {
+ intersectionFound = false;
+ break;
+ }
+ }
+ if (intersectionFound && minS != -FLT_MAX && maxS != FLT_MIN)
+ {
+ HullEdge& s = edges.insert();
+ s.e0 = orig + minS * edgeDir;
+ s.e1 = orig + maxS * edgeDir;
+ }
+ }
+ }
+ }
+}
+
+struct ConvexMeshBuilder
+{
+ ConvexMeshBuilder(void) : mVertices("ConvexMeshBuilder::mVertice"), mIndices("ConvexMeshBuilder::mIndices") {}
+ void buildMesh(uint16_t numPlanes,const physx::PxVec4 *planes);
+ physx::shdfnd::Array<physx::PxVec3> mVertices;
+ physx::shdfnd::Array<uint16_t> mIndices;
+};
+
+static float det(physx::PxVec4 v0, physx::PxVec4 v1, physx::PxVec4 v2, physx::PxVec4 v3)
+{
+ const physx::PxVec3& d0 = reinterpret_cast<const physx::PxVec3&>(v0);
+ const physx::PxVec3& d1 = reinterpret_cast<const physx::PxVec3&>(v1);
+ const physx::PxVec3& d2 = reinterpret_cast<const physx::PxVec3&>(v2);
+ const physx::PxVec3& d3 = reinterpret_cast<const physx::PxVec3&>(v3);
+
+ return v0.w * d1.cross(d2).dot(d3)
+ - v1.w * d0.cross(d2).dot(d3)
+ + v2.w * d0.cross(d1).dot(d3)
+ - v3.w * d0.cross(d1).dot(d2);
+}
+
+static physx::PxVec3 intersect(physx::PxVec4 p0, physx::PxVec4 p1, physx::PxVec4 p2)
+{
+ const physx::PxVec3& d0 = reinterpret_cast<const physx::PxVec3&>(p0);
+ const physx::PxVec3& d1 = reinterpret_cast<const physx::PxVec3&>(p1);
+ const physx::PxVec3& d2 = reinterpret_cast<const physx::PxVec3&>(p2);
+
+ return (p0.w * d1.cross(d2)
+ + p1.w * d2.cross(d0)
+ + p2.w * d0.cross(d1))
+ / d0.dot(d2.cross(d1));
+}
+
+static const uint16_t sInvalid = uint16_t(-1);
+
+// restriction: only supports a single patch per vertex.
+struct HalfedgeMesh
+{
+ struct Halfedge
+ {
+ Halfedge(uint16_t vertex = sInvalid, uint16_t face = sInvalid,
+ uint16_t next = sInvalid, uint16_t prev = sInvalid)
+ : mVertex(vertex), mFace(face), mNext(next), mPrev(prev)
+ {}
+
+ uint16_t mVertex; // to
+ uint16_t mFace; // left
+ uint16_t mNext; // ccw
+ uint16_t mPrev; // cw
+ };
+
+ HalfedgeMesh() : mNumTriangles(0), mHalfedges("mHalfedges"),mVertices("mVertices"),mFaces("mFaces"),mPoints("mPoints") {}
+
+ uint16_t findHalfedge(uint16_t v0, uint16_t v1)
+ {
+ uint16_t h = mVertices[v0], start = h;
+ while(h != sInvalid && mHalfedges[h].mVertex != v1)
+ {
+ h = mHalfedges[h ^ 1u].mNext;
+ if(h == start)
+ return sInvalid;
+ }
+ return h;
+ }
+
+ void connect(uint16_t h0, uint16_t h1)
+ {
+ mHalfedges[h0].mNext = h1;
+ mHalfedges[h1].mPrev = h0;
+ }
+
+ void addTriangle(uint16_t v0, uint16_t v1, uint16_t v2)
+ {
+ // add new vertices
+ uint16_t n = physx::PxMax(v0, physx::PxMax(v1, v2))+1u;
+ if(mVertices.size() < n)
+ mVertices.resize(n, sInvalid);
+
+ // collect halfedges, prev and next of triangle
+ uint16_t verts[] = { v0, v1, v2 };
+ uint16_t handles[3], prev[3], next[3];
+ for(uint16_t i=0; i<3; ++i)
+ {
+ uint16_t j = (i+1u)%3;
+ uint16_t h = findHalfedge(verts[i], verts[j]);
+ if(h == sInvalid)
+ {
+ // add new edge
+ h = uint16_t(mHalfedges.size());
+ mHalfedges.pushBack(Halfedge(verts[j]));
+ mHalfedges.pushBack(Halfedge(verts[i]));
+ }
+ handles[i] = h;
+ prev[i] = mHalfedges[h].mPrev;
+ next[i] = mHalfedges[h].mNext;
+ }
+
+ // patch connectivity
+ for(uint16_t i=0; i<3; ++i)
+ {
+ uint16_t j = (i+1u)%3;
+
+ mHalfedges[handles[i]].mFace = uint16_t(mFaces.size());
+
+ // connect prev and next
+ connect(handles[i], handles[j]);
+
+ if(next[j] == sInvalid) // new next edge, connect opposite
+ connect(handles[j]^1u, next[i]!=sInvalid ? next[i] : handles[i]^1u);
+
+ if(prev[i] == sInvalid) // new prev edge, connect opposite
+ connect(prev[j]!=sInvalid ? prev[j] : handles[j]^1u, handles[i]^1u);
+
+ // prev is boundary, update middle vertex
+ if(mHalfedges[handles[i]^1u].mFace == sInvalid)
+ mVertices[verts[j]] = handles[i]^1u;
+ }
+
+ PX_ASSERT(mNumTriangles < 0xffff);
+ mFaces.pushBack(handles[2]);
+ ++mNumTriangles;
+ }
+
+ uint16_t removeTriangle(uint16_t f)
+ {
+ uint16_t result = sInvalid;
+
+ for(uint16_t i=0, h = mFaces[f]; i<3; ++i)
+ {
+ uint16_t v0 = mHalfedges[h^1u].mVertex;
+ uint16_t v1 = mHalfedges[h].mVertex;
+
+ mHalfedges[h].mFace = sInvalid;
+
+ if(mHalfedges[h^1u].mFace == sInvalid) // was boundary edge, remove
+ {
+ uint16_t v0Prev = mHalfedges[h ].mPrev;
+ uint16_t v0Next = mHalfedges[h^1u].mNext;
+ uint16_t v1Prev = mHalfedges[h^1u].mPrev;
+ uint16_t v1Next = mHalfedges[h ].mNext;
+
+ // update halfedge connectivity
+ connect(v0Prev, v0Next);
+ connect(v1Prev, v1Next);
+
+ // update vertex boundary or delete
+ mVertices[v0] = (v0Prev^1) == v0Next ? sInvalid : v0Next;
+ mVertices[v1] = (v1Prev^1) == v1Next ? sInvalid : v1Next;
+ }
+ else
+ {
+ mVertices[v0] = h; // update vertex boundary
+ result = v1;
+ }
+
+ h = mHalfedges[h].mNext;
+ }
+
+ mFaces[f] = sInvalid;
+ --mNumTriangles;
+
+ return result;
+ }
+
+ // true if vertex v is in front of face f
+ bool visible(uint16_t v, uint16_t f)
+ {
+ uint16_t h = mFaces[f];
+ if(h == sInvalid)
+ return false;
+
+ uint16_t v0 = mHalfedges[h].mVertex;
+ h = mHalfedges[h].mNext;
+ uint16_t v1 = mHalfedges[h].mVertex;
+ h = mHalfedges[h].mNext;
+ uint16_t v2 = mHalfedges[h].mVertex;
+ h = mHalfedges[h].mNext;
+
+ return det(mPoints[v], mPoints[v0], mPoints[v1], mPoints[v2]) < -1e-5f;
+ }
+
+ uint16_t mNumTriangles;
+ physx::shdfnd::Array<Halfedge> mHalfedges;
+ physx::shdfnd::Array<uint16_t> mVertices; // vertex -> (boundary) halfedge
+ physx::shdfnd::Array<uint16_t> mFaces; // face -> halfedge
+ physx::shdfnd::Array<physx::PxVec4> mPoints;
+};
+
+void ConvexMeshBuilder::buildMesh(uint16_t numPlanes,const physx::PxVec4 *planes)
+{
+ if(numPlanes < 4)
+ return; // todo: handle degenerate cases
+
+ HalfedgeMesh mesh;
+
+ // gather points (planes, that is)
+ mesh.mPoints.reserve(numPlanes);
+ for (uint32_t i=0; i<numPlanes; i++)
+ {
+ mesh.mPoints.pushBack(planes[i]);
+ }
+
+ // initialize to tetrahedron
+ mesh.addTriangle(0, 1, 2);
+ mesh.addTriangle(0, 3, 1);
+ mesh.addTriangle(1, 3, 2);
+ mesh.addTriangle(2, 3, 0);
+
+ // flip if inside-out
+ if(mesh.visible(3, 0))
+ physx::shdfnd::swap(mesh.mPoints[0], mesh.mPoints[1]);
+
+ // iterate through remaining points
+ for(uint16_t i=4; i<mesh.mPoints.size(); ++i)
+ {
+ // remove any visible triangle
+ uint16_t v0 = sInvalid;
+ for(uint16_t j=0; j<mesh.mFaces.size(); ++j)
+ {
+ if(mesh.visible(i, j))
+ v0 = physx::PxMin(v0, mesh.removeTriangle(j));
+ }
+
+ if(v0 == sInvalid)
+ continue; // no triangle removed
+
+ if(!mesh.mNumTriangles)
+ return; // empty mesh
+
+ // find non-deleted boundary vertex
+ for(uint16_t h=0; mesh.mVertices[v0] == sInvalid; h+=2)
+ {
+ if ((mesh.mHalfedges[h ].mFace == sInvalid) ^
+ (mesh.mHalfedges[h+1u].mFace == sInvalid))
+ {
+ v0 = mesh.mHalfedges[h].mVertex;
+ }
+ }
+
+ // tesselate hole
+ uint16_t start = v0;
+ do {
+ uint16_t h = mesh.mVertices[v0];
+ uint16_t v1 = mesh.mHalfedges[h].mVertex;
+ mesh.addTriangle(v0, v1, i);
+ v0 = v1;
+ } while(v0 != start);
+ }
+
+ // convert triangles to vertices (intersection of 3 planes)
+ physx::shdfnd::Array<uint32_t> face2Vertex(mesh.mFaces.size(), sInvalid);
+ for(uint32_t i=0; i<mesh.mFaces.size(); ++i)
+ {
+ uint16_t h = mesh.mFaces[i];
+ if(h == sInvalid)
+ continue;
+
+ uint16_t v0 = mesh.mHalfedges[h].mVertex;
+ h = mesh.mHalfedges[h].mNext;
+ uint16_t v1 = mesh.mHalfedges[h].mVertex;
+ h = mesh.mHalfedges[h].mNext;
+ uint16_t v2 = mesh.mHalfedges[h].mVertex;
+
+ face2Vertex[i] = mVertices.size();
+ mVertices.pushBack(intersect(mesh.mPoints[v0], mesh.mPoints[v1], mesh.mPoints[v2]));
+ }
+
+ // convert vertices to polygons (face one-ring)
+ for(uint32_t i=0; i<mesh.mVertices.size(); ++i)
+ {
+ uint16_t h = mesh.mVertices[i];
+ if(h == sInvalid)
+ continue;
+
+ uint16_t v0 = uint16_t(face2Vertex[mesh.mHalfedges[h].mFace]);
+ h = mesh.mHalfedges[h].mPrev^1u;
+ uint16_t v1 = uint16_t(face2Vertex[mesh.mHalfedges[h].mFace]);
+ bool state = true;
+ while( state )
+ {
+ h = mesh.mHalfedges[h].mPrev^1u;
+ uint16_t v2 = uint16_t(face2Vertex[mesh.mHalfedges[h].mFace]);
+
+ if(v0 == v2)
+ break;
+
+ physx::PxVec3 e0 = mVertices[v0] - mVertices[v2];
+ physx::PxVec3 e1 = mVertices[v1] - mVertices[v2];
+ if(e0.cross(e1).magnitudeSquared() < 1e-10f)
+ continue;
+
+ mIndices.pushBack(v0);
+ mIndices.pushBack(v2);
+ mIndices.pushBack(v1);
+
+ v1 = v2;
+ }
+
+ }
+}
+
+class Hull2MeshEdgesImpl : public Hull2MeshEdges, public physx::shdfnd::UserAllocated
+{
+public:
+ Hull2MeshEdgesImpl(void) : mEdges("HullEdges")
+ {
+
+ }
+ virtual ~Hull2MeshEdgesImpl(void)
+ {
+ }
+
+ virtual bool getHullMesh(uint32_t planeCount,const physx::PxPlane *planes,HullMesh &m)
+ {
+ bool ret = false;
+
+ mConvexMeshBuilder.buildMesh(uint16_t(planeCount),reinterpret_cast<const physx::PxVec4 *>(planes));
+
+ m.mVertexCount = mConvexMeshBuilder.mVertices.size();
+ if ( m.mVertexCount )
+ {
+ ret = true;
+ m.mTriCount = mConvexMeshBuilder.mIndices.size()/3;
+ m.mVertices = &mConvexMeshBuilder.mVertices[0];
+ m.mIndices = &mConvexMeshBuilder.mIndices[0];
+ }
+ return ret;
+ }
+
+ virtual const HullEdge *getHullEdges(uint32_t planeCount,const physx::PxPlane *planes,uint32_t &edgeCount)
+ {
+ const HullEdge *ret = NULL;
+
+ mEdges.clear();
+ calculatePolygonEdges(mEdges,planeCount,planes);
+ if ( !mEdges.empty() )
+ {
+ ret = &mEdges[0];
+ edgeCount = mEdges.size();
+ }
+
+ return ret;
+ }
+
+ virtual void release(void)
+ {
+ delete this;
+ }
+ physx::shdfnd::Array<HullEdge> mEdges;
+ ConvexMeshBuilder mConvexMeshBuilder;
+};
+
+Hull2MeshEdges *createHull2MeshEdges(void)
+{
+ Hull2MeshEdgesImpl *ret = PX_NEW(Hull2MeshEdgesImpl);
+ return static_cast< Hull2MeshEdges *>(ret);
+}
diff --git a/APEX_1.4/shared/general/RenderDebug/src/InternalRenderDebug.cpp b/APEX_1.4/shared/general/RenderDebug/src/InternalRenderDebug.cpp
new file mode 100644
index 00000000..afe73340
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/InternalRenderDebug.cpp
@@ -0,0 +1,2708 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved.
+
+#include "PsHashMap.h"
+#include "InternalRenderDebug.h"
+#include "RenderDebug.h"
+#include "RenderDebugImpl.h"
+#include "ProcessRenderDebug.h"
+#include "PsMemoryBuffer.h"
+
+#include "PsPool.h"
+#include "PsString.h"
+#include "PxBounds3.h"
+#include "StreamIO.h"
+
+namespace RENDER_DEBUG
+{
+
+#define RENDER_STATE_STACK_SIZE 16 // maximum size of the render state stack
+const float FM_PI = 3.1415926535897932384626433832795028841971693993751f;
+const float FM_DEG_TO_RAD = ((2.0f * FM_PI) / 360.0f);
+//const float FM_RAD_TO_DEG = (360.0f / (2.0f * FM_PI));
+
+
+class PostRenderDebug
+{
+ PX_NOCOPY(PostRenderDebug)
+public:
+
+ PostRenderDebug(void)
+ {
+ mSendBufferCount = 0;
+ // since all of these commands are processed internally, in memory buffers, we don't need to be endian specific.
+ mWorldSpace.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ mScreenSpace.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ mNoZ.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ }
+
+ ~PostRenderDebug(void)
+ {
+ }
+
+ PX_INLINE void postRenderDebug(DebugPrimitive *p,const RenderState &rs)
+ {
+// if ( p->mCommand == DebugCommand::DEBUG_GRAPH )
+// return;
+
+ uint32_t plen = DebugCommand::getPrimtiveSize(*p);
+ float dtime = rs.getDisplayTime();
+
+ switch ( p->mCommand )
+ {
+ case DebugCommand::DEBUG_GRAPH:
+ {
+ DebugGraphStream *dgs = static_cast< DebugGraphStream *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugGraphStream *>(p);
+ dgs->mSize = plen;
+ }
+ break;
+ case DebugCommand::DEBUG_CREATE_TRIANGLE_MESH:
+ {
+ DebugCreateTriangleMesh *dgs = static_cast< DebugCreateTriangleMesh *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugCreateTriangleMesh *>(p);
+ dgs->mSize = plen;
+ }
+ break;
+ case DebugCommand::DEBUG_RENDER_TRIANGLE_MESH_INSTANCES:
+ {
+ DebugRenderTriangleMeshInstances *dgs = static_cast< DebugRenderTriangleMeshInstances *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugRenderTriangleMeshInstances *>(p);
+ dgs->mSize = plen;
+ }
+ break;
+ case DebugCommand::DEBUG_CONVEX_HULL:
+ {
+ DebugConvexHull *dgs = static_cast< DebugConvexHull *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugConvexHull *>(p);
+ dgs->mSize = plen;
+ }
+
+ break;
+ case DebugCommand::DEBUG_RENDER_POINTS:
+ {
+ DebugRenderPoints *dgs = static_cast< DebugRenderPoints *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugRenderPoints *>(p);
+ dgs->mSize = plen;
+ }
+ break;
+ case DebugCommand::DEBUG_RENDER_LINES:
+ {
+ DebugRenderLines *dgs = static_cast< DebugRenderLines *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugRenderLines *>(p);
+ dgs->mSize = plen;
+ }
+ break;
+ case DebugCommand::DEBUG_RENDER_TRIANGLES:
+ {
+ DebugRenderTriangles *dgs = static_cast< DebugRenderTriangles *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugRenderTriangles *>(p);
+ dgs->mSize = plen;
+ }
+ break;
+ case DebugCommand::DEBUG_REFRESH_TRIANGLE_MESH_VERTICES:
+ {
+ DebugRefreshTriangleMeshVertices *dgs = static_cast< DebugRefreshTriangleMeshVertices *>(p);
+ plen = dgs->mSize;
+ p = reinterpret_cast<DebugPrimitive *>(dgs->mBuffer);
+ dgs = static_cast< DebugRefreshTriangleMeshVertices *>(p);
+ dgs->mSize = plen;
+ }
+ break;
+ }
+
+
+ if ( rs.isScreen() || p->mCommand == DebugCommand::DEBUG_GRAPH )
+ {
+ processState(rs,mScreenSpaceRenderState,mScreenSpace,dtime);
+ mScreenSpace.write(&dtime,sizeof(dtime));
+ mScreenSpace.write(p,plen);
+ }
+ else if ( rs.isUseZ() )
+ {
+ processState(rs,mWorldSpaceRenderState,mWorldSpace,dtime);
+ mWorldSpace.write(&dtime,sizeof(dtime));
+ mWorldSpace.write(p,plen);
+ }
+ else
+ {
+ processState(rs,mNoZRenderState,mNoZ,dtime);
+ mNoZ.write(&dtime,sizeof(dtime));
+ mNoZ.write(p,plen);
+ }
+ }
+
+ void release(void)
+ {
+ delete this;
+ }
+
+
+ bool processRenderDebug(ProcessRenderDebug *rd,float dtime,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+
+ PX_ASSERT(dtime>=0);
+ process(mWorldSpace,rd,dtime,iface,ProcessRenderDebug::WORLD_SPACE);
+ process(mNoZ,rd,dtime,iface,ProcessRenderDebug::WORLD_SPACE_NOZ);
+ process(mScreenSpace,rd,dtime,iface,ProcessRenderDebug::SCREEN_SPACE);
+ rd->flushFrame(iface);
+
+ new ( &mWorldSpaceRenderState ) RenderState;
+ new ( &mScreenSpaceRenderState ) RenderState;
+ new ( &mNoZRenderState ) RenderState;
+
+ return true;
+ }
+
+ PX_INLINE bool intersects(const uint8_t *a1,const uint8_t *a2,const uint8_t *b1,const uint8_t *b2)
+ {
+ bool ret = true;
+ if ( a1 >= b2 || b1 >= a2 ) ret = false;
+ return ret;
+ }
+
+ // This method processes the current stream of draw commands.
+ // Each draw command is preceded by its 'lifetime'.
+ // If the object is still alive after it is processed, it is retained in the buffer.
+ void process(physx::PsMemoryBuffer &stream,
+ ProcessRenderDebug *rd,
+ float dtime,
+ RENDER_DEBUG::RenderDebugInterface *iface,
+ ProcessRenderDebug::DisplayType type)
+ {
+ if ( stream.tellWrite() == 0 ) return;
+
+ uint8_t *dest = const_cast<uint8_t *>(stream.getWriteBuffer());
+
+ const uint8_t *sendStart = NULL;
+ const uint8_t *sendEnd = NULL;
+
+ float displayTime;
+ uint32_t r = stream.read(&displayTime,sizeof(displayTime));
+
+ BlockInfo *info = NULL;
+
+ while ( r == sizeof(displayTime) )
+ {
+ displayTime-=dtime;
+ bool alive = displayTime > 0.0f;
+ uint32_t cmd;
+ r = stream.peek(&cmd,sizeof(cmd));
+
+ PX_ASSERT( r == sizeof(cmd) );
+ PX_ASSERT( cmd < DebugCommand::DEBUG_LAST );
+
+ switch ( cmd )
+ {
+ case DebugCommand::DEBUG_MESSAGE:
+ case DebugCommand::DEBUG_CREATE_TRIANGLE_MESH:
+ case DebugCommand::DEBUG_RELEASE_TRIANGLE_MESH:
+ case DebugCommand::DEBUG_REFRESH_TRIANGLE_MESH_VERTICES:
+ case DebugCommand::DEBUG_CREATE_CUSTOM_TEXTURE:
+ case DebugCommand::DEBUG_REGISTER_INPUT_EVENT:
+ case DebugCommand::DEBUG_UNREGISTER_INPUT_EVENT:
+ case DebugCommand::DEBUG_RESET_INPUT_EVENTS:
+ case DebugCommand::DEBUG_SKIP_FRAME:
+ alive = false;
+ break;
+ }
+
+ const uint8_t *readLoc = stream.getReadLoc();
+ DebugPrimitive *dp = const_cast<DebugPrimitive*>(reinterpret_cast<const DebugPrimitive *>(readLoc));
+ uint32_t plen = DebugCommand::getPrimtiveSize(*dp);
+ stream.advanceReadLoc(plen);
+
+ if ( sendStart == NULL )
+ {
+ sendStart = readLoc;
+ }
+ sendEnd = readLoc+plen;
+
+ if ( dp->mCommand == DebugCommand::DEBUG_BLOCK_INFO )
+ {
+ DebugBlockInfo *db = static_cast< DebugBlockInfo *>(dp);
+ info = db->mInfo;
+
+ if ( info && info->mChanged )
+ {
+ db->mCurrentTransform = info->mPose;
+ info->mChanged = false;
+ }
+ if ( info && info->mVisibleState )
+ {
+ DebugPrimitive *setCurrentTransform = static_cast< DebugPrimitive *>(&db->mCurrentTransform);
+ mSendBuffer[mSendBufferCount] = setCurrentTransform;
+ mSendBufferCount++;
+ }
+ }
+ else if ( info )
+ {
+ if ( info->mVisibleState )
+ {
+ mSendBuffer[mSendBufferCount] = dp;
+ mSendBufferCount++;
+ }
+ else if (isRenderState(dp))
+ {
+ mSendBuffer[mSendBufferCount] = dp;
+ mSendBufferCount++;
+ }
+ }
+ else
+ {
+ mSendBuffer[mSendBufferCount] = dp;
+ mSendBufferCount++;
+ }
+
+ if ( mSendBufferCount == MAX_SEND_BUFFER )
+ {
+ rd->processRenderDebug(mSendBuffer,mSendBufferCount,iface,type);
+ mSendBufferCount = 0;
+ sendStart = sendEnd = NULL;
+ }
+
+ if ( alive )
+ {
+ if ( sendStart && intersects(sendStart,sendEnd,dest,dest+plen+sizeof(float)) )
+ {
+ if ( mSendBufferCount )
+ {
+ rd->processRenderDebug(mSendBuffer,mSendBufferCount,iface,type);
+ }
+ mSendBufferCount = 0;
+ sendStart = sendEnd = NULL;
+ }
+
+ // Store the new display time!
+ float *fdest = reinterpret_cast<float *>(dest);
+ *fdest = displayTime;
+ dest+=sizeof(float);
+
+ if ( dest != reinterpret_cast<uint8_t *>(dp) ) // if the source and dest are the same, we don't need to move memory
+ {
+ memcpy(dest,dp,plen);
+ }
+ dest+=plen;
+ }
+
+ r = stream.read(&displayTime,sizeof(displayTime));
+ }
+
+ if ( mSendBufferCount )
+ {
+ rd->processRenderDebug(mSendBuffer,mSendBufferCount,iface,type);
+ mSendBufferCount = 0;
+ }
+
+ if ( info )
+ {
+ info->mChanged = false;
+ }
+
+ stream.setWriteLoc(dest);
+ rd->flush(iface,type);
+ stream.seekRead(0);
+ }
+
+ void reset(BlockInfo *info)
+ {
+ reset(mWorldSpace,info);
+ reset(mNoZ,info);
+ reset(mScreenSpace,info);
+ }
+
+ // if resetInfo is NULL, then totally erase the persistent data stream.
+ // if resetInfo is non-NULL, then erease all parts of the stream which are associated with this data block.
+ void reset(physx::PsMemoryBuffer &stream,BlockInfo *resetInfo)
+ {
+ if ( stream.tellWrite() == 0 ) return;
+ // remove all data
+ if ( resetInfo )
+ {
+ uint8_t *dest = const_cast<uint8_t *>(stream.getWriteBuffer());
+ float displayTime;
+ uint32_t r = stream.read(&displayTime,sizeof(displayTime));
+ BlockInfo *info = NULL;
+ while ( r == sizeof(displayTime) )
+ {
+ char scratch[sizeof(DebugGraphStream)];
+ DebugGraphStream *dgs = reinterpret_cast<DebugGraphStream *>(scratch);
+ r = stream.peek(dgs,sizeof(DebugGraphStream));
+ PX_ASSERT( r >= 8);
+ PX_ASSERT( dgs->mCommand < DebugCommand::DEBUG_LAST );
+ uint32_t plen = DebugCommand::getPrimtiveSize(*dgs);
+ const uint8_t *readLoc = stream.getReadLoc();
+ DebugPrimitive *dp = reinterpret_cast<DebugPrimitive *>(const_cast<uint8_t*>(readLoc));
+ stream.advanceReadLoc(plen);
+ if ( dp->mCommand == DebugCommand::DEBUG_BLOCK_INFO )
+ {
+ DebugBlockInfo *db = static_cast< DebugBlockInfo *>(dp);
+ info = db->mInfo;
+ }
+ if ( info != resetInfo )
+ {
+ // Store the new display time!
+ float *fdest = reinterpret_cast<float *>(dest);
+ *fdest = displayTime;
+ dest+=sizeof(float);
+ if ( dest != reinterpret_cast<uint8_t *>(dp) ) // if the source and dest are the same, we don't need to move memory
+ {
+ memcpy(dest,dp,plen);
+ }
+ dest+=plen;
+
+ }
+ r = stream.read(&displayTime,sizeof(displayTime));
+ }
+ stream.setWriteLoc(dest);
+ stream.seekRead(0);
+ }
+ else
+ {
+ // kill all saved data!
+ uint8_t *dest = const_cast<uint8_t *>(stream.getWriteBuffer());
+ stream.setWriteLoc(dest);
+ stream.seekRead(0);
+ }
+ }
+
+ void updateBufferChangeCount(const RenderState &rs)
+ {
+ if ( rs.isScreen() /*|| p->mCommand == DebugCommand::DEBUG_GRAPH*/ )
+ mScreenSpaceRenderState.mChangeCount = rs.getChangeCount();
+ else if ( rs.isUseZ() )
+ mWorldSpaceRenderState.mChangeCount = rs.getChangeCount();
+ else
+ mNoZRenderState.mChangeCount = rs.getChangeCount();
+ }
+
+ void updatePostDrawGroupPose (const RenderState &rs)
+ {
+ float dtime = rs.getDisplayTime();
+
+ if ( rs.isScreen() /*|| p->mCommand == DebugCommand::DEBUG_GRAPH*/ )
+ setCurrentTransform(rs, mScreenSpaceRenderState, mScreenSpace, dtime);
+ else if ( rs.isUseZ() )
+ setCurrentTransform(rs, mWorldSpaceRenderState, mWorldSpace, dtime);
+ else
+ setCurrentTransform(rs, mNoZRenderState, mNoZ, dtime);
+ }
+
+private:
+
+ PX_INLINE void processState(const RenderState &source,
+ RenderState &dest,
+ physx::PsMemoryBuffer &stream,
+ float lifeTime)
+ {
+ if ( dest.getChangeCount() == 0 )
+ {
+ setColor(source,dest,stream,lifeTime);
+ setArrowColor(source,dest,stream,lifeTime);
+ setTexture(source,dest,stream,lifeTime);
+ setArrowSize(source,dest,stream,lifeTime);
+ setRenderScale(source,dest,stream,lifeTime);
+ setUserId(source,dest,stream,lifeTime);
+ setStates(source,dest,stream,lifeTime);
+ setTextScale(source,dest,stream,lifeTime);
+ setCurrentTransform(source,dest,stream,lifeTime);
+ setBlockInfo(source,dest,stream,lifeTime);
+ dest.incrementChangeCount();
+ }
+ else if ( source.getChangeCount() != dest.getChangeCount() )
+ {
+ applyStateChanges(source,dest,stream,lifeTime);
+ }
+ }
+
+ PX_INLINE void setColor(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugPrimitiveU32 d(DebugCommand::SET_CURRENT_COLOR,source.mColor);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mColor = source.mColor;
+ }
+
+ PX_INLINE void setRenderScale(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugPrimitiveF32 d(DebugCommand::SET_CURRENT_RENDER_SCALE,source.mRenderScale);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mRenderScale = source.mRenderScale;
+ }
+
+ PX_INLINE void setArrowSize(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugPrimitiveF32 d(DebugCommand::SET_CURRENT_ARROW_SIZE,source.mArrowSize);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mArrowSize = source.mArrowSize;
+ }
+
+ PX_INLINE void setUserId(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugPrimitiveU32 d(DebugCommand::SET_CURRENT_USER_ID,uint32_t(source.mUserId));
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mUserId = source.mUserId;
+ }
+
+ PX_INLINE void setArrowColor(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugPrimitiveU32 d(DebugCommand::SET_CURRENT_ARROW_COLOR,source.mArrowColor);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mArrowColor = source.mArrowColor;
+ }
+
+ PX_INLINE void setTexture(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ if ( dest.mTexture1 != source.mTexture1 )
+ {
+ DebugPrimitiveU32 d(DebugCommand::SET_CURRENT_TEXTURE1,source.mTexture1);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mTexture1 = source.mTexture1;
+ }
+ if ( dest.mTexture2 != source.mTexture2 )
+ {
+ DebugPrimitiveU32 d(DebugCommand::SET_CURRENT_TEXTURE2,source.mTexture2);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mTexture2 = source.mTexture2;
+ }
+ if ( dest.mTileRate1 != source.mTileRate2 )
+ {
+ DebugPrimitiveF32 d(DebugCommand::SET_CURRENT_TILE1,source.mTileRate1);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mTileRate1 = source.mTileRate1;
+ }
+ if ( dest.mTileRate2 != source.mTileRate2 )
+ {
+ DebugPrimitiveF32 d(DebugCommand::SET_CURRENT_TILE2,source.mTileRate2);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mTileRate2 = source.mTileRate2;
+ }
+
+ }
+
+
+ PX_INLINE void setStates(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugPrimitiveU32 d(DebugCommand::SET_CURRENT_RENDER_STATE,source.mStates);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mStates = source.mStates;
+ }
+
+ PX_INLINE void setTextScale(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugPrimitiveF32 d(DebugCommand::SET_CURRENT_TEXT_SCALE,source.mTextScale);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mTextScale = source.mTextScale;
+ }
+
+ PX_INLINE void setCurrentTransform(const RenderState &source,
+ RenderState &dest,
+ physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugSetCurrentTransform d(source.mPose ? *source.mPose : physx::PxMat44(physx::PxIdentity) );
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ if ( source.mPose )
+ {
+ dest.mCurrentPose = *source.mPose;
+ dest.mPose = &dest.mCurrentPose;
+ }
+ else
+ {
+ dest.mPose = NULL;
+ }
+ }
+
+ PX_INLINE void setBlockInfo(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ DebugBlockInfo d(source.mBlockInfo);
+ stream.write(&lifeTime,sizeof(lifeTime));
+ stream.write(&d,sizeof(d));
+ dest.mBlockInfo = source.mBlockInfo;
+ }
+
+
+ void applyStateChanges(const RenderState &source,RenderState &dest,physx::PsMemoryBuffer &stream,float lifeTime)
+ {
+ if ( source.mColor != dest.mColor )
+ {
+ setColor(source,dest,stream,lifeTime);
+ }
+ if ( source.mArrowColor != dest.mArrowColor )
+ {
+ setArrowColor(source,dest,stream,lifeTime);
+ }
+ {
+ setTexture(source,dest,stream,lifeTime);
+ }
+ if ( source.mRenderScale != dest.mRenderScale )
+ {
+ setRenderScale(source,dest,stream,lifeTime);
+ }
+ if ( source.mArrowSize != dest.mArrowSize )
+ {
+ setArrowSize(source,dest,stream,lifeTime);
+ }
+ if ( source.mUserId != dest.mUserId )
+ {
+ setUserId(source,dest,stream,lifeTime);
+ }
+ if ( source.mStates != dest.mStates )
+ {
+ setStates(source,dest,stream,lifeTime);
+ }
+ if ( source.mTextScale != dest.mTextScale )
+ {
+ setTextScale(source,dest,stream,lifeTime);
+ }
+ if ( source.mPose != dest.mPose )
+ {
+ if ( !sameMat44(source.mPose,dest.mPose) )
+ {
+ setCurrentTransform(source,dest,stream,lifeTime);
+ }
+ }
+ if ( source.mBlockInfo != dest.mBlockInfo )
+ {
+ setBlockInfo(source,dest,stream,lifeTime);
+ }
+ dest.mChangeCount = source.mChangeCount;
+ }
+
+ bool sameMat44(const physx::PxMat44 *a,const physx::PxMat44 *b) const
+ {
+ if ( a == b ) return true;
+ if ( a == NULL || b == NULL ) return false;
+ const float *f1 = a->front();
+ const float *f2 = b->front();
+ for (uint32_t i=0; i<16; i++)
+ {
+ float diff = physx::PxAbs(f1[i]-f2[i]);
+ if ( diff > 0.000001f ) return false;
+ }
+ return true;
+ }
+
+ bool isRenderState(const DebugPrimitive * const dp) const
+ {
+ return( dp->mCommand == DebugCommand::SET_CURRENT_COLOR ||
+ dp->mCommand == DebugCommand::SET_CURRENT_TILE1 ||
+ dp->mCommand == DebugCommand::SET_CURRENT_TILE2 ||
+ dp->mCommand == DebugCommand::SET_CURRENT_TEXTURE1 ||
+ dp->mCommand == DebugCommand::SET_CURRENT_TEXTURE2 ||
+ dp->mCommand == DebugCommand::SET_CURRENT_ARROW_COLOR ||
+ dp->mCommand == DebugCommand::SET_CURRENT_ARROW_SIZE ||
+ dp->mCommand == DebugCommand::SET_CURRENT_RENDER_SCALE ||
+ dp->mCommand == DebugCommand::SET_CURRENT_USER_ID ||
+ dp->mCommand == DebugCommand::SET_CURRENT_RENDER_STATE ||
+ dp->mCommand == DebugCommand::SET_CURRENT_TEXT_SCALE ||
+ dp->mCommand == DebugCommand::SET_CURRENT_TRANSFORM );
+ }
+
+ physx::PsMemoryBuffer mWorldSpace;
+ physx::PsMemoryBuffer mScreenSpace;
+ physx::PsMemoryBuffer mNoZ;
+
+ RenderState mWorldSpaceRenderState;
+ RenderState mScreenSpaceRenderState;
+ RenderState mNoZRenderState;
+
+ uint32_t mSendBufferCount;
+ const DebugPrimitive *mSendBuffer[MAX_SEND_BUFFER];
+};
+
+
+
+
+class InternalRenderDebug : public RenderDebugImpl, public physx::shdfnd::UserAllocated, PostRenderDebug
+{
+public:
+
+ InternalRenderDebug(ProcessRenderDebug *process,RenderDebugHook *renderDebugHook)
+ {
+ mCanSkip = true;
+ mRenderDebugHook = renderDebugHook;
+ mFrameTime = 1.0f / 60.0f;
+ mBlockIndex = 0;
+ mStackIndex = 0;
+ mUpdateCount = 0;
+ mOwnProcess = false;
+ if ( process )
+ {
+ mProcessRenderDebug = process;
+ }
+ else
+ {
+ mProcessRenderDebug = createProcessRenderDebug();
+ mOwnProcess = true;
+ }
+ initColors();
+ }
+
+ ~InternalRenderDebug(void)
+ {
+ if ( mOwnProcess )
+ {
+ mProcessRenderDebug->release();
+ }
+ }
+
+ virtual uint32_t getUpdateCount(void) const
+ {
+ return mUpdateCount;
+ }
+
+ virtual bool renderImpl(float dtime,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ bool ret = false;
+
+ ret = PostRenderDebug::processRenderDebug(mProcessRenderDebug,dtime,iface);
+ mUpdateCount++;
+
+ mProcessRenderDebug->finalizeFrame();
+ mCanSkip = true; // next frame state
+
+ return ret;
+ }
+
+ virtual void reset(int32_t blockIndex=-1) // -1 reset *everything*, 0 = reset everything except stuff inside blocks, > 0 reset a specific block of data.
+ {
+ if ( blockIndex == -1 )
+ {
+ PostRenderDebug::reset(NULL);
+ }
+ else
+ {
+ const physx::shdfnd::HashMap<uint32_t, BlockInfo *>::Entry *e = mBlocksHash.find(uint32_t(blockIndex));
+ if ( e )
+ {
+ BlockInfo *b = e->second;
+ PostRenderDebug::reset(b);
+ }
+ }
+ }
+
+
+ virtual void drawGrid(bool zup=false,uint32_t gridSize=40) // draw a grid.
+ {
+ DrawGrid d(zup,gridSize);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void pushRenderState(void)
+ {
+ PX_ASSERT( mStackIndex < RENDER_STATE_STACK_SIZE );
+ if ( mStackIndex < RENDER_STATE_STACK_SIZE )
+ {
+ mRenderStateStack[mStackIndex] = mCurrentState;
+ if ( mCurrentState.mPose )
+ {
+ mRenderStateStack[mStackIndex].mPose = &mRenderStateStack[mStackIndex].mCurrentPose;
+ }
+ mStackIndex++;
+ }
+ }
+
+ virtual void popRenderState(void)
+ {
+ PX_ASSERT(mStackIndex);
+ if ( mStackIndex > 0 )
+ {
+ mStackIndex--;
+ mCurrentState = mRenderStateStack[mStackIndex];
+ if ( mRenderStateStack[mStackIndex].mPose )
+ {
+ mCurrentState.mPose = &mCurrentState.mCurrentPose;
+ }
+ PostRenderDebug::updateBufferChangeCount(mCurrentState);
+ mCurrentState.incrementChangeCount();
+ }
+ }
+
+
+ virtual void setCurrentColor(uint32_t color=0xFFFFFF,uint32_t arrowColor=0xFF0000)
+ {
+ mCurrentState.mColor = color;
+ mCurrentState.mArrowColor = arrowColor;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual uint32_t getCurrentColor(void) const
+ {
+ return mCurrentState.mColor;
+ }
+
+ /**
+ \brief Set the current debug texture
+
+ \param textureEnum1 Which predefined texture to use as the primary texture
+ \param tileRate1 The tiling rate to use for the primary texture
+ \param textureEnum2 Which (optional) predefined texture to use as the primary texture
+ \param tileRate2 The tiling rate to use for the secondary texture
+ */
+ virtual void setCurrentTexture(DebugTextures::Enum textureEnum1,float tileRate1,DebugTextures::Enum textureEnum2,float tileRate2)
+ {
+ mCurrentState.mTexture1 = textureEnum1;
+ mCurrentState.mTexture2 = textureEnum2;
+ mCurrentState.mTileRate1 = tileRate1;
+ mCurrentState.mTileRate2 = tileRate2;
+ mCurrentState.incrementChangeCount();
+ }
+
+ /**
+ \brief Gets the current tiling rate of the primary texture
+
+ \return The current tiling rate of the primary texture
+ */
+ virtual float getCurrentTile1(void) const
+ {
+ return mCurrentState.mTileRate1;
+ }
+
+ /**
+ \brief Gets the current tiling rate of the secondary texture
+
+ \return The current tiling rate of the secondary texture
+ */
+ virtual float getCurrentTile2(void) const
+ {
+ return mCurrentState.mTileRate2;
+ }
+
+ /**
+ \brief Gets the current debug texture
+
+ \return The current texture id
+ */
+ virtual DebugTextures::Enum getCurrentTexture1(void) const
+ {
+ return static_cast<DebugTextures::Enum>(mCurrentState.mTexture1);
+ }
+
+ /**
+ \brief Gets the current debug texture
+
+ \return The current texture id
+ */
+ virtual DebugTextures::Enum getCurrentTexture2(void) const
+ {
+ return static_cast<DebugTextures::Enum>(mCurrentState.mTexture2);
+ }
+
+
+ virtual uint32_t getCurrentArrowColor(void) const
+ {
+ return mCurrentState.mArrowColor;
+ }
+
+
+ virtual void setCurrentUserId(int32_t userId)
+ {
+ mCurrentState.mUserId = userId;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual int32_t getCurrentUserId(void)
+ {
+ return mCurrentState.mUserId;
+ }
+
+ virtual void setCurrentDisplayTime(float displayTime=0.0001f)
+ {
+ mCurrentState.mDisplayTime = displayTime;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual float getRenderScale(void)
+ {
+ return mCurrentState.mRenderScale;
+ }
+
+ virtual void setRenderScale(float scale)
+ {
+ mCurrentState.mRenderScale = scale;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual void setCurrentState(uint32_t states=0)
+ {
+ mCurrentState.mStates = states;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual void addToCurrentState(RENDER_DEBUG::DebugRenderState::Enum state) // OR this state flag into the current state.
+ {
+ mCurrentState.mStates|=state;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual void removeFromCurrentState(RENDER_DEBUG::DebugRenderState::Enum state) // Remove this bit flat from the current state
+ {
+ mCurrentState.mStates&=~state;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual void setCurrentTextScale(float textScale)
+ {
+ mCurrentState.mTextScale = textScale;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual void setCurrentArrowSize(float arrowSize)
+ {
+ mCurrentState.mArrowSize = arrowSize;
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual uint32_t getCurrentState(void) const
+ {
+ return mCurrentState.mStates;
+ }
+
+ virtual void setRenderState(uint32_t states=0, // combination of render state flags
+ uint32_t color=0xFFFFFF, // base color
+ float displayTime=0.0001f, // duration of display items.
+ uint32_t arrowColor=0xFF0000, // secondary color, usually used for arrow head
+ float arrowSize=0.1f,
+ float renderScale=1.0f,
+ float textScale=1.0f) // seconary size, usually used for arrow head size.
+ {
+ uint32_t saveChangeCount = mCurrentState.mChangeCount;
+ new ( &mCurrentState ) RenderState(states,color,displayTime,arrowColor,arrowSize,renderScale,textScale);
+ mCurrentState.mChangeCount = saveChangeCount;
+ mCurrentState.incrementChangeCount();
+ }
+
+
+ virtual uint32_t getRenderState(uint32_t &color,float &displayTime,uint32_t &arrowColor,float &arrowSize,float &renderScale,float & /*textScale*/) const
+ {
+ color = mCurrentState.mColor;
+ displayTime = mCurrentState.mDisplayTime;
+ arrowColor = mCurrentState.mArrowColor;
+ arrowSize = mCurrentState.mArrowSize;
+ renderScale = mCurrentState.mRenderScale;
+ return mCurrentState.mStates;
+ }
+
+
+ virtual void endDrawGroup(void)
+ {
+ popRenderState();
+ PostRenderDebug::updatePostDrawGroupPose(mCurrentState);
+ }
+
+ virtual void setDrawGroupVisible(int32_t blockId,bool state)
+ {
+ const physx::shdfnd::HashMap<uint32_t, BlockInfo *>::Entry *e = mBlocksHash.find(uint32_t(blockId));
+ if ( e )
+ {
+ BlockInfo *b = e->second;
+ if ( b->mVisibleState != state )
+ {
+ b->mVisibleState = state;
+ }
+ }
+ }
+
+ virtual void debugPolygon(uint32_t pcount,const physx::PxVec3 *points)
+ {
+ if ( mCurrentState.isSolid() )
+ {
+ PX_ASSERT( pcount >= 3 );
+ PX_ASSERT( pcount <= 256 );
+ bool wasOverlay = mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ if( wasOverlay )
+ {
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.incrementChangeCount();
+ }
+ const physx::PxVec3 *v1 = &points[0];
+ const physx::PxVec3 *v2 = &points[1];
+ const physx::PxVec3 *v3 = &points[2];
+ debugTri(*v1, *v2, *v3);
+ for (uint32_t i=3; i<pcount; i++)
+ {
+ v2 = v3;
+ v3 = &points[i];
+ debugTri(*v1, *v2, *v3);
+ }
+ if ( wasOverlay )
+ {
+ for (uint32_t i=0; i<(pcount-1); i++)
+ {
+ debugLine( points[i], points[i+1] );
+ }
+ debugLine(points[pcount-1],points[0]);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.incrementChangeCount();
+ }
+ }
+ else
+ {
+ for (uint32_t i=0; i<(pcount-1); i++)
+ {
+ debugLine( points[i], points[i+1] );
+ }
+ debugLine(points[pcount-1],points[0]);
+ }
+ }
+
+ virtual void debugLine(const physx::PxVec3 &p1,const physx::PxVec3 &p2)
+ {
+ DebugLine d(p1,p2);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+
+ virtual void debugFrustum(const physx::PxMat44 &view,const physx::PxMat44 &proj)
+ {
+ DebugFrustum f(view,proj);
+ PostRenderDebug::postRenderDebug(&f,mCurrentState);
+ }
+
+ virtual void debugCone(float length,float innerAngle,float outerAngle,uint32_t subDivision,bool closeEnd)
+ {
+ DebugCone c(length,innerAngle,outerAngle,subDivision,closeEnd);
+ PostRenderDebug::postRenderDebug(&c,mCurrentState);
+ }
+
+ virtual void debugBound(const physx::PxBounds3 &_b)
+ {
+ DebugBound b(_b.minimum,_b.maximum );
+ PostRenderDebug::postRenderDebug(&b,mCurrentState);
+ }
+
+ virtual void debugBound(const physx::PxVec3 &bmin,const physx::PxVec3 &bmax)
+ {
+ DebugBound b(bmin,bmax);
+ PostRenderDebug::postRenderDebug(&b,mCurrentState);
+ }
+
+ virtual void debugPoint(const physx::PxVec3 &pos,float radius)
+ {
+ DebugPoint d(pos,radius);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugQuad(const physx::PxVec3 &pos,const physx::PxVec2 &scale,float rotation)
+ {
+ DebugQuad d(pos,scale,rotation);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+
+ virtual void debugPoint(const physx::PxVec3 &pos,const physx::PxVec3 &radius)
+ {
+ DebugPointScale d(pos,radius);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+
+ virtual void debugGraph(uint32_t /*numPoints*/, float * /*points*/, float /*graphMax*/, float /*graphXPos*/, float /*graphYPos*/, float /*graphWidth*/, float /*graphHeight*/, uint32_t /*colorSwitchIndex*/ = 0xFFFFFFFF)
+ {
+ PX_ALWAYS_ASSERT();
+ }
+
+
+ virtual void debugRect2d(float x1,float y1,float x2,float y2)
+ {
+ DebugRect2d d(x1,y1,x2,y2);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugGradientLine(const physx::PxVec3 &p1,const physx::PxVec3 &p2,const uint32_t &c1,const uint32_t &c2)
+ {
+ DebugGradientLine d(p1,p2,c1,c2);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugRay(const physx::PxVec3 &p1,const physx::PxVec3 &p2)
+ {
+ DebugRay d(p1,p2);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugCylinder(const physx::PxVec3 &p1,const physx::PxVec3 &p2,float radius)
+ {
+ DebugPointCylinder d(p1,p2,radius);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugThickRay(const physx::PxVec3 &p1,const physx::PxVec3 &p2,float raySize=0.02f, bool arrowTip=true)
+ {
+ DebugThickRay d(p1,p2,raySize,arrowTip);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugPlane(const physx::PxPlane &p,float radius1,float radius2)
+ {
+ DebugPlane d(p.n,p.d,radius1,radius2);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugTri(const physx::PxVec3 &p1,const physx::PxVec3 &p2,const physx::PxVec3 &p3)
+ {
+ DebugTri d(p1,p2,p3);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugTriNormals(const physx::PxVec3 &p1,const physx::PxVec3 &p2,const physx::PxVec3 &p3,const physx::PxVec3 &n1,const physx::PxVec3 &n2,const physx::PxVec3 &n3)
+ {
+ DebugTriNormals d(p1,p2,p3,n1,n2,n3);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugGradientTri(const physx::PxVec3 &p1,const physx::PxVec3 &p2,const physx::PxVec3 &p3,const uint32_t &c1,const uint32_t &c2,const uint32_t &c3)
+ {
+ DebugGradientTri d(p1,p2,p3,c1,c2,c3);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugGradientTriNormals(const physx::PxVec3 &p1,const physx::PxVec3 &p2,const physx::PxVec3 &p3,const physx::PxVec3 &n1,const physx::PxVec3 &n2,const physx::PxVec3 &n3,const uint32_t &c1,const uint32_t &c2,const uint32_t &c3)
+ {
+ DebugGradientTriNormals d(p1,p2,p3,n1,n2,n3,c1,c2,c3);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugSphere(const physx::PxVec3 &pos, float radius,uint32_t subdivision)
+ {
+ if ( subdivision < 1 )
+ {
+ subdivision = 1;
+ }
+ else if ( subdivision > 4 )
+ {
+ subdivision = 4;
+ }
+ physx::PxMat44 pose = physx::PxMat44(physx::PxIdentity);
+ pose.setPosition(pos);
+ debugOrientedSphere(radius, subdivision, pose);
+ }
+
+ void debugOrientedSphere(float radius, uint32_t subdivision,const physx::PxMat44 &transform)
+ {
+ pushRenderState();
+ if ( mCurrentState.mPose )
+ {
+ physx::PxMat44 xform = *mCurrentState.mPose*transform;
+ setPose(xform);
+ }
+ else
+ {
+ setPose(transform);
+ }
+
+ DebugSphere d(radius, subdivision);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+
+ popRenderState();
+ }
+
+ // a squashed sphere
+ virtual void debugOrientedSphere(const physx::PxVec3 &radius, uint32_t subdivision,const physx::PxMat44 &transform)
+ {
+ pushRenderState();
+ if ( mCurrentState.mPose )
+ {
+ physx::PxMat44 xform = *mCurrentState.mPose*transform;
+ setPose(xform);
+ }
+ else
+ {
+ setPose(transform);
+ }
+
+ DebugSquashedSphere d(radius, subdivision);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+
+ popRenderState();
+ }
+
+
+ virtual void debugCapsule(float radius,float height,uint32_t subdivision)
+ {
+ DebugCapsule d(radius,height,subdivision);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugCapsuleTapered(float radius1, float radius2, float height, uint32_t subdivision)
+ {
+ DebugTaperedCapsule d(radius1, radius2, height, subdivision);
+ PostRenderDebug::postRenderDebug(&d, mCurrentState);
+ }
+
+ virtual void debugCylinder(float radius,float height,bool closeSides,uint32_t subdivision)
+ {
+ DebugCylinder d(radius,height,subdivision,closeSides);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugCircle(const physx::PxVec3 &center,float radius,uint32_t subdivision)
+ {
+ pushRenderState();
+ physx::PxMat44 transform(physx::PxIdentity);
+ transform.setPosition(center);
+ if ( mCurrentState.mPose )
+ {
+ physx::PxMat44 xform = *mCurrentState.mPose*transform;
+ setPose(xform);
+ }
+ else
+ {
+ setPose(transform);
+ }
+ DebugCircle d(radius,subdivision,false);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ popRenderState();
+ }
+
+ virtual void debugAxes(const physx::PxMat44 &transform,float distance=0.1f,float brightness=1.0f,bool showXYZ=false,bool showRotation=false, uint32_t axisSwitch=4, DebugAxesRenderMode::Enum renderMode = DebugAxesRenderMode::DEBUG_AXES_RENDER_SOLID)
+ {
+ DebugAxes d(transform,distance,brightness,showXYZ,showRotation,axisSwitch, renderMode);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugArc(const physx::PxVec3 &center,const physx::PxVec3 &p1,const physx::PxVec3 &p2,float arrowSize=0.1f,bool showRoot=false)
+ {
+ DebugArc d(center,p1,p2,arrowSize,showRoot);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugThickArc(const physx::PxVec3 &center,const physx::PxVec3 &p1,const physx::PxVec3 &p2,float thickness=0.02f,bool showRoot=false)
+ {
+ DebugThickArc d(center,p1,p2,thickness,showRoot);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ virtual void debugDetailedSphere(const physx::PxVec3 &pos,float radius,uint32_t stepCount)
+ {
+ DebugDetailedSphere d(pos,radius,stepCount);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ /**
+ \brief Debug visualize a text string rendered using a simple 2d font.
+
+ \param x The X position of the text in normalized screen space 0 is the left of the screen and 1 is the right of the screen.
+ \param y The Y position of the text in normalized screen space 0 is the top of the screen and 1 is the bottom of the screen.
+ \param scale The scale of the font; these are not true-type fonts, so this is simple sprite scales. A scale of 0.5 is a nice default value.
+ \param shadowOffset The font is displayed with a drop shadow to make it easier to distinguish against the background; a value between 1 to 6 looks ok.
+ \param forceFixWidthNumbers This bool controls whether numeric values are printed as fixed width or not.
+ \param textColor the 32 bit ARGB value color to use for this piece of text.
+ \param fmt A printf style format string followed by optional arguments
+ */
+ virtual void debugText2D(float x,
+ float y,
+ float scale,
+ float shadowOffset,
+ bool forceFixWidthNumbers,
+ uint32_t textColor,
+ const char *fmt,...)
+ {
+ char wbuff[16384];
+ wbuff[16383] = 0;
+ va_list arg;
+ va_start( arg, fmt );
+ physx::shdfnd::vsnprintf(wbuff,sizeof(wbuff)-1, fmt, arg);
+ va_end(arg);
+ DebugText2D dt(physx::PxVec2(x,y),scale,shadowOffset,forceFixWidthNumbers,textColor,wbuff);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+
+ virtual void debugText(const physx::PxVec3 &pos,const char *fmt,...)
+ {
+ char wbuff[16384];
+ wbuff[16383] = 0;
+ va_list arg;
+ va_start( arg, fmt );
+ physx::shdfnd::vsnprintf(wbuff,sizeof(wbuff)-1, fmt, arg);
+ va_end(arg);
+ physx::PxMat44 pose = mCurrentState.mPose ? *mCurrentState.mPose : physx::PxMat44(physx::PxIdentity);
+ DebugText dt(pos,pose,wbuff);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ virtual void setViewMatrix(const physx::PxMat44 &view)
+ {
+ memcpy( mViewMatrix44, &view, 16*sizeof( float ) );
+ updateVP();
+ if ( mProcessRenderDebug )
+ {
+ const physx::PxMat44 *view44 = (reinterpret_cast<const physx::PxMat44 *>(mViewMatrix44));
+ mProcessRenderDebug->setViewMatrix(*view44);
+ }
+ }
+
+ virtual void setProjectionMatrix(const physx::PxMat44 &projection)
+ {
+ memcpy( mProjectionMatrix44, &projection, 16*sizeof( float ) );
+ updateVP();
+ }
+
+ void updateVP(void)
+ {
+ float* e = mViewProjectionMatrix44;
+ for( int c = 0; c < 4; ++c )
+ {
+ for( int r = 0; r < 4; ++r, ++e )
+ {
+ float sum = 0;
+ for( int k = 0; k < 4; ++k )
+ {
+ sum += mProjectionMatrix44[r+(k<<2)]*mViewMatrix44[k+(c<<2)];
+ }
+ *e = sum;
+ }
+ }
+ // grab the world-space eye position.
+ const physx::PxMat44 *view44 = (reinterpret_cast<const physx::PxMat44 *>(mViewMatrix44));
+ physx::PxMat44 viewInverse = view44->inverseRT();
+ mEyePos = viewInverse.transform( physx::PxVec3( 0.0f, 0.0f, 0.0f ));
+ }
+
+ virtual const float* getViewProjectionMatrix(void) const
+ {
+ return mViewProjectionMatrix44;
+ }
+
+ virtual const physx::PxMat44* getViewProjectionMatrixTyped(void) const
+ {
+ return (reinterpret_cast<const physx::PxMat44 *>(mViewProjectionMatrix44));
+ }
+
+
+ virtual const float *getViewMatrix(void) const
+ {
+ return mViewMatrix44; // returns column major array
+ }
+
+ virtual const physx::PxMat44 *getViewMatrixTyped(void) const
+ {
+ return (reinterpret_cast<const physx::PxMat44 *>(mViewMatrix44)); // returns column major array
+ }
+
+
+ virtual const float *getProjectionMatrix(void) const
+ {
+ return mProjectionMatrix44; // returns column major array
+ }
+
+ virtual const physx::PxMat44 *getProjectionMatrixTyped(void) const
+ {
+ return (reinterpret_cast<const physx::PxMat44 *>(mProjectionMatrix44)); // returns column major array
+ }
+
+
+ // quat to rotate v0 t0 v1
+ PX_INLINE physx::PxQuat rotationArc(const physx::PxVec3& v0, const physx::PxVec3& v1)
+ {
+ const physx::PxVec3 cross = v0.cross(v1);
+ const float d = v0.dot(v1);
+ if(d<=-0.99999f)
+ return (physx::PxAbs(v0.x)<0.1f ? physx::PxQuat(0.0f, v0.z, -v0.y, 0.0f) : physx::PxQuat(v0.y, -v0.x, 0.0, 0.0)).getNormalized();
+
+ const float s = physx::PxSqrt((1+d)*2), r = 1/s;
+
+ return physx::PxQuat(cross.x*r, cross.y*r, cross.z*r, s*0.5f).getNormalized();
+ }
+
+
+ /**
+ \brief A convenience method to convert a position and direction vector into a 4x4 transform
+
+ \param p0 Start position
+ \param p1 Rotate to position
+ \param xform Output transform
+
+ */
+ virtual void rotationArc(const physx::PxVec3 &p0,const physx::PxVec3 &p1,physx::PxMat44 &xform)
+ {
+ physx::PxVec3 dir = p1-p0;
+ dir.normalize();
+
+ physx::PxTransform t;
+ t.p = p0;
+ t.q = rotationArc(physx::PxVec3(0,1.0f,0),dir);
+ xform = physx::PxMat44(t);
+ }
+
+ /**
+ \brief A convenience method to convert a position and direction vector into a 4x4 transform
+
+ \param p0 The origin
+ \param p1 Rotate to position
+ \param xform Ouput transform
+
+ */
+ virtual void rotationArc(const float p0[3],const float p1[3],float xform[16])
+ {
+ rotationArc(*(reinterpret_cast<const physx::PxVec3 *>(p0)),*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<physx::PxMat44 *>(xform)));
+ }
+
+ virtual void eulerToQuat(const physx::PxVec3 &angles, physx::PxQuat &q) // angles are in degrees.
+ {
+ float roll = angles.x*0.5f*FM_DEG_TO_RAD;
+ float pitch = angles.y*0.5f*FM_DEG_TO_RAD;
+ float yaw = angles.z*0.5f*FM_DEG_TO_RAD;
+
+ float cr = cosf(roll);
+ float cp = cosf(pitch);
+ float cy = cosf(yaw);
+
+ float sr = sinf(roll);
+ float sp = sinf(pitch);
+ float sy = sinf(yaw);
+
+ float cpcy = cp * cy;
+ float spsy = sp * sy;
+ float spcy = sp * cy;
+ float cpsy = cp * sy;
+
+ float x = ( sr * cpcy - cr * spsy);
+ float y = ( cr * spcy + sr * cpsy);
+ float z = ( cr * cpsy - sr * spcy);
+ float w = cr * cpcy + sr * spsy;
+ q = physx::PxQuat(x,y,z,w);
+ }
+
+ virtual int32_t beginDrawGroup(const physx::PxMat44 &pose)
+ {
+ pushRenderState();
+
+ setRenderState(RENDER_DEBUG::DebugRenderState::InfiniteLifeSpan,0xFFFFFF,0.0001f,0xFF0000,0.1f,mCurrentState.mRenderScale,mCurrentState.mTextScale);
+
+ mBlockIndex++;
+ mCurrentState.mBlockInfo = mBlocks.construct();
+ mCurrentState.mBlockInfo->mHashValue = mBlockIndex;
+ mCurrentState.mBlockInfo->mPose = pose;
+ mBlocksHash[mBlockIndex] = mCurrentState.mBlockInfo;
+
+ return int32_t(mBlockIndex);
+ }
+
+ virtual void setDrawGroupPose(int32_t blockId,const physx::PxMat44 &pose)
+ {
+ const physx::shdfnd::HashMap<uint32_t, BlockInfo *>::Entry *e = mBlocksHash.find(uint32_t(blockId));
+ if ( e )
+ {
+ BlockInfo *b = e->second;
+ if ( memcmp(&pose,&b->mPose,sizeof(physx::PxMat44)) != 0 ) // if the pose has changed...
+ {
+ b->mPose = pose;
+ b->mChanged = true;
+ }
+ }
+ }
+
+ /**
+ \brief Sets the global pose for the current debug-rendering context. This is preserved on the state stack.
+
+ \param pos Sets the translation component
+ \param quat Sets the rotation component as a quat
+ */
+ virtual void setPose(const float pos[3],const float quat[4])
+ {
+ physx::PxTransform t(*(reinterpret_cast<const physx::PxVec3 *>(pos)),*(reinterpret_cast<const physx::PxQuat *>(quat)));
+ physx::PxMat44 xform(t);
+ setPose(xform.front());
+ }
+
+ /**
+ \brief Sets the global pose position only, does not change the rotation.
+
+ \param pos Sets the translation component
+ */
+ virtual void setPosition(const float pos[3])
+ {
+ setPosition( *(reinterpret_cast<const physx::PxVec3 *>(pos)));
+ }
+
+ /**
+ \brief Sets the global pose orientation only, does not change the position
+
+ \param quat Sets the orientation of the global pose
+ */
+ virtual void setOrientation(const float quat[3])
+ {
+ setOrientation( *(reinterpret_cast<const physx::PxQuat *>(quat)));
+ }
+
+ /**
+ \brief Sets the global pose back to identity
+ */
+ virtual void setIdentityPose(void)
+ {
+ mCurrentState.mPose = NULL;
+ mCurrentState.mCurrentPose = physx::PxMat44(physx::PxIdentity);
+ mCurrentState.incrementChangeCount();
+ }
+
+ /**
+ \brief Sets the global pose for the current debug-rendering context. This is preserved on the state stack.
+
+ \param pose Sets the pose from a position and quaternion rotation
+ */
+ virtual void setPose(const physx::PxTransform &pose)
+ {
+ physx::PxMat44 m(pose);
+ setPose(m);
+ }
+
+ /**
+ \brief Sets the global pose position only, does not change the rotation.
+
+ \param position Sets the translation component
+ */
+ virtual void setPosition(const physx::PxVec3 &position)
+ {
+ physx::PxMat44 m = mCurrentState.mCurrentPose;
+ m.setPosition(position);
+ setPose(m);
+ }
+
+ /**
+ \brief Sets the global pose orientation only, does not change the position
+
+ \param rot Sets the orientation of the global pose
+ */
+ virtual void setOrientation(const physx::PxQuat &rot)
+ {
+ physx::PxMat44 m(rot);
+ m.setPosition(mCurrentState.mCurrentPose.getPosition());
+ setPose(m);
+ }
+
+
+ virtual void setPose(const physx::PxMat44 &pose)
+ {
+ physx::PxMat44 id = physx::PxMat44(physx::PxIdentity);
+ if ( id.column0 != pose.column0 ||
+ id.column1 != pose.column1 ||
+ id.column2 != pose.column2 ||
+ id.column3 != pose.column3 )
+ {
+ mCurrentState.mCurrentPose = pose;
+ mCurrentState.mPose = &mCurrentState.mCurrentPose;
+ }
+ else
+ {
+ mCurrentState.mPose = NULL;
+ mCurrentState.mCurrentPose = physx::PxMat44(physx::PxIdentity);
+ }
+ mCurrentState.incrementChangeCount();
+ }
+
+ virtual const physx::PxMat44 * getPoseTyped(void) const
+ {
+ return &mCurrentState.mCurrentPose;
+ }
+
+ virtual const float *getPose(void) const
+ {
+ return reinterpret_cast<const float *>(&mCurrentState.mCurrentPose);
+ }
+
+
+ /* \brief Create an createDebugGraphDesc. This is the manual way of setting up a graph. Every parameter can
+ and must be customized when using this constructor.
+ */
+ virtual DebugGraphDesc* createDebugGraphDesc(void)
+ {
+ DebugGraphDesc* dGDPtr = static_cast<DebugGraphDesc *>(PX_ALLOC(sizeof(DebugGraphDesc), PX_DEBUG_EXP("DebugGraphDesc")));
+ new (dGDPtr ) DebugGraphDesc;
+
+ dGDPtr->mNumPoints = 0;
+ dGDPtr->mPoints = NULL;
+ dGDPtr->mGraphXLabel = NULL;
+ dGDPtr->mGraphYLabel = NULL;
+ dGDPtr->mGraphColor = 0x00FF0000;
+ dGDPtr->mArrowColor = 0x0000FF00;
+ dGDPtr->mColorSwitchIndex = uint32_t(-1);
+ dGDPtr->mGraphMax = 0.0f;
+ dGDPtr->mGraphXPos = 0.0f;
+ dGDPtr->mGraphYPos = 0.0f;
+ dGDPtr->mGraphWidth = 0.0f;
+ dGDPtr->mGraphHeight = 0.0f;
+ dGDPtr->mCutOffLevel = 0.0f;
+ return(dGDPtr);
+ }
+
+ virtual void releaseDebugGraphDesc(DebugGraphDesc *desc)
+ {
+ PX_FREE(desc);
+ }
+
+ /**
+ \brief Create an createDebugGraphDesc using the minimal amount of work. This constructor provides for six custom
+ graphs to be simultaneously drawn on the display at one time numbered 0 to 5. The position, color, and size
+ of the graphs are automatically set based on the graphNum argument.
+ */
+ #define LEFT_X (-0.9f)
+ #define RIGHT_X (+0.1f)
+ #define TOP_Y (+0.4f)
+ #define MID_Y (-0.2f)
+ #define BOTTOM_Y (-0.8f)
+ virtual DebugGraphDesc* createDebugGraphDesc(uint32_t graphNum,uint32_t dataCount,const float *dataArray, float maxY, char* xLabel, char* yLabel)
+ {
+ static struct
+ {
+ float xPos, yPos;
+ } graphData[MAX_GRAPHS] =
+ {
+ {LEFT_X, TOP_Y},
+ {LEFT_X, MID_Y},
+ {LEFT_X, BOTTOM_Y},
+ {RIGHT_X, TOP_Y},
+ {RIGHT_X, MID_Y},
+ {RIGHT_X, BOTTOM_Y}
+ };
+ PX_ASSERT(graphNum < MAX_GRAPHS);
+ DebugGraphDesc* dGDPtr = createDebugGraphDesc();
+
+ dGDPtr->mGraphColor = 0x00FF0000;
+ dGDPtr->mArrowColor = 0x0000FF00;
+ dGDPtr->mColorSwitchIndex = uint32_t(-1);
+
+ // no cut off line by default
+ dGDPtr->mCutOffLevel = 0.0f;
+ dGDPtr->mNumPoints = dataCount;
+ dGDPtr->mPoints = dataArray;
+ dGDPtr->mGraphMax = maxY;
+ dGDPtr->mGraphXLabel = xLabel;
+ dGDPtr->mGraphYLabel = yLabel;
+
+ dGDPtr->mGraphXPos = graphData[graphNum].xPos;
+ dGDPtr->mGraphYPos = graphData[graphNum].yPos;;
+ dGDPtr->mGraphWidth = GRAPH_WIDTH_DEFAULT;
+ dGDPtr->mGraphHeight = GRAPH_HEIGHT_DEFAULT;
+
+ return(dGDPtr);
+ }
+
+ virtual void debugGraph(const DebugGraphDesc& graphDesc)
+ {
+ DebugGraphStream d(graphDesc);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ /**
+ \brief Set a debug color value by name.
+ */
+ virtual void setDebugColor(RENDER_DEBUG::DebugColors::Enum colorEnum, uint32_t value)
+ {
+ if( colorEnum < RENDER_DEBUG::DebugColors::NUM_COLORS )
+ {
+ colors[ colorEnum ] = value;
+ }
+ }
+
+ /**
+ \brief Return a debug color value by name.
+ */
+ virtual uint32_t getDebugColor(RENDER_DEBUG::DebugColors::Enum colorEnum) const
+ {
+ if( colorEnum < RENDER_DEBUG::DebugColors::NUM_COLORS )
+ {
+ return colors[ colorEnum ];
+ }
+ return 0;
+ }
+
+ /**
+ \brief Return a debug color value by RGB inputs
+ */
+ virtual uint32_t getDebugColor(float red, float green, float blue) const
+ {
+ union
+ {
+ uint8_t colorChars[4];
+ uint32_t color;
+ };
+
+ colorChars[3] = 0xff; // alpha
+ colorChars[2] = uint8_t(red * 255);
+ colorChars[1] = uint8_t(green * 255);
+ colorChars[0] = uint8_t(blue * 255);
+
+ return color;
+ }
+
+ virtual void debugMessage(const char *fmt,...)
+ {
+ mCanSkip = false;
+ char wbuff[16384];
+ wbuff[16383] = 0;
+ va_list arg;
+ va_start( arg, fmt );
+ physx::shdfnd::vsnprintf(wbuff,sizeof(wbuff)-1, fmt, arg);
+ va_end(arg);
+ DebugMessage dt(wbuff);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ /**
+ \brief Render a set of instanced triangle meshes.
+ */
+ virtual void renderTriangleMeshInstances(uint32_t meshId, // The ID of the previously created triangle mesh
+ uint32_t instanceCount, // The number of instances to render
+ const RENDER_DEBUG::RenderDebugInstance *instances) // The array of poses for each instance
+ {
+ DebugRenderTriangleMeshInstances dt(meshId,instanceCount,instances);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+
+ /**
+ \brief Create a debug texture based on a filename
+
+ \param id The id associated with this custom texture, must be greater than 28; the reserved ids for detail textures
+ \param fname The name of the DDS file associated with this texture.
+ */
+ virtual void createCustomTexture(uint32_t id,const char *fname)
+ {
+ mCanSkip = false;
+ DebugCreateCustomTexture dt(id,fname);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+
+ /**
+ \brief Create a triangle mesh that we can render. Assumes an indexed triangle mesh. User provides a *unique* id. If it is not unique, this will fail.
+ */
+ virtual void createTriangleMesh(uint32_t meshId, // The unique mesh ID
+ uint32_t vcount, // The number of vertices in the triangle mesh
+ const RENDER_DEBUG::RenderDebugMeshVertex *meshVertices, // The array of vertices
+ uint32_t tcount, // The number of triangles (indices must contain tcount*3 values)
+ const uint32_t *indices) // The array of triangle mesh indices
+ {
+ mCanSkip = false;
+ DebugCreateTriangleMesh dt(meshId,vcount,meshVertices,tcount,indices);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ /**
+ \brief Refresh a sub-section of the vertices in a previously created triangle mesh.
+
+ \param vcount This is the number of vertices to refresh.
+ \param refreshVertices This is an array of revised vertex data.
+ \param refreshIndices This is an array of indices which correspond to the original triangle mesh submitted. There should be one index for each vertex.
+ */
+ virtual void refreshTriangleMeshVertices(uint32_t meshId,
+ uint32_t vcount,
+ const RenderDebugMeshVertex *refreshVertices,
+ const uint32_t *refreshIndices)
+ {
+ if ( vcount && refreshVertices && refreshIndices )
+ {
+ DebugRefreshTriangleMeshVertices dt(meshId,vcount,refreshVertices,refreshIndices);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+ }
+
+ /**
+ \brief Release a previously created triangle mesh
+ */
+ virtual void releaseTriangleMesh(uint32_t meshId)
+ {
+ mCanSkip = false;
+ DebugReleaseTriangleMesh d(meshId);
+ PostRenderDebug::postRenderDebug(&d,mCurrentState);
+ }
+
+ /**
+ \brief Render a set of data points, either as wire-frame cross hairs or as a small solid instanced mesh.
+
+ This callback provides the ability to (as rapidly as possible) render a large number of
+
+ \param mode Determines what mode to render the point data
+ \param meshId The ID of the previously created triangle mesh if rendering in mesh mode
+ \param textureId1 The ID of the primary texture
+ \param textureTile1 The UV tiling rate of the primary texture
+ \param textureId2 The ID of the secondary texture
+ \param textureTile2 The UV tiling rate of the secondary texture
+ \param pointCount The number of points to render
+ \param points The array of points to render
+ */
+ virtual void debugPoints(PointRenderMode mode,
+ uint32_t meshId,
+ uint32_t textureId1,
+ float textureTile1,
+ uint32_t textureId2,
+ float textureTile2,
+ uint32_t pointCount,
+ const float *points)
+ {
+ DebugRenderPoints dt(meshId,mode,textureId1,textureTile1,textureId2,textureTile2,pointCount,points);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ /**
+ \brief This method will produce a debug visualization of a convex hull; either as lines or solid triang;es depending on the current debug render state
+
+ \param planeCount The number of planes in the convex hull
+ \param planes The array of plane equations in the convex hull
+ */
+ virtual void debugConvexHull(uint32_t planeCount,
+ const float *planes)
+ {
+ DebugConvexHull dt(planeCount,planes);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ /**
+ \brief Implement this method to display lines output from the RenderDebug library
+
+ \param lcount The number of lines to draw (vertex count=lines*2)
+ \param vertices The pairs of vertices for each line segment
+ \param useZ Whether or not these should be zbuffered
+ \param isScreenSpace Whether or not these are in homogeneous screen-space co-ordinates
+ */
+ virtual void debugRenderLines(uint32_t lcount,
+ const RenderDebugVertex *vertices,
+ bool useZ,
+ bool isScreenSpace)
+ {
+ DebugRenderLines dt(lcount,vertices,useZ ? 1U : 0U,isScreenSpace ? 1U : 0U);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ /**
+ \brief Implement this method to display solid shaded triangles without any texture surce.
+
+ \param tcount The number of triangles to render. (vertex count=tcount*2)
+ \param vertices The vertices for each triangle
+ \param useZ Whether or not these should be zbuffered
+ \param isScreenSpace Whether or not these are in homogeneous screen-space co-ordinates
+ */
+ virtual void debugRenderTriangles(uint32_t tcount,
+ const RenderDebugSolidVertex *vertices,
+ bool useZ,
+ bool isScreenSpace)
+ {
+ DebugRenderTriangles dt(tcount,vertices,useZ ? 1U : 0U,isScreenSpace ? 1U : 0U);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+private:
+
+ void initColors()
+ {
+#define INIT_COLOR( name, defVal, minVal, maxVal ) \
+ colorsDefValue[ name ] = uint32_t(defVal); \
+ colorsMinValue[ name ] = uint32_t(minVal); \
+ colorsMaxValue[ name ] = uint32_t(maxVal);
+
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Default, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::PoseArrows, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::MeshStatic, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::MeshDynamic, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Shape, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Text0, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Text1, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::ForceArrowsLow, 0xffffff00, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::ForceArrowsNorm,0xff00ff00, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::ForceArrowsHigh,0xffff0000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Color0, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Color1, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Color2, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Color3, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Color4, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Color5, 0x00000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Red, 0xffff0000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Green, 0xff00ff00, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Blue, 0xff0000ff, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::DarkRed, 0xff800000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::DarkGreen, 0xff008000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::DarkBlue, 0xff000080, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::LightRed, 0xffff8080, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::LightGreen, 0xff80ff00, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::LightBlue, 0xff00ffff, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Purple, 0xffff00ff, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::DarkPurple, 0xff800080, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Yellow, 0xffffff00, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Orange, 0xffff8000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Gold, 0xff808000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Emerald, 0xff008080, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::White, 0xffffffff, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Black, 0xff000000, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::Gray, 0xff808080, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::LightGray, 0xffC0C0C0, 0, UINT32_MAX);
+ INIT_COLOR(RENDER_DEBUG::DebugColors::DarkGray, 0xff404040, 0, UINT32_MAX);
+#undef INIT_COLOR
+
+ memcpy( colors, colorsDefValue, sizeof(uint32_t) * RENDER_DEBUG::DebugColors::NUM_COLORS );
+ }
+
+ void releaseRenderDebug(void)
+ {
+ delete this;
+ }
+
+
+//*****************************************************
+//**** Non-typed version of methods
+//*****************************************************
+
+ virtual void debugPolygon(uint32_t pcount,const float *points)
+ {
+ debugPolygon(pcount,(reinterpret_cast<const physx::PxVec3 *>(points)));
+ }
+
+ virtual void debugLine(const float p1[3],const float p2[3])
+ {
+ debugLine( *(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)));
+ }
+
+ virtual void debugGradientLine(const float p1[3],const float p2[3],const uint32_t &c1,const uint32_t &c2)
+ {
+ debugGradientLine(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),c1,c2);
+ }
+
+ virtual void debugRay(const float p1[3],const float p2[3])
+ {
+ debugRay(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)));
+ }
+
+ virtual void debugCylinder(const float p1[3],const float p2[3],float radius)
+ {
+ debugCylinder(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),radius);
+ }
+
+ virtual void debugThickRay(const float p1[3],const float p2[3],float raySize=0.02f,bool includeArrow=true)
+ {
+ debugThickRay(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),raySize,includeArrow);
+ }
+
+ virtual void debugPlane(const float normal[3],float dCoff,float radius1,float radius2)
+ {
+ physx::PxPlane p(normal[0],normal[1],normal[2],dCoff);
+ debugPlane(p,radius1,radius2);
+ }
+
+ virtual void debugTri(const float p1[3],const float p2[3],const float p3[3])
+ {
+ debugTri(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),*(reinterpret_cast<const physx::PxVec3 *>(p3)));
+ }
+
+ virtual void debugTriNormals(const float p1[3],const float p2[3],const float p3[3],const float n1[3],const float n2[3],const float n3[3])
+ {
+ debugTriNormals(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),*(reinterpret_cast<const physx::PxVec3 *>(p3)),*(reinterpret_cast<const physx::PxVec3 *>(n1)),*(reinterpret_cast<const physx::PxVec3 *>(n2)),*(reinterpret_cast<const physx::PxVec3 *>(n3)));
+ }
+
+ virtual void debugGradientTri(const float p1[3],const float p2[3],const float p3[3],const uint32_t &c1,const uint32_t &c2,const uint32_t &c3)
+ {
+ debugGradientTri(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),*(reinterpret_cast<const physx::PxVec3 *>(p3)),c1,c2,c3);
+ }
+
+ virtual void debugGradientTriNormals(const float p1[3],const float p2[3],const float p3[3],const float n1[3],const float n2[3],const float n3[3],const uint32_t &c1,const uint32_t &c2,const uint32_t &c3)
+ {
+ debugGradientTriNormals(*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),*(reinterpret_cast<const physx::PxVec3 *>(p3)),*(reinterpret_cast<const physx::PxVec3 *>(n1)),*(reinterpret_cast<const physx::PxVec3 *>(n2)),*(reinterpret_cast<const physx::PxVec3 *>(n3)),c1,c2,c3);
+ }
+
+ virtual void debugBound(const float bmin[3],const float bmax[3])
+ {
+ physx::PxBounds3 b(*(reinterpret_cast<const physx::PxVec3 *>(bmin)),*(reinterpret_cast<const physx::PxVec3 *>(bmax)));
+ debugBound(b);
+ }
+
+ virtual void debugSphere(const float pos[3],float radius,uint32_t subdivision)
+ {
+ debugSphere(*(reinterpret_cast<const physx::PxVec3 *>(pos)),radius,subdivision);
+ }
+
+
+ virtual void debugCircle(const float center[3],float radius,uint32_t subdivision)
+ {
+ debugCircle(*(reinterpret_cast<const physx::PxVec3 *>(center)),radius,subdivision);
+ }
+
+ virtual void debugPoint(const float pos[3],float radius)
+ {
+ debugPoint(*(reinterpret_cast<const physx::PxVec3 *>(pos)),radius);
+ }
+
+ virtual void debugPoint(const float pos[3],const float scale[3])
+ {
+ debugPoint(*(reinterpret_cast<const physx::PxVec3 *>(pos)),*(reinterpret_cast<const physx::PxVec3 *>(scale)));
+ }
+
+ virtual void debugQuad(const float pos[3],const float scale[2],float orientation)
+ {
+ debugQuad(*(reinterpret_cast<const physx::PxVec3 *>(pos)),*reinterpret_cast<const physx::PxVec2 *>(scale),orientation);
+ }
+
+ virtual void debugAxes(const float transform[16],float distance=0.1f,float brightness=1.0f,bool showXYZ=false,bool showRotation=false,uint32_t axisSwitch=4, DebugAxesRenderMode::Enum renderMode = DebugAxesRenderMode::DEBUG_AXES_RENDER_SOLID)
+ {
+ debugAxes(*(reinterpret_cast<const physx::PxMat44 *>(transform)),distance,brightness,showXYZ,showRotation,axisSwitch,renderMode);
+ }
+
+ virtual void debugArc(const float center[3],const float p1[3],const float p2[3],float arrowSize=0.1f,bool showRoot=false)
+ {
+ debugArc(*(reinterpret_cast<const physx::PxVec3 *>(center)),*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),arrowSize,showRoot);
+ }
+
+ virtual void debugThickArc(const float center[3],const float p1[3],const float p2[3],float thickness=0.02f,bool showRoot=false)
+ {
+ debugThickArc(*(reinterpret_cast<const physx::PxVec3 *>(center)),*(reinterpret_cast<const physx::PxVec3 *>(p1)),*(reinterpret_cast<const physx::PxVec3 *>(p2)),thickness,showRoot);
+ }
+
+ virtual void debugText(const float pos[3],const char *fmt,...)
+ {
+ char wbuff[16384];
+ wbuff[16383] = 0;
+ va_list arg;
+ va_start( arg, fmt );
+ physx::shdfnd::vsnprintf(wbuff,sizeof(wbuff)-1, fmt, arg);
+ va_end(arg);
+ debugText(*(reinterpret_cast<const physx::PxVec3 *>(pos)),"%s",wbuff);
+ }
+
+ virtual void setViewMatrix(const float view[16])
+ {
+ setViewMatrix(*(reinterpret_cast<const physx::PxMat44 *>(view)));
+ }
+
+ virtual void setProjectionMatrix(const float projection[16])
+ {
+ setProjectionMatrix(*(reinterpret_cast<const physx::PxMat44 *>(projection)));
+ }
+
+ virtual void eulerToQuat(const float angles[3],float q[4]) // angles are in degrees.
+ {
+ eulerToQuat(*(reinterpret_cast<const physx::PxVec3 *>(angles)),*(reinterpret_cast<physx::PxQuat *>(q)));
+ }
+
+ virtual int32_t beginDrawGroup(const float pose[16])
+ {
+ return beginDrawGroup(*(reinterpret_cast<const physx::PxMat44 *>(pose)));
+ }
+
+ virtual void setDrawGroupPose(int32_t blockId,const float pose[16])
+ {
+ setDrawGroupPose(blockId,*(reinterpret_cast<const physx::PxMat44 *>(pose)));
+ }
+
+ virtual void debugDetailedSphere(const float pos[3],float radius,uint32_t stepCount)
+ {
+ debugDetailedSphere(*(reinterpret_cast<const physx::PxVec3 *>(pos)),radius,stepCount);
+ }
+
+ virtual void setPose(const float pose[16])
+ {
+ setPose(*(reinterpret_cast<const physx::PxMat44 *>(pose)));
+ }
+
+ virtual void debugFrustum(const float view[16],const float proj[16])
+ {
+ debugFrustum( *(reinterpret_cast<const physx::PxMat44 *>(view)),*(reinterpret_cast<const physx::PxMat44 *>(proj)));
+ }
+
+
+//*****************************************************
+// ** Methods which get hooked back through the main parent interface.
+ /**
+ \brief Begins a file-playback session. Returns the number of recorded frames in the recording file. Zero if the file was not valid.
+ */
+ virtual uint32_t setFilePlayback(const char *fileName)
+ {
+ return mRenderDebugHook->setFilePlayback(fileName);
+ }
+
+ /**
+ \brief Set's the file playback to a specific frame. Returns true if successful.
+ */
+ virtual bool setPlaybackFrame(uint32_t playbackFrame)
+ {
+ return mRenderDebugHook->setPlaybackFrame(playbackFrame);
+ }
+
+ /**
+ \brief Returns the number of recorded frames in the debug render recording file.
+ */
+ virtual uint32_t getPlaybackFrameCount(void) const
+ {
+ return mRenderDebugHook->getPlaybackFrameCount();
+ }
+
+ /**
+ \brief Stops the current recording playback.
+ */
+ virtual void stopPlayback(void)
+ {
+ mRenderDebugHook->stopPlayback();
+ }
+
+ /**
+ \brief Do a 'try' lock on the global render debug mutex. This is simply provided as an optional convenience if you are accessing RenderDebug from multiple threads and want to prevent contention.
+ */
+ virtual bool trylock(void)
+ {
+ return mRenderDebugHook->trylock();
+ }
+
+ /**
+ \brief Lock the global render-debug mutex to avoid thread contention.
+ */
+ virtual void lock(void)
+ {
+ mRenderDebugHook->lock();
+ }
+
+ /**
+ \brief Unlock the global render-debug mutex
+ */
+ virtual void unlock(void)
+ {
+ mRenderDebugHook->unlock();
+ }
+
+ /**
+ \brief Convenience method to return a unique mesh id number (simply a global counter to avoid clashing with other ids
+ */
+ virtual uint32_t getMeshId(void)
+ {
+ return mRenderDebugHook->getMeshId();
+ }
+
+ /**
+ \brief Send a command from the server to the client. This could be any arbitrary console command, it can also be mouse drag events, debug visualization events, etc.
+ * the client receives this command in argc/argv format.
+ */
+ virtual bool sendRemoteCommand(const char *fmt,...)
+ {
+ char buff[16384];
+ buff[16383] = 0;
+ va_list arg;
+ va_start( arg, fmt );
+ physx::shdfnd::vsnprintf(buff,sizeof(buff)-1, fmt, arg);
+ va_end(arg);
+ return mRenderDebugHook->sendRemoteCommand("%s",buff);
+ }
+
+ /**
+ \brief If running in client mode, poll this method to retrieve any pending commands from the server. If it returns NULL then there are no more commands.
+ */
+ virtual const char ** getRemoteCommand(uint32_t &argc)
+ {
+ return mRenderDebugHook->getRemoteCommand(argc);
+ }
+
+ /**
+ \brief Transmits an arbitrary block of binary data to the remote machine. The block of data can have a command and id associated with it.
+
+ It is important to note that due to the fact the RenderDebug system is synchronized every single frame, it is strongly recommended
+ that you only use this feature for relatively small data items; probably on the order of a few megabytes at most. If you try to do
+ a very large transfer, in theory it would work, but it might take a very long time to complete and look like a hang since it will
+ essentially be blocking.
+
+ \param nameSpace An arbitrary command associated with this data transfer, for example this could indicate a remote file request.
+ \param resourceName An arbitrary id associated with this data transfer, for example the id could be the file name of a file transfer request.
+ \param data The block of binary data to transmit, you are responsible for maintaining endian correctness of the internal data if necessary.
+ \param dlen The length of the lock of data to transmit.
+
+ \return Returns true if the data was queued to be transmitted, false if it failed.
+ */
+ virtual bool sendRemoteResource(const char *nameSpace,
+ const char *resourceName,
+ const void *data,
+ uint32_t dlen)
+ {
+ return mRenderDebugHook->sendRemoteResource(nameSpace,resourceName,data,dlen);
+ }
+
+
+ /**
+ \brief Retrieves a block of remotely transmitted binary data.
+
+ \param nameSpace A a reference to a pointer which will store the namespace (type) associated with this data transfer, for example this could indicate a remote file request.
+ \param resourceName A reference to a pointer which will store the resource name associated with this data transfer, for example the resource name could be the file name of a file transfer request.
+ \param dlen A reference that will contain length of the lock of data received.
+ \param remoteIsBigEndian A reference to a boolean which will be set to true if the remote machine that sent this data is big endian format.
+
+ \retrun A pointer to the block of data received.
+ */
+ virtual const void * getRemoteResource(const char *&nameSpace,
+ const char *&resourceName,
+ uint32_t &dlen,
+ bool &remoteIsBigEndian)
+ {
+ return mRenderDebugHook->getRemoteResource(nameSpace,resourceName,dlen,remoteIsBigEndian);
+ }
+
+ /**
+ \brief This function allows you to request a file from the remote machine by name. If successful it will be returned via 'getRemoteData'
+
+ \param command The command field associated with this request which will be returned by 'getRemoteData'
+ \param fileName The filename being requested from the remote machine.
+
+ \return Returns true if the request was queued to be transmitted, false if it failed.
+ */
+ virtual bool requestRemoteResource(const char *command,
+ const char *fileName)
+ {
+ return mRenderDebugHook->requestRemoteResource(command,fileName);
+ }
+
+ /**
+ \brief Report what 'Run' mode we are operation gin.
+ */
+ virtual RenderDebug::RunMode getRunMode(void)
+ {
+ return mRenderDebugHook->getRunMode();
+ }
+
+ /**
+ \brief Returns true if we still have a valid connection to the server.
+ */
+ virtual bool isConnected(void) const
+ {
+ return mRenderDebugHook->isConnected();
+ }
+
+ /**
+ \brief Returns the current synchronized frame between client/server communications. Returns zero if no active connection exists.
+ */
+ virtual uint32_t getCommunicationsFrame(void) const
+ {
+ return mRenderDebugHook->getCommunicationsFrame();
+ }
+
+ virtual const char *getRemoteApplicationName(void)
+ {
+ return mRenderDebugHook->getRemoteApplicationName();
+ }
+
+ /**
+ \brief Returns the optional typed methods for various render debug routines.
+ */
+ virtual RenderDebugTyped *getRenderDebugTyped(void)
+ {
+ return mRenderDebugHook->getRenderDebugTyped();
+ }
+
+ /**
+ \brief Release the render debug class
+ */
+ virtual void release(void)
+ {
+ mRenderDebugHook->release();
+ }
+
+ virtual bool render(float dtime,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ return mRenderDebugHook->render(dtime,iface);
+ }
+
+ /**
+ \brief register a digital input event (maps to windows keyboard commands)
+
+ \param eventId The eventId for this input event; if it is a custom event it must be greater than NUM_SAMPLE_FRAMEWORK_INPUT_EVENT_IDS
+ \param inputId This the pre-defined keyboard code for this input event.
+ */
+ virtual void registerDigitalInputEvent(InputEventIds::Enum eventId,InputIds::Enum inputId)
+ {
+ mCanSkip = false;
+ DebugRegisterInputEvent dt(true,eventId,0.0f,inputId);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ virtual void unregisterInputEvent(InputEventIds::Enum eventId)
+ {
+ mCanSkip = false;
+ DebugUnregisterInputEvent dt(eventId);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+
+ /**
+ \brief register a digital input event (maps to windows keyboard commands)
+
+ \param eventId The eventId for this input event; if it is a custom event it must be greater than NUM_SAMPLE_FRAMEWORK_INPUT_EVENT_IDS
+ \param sensitivity The sensitivity value associated with this anaglog devent; default value is 1.0
+ \param inputId This the pre-defined analog code for this input event.
+ */
+ virtual void registerAnalogInputEvent(InputEventIds::Enum eventId,float sensitivity,InputIds::Enum inputId)
+ {
+ mCanSkip = false;
+ DebugRegisterInputEvent dt(false,eventId,sensitivity,inputId);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ /**
+ \brief Reset all input events to an empty state
+ */
+ virtual void resetInputEvents(void)
+ {
+ mCanSkip = false;
+ DebugPrimitiveU32 dt(DebugCommand::DEBUG_RESET_INPUT_EVENTS,0);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+
+ virtual void sendInputEvent(const InputEvent &ev)
+ {
+ if ( mRenderDebugHook )
+ {
+ mRenderDebugHook->sendInputEvent(ev);
+ }
+ }
+
+ /**
+ \brief Returns any incoming input event for processing purposes
+ */
+ virtual const InputEvent *getInputEvent(bool flush)
+ {
+ const InputEvent *e = NULL;
+
+ if ( mRenderDebugHook )
+ {
+ e = mRenderDebugHook->getInputEvent(flush);
+ }
+ return e;
+ }
+
+ /**
+ \brief Set the base file name to record communications tream; or NULL to disable it.
+
+ \param fileName The base name of the file to record the communications channel stream to, or NULL to disable it.
+ */
+ virtual bool setStreamFilename(const char *fileName)
+ {
+ bool ret = false;
+ if ( mRenderDebugHook )
+ {
+ ret = mRenderDebugHook->setStreamFilename(fileName);
+ }
+ return ret;
+ }
+
+ /**
+ \brief Begin playing back a communications stream recording
+
+ \param fileName The name of the previously captured communications stream file
+ */
+ virtual bool setStreamPlayback(const char *fileName)
+ {
+ bool ret = false;
+ if ( mRenderDebugHook )
+ {
+ ret = mRenderDebugHook->setStreamPlayback(fileName);
+ }
+ return ret;
+ }
+
+ /**
+ \brief Special case command that affects how the server processes the previous frame of data.
+
+ \return Returns true if it is safe to skip this frame of data, false if there are required commands that must be executed.
+ */
+ virtual bool trySkipFrame(void)
+ {
+ if ( mCanSkip )
+ {
+ DebugPrimitiveU32 dt(DebugCommand::DEBUG_SKIP_FRAME,0);
+ PostRenderDebug::postRenderDebug(&dt,mCurrentState);
+ }
+ return mCanSkip;
+ }
+
+ bool mCanSkip;
+ RenderDebugHook *mRenderDebugHook;
+ uint32_t mUpdateCount;
+ ProcessRenderDebug *mProcessRenderDebug;
+ RenderState mCurrentState;
+ uint32_t mStackIndex;
+ RenderState mRenderStateStack[RENDER_STATE_STACK_SIZE];
+ mutable float mViewMatrix44[16];
+ mutable float mProjectionMatrix44[16];
+ mutable float mViewProjectionMatrix44[16];
+ physx::PxVec3 mEyePos;
+ //Colors for debug rendering purposes
+ uint32_t colors[RENDER_DEBUG::DebugColors::NUM_COLORS];
+ uint32_t colorsMinValue[RENDER_DEBUG::DebugColors::NUM_COLORS];
+ uint32_t colorsMaxValue[RENDER_DEBUG::DebugColors::NUM_COLORS];
+ uint32_t colorsDefValue[RENDER_DEBUG::DebugColors::NUM_COLORS];
+
+ uint32_t mBlockIndex;
+ physx::shdfnd::HashMap<uint32_t, BlockInfo *> mBlocksHash;
+ physx::shdfnd::Pool< BlockInfo > mBlocks;
+ float mFrameTime;
+ bool mOwnProcess;
+
+};
+
+DebugGraphStream::DebugGraphStream(const DebugGraphDesc &d) : DebugPrimitive(DebugCommand::DEBUG_GRAPH)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << d.mNumPoints;
+ stream.storeString(d.mGraphXLabel ? d.mGraphXLabel : "",true);
+ stream.storeString(d.mGraphYLabel ? d.mGraphYLabel : "",true);
+
+ mb.alignWrite(4);
+
+ for (uint32_t i=0; i<d.mNumPoints; i++)
+ {
+ stream << d.mPoints[i];
+ }
+ stream << d.mCutOffLevel;
+ stream << d.mGraphMax;
+ stream << d.mGraphXPos;
+ stream << d.mGraphYPos;
+ stream << d.mGraphWidth;
+ stream << d.mGraphHeight;
+ stream << d.mGraphColor;
+ stream << d.mArrowColor;
+ stream << d.mColorSwitchIndex;
+
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+ mAllocated = true;
+}
+
+DebugGraphStream::~DebugGraphStream(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+
+DebugCreateTriangleMesh::DebugCreateTriangleMesh(uint32_t meshId,
+ uint32_t vcount, // The number of vertices in the triangle mesh
+ const RENDER_DEBUG::RenderDebugMeshVertex *meshVertices, // The array of vertices
+ uint32_t tcount, // The number of triangles (indices must contain tcount*3 values)
+ const uint32_t *indices) : DebugPrimitive(DebugCommand::DEBUG_CREATE_TRIANGLE_MESH)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << meshId;
+ stream << vcount;
+ stream << tcount;
+
+ if ( vcount )
+ {
+ mb.write(meshVertices,sizeof(RENDER_DEBUG::RenderDebugMeshVertex)*vcount);
+ }
+
+ if ( tcount )
+ {
+ mb.write(indices,sizeof(uint32_t)*tcount*3);
+ }
+
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+
+ uint32_t *dest = reinterpret_cast<uint32_t *>(mBuffer);
+ dest[1] = mSize;
+
+ mAllocated = true;
+}
+
+DebugCreateTriangleMesh::~DebugCreateTriangleMesh(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+
+DebugRefreshTriangleMeshVertices::DebugRefreshTriangleMeshVertices(uint32_t meshId,
+ uint32_t vcount, // The number of vertices in the triangle mesh
+ const RENDER_DEBUG::RenderDebugMeshVertex *meshVertices, // The array of vertices
+ const uint32_t *indices) : DebugPrimitive(DebugCommand::DEBUG_REFRESH_TRIANGLE_MESH_VERTICES)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << meshId;
+ stream << vcount;
+
+ if ( vcount )
+ {
+ mb.write(meshVertices,sizeof(RENDER_DEBUG::RenderDebugMeshVertex)*vcount);
+ }
+
+ if ( vcount )
+ {
+ mb.write(indices,sizeof(uint32_t)*vcount);
+ }
+
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+
+ uint32_t *dest = reinterpret_cast<uint32_t *>(mBuffer);
+ dest[1] = mSize;
+
+ mAllocated = true;
+}
+
+DebugRefreshTriangleMeshVertices::~DebugRefreshTriangleMeshVertices(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+
+DebugRenderTriangleMeshInstances::DebugRenderTriangleMeshInstances(uint32_t meshId,
+ uint32_t instanceCount,
+ const RENDER_DEBUG::RenderDebugInstance *instances) : DebugPrimitive(DebugCommand::DEBUG_RENDER_TRIANGLE_MESH_INSTANCES)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << meshId;
+ stream << instanceCount;
+
+ if ( instanceCount )
+ {
+ mb.write(instances,sizeof(RENDER_DEBUG::RenderDebugInstance)*instanceCount);
+ }
+
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+
+ uint32_t *dest = reinterpret_cast<uint32_t *>(mBuffer);
+ dest[1] = mSize;
+
+ mAllocated = true;
+}
+
+DebugRenderTriangleMeshInstances::~DebugRenderTriangleMeshInstances(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+DebugConvexHull::DebugConvexHull(uint32_t planeCount,const float *planes) : DebugPrimitive(DebugCommand::DEBUG_CONVEX_HULL)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << planeCount;
+ if ( planeCount )
+ {
+ mb.write(planes,sizeof(float)*4*planeCount);
+ }
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+
+ uint32_t *dest = reinterpret_cast<uint32_t *>(mBuffer);
+ dest[1] = mSize;
+
+ mAllocated = true;
+}
+
+DebugConvexHull::~DebugConvexHull(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+DebugRenderPoints::DebugRenderPoints(uint32_t meshId,
+ PointRenderMode mode,
+ uint32_t textureId1,
+ float textureTile1,
+ uint32_t textureId2,
+ float textureTile2,
+ uint32_t pointCount,
+ const float *points) : DebugPrimitive(DebugCommand::DEBUG_RENDER_POINTS)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << meshId;
+ stream << uint32_t(mode);
+ stream << textureId1;
+ stream << textureTile1;
+ stream << textureId2;
+ stream << textureTile2;
+ stream << pointCount;
+
+ if ( pointCount )
+ {
+ mb.write(points,sizeof(float)*3*pointCount);
+ }
+
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+
+ uint32_t *dest = reinterpret_cast<uint32_t *>(mBuffer);
+ dest[1] = mSize;
+
+ mAllocated = true;
+}
+
+DebugRenderPoints::~DebugRenderPoints(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+DebugRenderLines::DebugRenderLines(uint32_t lcount,
+ const RenderDebugVertex *vertices,
+ uint32_t useZ,
+ uint32_t isScreenSpace) : DebugPrimitive(DebugCommand::DEBUG_RENDER_LINES)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << lcount;
+ stream << useZ;
+ stream << isScreenSpace;
+
+ if ( lcount )
+ {
+ mb.write(vertices,sizeof(RenderDebugVertex)*2*lcount);
+ }
+
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+
+ uint32_t *dest = reinterpret_cast<uint32_t *>(mBuffer);
+ dest[1] = mSize;
+
+ mAllocated = true;
+}
+
+DebugRenderLines::~DebugRenderLines(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+
+DebugRenderTriangles::DebugRenderTriangles(uint32_t tcount,
+ const RenderDebugSolidVertex *vertices,
+ uint32_t useZ,
+ uint32_t isScreenSpace) : DebugPrimitive(DebugCommand::DEBUG_RENDER_TRIANGLES)
+{
+ physx::PsMemoryBuffer mb;
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,0);
+
+ mSize = 0;
+ stream << mCommand;
+ stream << mSize;
+ stream << tcount;
+ stream << useZ;
+ stream << isScreenSpace;
+
+ if ( tcount )
+ {
+ mb.write(vertices,sizeof(RenderDebugSolidVertex)*3*tcount);
+ }
+
+ mBuffer = mb.getWriteBufferOwnership(mSize);
+
+ uint32_t *dest = reinterpret_cast<uint32_t*>(mBuffer);
+ dest[1] = mSize;
+
+ mAllocated = true;
+}
+
+DebugRenderTriangles::~DebugRenderTriangles(void)
+{
+ if ( mAllocated )
+ {
+ PX_FREE(mBuffer);
+ }
+}
+
+
+
+
+//
+
+RenderDebugImpl * createInternalRenderDebug(ProcessRenderDebug *process,RenderDebugHook *renderDebugHook)
+{
+ InternalRenderDebug *m = PX_NEW(InternalRenderDebug)(process,renderDebugHook);
+ return static_cast< RenderDebugImpl *>(m);
+}
+
+
+
+} // end of namespace
diff --git a/APEX_1.4/shared/general/RenderDebug/src/ProcessRenderDebug.cpp b/APEX_1.4/shared/general/RenderDebug/src/ProcessRenderDebug.cpp
new file mode 100644
index 00000000..41814a44
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/ProcessRenderDebug.cpp
@@ -0,0 +1,3342 @@
+// This code contains NVIDIA Confidential Information and is disclosed to you
+// under a form of NVIDIA software license agreement provided separately to you.
+//
+// Notice
+// NVIDIA Corporation and its licensors retain all intellectual property and
+// proprietary rights in and to this software and related documentation and
+// any modifications thereto. Any use, reproduction, disclosure, or
+// distribution of this software and related documentation without an express
+// license agreement from NVIDIA Corporation is strictly prohibited.
+//
+// ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
+// NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
+// THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
+// MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
+//
+// Information and code furnished is believed to be accurate and reliable.
+// However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
+// information or for any infringement of patents or other rights of third parties that may
+// result from its use. No license is granted by implication or otherwise under any patent
+// or patent rights of NVIDIA Corporation. Details are subject to change without notice.
+// This code supersedes and replaces all information previously supplied.
+// NVIDIA Corporation products are not authorized for use as critical
+// components in life support devices or systems without express written approval of
+// NVIDIA Corporation.
+//
+// Copyright (c) 2008-2013 NVIDIA Corporation. All rights reserved.
+
+#include "ProcessRenderDebug.h"
+#include "PsMemoryBuffer.h"
+#include "PxBounds3.h"
+#include "StreamIO.h"
+#include "Hull2MeshEdges.h"
+
+namespace RENDER_DEBUG
+{
+
+static float degToRad(const float a)
+{
+ return static_cast<float>(0.01745329251994329547) * a;
+}
+
+static physx::PxQuat slerp(const float t, const physx::PxQuat& left, const physx::PxQuat& right)
+{
+ const float quatEpsilon = (float(1.0e-8f));
+
+ float cosine = left.dot(right);
+ float sign = float(1);
+ if (cosine < 0)
+ {
+ cosine = -cosine;
+ sign = float(-1);
+ }
+
+ float sine = float(1) - cosine*cosine;
+
+ if(sine>=quatEpsilon*quatEpsilon)
+ {
+ sine = physx::PxSqrt(sine);
+ const float angle = physx::PxAtan2(sine, cosine);
+ const float i_sin_angle = float(1) / sine;
+
+ const float leftw = physx::PxSin(angle*(float(1)-t)) * i_sin_angle;
+ const float rightw = physx::PxSin(angle * t) * i_sin_angle * sign;
+
+ return left * leftw + right * rightw;
+ }
+
+ return left;
+}
+
+
+ physx::PxQuat NvShortestRotation(const physx::PxVec3& v0, const physx::PxVec3& v1)
+ {
+ const float d = v0.dot(v1);
+ const physx::PxVec3 cross = v0.cross(v1);
+
+ physx::PxQuat q = d>-1 ? physx::PxQuat(cross.x, cross.y, cross.z, 1+d)
+ : physx::PxAbs(v0.x)<0.1f ? physx::PxQuat(0.0f, v0.z, -v0.y, 0.0f) : physx::PxQuat(v0.y, -v0.x, 0.0f, 0.0f);
+
+ return q.getNormalized();
+ }
+
+
+
+ physx::PxMat44 invert(const physx::PxMat44 &m)
+ {
+ physx::PxMat44 inv;
+
+#define det3x3(a0, a1, a2, a3, a4, a5, a6, a7, a8) \
+ (a0 * (a4*a8 - a7*a5) - a1 * (a3*a8 - a6*a5) + a2 * (a3*a7 - a6*a4))
+
+ inv.column0.x = det3x3(m.column1.y, m.column1.z, m.column1.w, m.column2.y, m.column2.z, m.column2.w, m.column3.y, m.column3.z, m.column3.w);
+ inv.column0.y = -det3x3(m.column0.y, m.column0.z, m.column0.w, m.column2.y, m.column2.z, m.column2.w, m.column3.y, m.column3.z, m.column3.w);
+ inv.column0.z = det3x3(m.column0.y, m.column0.z, m.column0.w, m.column1.y, m.column1.z, m.column1.w, m.column3.y, m.column3.z, m.column3.w);
+ inv.column0.w = -det3x3(m.column0.y, m.column0.z, m.column0.w, m.column1.y, m.column1.z, m.column1.w, m.column2.y, m.column2.z, m.column2.w);
+
+ inv.column1.x = -det3x3(m.column1.x, m.column1.z, m.column1.w, m.column2.x, m.column2.z, m.column2.w, m.column3.x, m.column3.z, m.column3.w);
+ inv.column1.y = det3x3(m.column0.x, m.column0.z, m.column0.w, m.column2.x, m.column2.z, m.column2.w, m.column3.x, m.column3.z, m.column3.w);
+ inv.column1.z = -det3x3(m.column0.x, m.column0.z, m.column0.w, m.column1.x, m.column1.z, m.column1.w, m.column3.x, m.column3.z, m.column3.w);
+ inv.column1.w = det3x3(m.column0.x, m.column0.z, m.column0.w, m.column1.x, m.column1.z, m.column1.w, m.column2.x, m.column2.z, m.column2.w);
+
+ inv.column2.x = det3x3(m.column1.x, m.column1.y, m.column1.w, m.column2.x, m.column2.y, m.column2.w, m.column3.x, m.column3.y, m.column3.w);
+ inv.column2.y = -det3x3(m.column0.x, m.column0.y, m.column0.w, m.column2.x, m.column2.y, m.column2.w, m.column3.x, m.column3.y, m.column3.w);
+ inv.column2.z = det3x3(m.column0.x, m.column0.y, m.column0.w, m.column1.x, m.column1.y, m.column1.w, m.column3.x, m.column3.y, m.column3.w);
+ inv.column2.w = -det3x3(m.column0.x, m.column0.y, m.column0.w, m.column1.x, m.column1.y, m.column1.w, m.column2.x, m.column2.y, m.column2.w);
+
+ inv.column3.x = -det3x3(m.column1.x, m.column1.y, m.column1.z, m.column2.x, m.column2.y, m.column2.z, m.column3.x, m.column3.y, m.column3.z);
+ inv.column3.y = det3x3(m.column0.x, m.column0.y, m.column0.z, m.column2.x, m.column2.y, m.column2.z, m.column3.x, m.column3.y, m.column3.z);
+ inv.column3.z = -det3x3(m.column0.x, m.column0.y, m.column0.z, m.column1.x, m.column1.y, m.column1.z, m.column3.x, m.column3.y, m.column3.z);
+ inv.column3.w = det3x3(m.column0.x, m.column0.y, m.column0.z, m.column1.x, m.column1.y, m.column1.z, m.column2.x, m.column2.y, m.column2.z);
+
+#undef det3x3
+
+ float det = m.column0.x*inv.column0.x + m.column1.x*inv.column0.y + m.column2.x*inv.column0.z + m.column3.x*inv.column0.w;
+ PX_ASSERT(det!=0);
+ if(!det) det = 1.0f;
+ float invDet = 1.0f / det;
+
+ inv.column0 *= invDet;
+ inv.column1 *= invDet;
+ inv.column2 *= invDet;
+ inv.column3 *= invDet;
+
+ return inv;
+ }
+
+
+class ProcessRenderDebugHelper
+{
+public:
+ virtual void indirectDebugLine(const physx::PxVec3 &p1,const physx::PxVec3 &p2) = 0;
+protected:
+ virtual ~ProcessRenderDebugHelper(void) {}
+};
+
+const physx::PxVec3 debug_point[6] =
+{
+ physx::PxVec3(-1.0f, 0.0f, 0.0f), physx::PxVec3(1.0f, 0.0f, 0.0f),
+ physx::PxVec3(0.0f,-1.0f, 0.0f), physx::PxVec3(0.0f, 1.0f, 0.0f),
+ physx::PxVec3(0.0f, 0.0f,-1.0f), physx::PxVec3(0.0f, 0.0f, 1.0f)
+};
+
+// simple sphere, uses subdivision to enhance...
+static physx::PxVec3 simpleSpherePosition[6] =
+{
+ physx::PxVec3( 1.0f, 0.0f, 0.0f),
+ physx::PxVec3(-1.0f, 0.0f, 0.0f),
+ physx::PxVec3( 0.0f, 1.0f, 0.0f),
+ physx::PxVec3( 0.0f,-1.0f, 0.0f),
+ physx::PxVec3( 0.0f, 0.0f, 1.0f),
+ physx::PxVec3( 0.0f, 0.0f,-1.0f),
+};
+
+static uint32_t simpleSphereIndices[8*3] =
+{
+ 0, 2, 4,
+ 1, 4, 2,
+ 0, 5, 2,
+ 1, 2, 5,
+
+ 0, 4, 3,
+ 1, 3, 4,
+ 0, 3, 5,
+ 1, 5, 3,
+};
+
+
+const float FM_PI = 3.1415926535897932384626433832795028841971693993751f;
+const float FM_DEG_TO_RAD = ((2.0f * FM_PI) / 360.0f);
+//const float FM_RAD_TO_DEG = (360.0f / (2.0f * FM_PI));
+
+PX_INLINE void pxVec3FromArray(physx::PxVec3 &p,const float *pos)
+{
+ p.x = pos[0];
+ p.y = pos[1];
+ p.z = pos[2];
+}
+
+// quat to rotate v0 t0 v1
+static PX_INLINE physx::PxQuat rotationArc(const physx::PxVec3& v0, const physx::PxVec3& v1)
+{
+ const physx::PxVec3 cross = v0.cross(v1);
+ const float d = v0.dot(v1);
+ if(d<=-0.99999f)
+ return (physx::PxAbs(v0.x)<0.1f ? physx::PxQuat(0.0f, v0.z, -v0.y, 0.0f) : physx::PxQuat(v0.y, -v0.x, 0.0, 0.0)).getNormalized();
+
+ const float s = physx::PxSqrt((1+d)*2), r = 1/s;
+
+ return physx::PxQuat(cross.x*r, cross.y*r, cross.z*r, s*0.5f).getNormalized();
+}
+
+static PX_INLINE void rotationArc(const physx::PxVec3 &v0,const physx::PxVec3 &v1,physx::PxQuat &quat)
+{
+ quat = rotationArc(v0,v1);
+}
+
+/*const float debug_sphere[32*9] =
+{
+ 0.0000f, 0.0000f, 1.0000f, 0.7071f, 0.0000f, 0.7071f, 0.0000f, 0.7071f, 0.7071f,
+ 0.7071f, 0.0000f, 0.7071f, 1.0000f, 0.0000f, 0.0000f, 0.7071f, 0.7071f, 0.0000f,
+ 0.7071f, 0.0000f, 0.7071f, 0.7071f, 0.7071f, 0.0000f, 0.0000f, 0.7071f, 0.7071f,
+ 0.0000f, 0.7071f, 0.7071f, 0.7071f, 0.7071f, 0.0000f, 0.0000f, 1.0000f, 0.0000f,
+ 0.0000f, 0.0000f, 1.0000f, 0.0000f, 0.7071f, 0.7071f, -0.7071f, 0.0000f, 0.7071f,
+ 0.0000f, 0.7071f, 0.7071f, 0.0000f, 1.0000f, 0.0000f, -0.7071f, 0.7071f, 0.0000f,
+ 0.0000f, 0.7071f, 0.7071f, -0.7071f, 0.7071f, 0.0000f, -0.7071f, 0.0000f, 0.7071f,
+ -0.7071f, 0.0000f, 0.7071f, -0.7071f, 0.7071f, 0.0000f, -1.0000f, 0.0000f, 0.0000f,
+ 0.0000f, 0.0000f, 1.0000f, -0.7071f, 0.0000f, 0.7071f, 0.0000f, -0.7071f, 0.7071f,
+ -0.7071f, 0.0000f, 0.7071f, -1.0000f, 0.0000f, 0.0000f, -0.7071f, -0.7071f, 0.0000f,
+ -0.7071f, 0.0000f, 0.7071f, -0.7071f, -0.7071f, 0.0000f, 0.0000f, -0.7071f, 0.7071f,
+ 0.0000f, -0.7071f, 0.7071f, -0.7071f, -0.7071f, 0.0000f, 0.0000f, -1.0000f, 0.0000f,
+ 0.0000f, 0.0000f, 1.0000f, 0.0000f, -0.7071f, 0.7071f, 0.7071f, 0.0000f, 0.7071f,
+ 0.0000f, -0.7071f, 0.7071f, 0.0000f, -1.0000f, 0.0000f, 0.7071f, -0.7071f, 0.0000f,
+ 0.0000f, -0.7071f, 0.7071f, 0.7071f, -0.7071f, 0.0000f, 0.7071f, 0.0000f, 0.7071f,
+ 0.7071f, 0.0000f, 0.7071f, 0.7071f, -0.7071f, 0.0000f, 1.0000f, 0.0000f, 0.0000f,
+ 0.0000f, 0.0000f, -1.0000f, 0.0000f, 0.7071f, -0.7071f, 0.7071f, 0.0000f, -0.7071f,
+ 0.0000f, 0.7071f, -0.7071f, 0.0000f, 1.0000f, 0.0000f, 0.7071f, 0.7071f, 0.0000f,
+ 0.0000f, 0.7071f, -0.7071f, 0.7071f, 0.7071f, 0.0000f, 0.7071f, 0.0000f, -0.7071f,
+ 0.7071f, 0.0000f, -0.7071f, 0.7071f, 0.7071f, 0.0000f, 1.0000f, 0.0000f, 0.0000f,
+ 0.0000f, 0.0000f, -1.0000f, -0.7071f, 0.0000f, -0.7071f, 0.0000f, 0.7071f, -0.7071f,
+ -0.7071f, 0.0000f, -0.7071f, -1.0000f, 0.0000f, 0.0000f, -0.7071f, 0.7071f, 0.0000f,
+ -0.7071f, 0.0000f, -0.7071f, -0.7071f, 0.7071f, 0.0000f, 0.0000f, 0.7071f, -0.7071f,
+ 0.0000f, 0.7071f, -0.7071f, -0.7071f, 0.7071f, 0.0000f, 0.0000f, 1.0000f, 0.0000f,
+ 0.0000f, 0.0000f, -1.0000f, 0.0000f, -0.7071f, -0.7071f, -0.7071f, 0.0000f, -0.7071f,
+ 0.0000f, -0.7071f, -0.7071f, 0.0000f, -1.0000f, 0.0000f, -0.7071f, -0.7071f, 0.0000f,
+ 0.0000f, -0.7071f, -0.7071f, -0.7071f, -0.7071f, 0.0000f, -0.7071f, 0.0000f, -0.7071f,
+ -0.7071f, 0.0000f, -0.7071f, -0.7071f, -0.7071f, 0.0000f, -1.0000f, 0.0000f, 0.0000f,
+ 0.0000f, 0.0000f, -1.0000f, 0.7071f, 0.0000f, -0.7071f, 0.0000f, -0.7071f, -0.7071f,
+ 0.7071f, 0.0000f, -0.7071f, 1.0000f, 0.0000f, 0.0000f, 0.7071f, -0.7071f, 0.0000f,
+ 0.7071f, 0.0000f, -0.7071f, 0.7071f, -0.7071f, 0.0000f, 0.0000f, -0.7071f, -0.7071f,
+ 0.0000f, -0.7071f, -0.7071f, 0.7071f, -0.7071f, 0.0000f, 0.0000f, -1.0000f, 0.0000f,
+};*/
+
+
+
+// font info:
+//
+//Peter Holzmann, Octopus Enterprises
+//USPS: 19611 La Mar Court, Cupertino, CA 95014
+//UUCP: {hplabs!hpdsd,pyramid}!octopus!pete
+//Phone: 408/996-7746
+//
+//This distribution is made possible through the collective encouragement
+//of the Usenet Font Consortium, a mailing list that sprang to life to get
+//this accomplished and that will now most likely disappear into the mists
+//of time... Thanks are especially due to Jim Hurt, who provided the packed
+//font data for the distribution, along with a lot of other help.
+//
+//This file describes the Hershey Fonts in general, along with a description of
+//the other files in this distribution and a simple re-distribution restriction.
+//
+//USE RESTRICTION:
+// This distribution of the Hershey Fonts may be used by anyone for
+// any purpose, commercial or otherwise, providing that:
+// 1. The following acknowledgements must be distributed with
+// the font data:
+// - The Hershey Fonts were originally created by Dr.
+// A. V. Hershey while working at the U. S.
+// National Bureau of Standards.
+// - The format of the Font data in this distribution
+// was originally created by
+// James Hurt
+// Cognition, Inc.
+// 900 Technology Park Drive
+// Billerica, MA 01821
+// (mit-eddie!ci-dandelion!hurt)
+// 2. The font data in this distribution may be converted into
+// any other format *EXCEPT* the format distributed by
+// the U.S. NTIS (which organization holds the rights
+// to the distribution and use of the font data in that
+// particular format). Not that anybody would really
+// *want* to use their format... each point is described
+// in eight bytes as "xxx yyy:", where xxx and yyy are
+// the coordinate values as ASCII numbers.
+
+
+uint8_t g_font[6350] = {
+ 0x46,0x4F,0x4E,0x54,0x01,0x00,0x00,0x00,0x43,0x01,0x00,0x00,0x5E,0x00,0x00,0x00,0xC4,0x06,0x00,0x00,0x0A,0xD7,0x23,0x3C,0x3D,0x0A,0x57,0x3E,0x0A,0xD7,0x23,0x3C,
+ 0x28,0x5C,0x8F,0x3D,0x0A,0xD7,0x23,0x3C,0x08,0xD7,0xA3,0x3C,0x00,0x00,0x00,0x00,0x08,0xD7,0x23,0x3C,0x0A,0xD7,0x23,0x3C,0x00,0x00,0x00,0x00,0x0A,0xD7,0xA3,0x3C,
+ 0x08,0xD7,0x23,0x3C,0x00,0x00,0x00,0x00,0x3D,0x0A,0x57,0x3E,0x00,0x00,0x00,0x00,0x28,0x5C,0x0F,0x3E,0x0A,0xD7,0xA3,0x3D,0x3D,0x0A,0x57,0x3E,0x0A,0xD7,0xA3,0x3D,
+ 0x28,0x5C,0x0F,0x3E,0x0A,0xD7,0xA3,0x3D,0x00,0x00,0x80,0x3E,0x0C,0xD7,0x23,0x3C,0x29,0x5C,0x8F,0xBD,0x29,0x5C,0x0F,0x3E,0x00,0x00,0x80,0x3E,0x29,0x5C,0x8F,0x3D,
+ 0x29,0x5C,0x8F,0xBD,0x0C,0xD7,0x23,0x3C,0x8F,0xC2,0xF5,0x3D,0x9A,0x99,0x19,0x3E,0x8F,0xC2,0xF5,0x3D,0x00,0x00,0x00,0x00,0x8E,0xC2,0x75,0x3D,0x29,0x5C,0x0F,0x3E,
+ 0x8E,0xC2,0x75,0x3D,0xCD,0xCC,0x4C,0x3D,0x00,0x00,0x80,0x3E,0xCD,0xCC,0x4C,0x3D,0x0A,0xD7,0x23,0xBD,0xEC,0x51,0xB8,0x3D,0x00,0x00,0x80,0x3E,0xEC,0x51,0xB8,0x3D,
+ 0x0A,0xD7,0x23,0xBD,0x29,0x5C,0x0F,0x3E,0xEB,0x51,0x38,0x3E,0x8F,0xC2,0xF5,0x3D,0xCC,0xCC,0x4C,0x3E,0xEC,0x51,0xB8,0x3D,0x3D,0x0A,0x57,0x3E,0xCD,0xCC,0x4C,0x3D,
+ 0x3D,0x0A,0x57,0x3E,0x0C,0xD7,0xA3,0x3C,0xCC,0xCC,0x4C,0x3E,0x00,0x00,0x00,0x00,0xEB,0x51,0x38,0x3E,0x00,0x00,0x00,0x00,0x0A,0xD7,0x23,0x3E,0x0C,0xD7,0x23,0x3C,
+ 0x28,0x5C,0x0F,0x3E,0x0C,0xD7,0xA3,0x3C,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0x23,0x3D,0x8F,0xC2,0xF5,0x3D,0xCD,0xCC,0xCC,0x3D,0xCC,0xCC,0xCC,0x3D,0x8F,0xC2,0xF5,0x3D,
+ 0xEB,0x51,0xB8,0x3D,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0xA3,0x3D,0x29,0x5C,0x0F,0x3E,0x8E,0xC2,0xF5,0x3C,0x8F,0xC2,0xF5,0x3D,0x08,0xD7,0x23,0x3C,0xEC,0x51,0xB8,0x3D,
+ 0x00,0x00,0x00,0x00,0xCD,0xCC,0x4C,0x3D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8E,0xC2,0xF5,0x3C,0xEB,0x51,0x38,0x3E,0x3D,0x0A,0x57,0x3E,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00,0x28,0x5C,0x8F,0x3D,0x5C,0x8F,0x42,0x3E,0x28,0x5C,0x8F,0x3D,0x7A,0x14,0x2E,0x3E,0x8E,0xC2,0x75,0x3D,0x99,0x99,0x19,0x3E,0x0A,0xD7,0x23,0x3D,
+ 0x28,0x5C,0x0F,0x3E,0x08,0xD7,0xA3,0x3C,0x28,0x5C,0x0F,0x3E,0x08,0xD7,0x23,0x3C,0xCC,0xCC,0x4C,0x3E,0x8E,0xC2,0xF5,0x3C,0x3D,0x0A,0x57,0x3E,0x28,0x5C,0x8F,0x3D,
+ 0xCC,0xCC,0x4C,0x3E,0xCC,0xCC,0xCC,0x3D,0x5C,0x8F,0x42,0x3E,0xB8,0x1E,0x05,0x3E,0x5C,0x8F,0x42,0x3E,0x0A,0xD7,0x23,0x3E,0xCC,0xCC,0x4C,0x3E,0x28,0x5C,0x0F,0x3E,
+ 0x28,0x5C,0x8F,0x3D,0x8F,0xC2,0xF5,0x3D,0x8E,0xC2,0x75,0x3D,0xAE,0x47,0xE1,0x3D,0x0A,0xD7,0x23,0x3D,0xAE,0x47,0xE1,0x3D,0x08,0xD7,0xA3,0x3C,0xB8,0x1E,0x05,0x3E,
+ 0x00,0x00,0x00,0x00,0x99,0x99,0x19,0x3E,0x00,0x00,0x00,0x00,0x7A,0x14,0x2E,0x3E,0x08,0xD7,0x23,0x3C,0xEB,0x51,0x38,0x3E,0x8E,0xC2,0xF5,0x3C,0xEB,0x51,0x38,0x3E,
+ 0xCC,0xCC,0x4C,0x3D,0x0A,0xD7,0x23,0x3E,0x28,0x5C,0x8F,0x3D,0xCC,0xCC,0x4C,0x3E,0x8F,0xC2,0xF5,0x3D,0xCC,0xCC,0x4C,0x3E,0xB8,0x1E,0x05,0x3E,0x5C,0x8F,0x42,0x3E,
+ 0x28,0x5C,0x0F,0x3E,0xEB,0x51,0x38,0x3E,0x28,0x5C,0x0F,0x3E,0x7A,0x14,0x2E,0x3E,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0x23,0x3E,0xAE,0x47,0xE1,0x3D,0x8E,0xC2,0xF5,0x3D,
+ 0x8E,0xC2,0xF5,0x3C,0xCC,0xCC,0xCC,0x3D,0x08,0xD7,0x23,0x3C,0x0A,0xD7,0xA3,0x3D,0x00,0x00,0x00,0x00,0x09,0xD7,0x23,0x3D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+ 0x0A,0xD7,0x23,0x3D,0x08,0xD7,0x23,0x3C,0x0A,0xD7,0xA3,0x3D,0x08,0xD7,0xA3,0x3C,0xEB,0x51,0xB8,0x3D,0xEB,0x51,0xB8,0x3D,0xB8,0x1E,0x05,0x3E,0xCC,0xCC,0xCC,0x3D,
+ 0x28,0x5C,0x0F,0x3E,0xAD,0x47,0xE1,0x3D,0x0A,0xD7,0x23,0x3E,0xAD,0x47,0xE1,0x3D,0xEB,0x51,0x38,0x3E,0xCC,0xCC,0xCC,0x3D,0xCC,0xCC,0x4C,0x3E,0x8E,0xC2,0x75,0x3D,
+ 0xCC,0xCC,0x4C,0x3E,0xCC,0xCC,0x4C,0x3D,0xEB,0x51,0x38,0x3E,0xCC,0xCC,0x4C,0x3D,0x0A,0xD7,0x23,0x3E,0x8E,0xC2,0x75,0x3D,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0xA3,0x3D,
+ 0xCC,0xCC,0xCC,0x3D,0xB8,0x1E,0x05,0x3E,0x8E,0xC2,0xF5,0x3C,0x99,0x99,0x19,0x3E,0x08,0xD7,0x23,0x3C,0x7A,0x14,0x2E,0x3E,0x00,0x00,0x00,0x00,0x0A,0xD7,0x23,0x3C,
+ 0x5C,0x8F,0x42,0x3E,0x00,0x00,0x00,0x00,0xCC,0xCC,0x4C,0x3E,0x0A,0xD7,0xA3,0x3C,0xEB,0x51,0x38,0x3E,0x0A,0xD7,0x23,0x3C,0x0A,0xD7,0x23,0x3E,0x00,0x00,0x00,0x00,
+ 0x99,0x99,0x19,0x3E,0x29,0x5C,0x8F,0x3D,0x00,0x00,0x80,0x3E,0xCC,0xCC,0x4C,0x3D,0x1E,0x85,0x6B,0x3E,0x8F,0xC2,0xF5,0x3C,0xCC,0xCC,0x4C,0x3E,0x00,0x00,0x00,0x00,
+ 0xAE,0x47,0xE1,0x3D,0x00,0x00,0x00,0x00,0x28,0x5C,0x8F,0x3D,0x8F,0xC2,0xF5,0x3C,0x0C,0xD7,0xA3,0xBC,0xCC,0xCC,0x4C,0x3D,0xCE,0xCC,0x4C,0xBD,0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x80,0x3E,0x0A,0xD7,0xA3,0x3C,0x1E,0x85,0x6B,0x3E,0x0A,0xD7,0x23,0x3D,0xCC,0xCC,0x4C,0x3E,0x8F,0xC2,0x75,0x3D,0x0A,0xD7,0x23,0x3E,0x29,0x5C,0x8F,0x3D,
+ 0xAE,0x47,0xE1,0x3D,0x29,0x5C,0x8F,0x3D,0x28,0x5C,0x8F,0x3D,0x8F,0xC2,0x75,0x3D,0x08,0xD7,0xA3,0x3C,0x0A,0xD7,0x23,0x3D,0x0C,0xD7,0xA3,0xBC,0x0A,0xD7,0xA3,0x3C,
+ 0xCE,0xCC,0x4C,0xBD,0x00,0x00,0x00,0x00,0x29,0x5C,0x8F,0xBD,0xCC,0xCC,0x4C,0x3D,0x99,0x99,0x19,0x3E,0xCC,0xCC,0x4C,0x3D,0x8E,0xC2,0xF5,0x3C,0x00,0x00,0x00,0x00,
+ 0x8F,0xC2,0xF5,0x3D,0xCC,0xCC,0xCC,0x3D,0x8E,0xC2,0x75,0x3D,0xCC,0xCC,0xCC,0x3D,0x8F,0xC2,0xF5,0x3D,0xEB,0x51,0xB8,0x3D,0xEB,0x51,0x38,0x3E,0x00,0x00,0x00,0x00,
+ 0xEB,0x51,0xB8,0x3D,0xEB,0x51,0x38,0x3E,0xEB,0x51,0xB8,0x3D,0x0A,0xD7,0xA3,0x3C,0x0A,0xD7,0x23,0x3D,0x0A,0xD7,0x23,0x3C,0x8E,0xC2,0xF5,0x3C,0x0A,0xD7,0x23,0x3C,
+ 0xCC,0xCC,0x4C,0x3D,0x0A,0xD7,0xA3,0x3C,0x08,0xD7,0xA3,0x3C,0xEB,0x51,0x38,0x3E,0x00,0x00,0x80,0x3E,0x90,0xC2,0x75,0x3D,0x3D,0x0A,0x57,0x3E,0x0C,0xD7,0x23,0x3C,
+ 0x7A,0x14,0x2E,0x3E,0x0C,0xD7,0x23,0x3C,0x0A,0xD7,0x23,0x3D,0x90,0xC2,0xF5,0x3C,0x08,0xD7,0x23,0x3C,0x90,0xC2,0x75,0x3D,0x00,0x00,0x00,0x00,0xAE,0x47,0xE1,0x3D,
+ 0x08,0xD7,0x23,0x3C,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0x23,0x3D,0x29,0x5C,0x0F,0x3E,0xEB,0x51,0xB8,0x3D,0x29,0x5C,0x0F,0x3E,0x8F,0xC2,0xF5,0x3D,0xB8,0x1E,0x05,0x3E,
+ 0x7A,0x14,0x2E,0x3E,0xAE,0x47,0xE1,0x3D,0xCC,0xCC,0x4C,0x3E,0x00,0x00,0x00,0x00,0x7A,0x14,0x2E,0x3E,0x0C,0xD7,0xA3,0x3C,0x5C,0x8F,0x42,0x3E,0x8F,0xC2,0xF5,0x3D,
+ 0x5C,0x8F,0x42,0x3E,0xB8,0x1E,0x05,0x3E,0x99,0x99,0x19,0x3E,0x8F,0xC2,0xF5,0x3D,0xB8,0x1E,0x05,0x3E,0x29,0x5C,0x0F,0x3E,0x00,0x00,0x00,0x00,0x0C,0xD7,0xA3,0x3C,
+ 0x3D,0x0A,0x57,0x3E,0xB8,0x1E,0x05,0x3E,0x3D,0x0A,0x57,0x3E,0x29,0x5C,0x8F,0x3D,0xB8,0x1E,0x05,0x3E,0xCD,0xCC,0xCC,0x3D,0xB8,0x1E,0x05,0x3E,0x8F,0xC2,0xF5,0x3D,
+ 0x8F,0xC2,0xF5,0x3D,0xB8,0x1E,0x05,0x3E,0xAE,0x47,0xE1,0x3D,0x29,0x5C,0x0F,0x3E,0x0A,0xD7,0xA3,0x3D,0xCD,0xCC,0xCC,0x3D,0x3D,0x0A,0x57,0x3E,0x9A,0x99,0x19,0x3E,
+ 0x28,0x5C,0x8F,0x3D,0xCD,0xCC,0xCC,0x3D,0x00,0x00,0x00,0x00,0x8F,0xC2,0xF5,0x3D,0x3D,0x0A,0x57,0x3E,0xCD,0xCC,0x4C,0x3D,0x28,0x5C,0x0F,0x3E,0xAE,0x47,0xE1,0x3D,
+ 0xB8,0x1E,0x05,0x3E,0x8F,0xC2,0xF5,0x3D,0xEB,0x51,0x38,0x3E,0x29,0x5C,0x8F,0x3D,0x00,0x00,0x00,0x00,0xB8,0x1E,0x05,0x3E,0x8E,0xC2,0x75,0x3D,0xB8,0x1E,0x05,0x3E,
+ 0x28,0x5C,0x8F,0x3D,0x8F,0xC2,0xF5,0x3D,0xCC,0xCC,0xCC,0x3D,0x8F,0xC2,0xF5,0x3C,0x8F,0xC2,0xF5,0x3D,0x0C,0xD7,0x23,0x3C,0xCC,0xCC,0xCC,0x3D,0x29,0x5C,0x0F,0x3E,
+ 0x3D,0x0A,0x57,0x3E,0x0C,0xD7,0x23,0x3C,0xEB,0x51,0x38,0x3E,0x0A,0xD7,0x23,0x3D,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0xA3,0x3D,0x8F,0xC2,0xF5,0x3D,0xAE,0x47,0xE1,0x3D,
+ 0xAE,0x47,0xE1,0x3D,0xB8,0x1E,0x05,0x3E,0xEB,0x51,0xB8,0x3D,0x29,0x5C,0x0F,0x3E,0x0A,0xD7,0x23,0x3D,0xB8,0x1E,0x05,0x3E,0x08,0xD7,0xA3,0x3C,0x0C,0xD7,0x23,0x3C,
+ 0xEB,0x51,0xB8,0x3D,0x90,0xC2,0xF5,0x3C,0xAE,0x47,0xE1,0x3D,0x90,0xC2,0x75,0x3D,0x8F,0xC2,0xF5,0x3D,0x8F,0xC2,0xF5,0x3D,0x28,0x5C,0x0F,0x3E,0xB8,0x1E,0x05,0x3E,
+ 0x0A,0xD7,0x23,0x3E,0xB8,0x1E,0x05,0x3E,0xEB,0x51,0x38,0x3E,0xB8,0x1E,0x05,0x3E,0x28,0x5C,0x0F,0x3E,0x8F,0xC2,0xF5,0x3D,0xAE,0x47,0xE1,0x3D,0xCD,0xCC,0xCC,0x3D,
+ 0xEB,0x51,0xB8,0x3D,0x29,0x5C,0x8F,0x3D,0x0A,0xD7,0xA3,0x3D,0x90,0xC2,0x75,0x3D,0x0A,0xD7,0xA3,0x3D,0x90,0xC2,0xF5,0x3C,0xEB,0x51,0xB8,0x3D,0x0C,0xD7,0x23,0x3C,
+ 0xAE,0x47,0xE1,0x3D,0x29,0x5C,0x8F,0x3D,0x3D,0x0A,0x57,0x3E,0x8F,0xC2,0xF5,0x3D,0x0A,0xD7,0x23,0x3D,0x0A,0xD7,0xA3,0x3C,0xAE,0x47,0xE1,0x3D,0x0A,0xD7,0x23,0x3E,
+ 0xEB,0x51,0x38,0x3E,0x0A,0xD7,0x23,0x3E,0x00,0x00,0x00,0x00,0xEB,0x51,0x38,0x3E,0x8F,0xC2,0xF5,0x3D,0xEB,0x51,0x38,0x3E,0x8E,0xC2,0x75,0x3D,0x0A,0xD7,0x23,0x3E,
+ 0xEB,0x51,0xB8,0x3D,0x0A,0xD7,0x23,0x3D,0x3D,0x0A,0x57,0x3E,0xAE,0x47,0xE1,0x3D,0x5C,0x8F,0x42,0x3E,0x8F,0xC2,0xF5,0x3D,0x7A,0x14,0x2E,0x3E,0x8F,0xC2,0xF5,0x3D,
+ 0x99,0x99,0x19,0x3E,0x8F,0xC2,0x75,0x3D,0xCC,0xCC,0xCC,0x3D,0x8F,0xC2,0x75,0x3D,0x28,0x5C,0x8F,0x3D,0xCC,0xCC,0x4C,0x3D,0x08,0xD7,0x23,0x3C,0x29,0x5C,0x8F,0x3D,
+ 0x08,0xD7,0x23,0x3C,0xEB,0x51,0xB8,0x3D,0x99,0x99,0x19,0x3E,0x28,0x5C,0x8F,0x3D,0x0A,0xD7,0x23,0x3E,0x0A,0xD7,0x23,0x3D,0x0A,0xD7,0x23,0x3E,0x09,0xD7,0xA3,0x3C,
+ 0x99,0x99,0x19,0x3E,0x00,0x00,0x00,0x00,0x0A,0xD7,0xA3,0x3D,0x08,0xD7,0x23,0x3C,0x8E,0xC2,0x75,0x3D,0x8E,0xC2,0xF5,0x3C,0xCC,0xCC,0x4C,0x3D,0x8E,0xC2,0x75,0x3D,
+ 0xCC,0xCC,0x4C,0x3D,0x0A,0xD7,0xA3,0x3D,0x8E,0xC2,0x75,0x3D,0xEB,0x51,0xB8,0x3D,0x0A,0xD7,0xA3,0x3D,0x09,0xD7,0xA3,0x3C,0x8E,0xC2,0x75,0x3D,0xCC,0xCC,0xCC,0x3D,
+ 0x0A,0xD7,0x23,0x3E,0xEB,0x51,0xB8,0x3D,0x8E,0xC2,0x75,0x3D,0xAE,0x47,0xE1,0x3D,0xCC,0xCC,0x4C,0x3D,0xB8,0x1E,0x05,0x3E,0xCC,0xCC,0x4C,0x3D,0x0A,0xD7,0x23,0x3E,
+ 0xCC,0xCC,0xCC,0x3D,0x0A,0xD7,0x23,0x3E,0x8F,0xC2,0xF5,0x3D,0x99,0x99,0x19,0x3E,0x99,0x99,0x19,0x3E,0x28,0x5C,0x0F,0x3E,0x7A,0x14,0x2E,0x3E,0x90,0xC2,0xF5,0x3C,
+ 0x28,0x5C,0x8F,0x3D,0x29,0x5C,0x0F,0x3E,0x99,0x99,0x19,0x3E,0xB8,0x1E,0x05,0x3E,0xB8,0x1E,0x05,0x3E,0xEC,0x51,0xB8,0x3D,0xAE,0x47,0xE1,0x3D,0x9A,0x99,0x19,0x3E,
+ 0x0A,0xD7,0x23,0x3E,0x00,0x00,0x00,0x00,0xB8,0x1E,0x05,0x3E,0x0C,0xD7,0xA3,0x3C,0x8E,0xC2,0xF5,0x3C,0x0A,0xD7,0x23,0x3D,0x08,0xD7,0x23,0x3C,0x9A,0x99,0x19,0x3E,
+ 0xCC,0xCC,0x4C,0x3D,0x29,0x5C,0x0F,0x3E,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0xA3,0x3D,0xAE,0x47,0xE1,0x3D,0x9A,0x99,0x19,0x3E,0x0A,0xD7,0xA3,0x3D,0xCD,0xCC,0xCC,0x3D,
+ 0x0A,0xD7,0xA3,0x3D,0x29,0x5C,0x0F,0x3E,0xAE,0x47,0xE1,0x3D,0xCC,0xCC,0xCC,0x3D,0xCC,0xCC,0x4C,0x3D,0xEB,0x51,0xB8,0x3D,0x08,0xD7,0xA3,0x3C,0x0A,0xD7,0xA3,0x3D,
+ 0x08,0xD7,0x23,0x3C,0x00,0x00,0x00,0x00,0xCC,0xCC,0x4C,0x3D,0xCD,0xCC,0x4C,0x3D,0x8F,0xC2,0xF5,0x3D,0x8F,0xC2,0xF5,0x3D,0x00,0x00,0x00,0x00,0x0A,0xD7,0x23,0x3E,
+ 0x3D,0x0A,0x57,0x3E,0x0A,0xD7,0x23,0x3E,0x0A,0xD7,0xA3,0x3D,0x0A,0xD7,0x23,0x3E,0xB8,0x1E,0x05,0x3E,0x29,0x5C,0x0F,0x3E,0x28,0x5C,0x0F,0x3E,0xB8,0x1E,0x05,0x3E,
+ 0x8F,0xC2,0xF5,0x3D,0xEC,0x51,0xB8,0x3D,0xCC,0xCC,0xCC,0x3D,0x00,0x00,0x00,0x00,0xCC,0xCC,0xCC,0x3D,0xEB,0x51,0xB8,0x3D,0x0A,0xD7,0x23,0x3D,0x9A,0x99,0x19,0x3E,
+ 0x0C,0xD7,0xA3,0xBC,0xCC,0xCC,0x4C,0x3E,0x3D,0x0A,0x57,0x3E,0x0A,0xD7,0x23,0x3C,0x00,0x00,0x80,0x3E,0x29,0x5C,0x0F,0x3E,0x90,0xC2,0xF5,0xBC,0x8F,0xC2,0x75,0x3D,
+ 0x00,0x00,0x80,0x3E,0x8F,0xC2,0x75,0x3D,0x29,0x5C,0x8F,0xBD,0x0A,0xD7,0xA3,0x3D,0x1E,0x85,0x6B,0x3E,0xEB,0x51,0x38,0x3E,0x29,0x5C,0x8F,0xBD,0x0A,0xD7,0xA3,0x3C,
+ 0x0A,0xD7,0x23,0x3E,0x0A,0xD7,0xA3,0x3C,0x8F,0xC2,0xF5,0x3D,0x0A,0xD7,0x23,0x3C,0xB8,0x1E,0x05,0x3E,0x8F,0xC2,0xF5,0x3C,0xB8,0x1E,0x05,0x3E,0x29,0x5C,0x8F,0x3D,
+ 0x28,0x5C,0x0F,0x3E,0x8F,0xC2,0xF5,0x3D,0x0A,0xD7,0xA3,0x3D,0xAE,0x47,0xE1,0x3D,0x8E,0xC2,0xF5,0x3C,0xEB,0x51,0xB8,0x3D,0x08,0xD7,0x23,0x3C,0xAE,0x47,0xE1,0x3D,
+ 0x8F,0xC2,0xF5,0x3D,0x8F,0xC2,0xF5,0x3C,0x7A,0x14,0x2E,0x3E,0x8F,0xC2,0xF5,0x3C,0x00,0x00,0x00,0x00,0x8F,0xC2,0xF5,0x3D,0x0C,0xD7,0xA3,0xBC,0xAE,0x47,0xE1,0x3D,
+ 0xCE,0xCC,0x4C,0xBD,0xCC,0xCC,0xCC,0x3D,0x8E,0xC2,0x75,0xBD,0x0A,0xD7,0xA3,0x3D,0x29,0x5C,0x8F,0xBD,0xCC,0xCC,0x4C,0x3D,0x29,0x5C,0x8F,0xBD,0x8F,0xC2,0xF5,0x3C,
+ 0x8E,0xC2,0x75,0xBD,0xAE,0x47,0xE1,0x3D,0xCC,0xCC,0xCC,0x3D,0xAE,0x47,0xE1,0x3D,0x00,0x00,0x00,0x00,0x0A,0xD7,0x23,0x3C,0xAE,0x47,0x61,0x3E,0xCC,0xCC,0x4C,0x3D,
+ 0xCC,0xCC,0x4C,0x3E,0xCC,0xCC,0x4C,0x3D,0xAE,0x47,0x61,0x3E,0xCC,0xCC,0x4C,0x3D,0x90,0xC2,0xF5,0xBC,0x0A,0xD7,0x23,0x3D,0x8E,0xC2,0x75,0xBD,0x0A,0xD7,0xA3,0x3C,
+ 0x29,0x5C,0x8F,0xBD,0x0A,0xD7,0x23,0x3D,0x0A,0xD7,0xA3,0x3D,0x0A,0xD7,0x23,0x3E,0x28,0x5C,0x0F,0x3E,0x3D,0x0A,0x57,0x3E,0xB8,0x1E,0x05,0x3E,0xAE,0x47,0x61,0x3E,
+ 0xCC,0xCC,0xCC,0x3D,0xAE,0x47,0x61,0x3E,0x00,0x00,0x00,0x00,0x8F,0xC2,0xF5,0x3D,0x29,0x5C,0x8F,0xBD,0x8E,0xC2,0xF5,0x3C,0x0A,0xD7,0xA3,0x3D,0x0A,0xD7,0xA3,0x3D,
+ 0x28,0x5C,0x8F,0x3D,0x08,0xD7,0x23,0x3C,0x08,0xD7,0x23,0x3C,0x8F,0xC2,0xF5,0x3C,0x0A,0xD7,0x23,0x3D,0xAE,0x47,0xE1,0x3D,0x28,0x5C,0x0F,0x3E,0x8F,0xC2,0xF5,0x3C,
+ 0x8E,0xC2,0x75,0x3E,0x0A,0xD7,0xA3,0x3C,0x7A,0x14,0x2E,0x3E,0x8F,0xC2,0xF5,0x3C,0x0A,0xD7,0x23,0x3E,0x0A,0xD7,0xA3,0x3C,0xCC,0xCC,0xCC,0x3D,0x0A,0xD7,0xA3,0x3C,
+ 0xAE,0x47,0x61,0x3E,0x8F,0xC2,0xF5,0x3C,0xEB,0x51,0x38,0x3E,0x0A,0xD7,0x23,0x3D,0x7A,0x14,0x2E,0x3E,0xCC,0xCC,0x4C,0x3D,0xB8,0x1E,0x05,0x3E,0x0A,0xD7,0x23,0x3D,
+ 0xAE,0x47,0xE1,0x3D,0x0A,0xD7,0x23,0x3D,0x28,0x5C,0x8F,0x3D,0xCC,0xCC,0x4C,0x3D,0xCC,0xCC,0x4C,0x3D,0x0A,0xD7,0xA3,0x3C,0x0C,0xD7,0xA3,0xBC,0x0A,0xD7,0xA3,0x3C,
+ 0x0A,0xD7,0x23,0xBD,0x0A,0xD7,0xA3,0x3C,0x0A,0xD7,0xA3,0x3D,0x0A,0xD7,0x23,0x3D,0x8E,0xC2,0x75,0x3D,0x0A,0xD7,0xA3,0x3C,0x8E,0xC2,0x75,0x3E,0x8F,0xC2,0xF5,0x3C,
+ 0x1E,0x85,0x6B,0x3E,0x0A,0xD7,0x23,0x3D,0x5C,0x8F,0x42,0x3E,0x8F,0xC2,0xF5,0x3C,0xCC,0xCC,0xCC,0x3D,0x8F,0xC2,0xF5,0x3C,0xAE,0x47,0x61,0x3E,0xCC,0xCC,0x4C,0x3D,
+ 0xEB,0x51,0xB8,0x3D,0x0A,0xD7,0xA3,0x3C,0x00,0x00,0x00,0x00,0x8F,0xC2,0xF5,0x3C,0x0A,0xD7,0x23,0xBD,0x0A,0xD7,0xA3,0x3C,0x8E,0xC2,0x75,0xBD,0xAE,0x47,0xE1,0x3D,
+ 0x0A,0xD7,0xA3,0x3D,0x7A,0x14,0x2E,0x3E,0x0A,0xD7,0xA3,0x3D,0xEB,0x51,0x38,0x3E,0xCC,0xCC,0xCC,0x3D,0xCC,0xCC,0x4C,0x3D,0xAE,0x47,0xE1,0x3D,0x28,0x5C,0x8F,0x3D,
+ 0xCC,0xCC,0xCC,0x3D,0xAE,0x47,0xE1,0x3D,0x28,0x5C,0x8F,0x3D,0x99,0x99,0x19,0x3E,0x8E,0xC2,0x75,0x3D,0x7A,0x14,0x2E,0x3E,0x28,0x5C,0x8F,0x3D,0xAE,0x47,0xE1,0x3D,
+ 0x3D,0x0A,0x57,0x3E,0x9A,0x99,0x19,0x3E,0x3D,0x0A,0x57,0x3E,0x21,0x0A,0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x03,0x00,0x04,0x00,0x04,0x00,0x05,0x00,0x05,
+ 0x00,0x02,0x00,0x22,0x04,0x00,0x06,0x00,0x07,0x00,0x08,0x00,0x09,0x00,0x23,0x08,0x00,0x0A,0x00,0x0B,0x00,0x0C,0x00,0x0D,0x00,0x0E,0x00,0x0F,0x00,0x10,0x00,0x11,
+ 0x00,0x24,0x2A,0x00,0x12,0x00,0x13,0x00,0x14,0x00,0x15,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x18,0x00,0x18,0x00,0x19,0x00,0x19,0x00,0x1A,0x00,0x1A,0x00,0x1B,0x00,
+ 0x1B,0x00,0x1C,0x00,0x1C,0x00,0x1D,0x00,0x1D,0x00,0x1E,0x00,0x1E,0x00,0x1F,0x00,0x1F,0x00,0x20,0x00,0x20,0x00,0x21,0x00,0x21,0x00,0x22,0x00,0x22,0x00,0x11,0x00,
+ 0x11,0x00,0x23,0x00,0x23,0x00,0x24,0x00,0x24,0x00,0x25,0x00,0x25,0x00,0x26,0x00,0x26,0x00,0x05,0x00,0x05,0x00,0x27,0x00,0x25,0x34,0x00,0x28,0x00,0x29,0x00,0x19,
+ 0x00,0x2A,0x00,0x2A,0x00,0x2B,0x00,0x2B,0x00,0x2C,0x00,0x2C,0x00,0x2D,0x00,0x2D,0x00,0x2E,0x00,0x2E,0x00,0x1C,0x00,0x1C,0x00,0x1B,0x00,0x1B,0x00,0x2F,0x00,0x2F,
+ 0x00,0x30,0x00,0x30,0x00,0x19,0x00,0x19,0x00,0x31,0x00,0x31,0x00,0x32,0x00,0x32,0x00,0x33,0x00,0x33,0x00,0x34,0x00,0x34,0x00,0x28,0x00,0x35,0x00,0x36,0x00,0x36,
+ 0x00,0x37,0x00,0x37,0x00,0x38,0x00,0x38,0x00,0x39,0x00,0x39,0x00,0x3A,0x00,0x3A,0x00,0x3B,0x00,0x3B,0x00,0x3C,0x00,0x3C,0x00,0x3D,0x00,0x3D,0x00,0x3E,0x00,0x3E,
+ 0x00,0x35,0x00,0x26,0x3C,0x00,0x3F,0x00,0x40,0x00,0x40,0x00,0x41,0x00,0x41,0x00,0x42,0x00,0x42,0x00,0x43,0x00,0x43,0x00,0x44,0x00,0x44,0x00,0x11,0x00,0x11,0x00,
+ 0x45,0x00,0x45,0x00,0x46,0x00,0x46,0x00,0x47,0x00,0x47,0x00,0x48,0x00,0x48,0x00,0x05,0x00,0x05,0x00,0x02,0x00,0x02,0x00,0x49,0x00,0x49,0x00,0x10,0x00,0x10,0x00,
+ 0x4A,0x00,0x4A,0x00,0x4B,0x00,0x4B,0x00,0x4C,0x00,0x4C,0x00,0x4D,0x00,0x4D,0x00,0x4E,0x00,0x4E,0x00,0x4F,0x00,0x4F,0x00,0x50,0x00,0x50,0x00,0x08,0x00,0x08,0x00,
+ 0x51,0x00,0x51,0x00,0x52,0x00,0x52,0x00,0x53,0x00,0x53,0x00,0x54,0x00,0x54,0x00,0x55,0x00,0x55,0x00,0x56,0x00,0x56,0x00,0x57,0x00,0x57,0x00,0x58,0x00,0x27,0x0C,
+ 0x00,0x59,0x00,0x5A,0x00,0x5A,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x1A,0x00,0x5B,0x00,0x5B,0x00,0x5C,0x00,0x5C,0x00,0x5D,0x00,0x28,0x12,0x00,0x5E,0x00,0x5F,0x00,
+ 0x5F,0x00,0x60,0x00,0x60,0x00,0x5C,0x00,0x5C,0x00,0x61,0x00,0x61,0x00,0x62,0x00,0x62,0x00,0x02,0x00,0x02,0x00,0x63,0x00,0x63,0x00,0x64,0x00,0x64,0x00,0x0D,0x00,
+ 0x29,0x12,0x00,0x65,0x00,0x66,0x00,0x66,0x00,0x67,0x00,0x67,0x00,0x68,0x00,0x68,0x00,0x69,0x00,0x69,0x00,0x6A,0x00,0x6A,0x00,0x6B,0x00,0x6B,0x00,0x6C,0x00,0x6C,
+ 0x00,0x6D,0x00,0x6D,0x00,0x6E,0x00,0x2A,0x06,0x00,0x6F,0x00,0x70,0x00,0x71,0x00,0x72,0x00,0x73,0x00,0x10,0x00,0x2B,0x04,0x00,0x74,0x00,0x25,0x00,0x75,0x00,0x76,
+ 0x00,0x2C,0x0C,0x00,0x77,0x00,0x78,0x00,0x78,0x00,0x49,0x00,0x49,0x00,0x79,0x00,0x79,0x00,0x77,0x00,0x77,0x00,0x7A,0x00,0x7A,0x00,0x29,0x00,0x2D,0x02,0x00,0x75,
+ 0x00,0x76,0x00,0x2E,0x08,0x00,0x79,0x00,0x49,0x00,0x49,0x00,0x78,0x00,0x78,0x00,0x77,0x00,0x77,0x00,0x79,0x00,0x2F,0x02,0x00,0x7B,0x00,0x6E,0x00,0x30,0x20,0x00,
+ 0x7C,0x00,0x60,0x00,0x60,0x00,0x7D,0x00,0x7D,0x00,0x71,0x00,0x71,0x00,0x75,0x00,0x75,0x00,0x7E,0x00,0x7E,0x00,0x7F,0x00,0x7F,0x00,0x80,0x00,0x80,0x00,0x47,0x00,
+ 0x47,0x00,0x81,0x00,0x81,0x00,0x82,0x00,0x82,0x00,0x83,0x00,0x83,0x00,0x84,0x00,0x84,0x00,0x85,0x00,0x85,0x00,0x86,0x00,0x86,0x00,0x08,0x00,0x08,0x00,0x7C,0x00,
+ 0x31,0x06,0x00,0x87,0x00,0x5B,0x00,0x5B,0x00,0x19,0x00,0x19,0x00,0x26,0x00,0x32,0x1A,0x00,0x5C,0x00,0x7D,0x00,0x7D,0x00,0x88,0x00,0x88,0x00,0x60,0x00,0x60,0x00,
+ 0x19,0x00,0x19,0x00,0x18,0x00,0x18,0x00,0x86,0x00,0x86,0x00,0x89,0x00,0x89,0x00,0x85,0x00,0x85,0x00,0x8A,0x00,0x8A,0x00,0x8B,0x00,0x8B,0x00,0x20,0x00,0x20,0x00,
+ 0x29,0x00,0x29,0x00,0x8C,0x00,0x33,0x1C,0x00,0x8D,0x00,0x8E,0x00,0x8E,0x00,0x8F,0x00,0x8F,0x00,0x90,0x00,0x90,0x00,0x91,0x00,0x91,0x00,0x92,0x00,0x92,0x00,0x93,
+ 0x00,0x93,0x00,0x11,0x00,0x11,0x00,0x56,0x00,0x56,0x00,0x81,0x00,0x81,0x00,0x47,0x00,0x47,0x00,0x26,0x00,0x26,0x00,0x05,0x00,0x05,0x00,0x02,0x00,0x02,0x00,0x49,
+ 0x00,0x34,0x06,0x00,0x94,0x00,0x62,0x00,0x62,0x00,0x95,0x00,0x94,0x00,0x96,0x00,0x35,0x20,0x00,0x97,0x00,0x8D,0x00,0x8D,0x00,0x0E,0x00,0x0E,0x00,0x1E,0x00,0x1E,
+ 0x00,0x98,0x00,0x98,0x00,0x09,0x00,0x09,0x00,0x99,0x00,0x99,0x00,0x92,0x00,0x92,0x00,0x93,0x00,0x93,0x00,0x11,0x00,0x11,0x00,0x56,0x00,0x56,0x00,0x81,0x00,0x81,
+ 0x00,0x47,0x00,0x47,0x00,0x26,0x00,0x26,0x00,0x05,0x00,0x05,0x00,0x02,0x00,0x02,0x00,0x49,0x00,0x36,0x2C,0x00,0x9A,0x00,0x86,0x00,0x86,0x00,0x08,0x00,0x08,0x00,
+ 0x7C,0x00,0x7C,0x00,0x60,0x00,0x60,0x00,0x7D,0x00,0x7D,0x00,0x71,0x00,0x71,0x00,0x62,0x00,0x62,0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x80,0x00,0x80,0x00,
+ 0x9B,0x00,0x9B,0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x45,0x00,0x9C,0x00,0x9C,0x00,0x9D,0x00,0x9D,0x00,0x9E,0x00,0x9E,0x00,0x73,0x00,0x73,0x00,0x8F,0x00,0x8F,0x00,
+ 0x54,0x00,0x54,0x00,0x9F,0x00,0x9F,0x00,0xA0,0x00,0xA0,0x00,0x62,0x00,0x37,0x04,0x00,0xA1,0x00,0x48,0x00,0x06,0x00,0xA1,0x00,0x38,0x38,0x00,0x19,0x00,0x1A,0x00,
+ 0x1A,0x00,0xA2,0x00,0xA2,0x00,0x5C,0x00,0x5C,0x00,0x2E,0x00,0x2E,0x00,0xA3,0x00,0xA3,0x00,0xA4,0x00,0xA4,0x00,0xA5,0x00,0xA5,0x00,0xA6,0x00,0xA6,0x00,0x35,0x00,
+ 0x35,0x00,0xA7,0x00,0xA7,0x00,0xA8,0x00,0xA8,0x00,0x24,0x00,0x24,0x00,0x25,0x00,0x25,0x00,0x26,0x00,0x26,0x00,0x05,0x00,0x05,0x00,0x02,0x00,0x02,0x00,0x49,0x00,
+ 0x49,0x00,0x62,0x00,0x62,0x00,0xA9,0x00,0xA9,0x00,0xAA,0x00,0xAA,0x00,0xAB,0x00,0xAB,0x00,0x90,0x00,0x90,0x00,0xAC,0x00,0xAC,0x00,0xAD,0x00,0xAD,0x00,0xAE,0x00,
+ 0xAE,0x00,0x17,0x00,0x17,0x00,0x18,0x00,0x18,0x00,0x19,0x00,0x39,0x2C,0x00,0xAF,0x00,0xB0,0x00,0xB0,0x00,0xB1,0x00,0xB1,0x00,0xB2,0x00,0xB2,0x00,0xB3,0x00,0xB3,
+ 0x00,0xB4,0x00,0xB4,0x00,0xB5,0x00,0xB5,0x00,0x07,0x00,0x07,0x00,0x5D,0x00,0x5D,0x00,0xA2,0x00,0xA2,0x00,0x60,0x00,0x60,0x00,0x7C,0x00,0x7C,0x00,0xB6,0x00,0xB6,
+ 0x00,0x50,0x00,0x50,0x00,0x9A,0x00,0x9A,0x00,0xAF,0x00,0xAF,0x00,0xA6,0x00,0xA6,0x00,0xB7,0x00,0xB7,0x00,0x46,0x00,0x46,0x00,0x9B,0x00,0x9B,0x00,0x26,0x00,0x26,
+ 0x00,0x05,0x00,0x05,0x00,0x78,0x00,0x3A,0x10,0x00,0x0E,0x00,0x61,0x00,0x61,0x00,0xA0,0x00,0xA0,0x00,0xB8,0x00,0xB8,0x00,0x0E,0x00,0x79,0x00,0x49,0x00,0x49,0x00,
+ 0x78,0x00,0x78,0x00,0x77,0x00,0x77,0x00,0x79,0x00,0x3B,0x14,0x00,0x0E,0x00,0x61,0x00,0x61,0x00,0xA0,0x00,0xA0,0x00,0xB8,0x00,0xB8,0x00,0x0E,0x00,0x77,0x00,0x78,
+ 0x00,0x78,0x00,0x49,0x00,0x49,0x00,0x79,0x00,0x79,0x00,0x77,0x00,0x77,0x00,0x7A,0x00,0x7A,0x00,0x29,0x00,0x3C,0x04,0x00,0xB9,0x00,0x75,0x00,0x75,0x00,0xBA,0x00,
+ 0x3D,0x04,0x00,0x71,0x00,0xBB,0x00,0x10,0x00,0xBC,0x00,0x3E,0x04,0x00,0x1B,0x00,0xBD,0x00,0xBD,0x00,0x29,0x00,0x3F,0x22,0x00,0x1C,0x00,0x87,0x00,0x87,0x00,0x59,
+ 0x00,0x59,0x00,0x1A,0x00,0x1A,0x00,0xBE,0x00,0xBE,0x00,0x08,0x00,0x08,0x00,0x50,0x00,0x50,0x00,0xBF,0x00,0xBF,0x00,0xC0,0x00,0xC0,0x00,0xC1,0x00,0xC1,0x00,0x99,
+ 0x00,0x99,0x00,0x73,0x00,0x73,0x00,0xC2,0x00,0xC2,0x00,0xC3,0x00,0x6B,0x00,0xC4,0x00,0xC4,0x00,0x80,0x00,0x80,0x00,0xC5,0x00,0xC5,0x00,0x6B,0x00,0x40,0x34,0x00,
+ 0x90,0x00,0xC6,0x00,0xC6,0x00,0xC7,0x00,0xC7,0x00,0xC8,0x00,0xC8,0x00,0xC9,0x00,0xC9,0x00,0x1D,0x00,0x1D,0x00,0x61,0x00,0x61,0x00,0xCA,0x00,0xCA,0x00,0xCB,0x00,
+ 0xCB,0x00,0xCC,0x00,0xCC,0x00,0xCD,0x00,0xCD,0x00,0xCE,0x00,0xCE,0x00,0xCF,0x00,0xC8,0x00,0x2E,0x00,0x2E,0x00,0xB5,0x00,0xB5,0x00,0x4A,0x00,0x4A,0x00,0xD0,0x00,
+ 0xD0,0x00,0xCC,0x00,0xD1,0x00,0xCF,0x00,0xCF,0x00,0xD2,0x00,0xD2,0x00,0xD3,0x00,0xD3,0x00,0xD4,0x00,0xD4,0x00,0x95,0x00,0x95,0x00,0xD5,0x00,0xD5,0x00,0xD6,0x00,
+ 0xD6,0x00,0xD7,0x00,0xD7,0x00,0xD8,0x00,0x41,0x06,0x00,0x08,0x00,0x29,0x00,0x08,0x00,0xBA,0x00,0xD9,0x00,0x9D,0x00,0x42,0x24,0x00,0x06,0x00,0x29,0x00,0x06,0x00,
+ 0x18,0x00,0x18,0x00,0x17,0x00,0x17,0x00,0x33,0x00,0x33,0x00,0xD8,0x00,0xD8,0x00,0xDA,0x00,0xDA,0x00,0xDB,0x00,0xDB,0x00,0x91,0x00,0x91,0x00,0xDC,0x00,0x61,0x00,
+ 0xDC,0x00,0xDC,0x00,0x9E,0x00,0x9E,0x00,0xA6,0x00,0xA6,0x00,0x35,0x00,0x35,0x00,0xA7,0x00,0xA7,0x00,0xA8,0x00,0xA8,0x00,0x24,0x00,0x24,0x00,0x25,0x00,0x25,0x00,
+ 0x29,0x00,0x43,0x22,0x00,0xDD,0x00,0x16,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x94,0x00,0x94,0x00,0x7C,0x00,0x7C,0x00,0x67,0x00,0x67,0x00,0x5B,0x00,0x5B,0x00,0x5C,
+ 0x00,0x5C,0x00,0xDE,0x00,0xDE,0x00,0xCA,0x00,0xCA,0x00,0x79,0x00,0x79,0x00,0xDF,0x00,0xDF,0x00,0xE0,0x00,0xE0,0x00,0x80,0x00,0x80,0x00,0x96,0x00,0x96,0x00,0x24,
+ 0x00,0x24,0x00,0x23,0x00,0x23,0x00,0xE1,0x00,0x44,0x18,0x00,0x06,0x00,0x29,0x00,0x06,0x00,0xB6,0x00,0xB6,0x00,0x50,0x00,0x50,0x00,0x9A,0x00,0x9A,0x00,0xAD,0x00,
+ 0xAD,0x00,0xE2,0x00,0xE2,0x00,0x93,0x00,0x93,0x00,0xD4,0x00,0xD4,0x00,0x45,0x00,0x45,0x00,0x46,0x00,0x46,0x00,0x9B,0x00,0x9B,0x00,0x29,0x00,0x45,0x08,0x00,0x06,
+ 0x00,0x29,0x00,0x06,0x00,0x8E,0x00,0x61,0x00,0xE3,0x00,0x29,0x00,0x39,0x00,0x46,0x06,0x00,0x06,0x00,0x29,0x00,0x06,0x00,0x8E,0x00,0x61,0x00,0xE3,0x00,0x47,0x26,
+ 0x00,0xDD,0x00,0x16,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x94,0x00,0x94,0x00,0x7C,0x00,0x7C,0x00,0x67,0x00,0x67,0x00,0x5B,0x00,0x5B,0x00,0x5C,0x00,0x5C,0x00,0xDE,
+ 0x00,0xDE,0x00,0xCA,0x00,0xCA,0x00,0x79,0x00,0x79,0x00,0xDF,0x00,0xDF,0x00,0xE0,0x00,0xE0,0x00,0x80,0x00,0x80,0x00,0x96,0x00,0x96,0x00,0x24,0x00,0x24,0x00,0x23,
+ 0x00,0x23,0x00,0xE1,0x00,0xE1,0x00,0xE4,0x00,0xE5,0x00,0xE4,0x00,0x48,0x06,0x00,0x06,0x00,0x29,0x00,0xA1,0x00,0x8C,0x00,0x61,0x00,0xE6,0x00,0x49,0x02,0x00,0x06,
+ 0x00,0x29,0x00,0x4A,0x12,0x00,0x94,0x00,0xE7,0x00,0xE7,0x00,0xE8,0x00,0xE8,0x00,0xE9,0x00,0xE9,0x00,0x80,0x00,0x80,0x00,0x48,0x00,0x48,0x00,0x05,0x00,0x05,0x00,
+ 0x02,0x00,0x02,0x00,0xEA,0x00,0xEA,0x00,0x62,0x00,0x4B,0x06,0x00,0x06,0x00,0x29,0x00,0xA1,0x00,0x62,0x00,0xEB,0x00,0x8C,0x00,0x4C,0x04,0x00,0x06,0x00,0x29,0x00,
+ 0x29,0x00,0xEC,0x00,0x4D,0x08,0x00,0x06,0x00,0x29,0x00,0x06,0x00,0x47,0x00,0xED,0x00,0x47,0x00,0xED,0x00,0xBA,0x00,0x4E,0x06,0x00,0x06,0x00,0x29,0x00,0x06,0x00,
+ 0x8C,0x00,0xA1,0x00,0x8C,0x00,0x4F,0x28,0x00,0x7C,0x00,0x67,0x00,0x67,0x00,0x5B,0x00,0x5B,0x00,0x5C,0x00,0x5C,0x00,0xDE,0x00,0xDE,0x00,0xCA,0x00,0xCA,0x00,0x79,
+ 0x00,0x79,0x00,0xDF,0x00,0xDF,0x00,0xE0,0x00,0xE0,0x00,0x80,0x00,0x80,0x00,0x96,0x00,0x96,0x00,0x24,0x00,0x24,0x00,0x23,0x00,0x23,0x00,0xE1,0x00,0xE1,0x00,0xEE,
+ 0x00,0xEE,0x00,0xEF,0x00,0xEF,0x00,0xDD,0x00,0xDD,0x00,0x16,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x94,0x00,0x94,0x00,0x7C,0x00,0x50,0x14,0x00,0x06,0x00,0x29,0x00,
+ 0x06,0x00,0x18,0x00,0x18,0x00,0x17,0x00,0x17,0x00,0x33,0x00,0x33,0x00,0xD8,0x00,0xD8,0x00,0xF0,0x00,0xF0,0x00,0xF1,0x00,0xF1,0x00,0xB0,0x00,0xB0,0x00,0xF2,0x00,
+ 0xF2,0x00,0xF3,0x00,0x51,0x2A,0x00,0x7C,0x00,0x67,0x00,0x67,0x00,0x5B,0x00,0x5B,0x00,0x5C,0x00,0x5C,0x00,0xDE,0x00,0xDE,0x00,0xCA,0x00,0xCA,0x00,0x79,0x00,0x79,
+ 0x00,0xDF,0x00,0xDF,0x00,0xE0,0x00,0xE0,0x00,0x80,0x00,0x80,0x00,0x96,0x00,0x96,0x00,0x24,0x00,0x24,0x00,0x23,0x00,0x23,0x00,0xE1,0x00,0xE1,0x00,0xEE,0x00,0xEE,
+ 0x00,0xEF,0x00,0xEF,0x00,0xDD,0x00,0xDD,0x00,0x16,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x94,0x00,0x94,0x00,0x7C,0x00,0xF4,0x00,0xF5,0x00,0x52,0x16,0x00,0x06,0x00,
+ 0x29,0x00,0x06,0x00,0x18,0x00,0x18,0x00,0x17,0x00,0x17,0x00,0x33,0x00,0x33,0x00,0xD8,0x00,0xD8,0x00,0xDA,0x00,0xDA,0x00,0xDB,0x00,0xDB,0x00,0x91,0x00,0x91,0x00,
+ 0xDC,0x00,0xDC,0x00,0x61,0x00,0x69,0x00,0x8C,0x00,0x53,0x26,0x00,0x16,0x00,0x17,0x00,0x17,0x00,0x18,0x00,0x18,0x00,0x19,0x00,0x19,0x00,0x1A,0x00,0x1A,0x00,0x1B,
+ 0x00,0x1B,0x00,0x1C,0x00,0x1C,0x00,0x1D,0x00,0x1D,0x00,0x1E,0x00,0x1E,0x00,0x1F,0x00,0x1F,0x00,0x20,0x00,0x20,0x00,0x21,0x00,0x21,0x00,0x22,0x00,0x22,0x00,0x11,
+ 0x00,0x11,0x00,0x23,0x00,0x23,0x00,0x24,0x00,0x24,0x00,0x25,0x00,0x25,0x00,0x26,0x00,0x26,0x00,0x05,0x00,0x05,0x00,0x27,0x00,0x54,0x04,0x00,0xB6,0x00,0x9B,0x00,
+ 0x06,0x00,0xA1,0x00,0x55,0x12,0x00,0x06,0x00,0x10,0x00,0x10,0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x80,0x00,0x80,0x00,0x47,0x00,0x47,0x00,0x81,0x00,0x81,
+ 0x00,0x56,0x00,0x56,0x00,0x11,0x00,0x11,0x00,0xA1,0x00,0x56,0x04,0x00,0x06,0x00,0x47,0x00,0xED,0x00,0x47,0x00,0x57,0x08,0x00,0x06,0x00,0x26,0x00,0x94,0x00,0x26,
+ 0x00,0x94,0x00,0x3A,0x00,0xF6,0x00,0x3A,0x00,0x58,0x04,0x00,0x06,0x00,0x8C,0x00,0xA1,0x00,0x29,0x00,0x59,0x06,0x00,0x06,0x00,0xE3,0x00,0xE3,0x00,0x47,0x00,0xED,
+ 0x00,0xE3,0x00,0x5A,0x06,0x00,0xA1,0x00,0x29,0x00,0x06,0x00,0xA1,0x00,0x29,0x00,0x8C,0x00,0x5B,0x08,0x00,0x65,0x00,0x6E,0x00,0xF7,0x00,0x0B,0x00,0x65,0x00,0x5E,
+ 0x00,0x6E,0x00,0x0D,0x00,0x5C,0x02,0x00,0x06,0x00,0xF8,0x00,0x5D,0x08,0x00,0xF9,0x00,0xFA,0x00,0x5E,0x00,0x0D,0x00,0x65,0x00,0x5E,0x00,0x6E,0x00,0x0D,0x00,0x5E,
+ 0x04,0x00,0xFB,0x00,0x75,0x00,0xFB,0x00,0xBD,0x00,0x5F,0x02,0x00,0x6E,0x00,0xFC,0x00,0x60,0x0C,0x00,0xFD,0x00,0x07,0x00,0x07,0x00,0x71,0x00,0x71,0x00,0xB5,0x00,
+ 0xB5,0x00,0xFE,0x00,0xFE,0x00,0xFF,0x00,0xFF,0x00,0x71,0x00,0x61,0x1C,0x00,0xAC,0x00,0xEC,0x00,0xB0,0x00,0x90,0x00,0x90,0x00,0x09,0x00,0x09,0x00,0x98,0x00,0x98,
+ 0x00,0x00,0x01,0x00,0x01,0xB5,0x00,0xB5,0x00,0xCA,0x00,0xCA,0x00,0x10,0x00,0x10,0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x26,0x00,0x26,0x00,0x47,0x00,0x47,
+ 0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x62,0x1C,0x00,0x06,0x00,0x29,0x00,0x61,0x00,0x1E,0x00,0x1E,0x00,0x2D,0x00,0x2D,0x00,0x01,0x01,0x01,0x01,0x4C,0x00,0x4C,0x00,
+ 0xA5,0x00,0xA5,0x00,0x02,0x01,0x02,0x01,0x36,0x00,0x36,0x00,0x03,0x01,0x03,0x01,0x04,0x01,0x04,0x01,0x9B,0x00,0x9B,0x00,0x48,0x00,0x48,0x00,0x05,0x00,0x05,0x00,
+ 0x27,0x00,0x63,0x1A,0x00,0xB0,0x00,0x90,0x00,0x90,0x00,0x09,0x00,0x09,0x00,0x98,0x00,0x98,0x00,0x00,0x01,0x00,0x01,0xB5,0x00,0xB5,0x00,0xCA,0x00,0xCA,0x00,0x10,
+ 0x00,0x10,0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x26,0x00,0x26,0x00,0x47,0x00,0x47,0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x64,0x1C,0x00,0x97,0x00,0xEC,0x00,
+ 0xB0,0x00,0x90,0x00,0x90,0x00,0x09,0x00,0x09,0x00,0x98,0x00,0x98,0x00,0x00,0x01,0x00,0x01,0xB5,0x00,0xB5,0x00,0xCA,0x00,0xCA,0x00,0x10,0x00,0x10,0x00,0x78,0x00,
+ 0x78,0x00,0x7F,0x00,0x7F,0x00,0x26,0x00,0x26,0x00,0x47,0x00,0x47,0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x65,0x20,0x00,0xCA,0x00,0x02,0x01,0x02,0x01,0x9E,0x00,0x9E,
+ 0x00,0x05,0x01,0x05,0x01,0x90,0x00,0x90,0x00,0x09,0x00,0x09,0x00,0x98,0x00,0x98,0x00,0x00,0x01,0x00,0x01,0xB5,0x00,0xB5,0x00,0xCA,0x00,0xCA,0x00,0x10,0x00,0x10,
+ 0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x26,0x00,0x26,0x00,0x47,0x00,0x47,0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x66,0x0A,0x00,0x08,0x00,0x7C,0x00,0x7C,0x00,
+ 0x67,0x00,0x67,0x00,0x06,0x01,0x06,0x01,0x07,0x01,0x07,0x00,0x01,0x01,0x67,0x26,0x00,0xAC,0x00,0x08,0x01,0x08,0x01,0x09,0x01,0x09,0x01,0x0A,0x01,0x0A,0x01,0x0B,
+ 0x01,0x0B,0x01,0x0C,0x01,0x0C,0x01,0x0D,0x01,0xB0,0x00,0x90,0x00,0x90,0x00,0x09,0x00,0x09,0x00,0x98,0x00,0x98,0x00,0x00,0x01,0x00,0x01,0xB5,0x00,0xB5,0x00,0xCA,
+ 0x00,0xCA,0x00,0x10,0x00,0x10,0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x26,0x00,0x26,0x00,0x47,0x00,0x47,0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x68,0x0E,0x00,
+ 0x06,0x00,0x29,0x00,0xF3,0x00,0x00,0x01,0x00,0x01,0x98,0x00,0x98,0x00,0x09,0x00,0x09,0x00,0x90,0x00,0x90,0x00,0x0E,0x01,0x0E,0x01,0x0F,0x01,0x69,0x0A,0x00,0x06,
+ 0x00,0x2F,0x00,0x2F,0x00,0x8D,0x00,0x8D,0x00,0x10,0x01,0x10,0x01,0x06,0x00,0x1D,0x00,0x04,0x00,0x6A,0x10,0x00,0xBE,0x00,0x11,0x01,0x11,0x01,0x7C,0x00,0x7C,0x00,
+ 0x12,0x01,0x12,0x01,0xBE,0x00,0x98,0x00,0x13,0x01,0x13,0x01,0x14,0x01,0x14,0x01,0x15,0x01,0x15,0x01,0x6E,0x00,0x6B,0x06,0x00,0x06,0x00,0x29,0x00,0x4D,0x00,0x49,
+ 0x00,0x16,0x01,0x0F,0x01,0x6C,0x02,0x00,0x06,0x00,0x29,0x00,0x6D,0x1A,0x00,0x07,0x00,0x29,0x00,0xF3,0x00,0x00,0x01,0x00,0x01,0x98,0x00,0x98,0x00,0x09,0x00,0x09,
+ 0x00,0x90,0x00,0x90,0x00,0x0E,0x01,0x0E,0x01,0x0F,0x01,0x0E,0x01,0xE2,0x00,0xE2,0x00,0x17,0x01,0x17,0x01,0x41,0x00,0x41,0x00,0x18,0x01,0x18,0x01,0x19,0x01,0x19,
+ 0x01,0x1A,0x01,0x6E,0x0E,0x00,0x07,0x00,0x29,0x00,0xF3,0x00,0x00,0x01,0x00,0x01,0x98,0x00,0x98,0x00,0x09,0x00,0x09,0x00,0x90,0x00,0x90,0x00,0x0E,0x01,0x0E,0x01,
+ 0x0F,0x01,0x6F,0x20,0x00,0x98,0x00,0x00,0x01,0x00,0x01,0xB5,0x00,0xB5,0x00,0xCA,0x00,0xCA,0x00,0x10,0x00,0x10,0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x26,
+ 0x00,0x26,0x00,0x47,0x00,0x47,0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x45,0x00,0x9C,0x00,0x9C,0x00,0x22,0x00,0x22,0x00,0xB0,0x00,0xB0,0x00,0x90,0x00,0x90,0x00,0x09,
+ 0x00,0x09,0x00,0x98,0x00,0x70,0x1C,0x00,0x07,0x00,0x6E,0x00,0x61,0x00,0x1E,0x00,0x1E,0x00,0x2D,0x00,0x2D,0x00,0x01,0x01,0x01,0x01,0x4C,0x00,0x4C,0x00,0xA5,0x00,
+ 0xA5,0x00,0x02,0x01,0x02,0x01,0x36,0x00,0x36,0x00,0x03,0x01,0x03,0x01,0x04,0x01,0x04,0x01,0x9B,0x00,0x9B,0x00,0x48,0x00,0x48,0x00,0x05,0x00,0x05,0x00,0x27,0x00,
+ 0x71,0x1C,0x00,0xAC,0x00,0x1B,0x01,0xB0,0x00,0x90,0x00,0x90,0x00,0x09,0x00,0x09,0x00,0x98,0x00,0x98,0x00,0x00,0x01,0x00,0x01,0xB5,0x00,0xB5,0x00,0xCA,0x00,0xCA,
+ 0x00,0x10,0x00,0x10,0x00,0x78,0x00,0x78,0x00,0x7F,0x00,0x7F,0x00,0x26,0x00,0x26,0x00,0x47,0x00,0x47,0x00,0x46,0x00,0x46,0x00,0x45,0x00,0x72,0x0A,0x00,0x07,0x00,
+ 0x29,0x00,0xCA,0x00,0xB5,0x00,0xB5,0x00,0x00,0x01,0x00,0x01,0x98,0x00,0x98,0x00,0x09,0x00,0x73,0x20,0x00,0xA5,0x00,0x90,0x00,0x90,0x00,0x01,0x01,0x01,0x01,0x2D,
+ 0x00,0x2D,0x00,0xFF,0x00,0xFF,0x00,0x61,0x00,0x61,0x00,0xA9,0x00,0xA9,0x00,0x1C,0x01,0x1C,0x01,0x1D,0x01,0x1D,0x01,0x72,0x00,0x72,0x00,0x37,0x00,0x37,0x00,0x03,
+ 0x01,0x03,0x01,0x46,0x00,0x46,0x00,0x9B,0x00,0x9B,0x00,0x48,0x00,0x48,0x00,0x1E,0x01,0x1E,0x01,0x27,0x00,0x74,0x0A,0x00,0x30,0x00,0x1F,0x01,0x1F,0x01,0xE0,0x00,
+ 0xE0,0x00,0x80,0x00,0x80,0x00,0x47,0x00,0x07,0x00,0x01,0x01,0x75,0x0E,0x00,0x07,0x00,0x49,0x00,0x49,0x00,0x1E,0x01,0x1E,0x01,0x07,0x01,0x07,0x01,0x80,0x00,0x80,
+ 0x00,0xE9,0x00,0xE9,0x00,0x37,0x00,0x20,0x01,0x0F,0x01,0x76,0x04,0x00,0x07,0x00,0x80,0x00,0xAC,0x00,0x80,0x00,0x77,0x08,0x00,0x07,0x00,0x48,0x00,0x09,0x00,0x48,
+ 0x00,0x09,0x00,0xEC,0x00,0x17,0x01,0xEC,0x00,0x78,0x04,0x00,0x07,0x00,0x0F,0x01,0x20,0x01,0x29,0x00,0x79,0x0C,0x00,0x1D,0x00,0x9B,0x00,0xAF,0x00,0x9B,0x00,0x9B,
+ 0x00,0x13,0x00,0x13,0x00,0x0D,0x01,0x0D,0x01,0x0B,0x00,0x0B,0x00,0x6E,0x00,0x7A,0x06,0x00,0x20,0x01,0x29,0x00,0x07,0x00,0x20,0x01,0x29,0x00,0x0F,0x01,0x7B,0x34,
+ 0x00,0x12,0x00,0x21,0x01,0x21,0x01,0x66,0x00,0x66,0x00,0x00,0x00,0x00,0x00,0x59,0x00,0x59,0x00,0x22,0x01,0x22,0x01,0x23,0x01,0x23,0x01,0x2D,0x00,0x2D,0x00,0x1F,
+ 0x00,0x1F,0x00,0x24,0x01,0x21,0x01,0x25,0x01,0x25,0x01,0x1A,0x00,0x1A,0x00,0x26,0x01,0x26,0x01,0x27,0x01,0x27,0x01,0x6F,0x00,0x6F,0x00,0x28,0x01,0x28,0x01,0x29,
+ 0x01,0x29,0x01,0x75,0x00,0x75,0x00,0x2A,0x01,0x2A,0x01,0x2B,0x01,0x2B,0x01,0x70,0x00,0x70,0x00,0xE0,0x00,0xE0,0x00,0x07,0x01,0x07,0x01,0x2C,0x01,0x2C,0x01,0x2D,
+ 0x01,0x2D,0x01,0x0D,0x01,0x2E,0x01,0x2F,0x01,0x7C,0x02,0x00,0x65,0x00,0x6E,0x00,0x7D,0x34,0x00,0x65,0x00,0x30,0x01,0x30,0x01,0x31,0x01,0x31,0x01,0xBE,0x00,0xBE,
+ 0x00,0x32,0x01,0x32,0x01,0x06,0x01,0x06,0x01,0xFD,0x00,0xFD,0x00,0x1D,0x00,0x1D,0x00,0x0E,0x00,0x0E,0x00,0x33,0x01,0x30,0x01,0x34,0x01,0x34,0x01,0x60,0x00,0x60,
+ 0x00,0x5B,0x00,0x5B,0x00,0x7D,0x00,0x7D,0x00,0x5D,0x00,0x5D,0x00,0xDE,0x00,0xDE,0x00,0xB5,0x00,0xB5,0x00,0x35,0x01,0x35,0x01,0x01,0x00,0x01,0x00,0xEA,0x00,0xEA,
+ 0x00,0x27,0x00,0x27,0x00,0x1E,0x01,0x1E,0x01,0x36,0x01,0x36,0x01,0x63,0x00,0x63,0x00,0x37,0x01,0x37,0x01,0x38,0x01,0x1C,0x01,0xCB,0x00,0x7E,0x28,0x00,0x10,0x00,
+ 0xCA,0x00,0xCA,0x00,0xB5,0x00,0xB5,0x00,0x9F,0x00,0x9F,0x00,0xEB,0x00,0xEB,0x00,0x69,0x00,0x69,0x00,0x39,0x01,0x39,0x01,0x9D,0x00,0x9D,0x00,0x95,0x00,0x95,0x00,
+ 0x3A,0x01,0x3A,0x01,0x3B,0x01,0xCA,0x00,0xA0,0x00,0xA0,0x00,0xAA,0x00,0xAA,0x00,0x3C,0x01,0x3C,0x01,0x3D,0x01,0x3D,0x01,0x3E,0x01,0x3E,0x01,0x9C,0x00,0x9C,0x00,
+ 0x3F,0x01,0x3F,0x01,0x40,0x01,0x40,0x01,0x3B,0x01,0x3B,0x01,0xBB,0x00
+};
+
+static bool isFirst=true;
+static bool isBigEndian() { int i = 1; return *(reinterpret_cast<char*>(&i))==0; }
+
+inline void Swap2Bytes(char* data)
+{
+ char one_byte;
+ one_byte = data[0]; data[0] = data[1]; data[1] = one_byte;
+}
+
+inline void Swap4Bytes(char* data)
+{
+ char one_byte;
+ one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
+ one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
+}
+
+inline void Swap8Bytes(char* data)
+{
+ char one_byte;
+ one_byte = data[0]; data[0] = data[7]; data[7] = one_byte;
+ one_byte = data[1]; data[1] = data[6]; data[6] = one_byte;
+ one_byte = data[2]; data[2] = data[5]; data[5] = one_byte;
+ one_byte = data[3]; data[3] = data[4]; data[4] = one_byte;
+}
+
+static inline uint8_t * getUShort(uint8_t *data,unsigned short &v)
+{
+ unsigned short *src = reinterpret_cast<unsigned short *>(data);
+ if ( isBigEndian() && isFirst )
+ {
+ Swap2Bytes(reinterpret_cast<char *>(data));
+ }
+ v = src[0];
+ data+=sizeof(unsigned short);
+ return data;
+}
+
+static inline uint8_t * getUint(uint8_t *data,uint32_t &v)
+{
+ uint32_t *src = reinterpret_cast<uint32_t *>(data);
+ if ( isBigEndian() && isFirst )
+ {
+ Swap4Bytes(reinterpret_cast<char *>(data));
+ }
+ v = src[0];
+ data+=sizeof(uint32_t);
+ return data;
+}
+
+class FontChar
+{
+public:
+ FontChar(void)
+ {
+ mIndexCount = 0;
+ mIndices = 0;
+ mX1 = mY1 = mX2 = mY2 = 0;
+ }
+
+ uint8_t * init(uint8_t *data,const float *vertices)
+ {
+ data = getUShort(data,mIndexCount);
+ mIndices = reinterpret_cast<unsigned short *>(data);
+
+ if ( isBigEndian() && isFirst )
+ {
+ for (uint16_t i=0; i<mIndexCount; i++)
+ {
+ Swap2Bytes(reinterpret_cast<char *>(&mIndices[i]));
+ }
+ }
+
+ data+=(mIndexCount*sizeof(unsigned short));
+ for (uint32_t i=0; i<mIndexCount; i++)
+ {
+ uint32_t index = mIndices[i];
+ const float *vertex = &vertices[index*2];
+
+ if ( i == 0 )
+ {
+ mX1 = mX2 = vertex[0];
+ mY1 = mY2 = vertex[1];
+ }
+ else
+ {
+ if ( vertex[0] < mX1 ) mX1 = vertex[0];
+ if ( vertex[1] < mY1 ) mY1 = vertex[1];
+
+ if ( vertex[0] > mX2 ) mX2 = vertex[0];
+ if ( vertex[1] > mY2 ) mY2 = vertex[1];
+
+ }
+ }
+
+ return data;
+ }
+
+ void vputc(const float *vertices,ProcessRenderDebugHelper *debug,float textScale,float &x,float &y)
+ {
+ if ( mIndices )
+ {
+ uint32_t lineCount = uint32_t(mIndexCount/2);
+ float spacing = (mX2-mX1)+0.05f;
+ for (uint32_t i=0; i<lineCount; i++)
+ {
+ unsigned short i1 = mIndices[i*2+0];
+ unsigned short i2 = mIndices[i*2+1];
+
+ const float *v1 = &vertices[i1*2];
+ const float *v2 = &vertices[i2*2];
+
+ physx::PxVec3 p1(v1[0]+x,v1[1]+y,0);
+ physx::PxVec3 p2(v2[0]+x,v2[1]+y,0);
+ p1*=textScale;
+ p2*=textScale;
+
+ debug->indirectDebugLine(p1,p2);
+
+ }
+ x+=spacing;
+ }
+ else
+ {
+ x+=0.1f;
+ }
+ }
+
+ float getWidth(void) const
+ {
+ float ret = 0.1f;
+ if ( mIndexCount > 0 )
+ {
+ ret = (mX2-mX1)+0.05f;
+ }
+ return ret;
+ }
+
+
+ float mX1;
+ float mX2;
+ float mY1;
+ float mY2;
+ unsigned short mIndexCount;
+ unsigned short *mIndices;
+};
+
+
+#define FONT_VERSION 1
+
+class MyVectorFont : public physx::shdfnd::UserAllocated
+{
+public:
+ MyVectorFont(void)
+ {
+ mVersion = 0;
+ mVcount = 0;
+ mCount = 0;
+ mVertices = 0;
+ initFont(g_font);
+ }
+
+ virtual ~MyVectorFont(void)
+ {
+ release();
+ }
+
+ void release(void)
+ {
+ mVersion = 0;
+ mVcount = 0;
+ mCount = 0;
+ mVertices = 0;
+ }
+
+ void initFont(uint8_t *font)
+ {
+ release();
+ if ( font[0] == 'F' && font[1] == 'O' && font[2] == 'N' && font[3] == 'T' )
+ {
+ font+=4;
+ font = getUint(font,mVersion);
+ if ( mVersion == FONT_VERSION )
+ {
+ font = getUint(font,mVcount);
+ font = getUint(font,mCount);
+ font = getUint(font,mIcount);
+ uint32_t vsize = sizeof(float)*mVcount*2;
+ mVertices = reinterpret_cast<float *>(font);
+ if ( isBigEndian() && isFirst )
+ {
+ for (uint32_t i=0; i<(mVcount*2); i++)
+ {
+ Swap4Bytes(reinterpret_cast<char *>(&mVertices[i]));
+ }
+ }
+ font+=vsize;
+ for (uint32_t i=0; i<mCount; i++)
+ {
+ uint8_t c = *font++;
+ font = mCharacters[c].init(font,mVertices);
+ }
+ }
+ isFirst = false;
+ }
+ }
+
+ void vprint(const char *buffer,ProcessRenderDebugHelper *debug,float textScale,bool centered)
+ {
+ const char *scan = buffer;
+ float x = 0;
+ float y = 0;
+ if ( centered )
+ {
+ float wid=0;
+ while ( *scan )
+ {
+ unsigned c = unsigned(*scan++);
+ wid+=mCharacters[c].getWidth();
+ }
+ x = -wid*0.5f;
+ scan = buffer;
+ }
+ while ( *scan )
+ {
+ unsigned c = unsigned(*scan++);
+ mCharacters[c].vputc(mVertices,debug,textScale,x,y);
+ }
+ }
+
+private:
+ uint32_t mVersion;
+ uint32_t mVcount;
+ uint32_t mCount;
+ float *mVertices;
+ uint32_t mIcount;
+ FontChar mCharacters[256];
+};
+
+
+
+
+class ProcessRenderDebugImpl : public ProcessRenderDebug, public physx::shdfnd::UserAllocated, public ProcessRenderDebugHelper
+{
+public:
+
+ ProcessRenderDebugImpl(void)
+ {
+ mViewMatrix = physx::PxMat44(physx::PxIdentity);
+ mLines = NULL;
+ mLineVertexCount = 0;
+ mMaxLineVertexCount = 0;
+ mTriangles = NULL;
+ mSolidVertexCount = 0;
+ mMaxSolidVertexCount = 0;
+ }
+
+ virtual ~ProcessRenderDebugImpl(void)
+ {
+ PX_FREE(mLines);
+ PX_FREE(mTriangles);
+ }
+
+ void flushLines(void)
+ {
+ if (mLines != NULL && mInterface != NULL && mLineVertexCount > 0)
+ {
+ mInterface->debugRenderLines(mLineVertexCount/2,mLines,mDisplayType!=WORLD_SPACE_NOZ,mDisplayType==SCREEN_SPACE);
+ }
+ if (mLines == NULL)
+ {
+ mLines = static_cast<RENDER_DEBUG::RenderDebugVertex *>(PX_ALLOC(sizeof(RENDER_DEBUG::RenderDebugVertex)*MAX_LINE_VERTEX, PX_DEBUG_EXP("RenderDebugVertex")));
+ mMaxLineVertexCount = MAX_LINE_VERTEX;
+ }
+ mLineVertexCount = 0;
+ }
+
+ void flushTriangles(void)
+ {
+ if (mTriangles != NULL && mInterface != NULL && mSolidVertexCount > 0)
+ {
+ mInterface->debugRenderTriangles(mSolidVertexCount/3,mTriangles,mDisplayType!=WORLD_SPACE_NOZ,mDisplayType==SCREEN_SPACE);
+ }
+ if (mTriangles == NULL)
+ {
+ mTriangles = static_cast<RENDER_DEBUG::RenderDebugSolidVertex *>(PX_ALLOC(sizeof(RENDER_DEBUG::RenderDebugSolidVertex)*MAX_SOLID_VERTEX, PX_DEBUG_EXP("RENDER_DEBUG::RenderDebugSolidVertex")));
+ mMaxSolidVertexCount = MAX_SOLID_VERTEX;
+ }
+ mSolidVertexCount = 0;
+ }
+
+ virtual void flush(RENDER_DEBUG::RenderDebugInterface *iface,DisplayType type)
+ {
+ mInterface = iface;
+ mDisplayType = type;
+ flushLines();
+ flushTriangles();
+ new ( &mCurrentState ) RenderState; // reset renderstate to inifial conditions.
+ }
+
+ bool isIdentity(const physx::PxMat44 &t) const
+ {
+ physx::PxMat44 id = physx::PxMat44(physx::PxIdentity);
+ const float *f1 = t.front();
+ const float *f2 = id.front();
+ for (uint32_t i=0; i<16; i++)
+ {
+ float diff = physx::PxAbs( f1[i] - f2[i] );
+ if ( diff > 0.000001f )
+ return false;
+ }
+ return true;
+ }
+
+ virtual void processRenderDebug(const DebugPrimitive **plist,uint32_t pcount,RENDER_DEBUG::RenderDebugInterface *iface,DisplayType type)
+ {
+ mInterface = iface;
+ mDisplayType = type;
+
+ for (uint32_t i=0; i<pcount; i++)
+ {
+ const DebugPrimitive &p = *plist[i];
+ switch ( p.mCommand )
+ {
+ case DebugCommand::DEBUG_RELEASE_TRIANGLE_MESH:
+ if ( iface )
+ {
+ const DebugReleaseTriangleMesh &d = static_cast< const DebugReleaseTriangleMesh &>(p);
+ iface->releaseTriangleMesh(d.mMeshId);
+ }
+ break;
+ case DebugCommand::DEBUG_RENDER_TRIANGLE_MESH_INSTANCES:
+ {
+ const DebugRenderTriangleMeshInstances &dgs = static_cast< const DebugRenderTriangleMeshInstances &>(p);
+ debugRenderTriangleMeshInstances(dgs,iface);
+ }
+ break;
+ case DebugCommand::DEBUG_CONVEX_HULL:
+ {
+ const DebugConvexHull &dgs = static_cast< const DebugConvexHull &>(p);
+ debugConvexHull(dgs);
+ }
+ break;
+ case DebugCommand::DEBUG_RENDER_POINTS:
+ {
+ const DebugRenderPoints &dgs = static_cast< const DebugRenderPoints &>(p);
+ debugRenderPoints(dgs,iface);
+ }
+ break;
+ case DebugCommand::DEBUG_RENDER_LINES:
+ {
+ const DebugRenderLines &dgs = static_cast< const DebugRenderLines &>(p);
+ debugRenderLines(dgs,iface);
+ }
+ break;
+ case DebugCommand::DEBUG_RENDER_TRIANGLES:
+ {
+ const DebugRenderTriangles &dgs = static_cast< const DebugRenderTriangles &>(p);
+ debugRenderTriangles(dgs,iface);
+ }
+ break;
+ case DebugCommand::DEBUG_UNREGISTER_INPUT_EVENT:
+ if ( iface )
+ {
+ const DebugUnregisterInputEvent &d = static_cast< const DebugUnregisterInputEvent &>(p);
+ iface->unregisterInputEvent(static_cast<InputEventIds::Enum>(d.mEventId));
+ }
+ break;
+ case DebugCommand::DEBUG_REGISTER_INPUT_EVENT:
+ if ( iface )
+ {
+ const DebugRegisterInputEvent &d = static_cast< const DebugRegisterInputEvent &>(p);
+ if ( d.mDigital )
+ {
+ iface->registerDigitalInputEvent(static_cast<InputEventIds::Enum>(d.mEventId), static_cast<InputIds::Enum>(d.mInputId));
+ }
+ else
+ {
+ iface->registerAnalogInputEvent(static_cast<InputEventIds::Enum>(d.mEventId), d.mSensitivity, static_cast<InputIds::Enum>(d.mInputId));
+ }
+ }
+ break;
+ case DebugCommand::DEBUG_SKIP_FRAME:
+ break;
+ case DebugCommand::DEBUG_RESET_INPUT_EVENTS:
+ if ( iface )
+ {
+ iface->resetInputEvents();
+ }
+ break;
+ case DebugCommand::DEBUG_CREATE_TRIANGLE_MESH:
+ {
+ const DebugCreateTriangleMesh &dgs = static_cast< const DebugCreateTriangleMesh &>(p);
+ debugCreateTriangleMesh(dgs,iface);
+ }
+ break;
+ case DebugCommand::DEBUG_REFRESH_TRIANGLE_MESH_VERTICES:
+ {
+ const DebugRefreshTriangleMeshVertices &dgs = static_cast< const DebugRefreshTriangleMeshVertices &>(p);
+ debugRefreshTriangleMeshVertices(dgs,iface);
+ }
+ break;
+ case DebugCommand::DEBUG_GRAPH:
+ {
+ const DebugGraphStream &dgs = static_cast< const DebugGraphStream &>(p);
+ debugGraph(dgs);
+ }
+ break;
+ case DebugCommand::DEBUG_GRADIENT_TRI:
+ {
+ const DebugGradientTri &dg = static_cast< const DebugGradientTri &>(p);
+ debugGradientTri(dg);
+ if ( iface )
+ {
+ RenderDebugSolidVertex verts[3];
+ verts[0].mPos[0] = dg.mP1.x; verts[0].mPos[1] = dg.mP1.y; verts[0].mPos[2] = dg.mP1.z;
+ verts[1].mPos[0] = dg.mP2.x; verts[1].mPos[1] = dg.mP2.y; verts[1].mPos[2] = dg.mP2.z;
+ verts[2].mPos[0] = dg.mP3.x; verts[2].mPos[1] = dg.mP3.y; verts[2].mPos[2] = dg.mP3.z;
+ const physx::PxVec3 v1(dg.mP1.x, dg.mP1.y, dg.mP1.z),
+ v2(dg.mP2.x, dg.mP2.y, dg.mP2.z),
+ v3(dg.mP3.x, dg.mP3.y, dg.mP3.z);
+
+ const physx::PxVec3 n = physx::PxVec3(v2-v1).cross(physx::PxVec3(v3-v1)).getNormalized();
+ verts[0].mNormal[0] = n.x;
+ verts[0].mNormal[1] = n.y;
+ verts[0].mNormal[2] = n.z;
+ verts[1].mNormal[0] = n.x;
+ verts[1].mNormal[1] = n.y;
+ verts[1].mNormal[2] = n.z;
+ verts[2].mNormal[0] = n.x;
+ verts[2].mNormal[1] = n.y;
+ verts[2].mNormal[2] = n.z;
+ iface->debugRenderTriangles(1, verts, false, false);
+ }
+ }
+ break;
+ case DebugCommand::SET_CURRENT_TRANSFORM:
+ {
+ const DebugSetCurrentTransform &dg = static_cast< const DebugSetCurrentTransform &>(p);
+ if ( isIdentity(dg.mTransform ))
+ {
+ mCurrentState.mPose = NULL;
+ }
+ else
+ {
+ mCurrentState.mCurrentPose = dg.mTransform;
+ mCurrentState.mPose = &mCurrentState.mCurrentPose;
+ }
+ }
+ break;
+ case DebugCommand::DEBUG_LINE:
+ {
+ const DebugLine &dg = static_cast< const DebugLine &>(p);
+ debugLine(dg.mP1,dg.mP2,mCurrentState.mColor,mCurrentState.mColor);
+ }
+ break;
+ case DebugCommand::DRAW_GRID:
+ {
+ const DrawGrid &dg = static_cast< const DrawGrid &>(p);
+ drawGrid(dg);
+ }
+ break;
+ case DebugCommand::SET_CURRENT_COLOR:
+ {
+ const DebugPrimitiveU32 &dg = static_cast< const DebugPrimitiveU32 &>(p);
+ mCurrentState.mColor = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_ARROW_COLOR:
+ {
+ const DebugPrimitiveU32 &dg = static_cast< const DebugPrimitiveU32 &>(p);
+ mCurrentState.mArrowColor = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_TILE1:
+ {
+ const DebugPrimitiveF32 &dg = static_cast< const DebugPrimitiveF32 &>(p);
+ mCurrentState.mTileRate1 = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_TILE2:
+ {
+ const DebugPrimitiveF32 &dg = static_cast< const DebugPrimitiveF32 &>(p);
+ mCurrentState.mTileRate2 = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_TEXTURE1:
+ {
+ const DebugPrimitiveU32 &dg = static_cast< const DebugPrimitiveU32 &>(p);
+ mCurrentState.mTexture1 = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_TEXTURE2:
+ {
+ const DebugPrimitiveU32 &dg = static_cast< const DebugPrimitiveU32 &>(p);
+ mCurrentState.mTexture2 = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_USER_ID:
+ {
+ const DebugPrimitiveU32 &dg = static_cast< const DebugPrimitiveU32 &>(p);
+ mCurrentState.mUserId = int32_t(dg.mValue);
+ }
+ break;
+ case DebugCommand::SET_CURRENT_RENDER_SCALE:
+ {
+ const DebugPrimitiveF32 &dg = static_cast< const DebugPrimitiveF32 &>(p);
+ mCurrentState.mRenderScale = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_ARROW_SIZE:
+ {
+ const DebugPrimitiveF32 &dg = static_cast< const DebugPrimitiveF32 &>(p);
+ mCurrentState.mArrowSize = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_RENDER_STATE:
+ {
+ const DebugPrimitiveU32 &dg = static_cast< const DebugPrimitiveU32 &>(p);
+ mCurrentState.mStates = dg.mValue;
+ }
+ break;
+ case DebugCommand::SET_CURRENT_TEXT_SCALE:
+ {
+ const DebugPrimitiveF32 &dg = static_cast< const DebugPrimitiveF32 &>(p);
+ mCurrentState.mTextScale = dg.mValue;
+ }
+ break;
+ case DebugCommand::DEBUG_TEXT:
+ {
+ const DebugText &dg = static_cast< const DebugText &>(p);
+ debugText(dg);
+ }
+ break;
+ case DebugCommand::DEBUG_TEXT2D:
+ if ( iface )
+ {
+ const DebugText2D &dg = static_cast< const DebugText2D &>(p);
+ iface->debugText2D(dg.mPosition.x,dg.mPosition.y,dg.mScale,dg.mShadowOffset,dg.mForceFixWidthNumbers ? true : false,dg.mTextColor, dg.mText );
+ }
+ break;
+ case DebugCommand::DEBUG_BOUND:
+ {
+ const DebugBound &db = static_cast< const DebugBound &>(p);
+ debugBound(db);
+ }
+ break;
+ case DebugCommand::DEBUG_QUAD:
+ {
+ const DebugQuad &b = static_cast< const DebugQuad &>(p);
+ debugQuad(b);
+ }
+ break;
+ case DebugCommand::DEBUG_POINT:
+ {
+ const DebugPoint &b = static_cast< const DebugPoint &>(p);
+ debugPoint(b);
+ }
+ break;
+ case DebugCommand::DEBUG_POINT_SCALE:
+ {
+ const DebugPointScale &b = static_cast< const DebugPointScale &>(p);
+ debugPoint(b);
+ }
+ break;
+ case DebugCommand::DEBUG_RECT2D:
+ {
+ const DebugRect2d &d = static_cast<const DebugRect2d &>(p);
+ debugRect2d(d);
+ }
+ break;
+ case DebugCommand::DEBUG_GRADIENT_LINE:
+ {
+ const DebugGradientLine &d = static_cast< const DebugGradientLine &>(p);
+ debugGradientLine(d);
+ }
+ break;
+ case DebugCommand::DEBUG_RAY:
+ {
+ const DebugRay &d = static_cast< const DebugRay &>(p);
+ debugRay(d);
+ }
+ break;
+ case DebugCommand::DEBUG_CYLINDER:
+ {
+ const DebugCylinder &d = static_cast< const DebugCylinder &>(p);
+ debugCylinder(d);
+ }
+ break;
+ case DebugCommand::DEBUG_CIRCLE:
+ {
+ const DebugCircle &d = static_cast< const DebugCircle &>(p);
+ debugCircle(d);
+ }
+ break;
+ case DebugCommand::DEBUG_POINT_CYLINDER:
+ {
+ const DebugPointCylinder &d = static_cast< const DebugPointCylinder &>(p);
+ debugPointCylinder(d);
+ }
+ break;
+ case DebugCommand::DEBUG_THICK_RAY:
+ {
+ const DebugThickRay &d = static_cast< const DebugThickRay &>(p);
+ debugThickRay(d);
+ }
+ break;
+ case DebugCommand::DEBUG_PLANE:
+ {
+ const DebugPlane &d = static_cast< const DebugPlane &>(p);
+ debugPlane(d);
+ }
+ break;
+ case DebugCommand::DEBUG_TRI:
+ {
+ const DebugTri &d = static_cast< const DebugTri &>(p);
+ debugTri(&d.mP1,&d.mP2,&d.mP3,NULL,NULL,NULL,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,false);
+ }
+ break;
+ case DebugCommand::DEBUG_TRI_NORMALS:
+ {
+ const DebugTriNormals &d = static_cast< const DebugTriNormals &>(p);
+ debugTriNormals(d);
+ }
+ break;
+ case DebugCommand::DEBUG_GRADIENT_TRI_NORMALS:
+ {
+ const DebugGradientTriNormals &d = static_cast< const DebugGradientTriNormals &>(p);
+ debugGradientTriNormals(d);
+ }
+ break;
+ case DebugCommand::DEBUG_SPHERE:
+ {
+ const DebugSphere &d = static_cast< const DebugSphere &>(p);
+ debugSphere(d);
+ }
+ break;
+ case DebugCommand::DEBUG_SQUASHED_SPHERE:
+ {
+ const DebugSquashedSphere &d = static_cast< const DebugSquashedSphere &>(p);
+ debugSphere(d);
+ }
+ break;
+ case DebugCommand::DEBUG_CAPSULE:
+ {
+ const DebugCapsule &d = static_cast<const DebugCapsule &>(p);
+ debugCapsule(d);
+ }
+ break;
+ case DebugCommand::DEBUG_CAPSULE_TAPERED:
+ {
+ const DebugTaperedCapsule&d = static_cast<const DebugTaperedCapsule&>(p);
+ debugTaperedCapsule(d);
+ }
+ break;
+ case DebugCommand::DEBUG_AXES:
+ {
+ const DebugAxes &d = static_cast< const DebugAxes &>(p);
+ debugAxes(d);
+ }
+ break;
+ case DebugCommand::DEBUG_ARC:
+ {
+ const DebugArc &d = static_cast< const DebugArc &>(p);
+ debugArc(d);
+ }
+ break;
+ case DebugCommand::DEBUG_THICK_ARC:
+ {
+ const DebugThickArc &d = static_cast< const DebugThickArc &>(p);
+ debugThickArc(d);
+ }
+ break;
+ case DebugCommand::DEBUG_DETAILED_SPHERE:
+ {
+ const DebugDetailedSphere &d = static_cast< const DebugDetailedSphere &>(p);
+ debugDetailedSphere(d);
+ }
+ break;
+ case DebugCommand::DEBUG_MESSAGE:
+ {
+ const DebugMessage &d = static_cast< const DebugMessage &>(p);
+ mInterface->debugMessage(d.mText);
+ }
+ break;
+ case DebugCommand::DEBUG_CREATE_CUSTOM_TEXTURE:
+ {
+ const DebugCreateCustomTexture &d = static_cast< const DebugCreateCustomTexture &>(p);
+ mInterface->createCustomTexture(d.mId,d.mTextureName);
+ }
+ break;
+ case DebugCommand::DEBUG_FRUSTUM:
+ {
+ const DebugFrustum &f = static_cast< const DebugFrustum &>(p);
+ debugFrustum(f.mView,f.mProj);
+ }
+ break;
+ case DebugCommand::DEBUG_CONE:
+ {
+ const DebugCone &c = static_cast< const DebugCone &>(p);
+ debugCone(c);
+ }
+ break;
+ case DebugCommand::DEBUG_BLOCK_INFO:
+ {
+ }
+ break;
+ case DebugCommand::DEBUG_LAST:
+ break;
+ default:
+ PX_ALWAYS_ASSERT();
+ break;
+ }
+ }
+ }
+
+ virtual void release(void)
+ {
+ delete this;
+ }
+
+ PX_INLINE int32_t clampColor(int32_t c)
+ {
+ if ( c < 0 )
+ {
+ c = 0;
+ }
+ else if ( c > 255 )
+ {
+ c = 255;
+ }
+ return c;
+ }
+
+ void debugText(const DebugText &dg)
+ {
+ physx::PxMat44 *savePose = mCurrentState.mPose;
+ mCurrentState.mPose = NULL;
+ physx::PxMat44 pose = dg.mPose;
+ pose.setPosition( pose.getPosition()+dg.mPosition );
+ if ( savePose )
+ {
+ pose = *savePose * pose;
+ }
+
+ if ( mCurrentState.isCameraFacing() )
+ {
+ float *cameraWorldPose = const_cast<float*>(pose.front());
+ const float *viewMatrix = mViewMatrix.front();
+ cameraWorldPose[0] = viewMatrix[0];
+ cameraWorldPose[1] = viewMatrix[4];
+ cameraWorldPose[2] = viewMatrix[8];
+ cameraWorldPose[3] = 0;
+
+ cameraWorldPose[4] = viewMatrix[1];
+ cameraWorldPose[5] = viewMatrix[5];
+ cameraWorldPose[6] = viewMatrix[9];
+ cameraWorldPose[7] = 0;
+
+ cameraWorldPose[8] = viewMatrix[2];
+ cameraWorldPose[9] = viewMatrix[6];
+ cameraWorldPose[10] = viewMatrix[10];
+ cameraWorldPose[11] = 0;
+ }
+ mCurrentState.mPose = &pose;
+ mVectorFont.vprint(dg.mText, this, mCurrentState.mTextScale, mCurrentState.isCentered() );
+ mCurrentState.mPose = savePose;
+ }
+
+ uint32_t getColor(uint32_t r,uint32_t g,uint32_t b,float percent = 0.0f)
+ {
+ uint32_t dr = uint32_t(static_cast<float>(r)*percent);
+ uint32_t dg = uint32_t(static_cast<float>(g)*percent);
+ uint32_t db = uint32_t(static_cast<float>(b)*percent);
+ r-=dr;
+ g-=dg;
+ b-=db;
+
+ const uint32_t c = 0xff000000 | (r<<16) | (g<<8) | b;
+ return c;
+ }
+
+
+ PX_INLINE void swapYZ(physx::PxVec3 &p)
+ {
+ float y = p.y;
+ p.y = p.z;
+ p.z = y;
+ }
+
+ void drawGrid(const DrawGrid &dg)
+ {
+ bool zup = dg.mZup ? true : false;
+ uint32_t gridSize = dg.mGridSize;
+ int32_t GRIDSIZE = int32_t(gridSize);
+
+ uint32_t c1 = getColor(133,153,181,0.1f);
+ uint32_t c2 = getColor(133,153,181,0.3f);
+ uint32_t c3 = getColor(133,153,181,0.5f);
+
+ const float TSCALE = 1.0f;
+
+ float BASELOC = 0-0.05f;
+
+ for (int32_t x=-GRIDSIZE; x<=GRIDSIZE; x++)
+ {
+ uint32_t c = c1;
+ if ( (x%10) == 0 ) c = c2;
+ if ( (x%GRIDSIZE) == 0 ) c = c3;
+
+ physx::PxVec3 p1( static_cast<float>(x), static_cast<float>(-GRIDSIZE), BASELOC );
+ physx::PxVec3 p2( static_cast<float>(x), static_cast<float>(+GRIDSIZE), BASELOC );
+
+ p1*=TSCALE;
+ p2*=TSCALE;
+
+ if ( !zup )
+ {
+ swapYZ(p1);
+ swapYZ(p2);
+ }
+ debugLine(p1,p2,c,c);
+
+
+ }
+
+ for (int32_t y=-GRIDSIZE; y<=GRIDSIZE; y++)
+ {
+ uint32_t c = c1;
+
+ if ( (y%10) == 0 ) c = c2;
+ if ( (y%GRIDSIZE) == 0 ) c = c3;
+
+ physx::PxVec3 p1(static_cast<float>(-GRIDSIZE), static_cast<float>(y), BASELOC);
+ physx::PxVec3 p2(static_cast<float>(+GRIDSIZE), static_cast<float>(y), BASELOC);
+
+ p1*=TSCALE;
+ p2*=TSCALE;
+
+ if ( !zup )
+ {
+ swapYZ(p1);
+ swapYZ(p2);
+ }
+
+ debugLine(p1,p2,c,c);
+ }
+ }
+
+ PX_INLINE void debugLine(const physx::PxVec3 &p1,const physx::PxVec3 &p2,uint32_t color1,uint32_t color2)
+ {
+ RENDER_DEBUG::RenderDebugVertex *v = getDebugVertex(2);
+
+ if ( mCurrentState.mPose )
+ {
+ physx::PxVec3 _p1 = mCurrentState.mPose->transform(p1);
+ physx::PxVec3 _p2 = mCurrentState.mPose->transform(p2);
+ v[0].mPos[0] = _p1.x*mCurrentState.mRenderScale;
+ v[0].mPos[1] = _p1.y*mCurrentState.mRenderScale;
+ v[0].mPos[2] = _p1.z*mCurrentState.mRenderScale;
+ v[0].mColor = color1;
+
+ v[1].mPos[0] = _p2.x*mCurrentState.mRenderScale;
+ v[1].mPos[1] = _p2.y*mCurrentState.mRenderScale;
+ v[1].mPos[2] = _p2.z*mCurrentState.mRenderScale;
+ v[1].mColor = color2;
+ }
+ else
+ {
+ v[0].mPos[0] = p1.x*mCurrentState.mRenderScale;
+ v[0].mPos[1] = p1.y*mCurrentState.mRenderScale;
+ v[0].mPos[2] = p1.z*mCurrentState.mRenderScale;
+ v[0].mColor = color1;
+
+ v[1].mPos[0] = p2.x*mCurrentState.mRenderScale;
+ v[1].mPos[1] = p2.y*mCurrentState.mRenderScale;
+ v[1].mPos[2] = p2.z*mCurrentState.mRenderScale;
+ v[1].mColor = color2;
+ }
+ }
+
+ PX_INLINE physx::PxVec3 rotate2d(const physx::PxVec3 &p,float r)
+ {
+ physx::PxVec3 ret;
+ ret.x = p.x*cosf(r) - p.y*sinf(r);
+ ret.y = p.x*sinf(r) + p.y*cosf(r);
+ ret.z = 0;
+ return ret;
+ }
+
+ PX_INLINE physx::PxVec3 facing(const physx::PxVec3 &p,const physx::PxMat44 &inverseViewMatrix)
+ {
+ return inverseViewMatrix.rotate(p);
+ }
+
+ PX_INLINE void debugQuad(const DebugQuad &p)
+ {
+ physx::PxVec3 points[4];
+
+ physx::PxMat44 inverseViewMatrix;
+
+ // get the inverse view matrix
+ float *cameraWorldPose = const_cast<float *>(inverseViewMatrix.front());
+ const float *viewMatrix = mViewMatrix.front();
+ cameraWorldPose[0] = viewMatrix[0];
+ cameraWorldPose[1] = viewMatrix[4];
+ cameraWorldPose[2] = viewMatrix[8];
+ cameraWorldPose[3] = 0;
+
+ cameraWorldPose[4] = viewMatrix[1];
+ cameraWorldPose[5] = viewMatrix[5];
+ cameraWorldPose[6] = viewMatrix[9];
+ cameraWorldPose[7] = 0;
+
+ cameraWorldPose[8] = viewMatrix[2];
+ cameraWorldPose[9] = viewMatrix[6];
+ cameraWorldPose[10] = viewMatrix[10];
+ cameraWorldPose[11] = 0;
+
+ // apply scale, rotation, and make the quad face the camera.
+ points[0] = facing(rotate2d(physx::PxVec3(-p.mScale.x*0.5f,-p.mScale.y*0.5f,0),p.mRotation),inverseViewMatrix)+p.mPos;
+ points[1] = facing(rotate2d(physx::PxVec3(p.mScale.x*0.5f,-p.mScale.y*0.5f,0),p.mRotation),inverseViewMatrix)+p.mPos;
+ points[2] = facing(rotate2d(physx::PxVec3(p.mScale.x*0.5f,p.mScale.y*0.5f,0),p.mRotation),inverseViewMatrix)+p.mPos;
+ points[3] = facing(rotate2d(physx::PxVec3(-p.mScale.x*0.5f,p.mScale.y*0.5f,0),p.mRotation),inverseViewMatrix)+p.mPos;
+
+
+ if ( mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded) || mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded) )
+ {
+ physx::PxVec3 normal(1.0f,1.0f,0);
+ uint32_t renderState = mCurrentState.mStates;
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+ debugTri(&points[0],&points[1],&points[2],&normal,&normal,&normal);
+ debugTri(&points[0],&points[2],&points[3],&normal,&normal,&normal);
+ mCurrentState.mStates = renderState;
+ }
+ if ( mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded) || !mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded) )
+ {
+ uint32_t currentColor = mCurrentState.mColor;
+ if ( mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded))
+ {
+ mCurrentState.mColor = mCurrentState.mArrowColor;
+ }
+ debugLine(points[0], points[1] );
+ debugLine(points[1], points[2] );
+ debugLine(points[2], points[3] );
+ debugLine(points[3], points[0] );
+ mCurrentState.mColor = currentColor;
+ }
+ }
+
+
+ PX_INLINE void debugPoint(const DebugPoint &p)
+ {
+ const physx::PxVec3 *source = debug_point;
+
+ for (int32_t i=0; i<3; i++)
+ {
+ physx::PxVec3 p1 = source[0]*p.mSize+p.mPos;
+ physx::PxVec3 p2 = source[1]*p.mSize+p.mPos;
+ source+=2;
+
+ debugLine(p1,p2);
+ }
+ }
+
+ PX_INLINE void debugPoint(const DebugPointScale &p)
+ {
+ const physx::PxVec3 *source = debug_point;
+
+ for (uint32_t i=0; i<3; i++)
+ {
+ physx::PxVec3 p1 = source[0]*p.mSize[i]+p.mPos;
+ physx::PxVec3 p2 = source[1]*p.mSize[i]+p.mPos;
+ source+=2;
+ debugLine(p1,p2);
+ }
+ }
+
+
+ PX_INLINE void debugGradientTri(const DebugGradientTri &tri)
+ {
+ debugTri(&tri.mP1,&tri.mP2,&tri.mP3,NULL,NULL,NULL,tri.mC1,tri.mC2,tri.mC3,true);
+ }
+
+ PX_INLINE void debugLine(const physx::PxVec3 &p1,const physx::PxVec3 &p2)
+ {
+ debugLine(p1,p2,mCurrentState.mColor,mCurrentState.mColor);
+ }
+
+ virtual void indirectDebugLine(const physx::PxVec3 &p1,const physx::PxVec3 &p2)
+ {
+ debugLine(p1,p2,mCurrentState.mColor,mCurrentState.mColor);
+ }
+
+ RENDER_DEBUG::RenderDebugVertex * getDebugVertex(uint32_t count)
+ {
+ if (( mLineVertexCount+count) > mMaxLineVertexCount )
+ {
+ flushLines();
+ }
+ PX_ASSERT( count < mMaxLineVertexCount );
+ RENDER_DEBUG::RenderDebugVertex *ret = &mLines[mLineVertexCount];
+ mLineVertexCount+=count;
+ return ret;
+ }
+
+ RENDER_DEBUG::RenderDebugSolidVertex * getDebugSolidVertex(uint32_t count)
+ {
+ if (( mSolidVertexCount+count) > mMaxSolidVertexCount )
+ {
+ flushTriangles();
+ }
+ PX_ASSERT( count < mMaxSolidVertexCount );
+ RENDER_DEBUG::RenderDebugSolidVertex *ret = &mTriangles[mSolidVertexCount];
+ mSolidVertexCount+=count;
+ return ret;
+ }
+
+ virtual void flushFrame(RENDER_DEBUG::RenderDebugInterface * /*iface*/)
+ {
+ }
+
+ PX_INLINE void debugBound(const DebugBound &b)
+ {
+ physx::PxVec3 box[8];
+ box[0] = physx::PxVec3( b.mBmin.x, b.mBmin.y, b.mBmin.z );
+ box[1] = physx::PxVec3( b.mBmax.x, b.mBmin.y, b.mBmin.z );
+ box[2] = physx::PxVec3( b.mBmax.x, b.mBmax.y, b.mBmin.z );
+ box[3] = physx::PxVec3( b.mBmin.x, b.mBmax.y, b.mBmin.z );
+ box[4] = physx::PxVec3( b.mBmin.x, b.mBmin.y, b.mBmax.z );
+ box[5] = physx::PxVec3( b.mBmax.x, b.mBmin.y, b.mBmax.z );
+ box[6] = physx::PxVec3( b.mBmax.x, b.mBmax.y, b.mBmax.z );
+ box[7] = physx::PxVec3( b.mBmin.x, b.mBmax.y, b.mBmax.z );
+ debugBound(box);
+ }
+
+ float computePlaneEquation(const physx::PxVec3 &A,const physx::PxVec3 &B,const physx::PxVec3 &C,physx::PxVec3 &normal)
+ {
+ physx::PxVec3 v = B - C;
+ physx::PxVec3 w = A - B;
+
+ physx::PxVec3 vw;
+
+ vw.x = v.y * w.z - v.z * w.y;
+ vw.y = v.z * w.x - v.x * w.z;
+ vw.z = v.x * w.y - v.y * w.x;
+
+ float mag = vw.magnitude();
+
+ if ( mag < 0.000001f )
+ {
+ mag = 0;
+ }
+ else
+ {
+ mag = 1.0f/mag;
+ }
+
+ normal = vw*mag;
+
+ float D = 0.0f - ((normal.x*A.x)+(normal.y*A.y)+(normal.z*A.z));
+
+ return D;
+ }
+
+ void debugTri(const physx::PxVec3 *_v1,const physx::PxVec3 *_v2,const physx::PxVec3 *_v3,const physx::PxVec3 *_n1=NULL,const physx::PxVec3 *_n2=NULL,const physx::PxVec3 *_n3=NULL,uint32_t c1=0xFFFFFFFF,uint32_t c2=0xFFFFFFFF,uint32_t c3=0xFFFFFFFF,bool useGradientColors=false)
+ {
+ if( mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::DoubleSided) )
+ {
+ debugTriOneSide(_v1, _v2, _v3, _n1, _n2, _n3, c1, c2, c3, useGradientColors, false);
+ debugTriOneSide(_v1, _v2, _v3, _n1, _n2, _n3, c1, c2, c3, useGradientColors, true);
+ }
+ else
+ {
+ debugTriOneSide(_v1, _v2, _v3, _n1, _n2, _n3, c1, c2, c3, useGradientColors, mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::CounterClockwise));
+ }
+ }
+
+ void debugTriOneSide(const physx::PxVec3 *_v1,
+ const physx::PxVec3 *_v2,
+ const physx::PxVec3 *_v3,
+ const physx::PxVec3 *_n1=NULL,
+ const physx::PxVec3 *_n2=NULL,
+ const physx::PxVec3 *_n3=NULL,
+ uint32_t c1=0xFFFFFFFF,
+ uint32_t c2=0xFFFFFFFF,
+ uint32_t c3=0xFFFFFFFF,
+ bool useGradientColors=false,
+ bool counterClockwise=false)
+ {
+ if (counterClockwise)
+ {
+ const physx::PxVec3 *temp = _v1;
+ _v1 = _v3;
+ _v3 = temp;
+ if ( _n1 )
+ {
+ temp = _n1;
+ _n1 = _n3;
+ _n3 = temp;
+ }
+ // switch colors too
+ {
+ uint32_t t = c1;
+ c1 = c3;
+ c3 = t;
+ }
+ }
+
+ if ( !useGradientColors )
+ {
+ c1 = mCurrentState.mColor;
+ c2 = mCurrentState.mColor;
+ c3 = mCurrentState.mColor;
+ }
+
+ physx::PxVec3 v1 = *_v1;
+ physx::PxVec3 v2 = *_v2;
+ physx::PxVec3 v3 = *_v3;
+
+ if (mCurrentState.mPose)
+ {
+ v1 = mCurrentState.mPose->transform(*_v1);
+ v2 = mCurrentState.mPose->transform(*_v2);
+ v3 = mCurrentState.mPose->transform(*_v3);
+ }
+
+ v1 *= mCurrentState.mRenderScale;
+ v2 *= mCurrentState.mRenderScale;
+ v3 *= mCurrentState.mRenderScale;
+
+ if (mCurrentState.isSolid())
+ {
+ RENDER_DEBUG::RenderDebugSolidVertex* verts = getDebugSolidVertex(3);
+
+ physx::PxVec3 n1, n2, n3;
+ if (_n1 == NULL)
+ {
+ computePlaneEquation(v3, v2, v1, n1);
+ if (counterClockwise)
+ {
+ n1 = -n1;
+ }
+ n2 = n1;
+ n3 = n1;
+ }
+ else
+ {
+ if (mCurrentState.mPose)
+ {
+ n1 = mCurrentState.mPose->rotate(*_n1);
+ n2 = mCurrentState.mPose->rotate(*_n2);
+ n3 = mCurrentState.mPose->rotate(*_n3);
+ }
+ else
+ {
+ n1 = *_n1;
+ n2 = *_n2;
+ n3 = *_n3;
+ }
+ }
+
+ verts[0].mPos[0] = v1.x;
+ verts[0].mPos[1] = v1.y;
+ verts[0].mPos[2] = v1.z;
+ verts[0].mColor = c1;
+ verts[0].mNormal[0] = n1.x;
+ verts[0].mNormal[1] = n1.y;
+ verts[0].mNormal[2] = n1.z;
+
+ verts[1].mPos[0] = v2.x;
+ verts[1].mPos[1] = v2.y;
+ verts[1].mPos[2] = v2.z;
+ verts[1].mColor = c2;
+ verts[1].mNormal[0] = n2.x;
+ verts[1].mNormal[1] = n2.y;
+ verts[1].mNormal[2] = n2.z;
+
+ verts[2].mPos[0] = v3.x;
+ verts[2].mPos[1] = v3.y;
+ verts[2].mPos[2] = v3.z;
+ verts[2].mColor = c3;
+ verts[2].mNormal[0] = n3.x;
+ verts[2].mNormal[1] = n3.y;
+ verts[2].mNormal[2] = n3.z;
+ }
+
+ if ( !mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded) || mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded) )
+ {
+ if ( mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded) )
+ {
+ c1 = c2 = c3 = mCurrentState.mArrowColor;
+ }
+ RENDER_DEBUG::RenderDebugVertex *lines = getDebugVertex(6);
+ // first vertex (start of first segment, end of third)
+ lines[0].mPos[0] = lines[5].mPos[0] = v1.x;
+ lines[0].mPos[1] = lines[5].mPos[1] = v1.y;
+ lines[0].mPos[2] = lines[5].mPos[2] = v1.z;
+ lines[0].mColor = lines[5].mColor = c1;
+
+ // second vertex (end of first segment, start of second)
+ lines[1].mPos[0] = lines[2].mPos[0] = v2.x;
+ lines[1].mPos[1] = lines[2].mPos[1] = v2.y;
+ lines[1].mPos[2] = lines[2].mPos[2] = v2.z;
+ lines[1].mColor = lines[2].mColor = c2;
+
+ // third vertex (end of second segment, start of third)
+ lines[3].mPos[0] = lines[4].mPos[0] = v3.x;
+ lines[3].mPos[1] = lines[4].mPos[1] = v3.y;
+ lines[3].mPos[2] = lines[4].mPos[2] = v3.z;
+ lines[3].mColor = lines[4].mColor = c3;
+ }
+ }
+
+
+ PX_INLINE void debugBound(const physx::PxVec3 *box)
+ {
+ if ( mCurrentState.isSolid() )
+ {
+ debugTri(&box[2],&box[1],&box[0]);
+ debugTri(&box[3],&box[2],&box[0]);
+
+ debugTri(&box[7],&box[2],&box[3]);
+ debugTri(&box[7],&box[6],&box[2]);
+
+ debugTri(&box[5],&box[1],&box[2]);
+ debugTri(&box[5],&box[2],&box[6]);
+
+ debugTri(&box[5],&box[4],&box[1]);
+ debugTri(&box[4],&box[0],&box[1]);
+
+ debugTri(&box[4],&box[6],&box[7]);
+ debugTri(&box[4],&box[5],&box[6]);
+
+ debugTri(&box[4],&box[7],&box[0]);
+ debugTri(&box[7],&box[3],&box[0]);
+ }
+ else
+ {
+ debugLine(box[0], box[1]);
+ debugLine(box[1], box[2]);
+ debugLine(box[2], box[3]);
+ debugLine(box[3], box[0]);
+
+ debugLine(box[4], box[5]);
+ debugLine(box[5], box[6]);
+ debugLine(box[6], box[7]);
+ debugLine(box[7], box[4]);
+
+ debugLine(box[0], box[4]);
+ debugLine(box[1], box[5]);
+ debugLine(box[2], box[6]);
+ debugLine(box[3], box[7]);
+ }
+ }
+
+
+ PX_INLINE void debugRect2d(const DebugRect2d &d)
+ {
+ physx::PxVec3 points[4];
+ points[0] = physx::PxVec3(d.mX1,d.mY1,0.0f);
+ points[1] = physx::PxVec3(d.mX2,d.mY1,0.0f);
+ points[2] = physx::PxVec3(d.mX2,d.mY2,0.0f);
+ points[3] = physx::PxVec3(d.mX1,d.mY2,0.0f);
+ debugPolygon(4,points);
+ }
+
+ PX_INLINE void debugGradientLine(const DebugGradientLine &d)
+ {
+ debugLine(d.mP1,d.mP2,d.mC1,d.mC2);
+ }
+
+ PX_INLINE void debugRay(const DebugRay &d)
+ {
+ debugLine(d.mP1,d.mP2);
+ physx::PxVec3 dir = d.mP2 - d.mP1;
+ float mag = dir.normalize();
+ float arrowSize = mCurrentState.mArrowSize;
+ if ( arrowSize > (mag*0.2f ))
+ {
+ arrowSize = mag*0.2f;
+ }
+ physx::PxVec3 ref(0,1.0f,0);
+ physx::PxQuat quat;
+ rotationArc(ref,dir,quat);
+ physx::PxMat44 matrix(quat);
+ matrix.setPosition(d.mP2);
+
+ uint32_t pcount = 0;
+ physx::PxVec3 points[24];
+ physx::PxVec3 *dest = points;
+
+ for (float a=30; a<=360; a+=30)
+ {
+ float r = a*FM_DEG_TO_RAD;
+ float x = physx::PxCos(r)*arrowSize;
+ float y = physx::PxSin(r)*arrowSize;
+
+ dest->x = x;
+ dest->y = -3*arrowSize;
+ dest->z = y;
+ dest++;
+ pcount++;
+ }
+
+ physx::PxVec3 *prev = &points[(pcount-1)];
+ physx::PxVec3 *p = points;
+ physx::PxVec3 center(0, -2.5f*arrowSize, 0);
+ physx::PxVec3 top(0, 0, 0 );
+
+ physx::PxVec3 _center = matrix.transform(center);
+ physx::PxVec3 _top = matrix.transform(top);
+
+
+ uint32_t saveState = mCurrentState.mStates;
+
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.mArrowColor = 0xFFFFFFFF;
+
+ for (uint32_t i=0; i<pcount; i++)
+ {
+ physx::PxVec3 _p = matrix.transform( *p );
+ physx::PxVec3 _prev = matrix.transform( *prev );
+
+ debugTri(&_p,&_center,&_prev);
+ debugTri(&_prev,&_top,&_p);
+
+ prev = p;
+ p++;
+ }
+ mCurrentState.mStates = saveState;
+
+ }
+
+ PX_INLINE void debugCylinder(const DebugCylinder &d)
+ {
+ const uint32_t numOfSegments = uint32_t(4 << physx::PxMin(d.mSubdivision, 6u)); // this maxes out at 4^6 = 256 segments
+ const float segmentAngle = physx::PxTwoPi / numOfSegments;
+ const float c = physx::PxCos(segmentAngle);
+ const float s = physx::PxSin(segmentAngle);
+ const physx::PxMat33 rotY(physx::PxVec3(c, 0,-s), physx::PxVec3(0, 1.0f, 0), physx::PxVec3(s, 0, c));
+
+ const float radiusDiff = d.mRadius1 - d.mRadius2;
+ physx::PxVec3 heightVec(radiusDiff / 2.0f, d.mHeight / 2.0f, 0.0f);
+
+ const float avgRadius = (d.mRadius1 + d.mRadius2) / 2.0f;
+ physx::PxVec3 currentVec(avgRadius, 0.0f, 0.0f);
+ physx::PxVec3 currentTangent(0.0f, 0.0f, 1.0f);
+ physx::PxVec3 currentNormal = heightVec.cross(currentTangent).getNormalized();
+
+ const physx::PxVec3 upperCenter(0.0f, d.mHeight / 2.0f, 0.0f);
+ const physx::PxVec3 lowerCenter(-upperCenter);
+
+
+ if (mCurrentState.isSolid())
+ {
+ for( uint32_t i=0; i<numOfSegments; ++i )
+ {
+ const physx::PxVec3 e0 = currentVec + heightVec;
+ const physx::PxVec3 e2 = currentVec - heightVec;
+ const physx::PxVec3 nC = currentNormal;
+
+ currentVec = rotY.transform(currentVec);
+ heightVec = rotY.transform(heightVec);
+ currentTangent = rotY.transform(currentTangent);
+ const physx::PxVec3 e1 = currentVec + heightVec;
+ const physx::PxVec3 e3 = currentVec - heightVec;
+ const physx::PxVec3 nN = currentNormal = heightVec.cross(currentTangent).getNormalized();
+
+ debugTri(&e0, &e2, &e3, &nC, &nC, &nN);
+ debugTri(&e3, &e1, &e0, &nN, &nN, &nC);
+
+ if (d.mCloseSides)
+ {
+ debugTri(&e0, &e1, &upperCenter);
+ debugTri(&e2, &lowerCenter, &e3);
+ }
+ else
+ {
+ debugTri(&e3, &e2, &e0, &nN, &nC, &nC);
+ debugTri(&e0, &e1, &e3, &nC, &nN, &nN);
+ }
+ }
+ }
+ else
+ {
+ for( uint32_t i=0; i<numOfSegments; ++i )
+ {
+ const physx::PxVec3 e0 = currentVec + heightVec;
+ const physx::PxVec3 e2 = currentVec - heightVec;
+
+ const physx::PxVec3 nextVec = rotY.transform(currentVec);
+ heightVec = rotY.transform(heightVec);
+ const physx::PxVec3 e1 = nextVec + heightVec;
+ const physx::PxVec3 e3 = nextVec - heightVec;
+
+ //const physx::PxVec3 nC = (-currentVec).getNormalized();
+
+ debugLine(e0, e2);
+ debugLine(e0, e1);
+ debugLine(e2, e3);
+
+ if (d.mCloseSides)
+ {
+ debugLine(upperCenter, e0);
+ debugLine(lowerCenter, e2);
+ }
+ currentVec = nextVec;
+ }
+ }
+ }
+
+ PX_INLINE void debugCircle(const DebugCircle &d)
+ {
+ const uint32_t numOfSegments = uint32_t(4 << physx::PxMin(d.mSubdivision, 6u)); // this maxes out at 4^6 = 256 segments
+ const float segmentAngle = physx::PxTwoPi / numOfSegments;
+ const float c = physx::PxCos(segmentAngle);
+ const float s = physx::PxSin(segmentAngle);
+
+ // rotation in ZX plane
+ const physx::PxMat33 rotY(physx::PxVec3(c, 0,-s), physx::PxVec3(0, 1.0f, 0), physx::PxVec3(s, 0, c));
+ physx::PxVec3 currentVec(d.mRadius, 0.0f, 0.0f);
+ if (d.mDrawSolidCircle)
+ {
+ physx::PxVec3* points = new physx::PxVec3[numOfSegments];
+ for( uint32_t i=0; i<numOfSegments; ++i, currentVec = rotY.transform(currentVec))
+ {
+ points[i] = d.mTransform.transform(currentVec);
+ }
+ debugPolygon(numOfSegments, points);
+ delete[] points;
+ }
+ else
+ {
+ for( uint32_t i=0; i<numOfSegments; ++i )
+ {
+ physx::PxVec3 p0 = currentVec;
+ physx::PxVec3 p1 = rotY.transform(currentVec);
+ currentVec = p1;
+
+ p0 = d.mTransform.transform(p0);
+ p1 = d.mTransform.transform(p1);
+ debugLine(p0, p1);
+ }
+ }
+ }
+
+ PX_INLINE void debugPolygon(uint32_t pcount,const physx::PxVec3 *points)
+ {
+ if ( mCurrentState.isSolid() )
+ {
+ PX_ASSERT( pcount >= 3 );
+ PX_ASSERT( pcount <= 256 );
+ bool wasOverlay = mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ if( wasOverlay )
+ {
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.incrementChangeCount();
+ }
+ const physx::PxVec3 *v1 = &points[0];
+ const physx::PxVec3 *v2 = &points[1];
+ const physx::PxVec3 *v3 = &points[2];
+ debugTri(v1, v2, v3, NULL, NULL, NULL, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, false);
+ for (uint32_t i=3; i<pcount; i++)
+ {
+ v2 = v3;
+ v3 = &points[i];
+ debugTri(v1, v2, v3, NULL, NULL, NULL, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, false);
+ }
+ if ( wasOverlay )
+ {
+ for (uint32_t i=0; i<(pcount-1); i++)
+ {
+ debugLine( points[i], points[i+1], mCurrentState.mArrowColor, mCurrentState.mArrowColor );
+ }
+ debugLine(points[pcount-1],points[0]);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.incrementChangeCount();
+ }
+ }
+ else
+ {
+ for (uint32_t i=0; i<(pcount-1); i++)
+ {
+ debugLine( points[i], points[i+1] );
+ }
+ debugLine(points[pcount-1],points[0]);
+ }
+ }
+
+ PX_INLINE void debugPointCylinder(const DebugPointCylinder &d)
+ {
+ physx::PxVec3 dir = d.mP2 - d.mP1;
+ dir.normalize();
+
+ physx::PxVec3 ref(0, 1.0f, 0);
+
+ physx::PxQuat quat;
+
+ rotationArc(ref,dir,quat);
+
+ physx::PxMat44 matrix1(quat);
+ physx::PxMat44 matrix2(quat);
+
+ matrix1.setPosition(d.mP2);
+ matrix2.setPosition(d.mP1);
+
+
+ uint32_t pcount = 0;
+ physx::PxVec3 points1[24];
+ physx::PxVec3 points2[24];
+
+ physx::PxVec3 *dest1 = points1;
+ physx::PxVec3 *dest2 = points2;
+
+
+ for (float a=30; a<=360; a+=30)
+ {
+ float r = a*FM_DEG_TO_RAD;
+ float x = physx::PxCos(r)*d.mRadius;
+ float y = physx::PxSin(r)*d.mRadius;
+
+ physx::PxVec3 p(x, 0, y);
+
+ (*dest1) = matrix1.transform(p);
+ (*dest2) = matrix2.transform(p);
+
+ dest1++;
+ dest2++;
+ pcount++;
+
+ }
+
+ PX_ASSERT( pcount < 24 );
+
+ if ( mCurrentState.isSolid() )
+ {
+
+ uint32_t saveState = mCurrentState.mStates;
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::CounterClockwise);
+
+ physx::PxVec3 *prev1 = &points1[(pcount-1)];
+ physx::PxVec3 *prev2 = &points2[(pcount-1)];
+
+ physx::PxVec3 *scan1 = points1;
+ physx::PxVec3 *scan2 = points2;
+
+ for (uint32_t i=0; i<pcount; i++)
+ {
+
+ debugTri(scan1,prev2,prev1);
+ debugTri(scan2,prev2,scan1);
+
+ prev1 = scan1;
+ prev2 = scan2;
+ scan1++;
+ scan2++;
+ }
+
+ debugPolygon(pcount,points2);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::CounterClockwise);
+ debugPolygon(pcount,points1);
+
+ mCurrentState.mStates = saveState;
+
+ }
+
+ if ( !mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded) || mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded) )
+ {
+
+ uint32_t color = mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded) ? mCurrentState.mArrowColor : mCurrentState.mColor;
+ physx::PxVec3 *prev1 = &points1[(pcount-1)];
+ physx::PxVec3 *prev2 = &points2[(pcount-1)];
+
+ physx::PxVec3 *scan1 = points1;
+ physx::PxVec3 *scan2 = points2;
+ for (uint32_t i=0; i<pcount; i++)
+ {
+ debugLine(*scan1,*scan2,color,color);
+
+ debugLine(d.mP2,*scan1,color,color);
+ debugLine(d.mP1,*scan2,color,color);
+
+ debugLine(*prev1,*scan1,color,color);
+ debugLine(*prev2,*scan2,color,color);
+
+ prev1 = scan1;
+ prev2 = scan2;
+
+ scan1++;
+ scan2++;
+ }
+ }
+ }
+
+ PX_INLINE void debugThickRay(const DebugThickRay &d)
+ {
+ RenderState save = mCurrentState;
+
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+
+ physx::PxVec3 dir = d.mP2 - d.mP1;
+ float mag = dir.normalize();
+ float arrowSize = physx::PxMin(physx::PxMax(mCurrentState.mArrowSize, d.mRaySize * 1.3f), mag * 0.2f);
+
+ physx::PxVec3 ref(0,1.0f,0);
+ physx::PxQuat quat;
+
+ rotationArc(ref,dir,quat);
+
+ physx::PxMat44 matrix(quat);
+ matrix.setPosition(d.mP2);
+
+
+ uint32_t pcount = 0;
+ physx::PxVec3 points[24];
+ physx::PxVec3 *dest = points;
+
+ for (float a=30; a<=360; a+=30)
+ {
+ float r = a*FM_DEG_TO_RAD;
+ float x = physx::PxCos(r)*arrowSize;
+ float y = physx::PxSin(r)*arrowSize;
+
+ dest->x = x;
+ dest->y = -3*arrowSize;
+ dest->z = y;
+
+ dest++;
+ pcount++;
+ }
+
+ physx::PxVec3 *prev = &points[(pcount-1)];
+ physx::PxVec3 *p = points;
+ physx::PxVec3 center(0, -2.5f*arrowSize, 0);
+ physx::PxVec3 top(0,0,0);
+
+ physx::PxVec3 _center;
+ physx::PxVec3 _top;
+
+ _center = matrix.transform(center);
+ _top = matrix.transform(top);
+
+ DebugPointCylinder dc(d.mP1,_center,d.mRaySize);
+ debugPointCylinder(dc);
+
+ //mCurrentState = save; - don't want triangles to be seen !
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+ mCurrentState.mColor = mCurrentState.mArrowColor;
+ mCurrentState.mArrowColor = mCurrentState.mOutlineColor;
+
+ if(d.mArrowTip)
+ {
+ for (uint32_t i=0; i<pcount; i++)
+ {
+
+ physx::PxVec3 _p;
+ physx::PxVec3 _prev;
+
+ _p = matrix.transform(*p);
+ _prev = matrix.transform(*prev);
+
+ debugTri(&_p,&_center,&_prev);
+ debugTri(&_prev,&_top,&_p);
+
+ prev = p;
+ p++;
+ }
+ }
+ else
+ {
+ DebugDetailedSphere sphere(_center, 0.1f * mag, 2);
+ debugDetailedSphere(sphere);
+ }
+
+ mCurrentState = save;
+ }
+
+ void debugPlane(const physx::PxVec3 &normal,float dCoff,float radius1,float radius2)
+ {
+ physx::PxVec3 ref(0,1.0f,0);
+ physx::PxQuat quat;
+ rotationArc(ref,normal,quat);
+ physx::PxMat44 matrix(quat);
+
+ float stepsize = 360/20;
+
+ physx::PxVec3 prev(0,0,0);
+
+ physx::PxVec3 origin(0,-dCoff,0);
+ physx::PxVec3 pos(origin), first(origin), center(origin);
+
+ center = matrix.transform(origin);
+ matrix.setPosition(center);
+
+ for (float d=0; d<360; d+=stepsize)
+ {
+ float a = degToRad(d);
+ physx::PxVec3 _pos(physx::PxCos(a)*radius1,0,physx::PxSin(a)*radius2);
+ pos = matrix.transform(_pos);
+
+ debugLine(center,pos);
+
+ if ( d == 0 )
+ {
+ first = pos;
+ }
+ else
+ {
+ debugLine(prev,pos);
+ }
+ prev = pos;
+ }
+
+ debugLine(first,pos);
+ }
+
+
+
+ PX_INLINE void debugPlane(const DebugPlane &d)
+ {
+ debugPlane(d.mNormal,d.mD,d.mRadius1*0.25f, d.mRadius2*0.25f);
+ debugPlane(d.mNormal,d.mD,d.mRadius1*0.5f, d.mRadius2*0.5f);
+ debugPlane(d.mNormal,d.mD,d.mRadius1*0.75f, d.mRadius2*0.75f);
+ debugPlane(d.mNormal,d.mD,d.mRadius1*1.0f, d.mRadius2*1.0f);
+ }
+
+ PX_INLINE void debugTriNormals(const DebugTriNormals &d)
+ {
+ debugTri(&d.mP1,&d.mP2,&d.mP3,&d.mN1,&d.mN2,&d.mN3);
+ }
+
+ PX_INLINE void debugGradientTriNormals(const DebugGradientTriNormals &d)
+ {
+ debugTri(&d.mP1,&d.mP2,&d.mP3,&d.mN1,&d.mN2,&d.mN3,d.mC1,d.mC2,d.mC3,true);
+ }
+
+ PX_INLINE void debugSphere(const DebugSquashedSphere &d)
+ {
+ for (uint32_t i = 0; i < 8; i++)
+ {
+ const physx::PxVec3 p0 = simpleSpherePosition[simpleSphereIndices[i*3+0]];
+ const physx::PxVec3 p1 = simpleSpherePosition[simpleSphereIndices[i*3+1]];
+ const physx::PxVec3 p2 = simpleSpherePosition[simpleSphereIndices[i*3+2]];
+ subdivideOnSphere(int(d.mSubdivision), p0, p1, p2, d.mRadius, 0.0f, 0.0f);
+ }
+ }
+
+
+ PX_INLINE void debugSphere(const DebugSphere &d)
+ {
+ for (uint32_t i = 0; i < 8; i++)
+ {
+ const physx::PxVec3 p0 = simpleSpherePosition[simpleSphereIndices[i*3+0]];
+ const physx::PxVec3 p1 = simpleSpherePosition[simpleSphereIndices[i*3+1]];
+ const physx::PxVec3 p2 = simpleSpherePosition[simpleSphereIndices[i*3+2]];
+ subdivideOnSphere(int(d.mSubdivision), p0, p1, p2, d.mRadius, 0.0f, 0.0f);
+ }
+ }
+
+ void subdivideOnSphere(int subdivision, const physx::PxVec3& p0, const physx::PxVec3& p1, const physx::PxVec3& p2, float radius, float height, float skew)
+ {
+ //physx::PxMat44 transform = physx::PxMat44(physx::PxIdentity);
+ if (subdivision <= 0)
+ {
+ physx::PxVec3 t[3];
+ physx::PxVec3 n[3] = { p0, p1, p2 };
+
+ if (height > 0.0f || skew != 0.0f)
+ {
+ const float upper = physx::PxSign(p0.y + p1.y + p2.y);
+
+ const physx::PxVec3 offset(0.0f, upper * height, 0.0f);
+ if (skew != 0.0f)
+ {
+ const float scale = upper - skew;
+ for (uint32_t i = 0; i < 3; i++)
+ {
+ const float ny = n[i].y;
+ //const float sny =((ny - 1.0f) * scale) + upper;
+ const float sny = upper > 0.0f ? (1.0f - (1.0f - ny) * scale) : (-1.0f + (1.0f + ny) * -scale);
+ PX_ASSERT(physx::PxAbs(sny) <= 1.0f);
+ n[i].y = 0.0f;
+ n[i].normalize();
+ n[i] *= physx::PxSqrt(1.0f - (sny * sny));
+ n[i].y = sny;
+ t[i] = n[i] * radius + offset;
+ }
+ }
+ else
+ {
+ t[0] = p0 * radius + offset;
+ t[1] = p1 * radius + offset;
+ t[2] = p2 * radius + offset;
+ }
+ }
+ else
+ {
+ t[0] = p0 * radius;
+ t[1] = p1 * radius;
+ t[2] = p2 * radius;
+ }
+
+ debugTri(t+0, t+1, t+2, n+0, n+1, n+2);
+ }
+ else
+ {
+ physx::PxVec3 p01 = p0 + p1; p01.normalize();
+ physx::PxVec3 p12 = p1 + p2; p12.normalize();
+ physx::PxVec3 p20 = p2 + p0; p20.normalize();
+
+ subdivideOnSphere(subdivision-1, p0, p01, p20, radius, height, skew);
+ subdivideOnSphere(subdivision-1, p1, p12, p01, radius, height, skew);
+ subdivideOnSphere(subdivision-1, p2, p20, p12, radius, height, skew);
+ subdivideOnSphere(subdivision-1, p01, p12, p20, radius, height, skew);
+ }
+ }
+
+
+ void subdivideOnSphere(int subdivision, const physx::PxVec3& p0, const physx::PxVec3& p1, const physx::PxVec3& p2, const physx::PxVec3 &radius, float height, float skew)
+ {
+ //physx::PxMat44 transform = physx::PxMat44(physx::PxIdentity);
+ if (subdivision <= 0)
+ {
+ physx::PxVec3 t[3];
+ physx::PxVec3 n[3] = { p0, p1, p2 };
+
+ if (height > 0.0f || skew != 0.0f)
+ {
+ const float upper = physx::PxSign(p0.y + p1.y + p2.y);
+
+ const physx::PxVec3 offset(0.0f, upper * height, 0.0f);
+ if (skew != 0.0f)
+ {
+ const float scale = upper - skew;
+ for (uint32_t i = 0; i < 3; i++)
+ {
+ const float ny = n[i].y;
+ //const float sny =((ny - 1.0f) * scale) + upper;
+ const float sny = upper > 0.0f ? (1.0f - (1.0f - ny) * scale) : (-1.0f + (1.0f + ny) * -scale);
+ PX_ASSERT(physx::PxAbs(sny) <= 1.0f);
+ n[i].y = 0.0f;
+ n[i].normalize();
+ n[i] *= physx::PxSqrt(1.0f - (sny * sny));
+ n[i].y = sny;
+ t[i] = n[i].multiply(radius) + offset;
+ }
+ }
+ else
+ {
+ t[0] = p0.multiply(radius) + offset;
+ t[1] = p1.multiply(radius) + offset;
+ t[2] = p2.multiply(radius) + offset;
+ }
+ }
+ else
+ {
+ t[0] = p0.multiply(radius);
+ t[1] = p1.multiply(radius);
+ t[2] = p2.multiply(radius);
+ }
+
+ debugTri(t+0, t+1, t+2, n+0, n+1, n+2);
+ }
+ else
+ {
+ physx::PxVec3 p01 = p0 + p1; p01.normalize();
+ physx::PxVec3 p12 = p1 + p2; p12.normalize();
+ physx::PxVec3 p20 = p2 + p0; p20.normalize();
+
+ subdivideOnSphere(subdivision-1, p0, p01, p20, radius, height, skew);
+ subdivideOnSphere(subdivision-1, p1, p12, p01, radius, height, skew);
+ subdivideOnSphere(subdivision-1, p2, p20, p12, radius, height, skew);
+ subdivideOnSphere(subdivision-1, p01, p12, p20, radius, height, skew);
+ }
+ }
+
+
+
+ PX_INLINE void debugCapsule(const DebugCapsule &d)
+ {
+ DebugCylinder c(d.mRadius,d.mHeight,d.mSubdivision,false);
+ debugCylinder(c);
+
+ const float height = d.mHeight * 0.5f;
+ for (uint32_t i = 0; i < 8; i++)
+ {
+ const physx::PxVec3 p0 = simpleSpherePosition[simpleSphereIndices[i*3+0]];
+ const physx::PxVec3 p1 = simpleSpherePosition[simpleSphereIndices[i*3+1]];
+ const physx::PxVec3 p2 = simpleSpherePosition[simpleSphereIndices[i*3+2]];
+ subdivideOnSphere(int(d.mSubdivision), p0, p1, p2, d.mRadius, height, 0.0f);
+ }
+ }
+
+ void debugCone(const DebugCone &d)
+ {
+ physx::PxVec3 prev;
+ physx::PxVec3 orig(0,0,0); // = xform.getPosition();
+
+ physx::PxVec3 center(0,d.mLength,0);
+
+ float s1 = tanf(d.mInnerAngle)*d.mLength;
+ float s2 = tanf(d.mOuterAngle)*d.mLength;
+
+ float stepSize = 360.0f / static_cast<float>(d.mSubdivision);
+
+ for (uint32_t i=0; i<=d.mSubdivision; i++)
+ {
+ float fv = static_cast<float>(i)*stepSize;
+ if ( i == d.mSubdivision )
+ {
+ fv = 0;
+ }
+ float r = fv*FM_DEG_TO_RAD;
+
+ float dx = s2*cosf(r);
+ float dy = s1*sinf(r);
+
+ physx::PxVec3 v(dx,d.mLength,dy);
+ if ( i != 0 )
+ {
+ debugTri(&orig,&prev,&v);
+ if ( d.mCloseEnd )
+ {
+ debugTri(&center,&v,&prev);
+ }
+ else
+ {
+ debugTri(&orig,&v,&prev);
+ }
+ }
+ prev = v;
+ }
+
+ }
+
+ void debugTaperedCapsule(const DebugTaperedCapsule& d)
+ {
+ physx::PxMat44* oldPose = mCurrentState.mPose;
+ physx::PxMat44 newPose = physx::PxMat44(physx::PxIdentity);
+
+ uint32_t subdivision = d.mSubdivision;
+
+ float radDiff = d.mRadius2 - d.mRadius1;
+ const float sinAlpha = radDiff / physx::PxSqrt(radDiff * radDiff + d.mHeight * d.mHeight);
+
+ float sphereSeparation = 0;
+ float skew = 0;
+ float radius[] = { d.mRadius1, d.mRadius2 };
+
+ const uint32_t oldColor = mCurrentState.mColor;
+
+ if (physx::PxAbs(sinAlpha) < 1.0f)
+ {
+ const float cosAlpha = physx::PxSqrt(1.0f - sinAlpha * sinAlpha);
+
+ const uint32_t minSubdivision = uint32_t(sinAlpha * sinAlpha * 4.0f) + 1;
+ const uint32_t maxSubdivision = 6;
+ subdivision = physx::PxMin(physx::PxMax(minSubdivision, d.mSubdivision), maxSubdivision);
+
+ const float heightOffset = sinAlpha * (d.mRadius1 + d.mRadius2) / 2.0f;
+ newPose.setPosition(newPose.getPosition() + physx::PxVec3(0.0f, heightOffset, 0.0f));
+ if (oldPose != NULL)
+ {
+ newPose = *oldPose * newPose;
+ }
+
+ // move the cylinder
+ mCurrentState.mPose = &newPose;
+
+ // shrink the cylinder
+ const float height = d.mHeight - physx::PxAbs(sinAlpha * (d.mRadius1 - d.mRadius2));
+
+ DebugCylinder c(d.mRadius1 * cosAlpha, d.mRadius2 * cosAlpha, height, subdivision, false);
+ debugCylinder(c);
+
+ // reset current pose
+ mCurrentState.mPose = oldPose;
+
+ sphereSeparation = d.mHeight * 0.5f;
+ skew = sinAlpha;
+ }
+ else
+ {
+ mCurrentState.mColor = 0x7f7fff; // light blue
+ radius[0] = radius[1] = physx::PxMax(d.mRadius1, d.mRadius2);
+ }
+
+
+ for (uint32_t i = 0; i < 8; i++)
+ {
+ physx::PxVec3 p[] =
+ {
+ simpleSpherePosition[simpleSphereIndices[i*3+0]],
+ simpleSpherePosition[simpleSphereIndices[i*3+1]],
+ simpleSpherePosition[simpleSphereIndices[i*3+2]]
+ };
+
+ subdivideOnSphere(int(subdivision), p[0], p[1], p[2], radius[i >> 2], sphereSeparation, skew);
+ }
+
+ mCurrentState.mColor = oldColor;
+ }
+
+ void quickSphere(const physx::PxVec3 &p,float radius,uint32_t color)
+ {
+ mCurrentState.mColor = color;
+ mCurrentState.mArrowColor = color;
+ mCurrentState.mStates = (mCurrentState.mStates & ~RENDER_DEBUG::DebugRenderState::SolidWireShaded) | RENDER_DEBUG::DebugRenderState::SolidShaded;
+ DebugDetailedSphere ds(p,radius,2);
+ debugDetailedSphere(ds);
+ mCurrentState.mStates = (mCurrentState.mStates & ~RENDER_DEBUG::DebugRenderState::SolidShaded) | RENDER_DEBUG::DebugRenderState::SolidWireShaded;
+ }
+
+ PX_INLINE void debugAxes(const DebugAxes &d)
+ {
+ physx::PxMat44 pose = d.mTransform;
+ float brightness = 1.0f - d.mBrightness;
+
+ uint32_t red = getColor(255, 0, 0, brightness);
+ uint32_t green = getColor( 0,255, 0, brightness);
+ uint32_t blue = getColor( 0, 0,255, brightness);
+ uint32_t yellow = getColor(255,255, 0, brightness);
+ uint32_t white = getColor(255, 255, 255, brightness);
+
+ uint32_t colorX = red, colorY = green, colorZ = blue;
+ if (d.mAxisSwitch & 4) //x
+ {
+ colorX = yellow;
+ }
+ if (d.mAxisSwitch & 2) //y
+ {
+ colorY = yellow;
+ }
+ if (d.mAxisSwitch & 1) //z
+ {
+ colorZ = yellow;
+ }
+
+ physx::PxVec3 px(d.mDistance,0,0);
+ physx::PxVec3 py(0,d.mDistance,0);
+ physx::PxVec3 pz(0,0,d.mDistance);
+
+ px = d.mTransform.transform(px);
+ py = d.mTransform.transform(py);
+ pz = d.mTransform.transform(pz);
+
+ physx::PxVec3 t = d.mTransform.getPosition();
+
+ RenderState save = mCurrentState;
+
+ mCurrentState.mArrowSize = d.mDistance*0.1f;
+ switch (d.mRenderMode)
+ {
+ case DebugAxesRenderMode::DEBUG_AXES_RENDER_SOLID:
+ {
+ quickSphere(t,d.mDistance*0.1f,yellow);
+ }
+ break;
+ case DebugAxesRenderMode::DEBUG_AXES_RENDER_LINES:
+ {
+ ;
+ }
+ break;
+ }
+ mCurrentState.mStates|=RENDER_DEBUG::DebugRenderState::CameraFacing;
+ mCurrentState.mStates|=RENDER_DEBUG::DebugRenderState::CenterText;
+ mCurrentState.mOutlineColor = white;
+
+ float axisSwitchScaleStart = 1.0f;
+ float axisSwitchScaleEnd = 1.0f;
+ switch (d.mRenderMode)
+ {
+ case DebugAxesRenderMode::DEBUG_AXES_RENDER_SOLID:
+ {
+ axisSwitchScaleStart = 1.0f;
+ axisSwitchScaleEnd = 4.0f;
+ }
+ break;
+ case DebugAxesRenderMode::DEBUG_AXES_RENDER_LINES:
+ {
+ axisSwitchScaleStart = 0.0f;
+ axisSwitchScaleEnd = 1.0f;
+ }
+ break;
+ }
+
+ if (d.mRenderMode == DebugAxesRenderMode::DEBUG_AXES_RENDER_LINES)
+ {
+ float triSizeFactor = 0.2f;
+ float circleSizeFactor = 0.1f;
+
+ physx::PxMat44 inverseViewMatrix = mViewMatrix.inverseRT();
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::DoubleSided);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+
+ DebugCircle circleCfg(0.0f, 10, true);
+ circleCfg.mTransform.column0 = inverseViewMatrix.column1;
+ circleCfg.mTransform.column1 = inverseViewMatrix.column2;
+ circleCfg.mTransform.column2 = inverseViewMatrix.column0;
+
+ physx::PxVec3 triNormal = physx::PxVec3(0,0,1);
+ {
+ mCurrentState.mColor = colorX;
+ mCurrentState.mArrowColor = colorX;
+ if (!d.mShowRotation)
+ {
+ physx::PxVec3 usedOrthoAxe = inverseViewMatrix.column2.getXYZ().cross(t - px);
+ usedOrthoAxe.normalize();
+ usedOrthoAxe *= d.mDistance;
+ physx::PxVec3 arrowVertices[] = {
+ px + (t - px) * triSizeFactor + usedOrthoAxe * triSizeFactor,
+ px,
+ px + (t - px) * triSizeFactor - usedOrthoAxe * triSizeFactor,
+ };
+ debugTri(arrowVertices+0, arrowVertices+1, arrowVertices+2, &triNormal, &triNormal, &triNormal, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, false);
+ debugLine(t, px + (t - px) * triSizeFactor);
+ }
+ else if (d.mShowRotation)
+ {
+ circleCfg.mRadius = ((t - px) * circleSizeFactor).magnitude();
+ circleCfg.mTransform.setPosition(px + (t - px) * circleSizeFactor);
+ debugCircle(circleCfg);
+ debugLine(t, px + (t - px) * circleSizeFactor);
+ }
+ if ( d.mShowXYZ )
+ {
+ mCurrentState.mTextScale = d.mDistance;
+ mCurrentState.mColor = white;
+ DebugText dt(px,physx::PxMat44(physx::PxIdentity),"X");
+ debugText(dt);
+ }
+ }
+
+ {
+ mCurrentState.mColor = colorY;
+ mCurrentState.mArrowColor = colorY;
+ if (!d.mShowRotation)
+ {
+ physx::PxVec3 usedOrthoAxe = inverseViewMatrix.column2.getXYZ().cross(t - py);
+ usedOrthoAxe.normalize();
+ usedOrthoAxe *= d.mDistance;
+ physx::PxVec3 arrowVertices[] = {
+ py + (t - py) * triSizeFactor + usedOrthoAxe * triSizeFactor,
+ py,
+ py + (t - py) * triSizeFactor - usedOrthoAxe * triSizeFactor,
+ };
+ debugTri(arrowVertices+0, arrowVertices+1, arrowVertices+2, &triNormal, &triNormal, &triNormal, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, false);
+ debugLine(t, py + (t - py) * triSizeFactor);
+ }
+ else if (d.mShowRotation)
+ {
+ circleCfg.mRadius = ((t - py) * circleSizeFactor).magnitude();
+ circleCfg.mTransform.setPosition(py + (t - py) * circleSizeFactor);
+ debugCircle(circleCfg);
+ debugLine(t, py + (t - py) * circleSizeFactor);
+ }
+ if ( d.mShowXYZ )
+ {
+ mCurrentState.mTextScale = d.mDistance;
+ mCurrentState.mColor = white;
+ DebugText dt(py,physx::PxMat44(physx::PxIdentity),"Y");
+ debugText(dt);
+ }
+ }
+
+ {
+ mCurrentState.mColor = colorZ;
+ mCurrentState.mArrowColor = colorZ;
+ if (!d.mShowRotation)
+ {
+ physx::PxVec3 usedOrthoAxe = inverseViewMatrix.column2.getXYZ().cross(t - pz);
+ usedOrthoAxe.normalize();
+ usedOrthoAxe *= d.mDistance;
+
+ physx::PxVec3 arrowVertices[] = {
+ pz + (t - pz) * triSizeFactor + usedOrthoAxe * triSizeFactor,
+ pz,
+ pz + (t - pz) * triSizeFactor - usedOrthoAxe * triSizeFactor,
+ };
+ debugTri(arrowVertices+0, arrowVertices+1, arrowVertices+2, &triNormal, &triNormal, &triNormal, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, false);
+ debugLine(t, pz + (t - pz) * triSizeFactor);
+ }
+ else if (d.mShowRotation)
+ {
+ circleCfg.mRadius = ((t - pz) * circleSizeFactor).magnitude();
+ circleCfg.mTransform.setPosition(pz + (t - pz) * circleSizeFactor);
+ debugCircle(circleCfg);
+ debugLine(t, pz + (t - pz) * circleSizeFactor);
+ }
+ if ( d.mShowXYZ )
+ {
+ mCurrentState.mTextScale = d.mDistance;
+ mCurrentState.mColor = white;
+ DebugText dt(pz,physx::PxMat44(physx::PxIdentity),"Z");
+ debugText(dt);
+ }
+ }
+ }
+ else if (d.mRenderMode == DebugAxesRenderMode::DEBUG_AXES_RENDER_SOLID)
+ {
+ {
+ mCurrentState.mColor = colorX;
+ mCurrentState.mArrowColor = colorX;
+
+ DebugThickRay dr(t, px, d.mDistance * 0.02f, !d.mShowRotation);
+ debugThickRay(dr);
+
+ if ( d.mShowXYZ )
+ {
+ mCurrentState.mTextScale = d.mDistance;
+ mCurrentState.mColor = white;
+ DebugText dt(px,physx::PxMat44(physx::PxIdentity),"X");
+ debugText(dt);
+ }
+ }
+
+ {
+ mCurrentState.mColor = colorY;
+ mCurrentState.mArrowColor = colorY;
+ DebugThickRay dr(t, py, d.mDistance*0.02f, !d.mShowRotation);
+ debugThickRay(dr);
+ if ( d.mShowXYZ )
+ {
+ mCurrentState.mTextScale = d.mDistance;
+ mCurrentState.mColor = white;
+ DebugText dt(py,physx::PxMat44(physx::PxIdentity),"Y");
+ debugText(dt);
+ }
+ }
+ {
+ mCurrentState.mColor = colorZ;
+ mCurrentState.mArrowColor = colorZ;
+ DebugThickRay dr(t, pz, d.mDistance * 0.02f, !d.mShowRotation);
+ debugThickRay(dr);
+ if ( d.mShowXYZ )
+ {
+ mCurrentState.mTextScale = d.mDistance;
+ mCurrentState.mColor = white;
+ DebugText dt(pz,physx::PxMat44(physx::PxIdentity),"Z");
+ debugText(dt);
+ }
+ }
+ }
+
+ if ( d.mAxisSwitch )
+ {
+ physx::PxVec3 p1, p2;
+ uint32_t brightYellow = getColor(255, 255, 0, 0.0f);
+ mCurrentState.mColor = brightYellow;
+
+ if (d.mAxisSwitch & 4) //x
+ {
+ p1 = physx::PxVec3(-1.0f * axisSwitchScaleStart, 0.0f, 0.0f);
+ p2 = physx::PxVec3(1.0f * axisSwitchScaleEnd, 0.0f, 0.0f);
+ p1 = pose.transform(p1);
+ p2 = pose.transform(p2);
+
+ debugLine(p1, p2);
+ }
+ if(d.mAxisSwitch & 2) //y
+ {
+ p1 = physx::PxVec3(0.0f, -1.0f * axisSwitchScaleStart, 0.0f);
+ p2 = physx::PxVec3(0.0f, 1.0f * axisSwitchScaleEnd, 0.0f);
+ p1 = pose.transform(p1);
+ p2 = pose.transform(p2);
+
+ debugLine(p1, p2);
+ }
+ if(d.mAxisSwitch & 1) //z
+ {
+ p1 = physx::PxVec3(0.0f, 0.0f, -1.0f * axisSwitchScaleStart);
+ p2 = physx::PxVec3(0.0f, 0.0f, 1.0f * axisSwitchScaleEnd);
+ p1 = pose.transform(p1);
+ p2 = pose.transform(p2);
+
+ debugLine(p1, p2);
+ }
+ }
+
+ mCurrentState = save;
+ }
+
+ PX_INLINE void debugArc(const DebugArc &d)
+ {
+ if ( d.mShowRoot )
+ {
+ debugLine(d.mCenter,d.mP1,0xFFFFFFFF,0xFFFFFFFF);
+ debugLine(d.mCenter,d.mP2,0xFFFFFFFF,0xFFFFFFFF);
+ }
+
+ physx::PxVec3 v1 = d.mP1-d.mCenter;
+ float d1 = v1.normalize();
+ physx::PxVec3 v2 = d.mP2-d.mCenter;
+ float d2 = v2.normalize();
+
+ physx::PxQuat quat;
+ rotationArc(v1,v2,quat);
+
+ physx::PxQuat q1 = physx::PxQuat(physx::PxIdentity);
+ physx::PxQuat q2 = quat;
+
+ physx::PxVec3 prev(0.0f);
+
+ int32_t count = 0;
+ for (float st=0; st<=(1.01f); st+=0.05f)
+ {
+ float dst = ((d2-d1)*st)+d1;
+ physx::PxQuat q;
+ q = slerp(st,q1,q2);
+ physx::PxMat44 m(q);
+ m.setPosition(d.mCenter);
+ physx::PxVec3 t = v1*dst;
+ t = m.transform(t);
+ if ( st != 0 )
+ {
+ if ( count == 20 )
+ {
+ DebugRay dr(prev,t);
+ debugRay(dr);
+ }
+ else
+ debugLine(prev,t);
+ }
+ prev = t;
+ count++;
+ }
+
+ }
+
+ PX_INLINE void debugThickArc(const DebugThickArc &d)
+ {
+ if ( d.mShowRoot )
+ {
+ debugLine(d.mCenter,d.mP1,0xFFFFFFFF,0xFFFFFFFF);
+ debugLine(d.mCenter,d.mP2,0xFFFFFFFF,0xFFFFFFFF);
+ }
+
+ physx::PxVec3 v1 = d.mP1-d.mCenter;
+ float d1 = v1.normalize();
+ physx::PxVec3 v2 = d.mP2-d.mCenter;
+ float d2 = v2.normalize();
+
+ physx::PxQuat quat;
+ rotationArc(v1,v2,quat);
+
+ physx::PxQuat q1 = physx::PxQuat(physx::PxIdentity);
+ physx::PxQuat q2 = quat;
+
+ physx::PxVec3 prev(0.0f);
+
+ int32_t count = 0;
+
+ for (float st=0; st<=(1.01f); st+=0.05f)
+ {
+ float dst = ((d2-d1)*st)+d1;
+ physx::PxQuat q;
+ q = slerp(st,q1,q2);
+ physx::PxMat44 m(q);
+ m.setPosition(d.mCenter);
+ physx::PxVec3 t = v1*dst;
+ t = m.transform(t);
+ if ( st != 0 )
+ {
+#if 0
+ if ( count == 20 )
+ {
+ float asave = mCurrentState.mArrowSize;
+ mCurrentState.mArrowSize = d.mThickness*4;
+ DebugThickRay dr(prev,t,d.mThickness);
+ debugThickRay(dr);
+ mCurrentState.mArrowSize = asave;
+ }
+ else
+#endif
+ {
+ uint32_t save = mCurrentState.mStates;
+
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+
+ DebugPointCylinder dc(prev,t,d.mThickness);
+ debugPointCylinder(dc);
+
+ mCurrentState.mStates = save;
+ }
+ }
+ prev = t;
+ count++;
+ }
+ }
+
+ void debugFrustumPlane(const physx::PxVec4 &_p1,const physx::PxVec4 &_p2,const physx::PxVec4 &_p3,const physx::PxVec4 &_p4,uint32_t color)
+ {
+ physx::PxVec3 p1(_p1.x,_p1.y,_p1.z);
+ physx::PxVec3 p2(_p2.x,_p2.y,_p2.z);
+ physx::PxVec3 p3(_p3.x,_p3.y,_p3.z);
+ physx::PxVec3 p4(_p4.x,_p4.y,_p4.z);
+
+ uint32_t save = mCurrentState.mStates;
+ uint32_t saveColor = mCurrentState.mColor;
+ mCurrentState.mColor = color;
+
+// mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded);
+// mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+
+ DebugTri t1(p1,p2,p3);
+ DebugTri t2(p1,p3,p4);
+
+ debugTri(&p1,&p2,&p3);
+ debugTri(&p1,&p3,&p4);
+
+ debugTri(&p3,&p2,&p1);
+ debugTri(&p4,&p3,&p1);
+
+ debugLine(p1,p2,0xFFFFFF,0xFFFFFF);
+ debugLine(p2,p3,0xFFFFFF,0xFFFFFF);
+ debugLine(p3,p4,0xFFFFFF,0xFFFFFF);
+ debugLine(p4,p1,0xFFFFFF,0xFFFFFF);
+
+ mCurrentState.mStates = save;
+ mCurrentState.mColor = saveColor;
+
+ }
+
+ PX_INLINE void debugFrustum(const physx::PxMat44 &iview,const physx::PxMat44 &proj)
+ {
+ // actually debug it here!
+ physx::PxMat44 viewProj = proj*iview;
+ physx::PxMat44 iviewProj = invert(viewProj);
+
+ physx::PxMat44 view = invert(iview);
+ DebugAxes d(view,0.3f,1.0f,false,false,4, DebugAxesRenderMode::DEBUG_AXES_RENDER_SOLID);
+ debugAxes(d); // debug visualize the view matrix
+
+ physx::PxVec4 v[8];
+
+
+ v[0] = physx::PxVec4(-1.0f,-1.0f,0,1.0f);
+ v[1] = physx::PxVec4(1.0f,-1.0f,0,1.0f);
+ v[2] = physx::PxVec4(1.0f,1.0f,0,1.0f);
+ v[3] = physx::PxVec4(-1.0f,1.0f,0,1.0f);
+
+ v[4] = physx::PxVec4(-1.0f,-1.0f,0.99999f,1.0f);
+ v[5] = physx::PxVec4(1.0f,-1.0f,0.99999f,1.0f);
+ v[6] = physx::PxVec4(1.0f,1.0f,0.99999f,1.0f);
+ v[7] = physx::PxVec4(-1.0f,1.0f,0.99999f,1.0f);
+
+
+
+ for (uint32_t i=0; i<8; i++)
+ {
+ v[i] = iviewProj.transform(v[i]);
+ v[i]*=1.0f/v[i].w; // unproject the point.
+ }
+
+ debugFrustumPlane(v[0],v[1],v[2],v[3],0xFF0000);
+ debugFrustumPlane(v[4],v[5],v[6],v[7],0xFF0000);
+
+ debugFrustumPlane(v[0],v[3],v[7],v[4],0x00FF00);
+ debugFrustumPlane(v[1],v[2],v[6],v[5],0x00FF00);
+
+ debugFrustumPlane(v[1],v[0],v[4],v[5],0x0000FF);
+ debugFrustumPlane(v[2],v[3],v[7],v[6],0x0000FF);
+
+
+ }
+
+ PX_INLINE void debugDetailedSphere(const DebugDetailedSphere &d)
+ {
+ physx::PxMat44* save = mCurrentState.mPose;
+ //physx::PxVec3 origTranslation = save != NULL ? save->getPosition() : physx::PxVec3(0.0f);
+ physx::PxMat44 myPose = physx::PxMat44(physx::PxIdentity);
+ myPose.setPosition(d.mPos);
+ if (save != NULL)
+ {
+ myPose = *save * myPose;
+ }
+ mCurrentState.mPose = &myPose;
+
+ DebugSphere d2(d.mRadius, d.mStepCount);
+ debugSphere(d2);
+
+ mCurrentState.mPose = save;
+ }
+
+ void skipString(physx::PsMemoryBuffer &mb)
+ {
+ char c;
+ uint32_t r = mb.read(&c,1);
+ while ( r && c )
+ {
+ r = mb.read(&c,1);
+ }
+ }
+
+ void debugCreateTriangleMesh(const DebugCreateTriangleMesh &dgs,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_CREATE_TRIANGLE_MESH);
+ PX_ASSERT(size==dgs.mSize);
+ uint32_t vcount=0;
+ uint32_t tcount=0;
+ uint32_t meshId=0;
+ stream >> meshId;
+ stream >> vcount;
+ stream >> tcount;
+ const uint8_t *scan = mb.getReadLoc();
+ const RENDER_DEBUG::RenderDebugMeshVertex *vertices = reinterpret_cast<const RENDER_DEBUG::RenderDebugMeshVertex *>(scan);
+ const uint32_t *indices = NULL;
+ if ( tcount )
+ {
+ scan+=(vcount*sizeof(RENDER_DEBUG::RenderDebugMeshVertex));
+ indices = reinterpret_cast<const uint32_t *>(scan);
+ }
+ if ( iface )
+ {
+ iface->createTriangleMesh(meshId,vcount,vertices,tcount,indices);
+ }
+ }
+
+ void debugRefreshTriangleMeshVertices(const DebugRefreshTriangleMeshVertices &dgs,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_REFRESH_TRIANGLE_MESH_VERTICES);
+ PX_ASSERT(size==dgs.mSize);
+ uint32_t vcount=0;
+ uint32_t meshId=0;
+ stream >> meshId;
+ stream >> vcount;
+ const uint8_t *scan = mb.getReadLoc();
+ const RENDER_DEBUG::RenderDebugMeshVertex *vertices = reinterpret_cast<const RENDER_DEBUG::RenderDebugMeshVertex *>(scan);
+ const uint32_t *indices = NULL;
+ scan+=(vcount*sizeof(RENDER_DEBUG::RenderDebugMeshVertex));
+ indices = reinterpret_cast<const uint32_t *>(scan);
+ if ( iface )
+ {
+ iface->refreshTriangleMeshVertices(meshId,vcount,vertices,indices);
+ }
+ }
+
+
+ void debugRenderTriangleMeshInstances(const DebugRenderTriangleMeshInstances &dgs,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_RENDER_TRIANGLE_MESH_INSTANCES);
+ PX_ASSERT(size==dgs.mSize);
+ uint32_t instanceCount=0;
+ uint32_t meshId=0;
+ stream >> meshId;
+ stream >> instanceCount;
+ if ( instanceCount && iface )
+ {
+ const uint8_t *scan = mb.getReadLoc();
+ const RENDER_DEBUG::RenderDebugInstance *instances = reinterpret_cast<const RENDER_DEBUG::RenderDebugInstance *>(scan);
+ iface->renderTriangleMeshInstances(meshId,mCurrentState.mTexture1,mCurrentState.mTileRate1,mCurrentState.mTexture2,mCurrentState.mTileRate2,instanceCount,instances);
+ }
+ }
+
+ void debugConvexHull(const DebugConvexHull &dgs)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_CONVEX_HULL);
+ PX_ASSERT(size==dgs.mSize);
+ uint32_t planeCount=0;
+ stream >> planeCount;
+ if ( planeCount )
+ {
+ const uint8_t *scan = mb.getReadLoc();
+ const float *planes = reinterpret_cast<const float *>(scan);
+
+ Hull2MeshEdges *h = createHull2MeshEdges();
+ if ( !mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded))
+ {
+ uint32_t edgeCount;
+ const HullEdge *edges = h->getHullEdges(planeCount, reinterpret_cast<const physx::PxPlane *>(planes), edgeCount);
+ if ( edges )
+ {
+ uint32_t saveColor = mCurrentState.mColor;
+ mCurrentState.mColor = mCurrentState.mArrowColor;
+ for (uint32_t i=0; i<edgeCount; i++)
+ {
+ const HullEdge &e = edges[i];
+ debugLine(e.e0,e.e1);
+ }
+ mCurrentState.mColor = saveColor;
+ }
+ }
+ if ( mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded) || mCurrentState.hasRenderState(RENDER_DEBUG::DebugRenderState::SolidWireShaded) )
+ {
+ HullMesh m;
+ if ( h->getHullMesh(planeCount, reinterpret_cast<const physx::PxPlane *>(planes), m) )
+ {
+ uint32_t saveState = mCurrentState.mStates;
+ mCurrentState.mStates&=~RENDER_DEBUG::DebugRenderState::SolidWireShaded;
+ mCurrentState.mStates|=RENDER_DEBUG::DebugRenderState::SolidShaded;
+ for (uint32_t i=0; i<m.mTriCount; i++)
+ {
+ uint16_t i1 = m.mIndices[i*3+0];
+ uint16_t i2 = m.mIndices[i*3+1];
+ uint16_t i3 = m.mIndices[i*3+2];
+ const physx::PxVec3 &p1 = m.mVertices[i1];
+ const physx::PxVec3 &p2 = m.mVertices[i2];
+ const physx::PxVec3 &p3 = m.mVertices[i3];
+ debugTri(&p1,&p2,&p3);
+ }
+ mCurrentState.mStates = saveState;
+ }
+ }
+ h->release();
+ }
+
+ }
+
+ void debugRenderPoints(const DebugRenderPoints &dgs,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_RENDER_POINTS);
+ PX_ASSERT(size==dgs.mSize);
+ uint32_t pointCount=0;
+ uint32_t meshId=0;
+ uint32_t mode=0;
+ uint32_t textureId1;
+ float textureTile1;
+ uint32_t textureId2;
+ float textureTile2;
+ stream >> meshId;
+ stream >> mode;
+ stream >> textureId1;
+ stream >> textureTile1;
+ stream >> textureId2;
+ stream >> textureTile2;
+ stream >> pointCount;
+ if ( pointCount && iface )
+ {
+ const uint8_t *scan = mb.getReadLoc();
+ const float *points = reinterpret_cast<const float *>(scan);
+ iface->debugPoints(static_cast<RENDER_DEBUG::PointRenderMode>(mode),meshId,mCurrentState.mArrowColor,mCurrentState.mArrowSize,textureId1,textureTile1,textureId2,textureTile2,pointCount,points);
+ }
+ }
+
+ void debugRenderTriangles(const DebugRenderTriangles &dgs,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_RENDER_TRIANGLES);
+ PX_ASSERT(size==dgs.mSize);
+ uint32_t tcount;
+ uint32_t useZ;
+ uint32_t isScreenSpace;
+ stream >> tcount;
+ stream >> useZ;
+ stream >> isScreenSpace;
+ if ( tcount && iface )
+ {
+ const uint8_t *scan = mb.getReadLoc();
+ const RenderDebugSolidVertex *points = reinterpret_cast<const RenderDebugSolidVertex *>(scan);
+ iface->debugRenderTriangles(tcount,points,useZ ? true : false,isScreenSpace ? true : false);
+ }
+ }
+
+ void debugRenderLines(const DebugRenderLines &dgs,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_RENDER_LINES);
+ PX_ASSERT(size==dgs.mSize);
+ uint32_t lcount;
+ uint32_t useZ;
+ uint32_t isScreenSpace;
+ stream >> lcount;
+ stream >> useZ;
+ stream >> isScreenSpace;
+ if ( lcount && iface )
+ {
+ const uint8_t *scan = mb.getReadLoc();
+ const RenderDebugVertex *lines = reinterpret_cast<const RenderDebugVertex *>(scan);
+ iface->debugRenderLines(lcount,lines,useZ ? true : false, isScreenSpace ? true : false );
+ }
+ }
+
+
+
+ void debugGraph(const DebugGraphStream &dgs)
+ {
+ const void *data = static_cast<const void *>(&dgs);
+ physx::PsMemoryBuffer mb(data,dgs.mSize);
+ mb.setEndianMode(physx::PxFileBuf::ENDIAN_NONE);
+ nvidia::StreamIO stream(mb,dgs.mSize);
+ uint32_t cmd,size;
+ stream >> cmd;
+ stream >> size;
+ PX_ASSERT(cmd==DebugCommand::DEBUG_GRAPH);
+ PX_ASSERT(size==dgs.mSize);
+
+ DebugGraphDesc d;
+
+ stream >> d.mNumPoints;
+ d.mGraphXLabel = reinterpret_cast<const char *>(mb.getReadLoc());
+ skipString(mb);
+ d.mGraphYLabel = reinterpret_cast<const char *>(mb.getReadLoc());
+ skipString(mb);
+
+ mb.alignRead(4);
+
+ d.mPoints = reinterpret_cast<const float *>(mb.getReadLoc());
+ mb.advanceReadLoc(sizeof(uint32_t)*d.mNumPoints);
+ stream >> d.mCutOffLevel;
+ stream >> d.mGraphMax;
+ stream >> d.mGraphXPos;
+ stream >> d.mGraphYPos;
+ stream >> d.mGraphWidth;
+ stream >> d.mGraphHeight;
+ stream >> d.mGraphColor;
+ stream >> d.mArrowColor;
+ stream >> d.mColorSwitchIndex;
+ debugGraph(d);
+ }
+
+ void debugGraph(const DebugGraphDesc& graphDesc)
+ {
+ // todo where should colors go???
+ const uint32_t black = getColor(0, 0, 0);
+ const uint32_t blue = getColor(0, 0, 255);
+ const uint32_t green = getColor(0, 255, 0);
+
+ RenderState saveState = mCurrentState;
+
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::ScreenSpace);
+ mCurrentState.setRenderState(RENDER_DEBUG::DebugRenderState::NoZbuffer);
+ mCurrentState.clearRenderState(RENDER_DEBUG::DebugRenderState::SolidShaded);
+
+ mCurrentState.mTextScale = 0.1f;
+ float textHeight = 0.04f; //in screen space -- would be nice to know this!
+
+ if(graphDesc.mCutOffLevel != 0.0f)
+ {
+ mCurrentState.setCurrentColor(blue, black);
+ debugLine(
+ physx::PxVec3(graphDesc.mGraphXPos, graphDesc.mGraphYPos + graphDesc.mCutOffLevel, 0.0f),
+ physx::PxVec3(graphDesc.mGraphXPos + graphDesc.mGraphWidth, graphDesc.mGraphYPos + graphDesc.mCutOffLevel, 0.0f));
+ }
+
+ mCurrentState.setCurrentColor(graphDesc.mGraphColor, graphDesc.mArrowColor); //set the draw colors
+ if( strlen(graphDesc.mGraphXLabel) > 0 )
+ {
+ DebugText txt( physx::PxVec3(graphDesc.mGraphXPos, graphDesc.mGraphYPos - textHeight,0),physx::PxMat44(physx::PxIdentity),graphDesc.mGraphXLabel);
+ debugText(txt);
+ }
+ if( graphDesc.mGraphYLabel[0] )
+ {
+ DebugText txt(physx::PxVec3(graphDesc.mGraphXPos, graphDesc.mGraphYPos + graphDesc.mGraphHeight, 0), physx::PxMat44(physx::PxIdentity), graphDesc.mGraphYLabel);
+ debugText(txt);
+ }
+
+ float lastX = graphDesc.mGraphXPos;
+ float lastY = graphDesc.mGraphYPos;
+ for (uint32_t i = 0; i < graphDesc.mNumPoints; i++)
+ {
+ float pointY = graphDesc.mPoints[i];
+ pointY = graphDesc.mGraphYPos + pointY * graphDesc.mGraphHeight / graphDesc.mGraphMax; //scale to screen
+ float x = graphDesc.mGraphXPos + graphDesc.mGraphWidth * i / graphDesc.mNumPoints;
+
+ if (graphDesc.mColorSwitchIndex == i)
+ mCurrentState.setCurrentColor( graphDesc.mArrowColor,
+ graphDesc.mGraphColor); //swap the colors
+
+ debugLine(physx::PxVec3(lastX,lastY,0), physx::PxVec3(x,pointY,0));
+ lastY = pointY;
+ lastX = x;
+ }
+
+ //graph axes
+ mCurrentState.setCurrentColor(green, green);
+ //screen space test line
+ debugLine( physx::PxVec3(graphDesc.mGraphXPos, graphDesc.mGraphYPos,0),
+ physx::PxVec3(graphDesc.mGraphXPos, graphDesc.mGraphYPos + graphDesc.mGraphHeight,0));
+ debugLine( physx::PxVec3(graphDesc.mGraphXPos, graphDesc.mGraphYPos,0),
+ physx::PxVec3(graphDesc.mGraphXPos + graphDesc.mGraphWidth, graphDesc.mGraphYPos,0));
+
+ mCurrentState = saveState;
+ }
+
+
+ virtual void setViewMatrix(const physx::PxMat44 &view)
+ {
+ mViewMatrix = view;
+ }
+
+ virtual void finalizeFrame(void)
+ {
+
+ }
+
+private:
+
+uint32_t mLineVertexCount;
+uint32_t mMaxLineVertexCount;
+RENDER_DEBUG::RenderDebugVertex *mLines;
+
+uint32_t mSolidVertexCount;
+uint32_t mMaxSolidVertexCount;
+RENDER_DEBUG::RenderDebugSolidVertex *mTriangles;
+
+RENDER_DEBUG::RenderDebugInterface *mInterface;
+DisplayType mDisplayType;
+RenderState mCurrentState;
+MyVectorFont mVectorFont;
+physx::PxMat44 mViewMatrix;
+
+};
+
+//
+
+ProcessRenderDebug * createProcessRenderDebug(void)
+{
+ ProcessRenderDebugImpl *m = PX_NEW(ProcessRenderDebugImpl);
+ return static_cast< ProcessRenderDebug *>(m);
+}
+
+
+} // end of namespace
diff --git a/APEX_1.4/shared/general/RenderDebug/src/PsCommLayer.cpp b/APEX_1.4/shared/general/RenderDebug/src/PsCommLayer.cpp
new file mode 100644
index 00000000..c82f17a7
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/PsCommLayer.cpp
@@ -0,0 +1,567 @@
+#include "PsCommLayer.h"
+
+#include "PsArray.h"
+#include "PsUserAllocated.h"
+#include "PsSocket.h"
+#include "PsThread.h"
+#include "PsAtomic.h"
+#include "PsMutex.h"
+#include "PxIntrinsics.h"
+
+namespace COMM_LAYER
+{
+
+// a simple hashing function
+static uint32_t simpleHash(const void *data,uint32_t dlen)
+{
+ uint32_t h = 5381;
+ const uint8_t *string = static_cast<const uint8_t *>(data);
+ for(const uint8_t *ptr = string; dlen; ptr++)
+ {
+ h = ((h<<5)+h)^(uint32_t(*ptr));
+ dlen--;
+ }
+ return h;
+}
+
+
+static PX_INLINE void swap4Bytes(void* _data)
+{
+ char *data = static_cast<char *>(_data);
+ char one_byte;
+ one_byte = data[0]; data[0] = data[3]; data[3] = one_byte;
+ one_byte = data[1]; data[1] = data[2]; data[2] = one_byte;
+}
+
+static PX_INLINE bool isBigEndian()
+{
+ int32_t i = 1;
+ return *(reinterpret_cast<char*>(&i))==0;
+}
+
+// This is a little helper class that contains the packets waiting to be sent.
+class CommPacket
+{
+public:
+ CommPacket(void)
+ {
+ if ( isBigEndian() )
+ {
+ mHeader[0] = 'B';
+ mBigEndianPacket = true;
+ }
+ else
+ {
+ mHeader[0] = 'C';
+ mBigEndianPacket = false;
+ }
+ mHeader[1] = 'P';
+ mHeader[2] = 'A';
+ mHeader[3] = 'C';
+ mHeader[4] = 'K';
+ mHeader[5] = 'E';
+ mHeader[6] = 'T';
+ mHeader[7] = 0;
+
+ mLength = 0;
+ mHash = 0;
+ mData = NULL;
+ }
+
+ void computeHash(void)
+ {
+ mHash = simpleHash(mHeader,sizeof(mHeader)+sizeof(mLength)); // compute the hash of the header + the hash of the length
+ }
+
+ bool isHeaderPacket(void)
+ {
+ bool ret = false;
+
+ if ( mHeader[0] == 'C' &&
+ mHeader[1] == 'P' &&
+ mHeader[2] == 'A' &&
+ mHeader[3] == 'C' &&
+ mHeader[4] == 'K' &&
+ mHeader[5] == 'E' &&
+ mHeader[6] == 'T' &&
+ mHeader[7] == 0 )
+ {
+ uint32_t hash = simpleHash(mHeader,sizeof(mHeader)+sizeof(mLength)); // compute the hash of the header + the hash of the length
+ uint32_t bhash = mHash;
+ if ( isBigEndian() )
+ {
+ swap4Bytes(&bhash);
+ }
+ if ( hash == bhash )
+ {
+ mBigEndianPacket = false;
+ ret = true;
+ }
+ }
+ else if ( mHeader[0] == 'B' &&
+ mHeader[1] == 'P' &&
+ mHeader[2] == 'A' &&
+ mHeader[3] == 'C' &&
+ mHeader[4] == 'K' &&
+ mHeader[5] == 'E' &&
+ mHeader[6] == 'T' &&
+ mHeader[7] == 0 )
+ {
+ uint32_t hash = simpleHash(mHeader,sizeof(mHeader)+sizeof(mLength)); // compute the hash of the header + the hash of the length
+ uint32_t bhash = mHash;
+ if ( !isBigEndian() )
+ {
+ swap4Bytes(&bhash);
+ }
+ if ( hash == bhash )
+ {
+ mBigEndianPacket = true;
+ ret = true;
+ }
+ }
+
+ return ret;
+ }
+
+ uint32_t getSize(void) const
+ {
+ return sizeof(mHeader)+sizeof(mLength)+sizeof(mHash);
+ }
+
+ uint32_t getLength(void) const
+ {
+ uint32_t l = mLength;
+ if ( isBigEndian() )
+ {
+ swap4Bytes(&l);
+ }
+ return l;
+ }
+
+ void setLength(uint32_t l)
+ {
+ mLength = l;
+ if ( isBigEndian() )
+ {
+ swap4Bytes(&mLength);
+ }
+ }
+
+ bool isBigEndianPacket(void) const
+ {
+ return mBigEndianPacket;
+ }
+
+private:
+ uint8_t mHeader[8];
+ uint32_t mLength;
+ uint32_t mHash;
+public:
+ uint8_t *mData;
+ bool mBigEndianPacket;
+};
+
+typedef physx::shdfnd::Array< CommPacket > CommPacketArray;
+
+class CommLayerImp : public CommLayer, public physx::shdfnd::Thread
+{
+ PX_NOCOPY(CommLayerImp)
+public:
+ CommLayerImp(const char *ipaddress,uint16_t portNumber,bool isServer) :
+ mReadPackets(PX_DEBUG_EXP("PsCommLayer::CommLayerImpl::mReadPackets"))
+ {
+ mListenPending = false;
+ mSendData = NULL;
+ mSendDataLength = 0;
+ mSendLoc = 0;
+ mTotalPendingSize = 0; // number of bytes of data pending to be sent
+ mTotalPendingCount = 0; // number of packets of data pending to be sent; count not size
+ mReadSize = 0;
+ mReadPacketHeaderLoc = 0;
+ mReadPacketLoc = 0;
+ mIsServer = isServer;
+ mPortNumber = portNumber;
+ mSocket = PX_NEW(physx::shdfnd::Socket)(false);
+ mClientConnected = false;
+ if ( isServer )
+ {
+ mConnected = mSocket->listen(portNumber);
+ mListenPending = true;
+ }
+ else
+ {
+ mConnected = mSocket->connect(ipaddress,portNumber);
+ }
+ if ( mConnected )
+ {
+ mSocket->setBlocking(false);
+ physx::shdfnd::Thread::start(0x4000);
+ }
+ }
+
+ virtual ~CommLayerImp(void)
+ {
+ physx::shdfnd::Thread::signalQuit();
+ physx::shdfnd::Thread::waitForQuit();
+ if ( mSocket )
+ {
+ mSocket->disconnect();
+ delete mSocket;
+ }
+ releaseAllReadData();
+ releaseAllSendData();
+ }
+
+ void releaseAllReadData(void)
+ {
+ PX_FREE(mReadPacketHeader.mData);
+ mReadPacketHeader.mData = NULL;
+ for (uint32_t i=0; i<mReadPackets.size(); i++)
+ {
+ PX_FREE(mReadPackets[i].mData);
+ }
+ mReadPackets.clear();
+ mReadSize = 0;
+ }
+
+ void releaseAllSendData(void)
+ {
+ // Free up memory allocated for pending sends not yet sent...
+ for (uint32_t i=0; i<mPendingSends.size(); i++)
+ {
+ CommPacket &sp = mPendingSends[i];
+ PX_FREE(sp.mData);
+ }
+ mPendingSends.clear();
+ PX_FREE(mSendData);
+ mSendData = NULL;
+ mTotalPendingCount = 0;
+ mTotalPendingSize = 0;
+ }
+
+ virtual bool sendMessage(const void *data,uint32_t len)
+ {
+ bool ret = false;
+ CommPacket sp;
+ sp.setLength(len);
+ sp.mData = static_cast<uint8_t *>(PX_ALLOC(len+sp.getSize(),"CommPacket"));
+ if ( sp.mData )
+ {
+ physx::intrinsics::memCopy(sp.mData+sp.getSize(),data,len);
+ mSendMutex.lock();
+ mPendingSends.pushBack(sp);
+ physx::shdfnd::atomicAdd(&mTotalPendingSize,int32_t(len));
+ physx::shdfnd::atomicAdd(&mTotalPendingCount,1);
+ mSendMutex.unlock();
+ ret = true;
+ }
+ return ret;
+ }
+
+ virtual uint32_t peekMessage(bool &isBigEndianPacket) // return the length of the next pending message
+ {
+ uint32_t ret = 0;
+
+ int32_t readSize = physx::shdfnd::atomicAdd(&mReadSize,0);
+ if ( readSize != 0 )
+ {
+ mReadPacketMutex.lock();
+ if ( !mReadPackets.empty() )
+ {
+ ret = mReadPackets[0].getLength();
+ isBigEndianPacket = mReadPackets[0].isBigEndianPacket();
+ }
+ mReadPacketMutex.unlock();
+ }
+
+ return ret;
+ }
+
+ virtual uint32_t getMessage(void *msg,uint32_t maxLength,bool &isBigEndianPacket) // receives a pending message
+ {
+ uint32_t ret = 0;
+
+ int32_t readSize = physx::shdfnd::atomicAdd(&mReadSize,0); // And data in the read queue?
+ if ( readSize != 0 ) // Yes..
+ {
+ mReadPacketMutex.lock(); // Lock the read packets mutex
+ CommPacket cp = mReadPackets[0]; // get the packet
+ if ( cp.getLength() <= maxLength ) // make sure it is shorter than the read buffer provided
+ {
+ physx::shdfnd::atomicAdd(&mReadSize,-int32_t(cp.getLength())); // subtract the read size semaphore to indicate the amount of data we snarfed from the read buffer.
+ mReadPackets.remove(0); // Remove the packet from the queue
+ mReadPacketMutex.unlock(); // Once we have pulled this off of the read queue it is save to release the mutex and add more.
+ physx::intrinsics::memCopy(msg,cp.mData,cp.getLength()); // Copy the packet to the callers buffer
+ ret = cp.getLength(); // set the return length
+ isBigEndianPacket = cp.isBigEndianPacket();
+ PX_FREE(cp.mData); // Free the read-data now that it has been copied into the users buffer.
+ }
+ else
+ {
+ mReadPacketMutex.unlock(); // Unlock the mutex
+ }
+ }
+ return ret;
+ }
+
+ virtual void release(void)
+ {
+ delete this;
+ }
+
+ bool isConnected(void) const
+ {
+ return mConnected;
+ }
+
+ virtual bool notifySocketConnection(physx::shdfnd::Socket *newConnection) // notify the caller that a new connection has been established.
+ {
+ PX_UNUSED(newConnection);
+ return true;
+ }
+
+ bool processSocketWrite(void)
+ {
+ while ( mSendData ) // if we are sending data..
+ {
+ uint32_t sendCount = mSendDataLength-mSendLoc;
+ if ( sendCount > 32768 )
+ {
+ sendCount = 32768;
+ }
+ const uint8_t *data = &mSendData[mSendLoc];
+ uint32_t sendAmount = mSocket->write(data,sendCount);
+ if ( sendAmount )
+ {
+ mSendLoc+=sendAmount;
+ if ( mSendLoc == mSendDataLength )
+ {
+ PX_FREE(mSendData);
+ mSendData = NULL;
+ mSendDataLength = 0;
+ mSendLoc = 0;
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ return mSendData ? true : false;
+ }
+
+ void processPendingSends(void)
+ {
+ int32_t pendingCount = physx::shdfnd::atomicAdd(&mTotalPendingCount,0);
+ while ( !processSocketWrite() && pendingCount != 0 )
+ {
+ mSendMutex.lock(); // Lock the send mutex before we check if there is data to send.
+ CommPacket sp = mPendingSends[0]; // Get the first packet to be sent.
+ physx::shdfnd::atomicAdd(&mTotalPendingSize,-int32_t(sp.getLength()));
+ physx::shdfnd::atomicAdd(&mTotalPendingCount,-1);
+ mPendingSends.remove(0); // Remove this packet from the pending send list.
+ mSendMutex.unlock(); // Unlock the mutex because at this point it is safe to post new send packets.
+ sp.computeHash();
+ physx::intrinsics::memCopy(sp.mData,&sp,sp.getSize());
+ mSendData = sp.mData;
+ mSendDataLength = sp.getLength()+sp.getSize();
+ mSendLoc = 0;
+ pendingCount = physx::shdfnd::atomicAdd(&mTotalPendingCount,0);
+ }
+ }
+
+ void resetServerSocket(void)
+ {
+ mSocket->disconnect(); // close the previous connection..
+ delete mSocket;
+ releaseAllReadData();
+ releaseAllSendData();
+ mSocket = PX_NEW(physx::shdfnd::Socket)(false);
+ mSocket->setBlocking(false);
+ mConnected = mSocket->listen(mPortNumber);
+ if ( !mConnected )
+ {
+ physx::shdfnd::Thread::signalQuit();
+ }
+ else
+ {
+ mListenPending = true;
+ }
+ }
+
+ //The thread execute function
+ virtual void execute()
+ {
+ setName("CommLayer"); // Set the name of the read
+
+ if ( mIsServer )
+ {
+ while( !quitIsSignalled() )
+ {
+ if ( mSocket->isConnected() )
+ {
+ mClientConnected = true;
+ processPendingSends();
+ bool haveData = processRead();
+ while ( haveData )
+ {
+ haveData = processRead();
+ }
+ if ( !mSocket->isConnected() ) // if we lost the client connection, then we need to fire up a new listen.
+ {
+ resetServerSocket();
+ }
+ }
+ else
+ {
+ mClientConnected = false;
+ if ( !mListenPending )
+ {
+ resetServerSocket();
+ }
+ bool connected = mSocket->accept(false);
+ if ( connected )
+ {
+ mSocket->setBlocking(false);
+ mListenPending = false;
+ }
+ }
+ physx::shdfnd::Thread::sleep(0);
+ }
+ }
+ else
+ {
+ while( !quitIsSignalled() && mSocket->isConnected() )
+ {
+ processPendingSends();
+ bool haveData = processRead();
+ while ( haveData )
+ {
+ haveData = processRead();
+ }
+ physx::shdfnd::Thread::sleep(0);
+ }
+ }
+ mClientConnected = false;
+ mConnected = false;
+ quit();
+ }
+
+ bool processRead(void)
+ {
+ bool ret = false;
+
+ if ( mReadPacketHeader.mData ) // if we are currently in the process of reading in a packet...
+ {
+ uint32_t remaining = mReadPacketHeader.getLength() - mReadPacketLoc;
+ uint8_t *readData = &mReadPacketHeader.mData[mReadPacketLoc];
+ uint32_t readCount = mSocket->read(readData,remaining);
+ if ( readCount )
+ {
+ ret = true;
+ mReadPacketLoc+=readCount;
+ if ( mReadPacketLoc == mReadPacketHeader.getLength() )
+ {
+ // The packet has been read!!
+ mReadPacketMutex.lock();
+ mReadPackets.pushBack(mReadPacketHeader);
+ physx::shdfnd::atomicAdd(&mReadSize,int32_t(mReadPacketHeader.getLength()));
+ mReadPacketMutex.unlock();
+ mReadPacketHeader.mData = NULL;
+ }
+ }
+ }
+ else
+ {
+ uint32_t remaining = mReadPacketHeader.getSize() - mReadPacketHeaderLoc; // the amount of the header we have still yet to read...
+ uint8_t *header = reinterpret_cast<uint8_t *>(&mReadPacketHeader);
+ uint8_t *readData = &header[mReadPacketHeaderLoc];
+ uint32_t readCount = mSocket->read(readData,remaining);
+ if ( readCount )
+ {
+ ret = true;
+ mReadPacketHeaderLoc+=readCount;
+ if ( mReadPacketHeaderLoc == mReadPacketHeader.getSize() )
+ {
+ if ( mReadPacketHeader.isHeaderPacket() ) // if it is a valid header packet..
+ {
+ PX_FREE(mReadPacketHeader.mData);
+ mReadPacketHeader.mData = static_cast<uint8_t *>(PX_ALLOC(mReadPacketHeader.getLength(),"ReadPacket"));
+ mReadPacketLoc = 0;
+ mReadPacketHeaderLoc = 0;
+ }
+ else
+ {
+ // We could be connecting somehow 'mid-stream' so we need to scan forward a byte at a time until we get a valid packet header.
+ // We do this by copying all of the old packet header + 1 byte, and set the next read location to read just one more byte at the end.
+ // This will cause the stream to 'resync' back to the head of the next packet.
+ CommPacket cp = mReadPacketHeader;
+ const uint8_t *source = reinterpret_cast<const uint8_t *>(&cp);
+ uint8_t *dest = reinterpret_cast<uint8_t *>(&mReadPacketHeader);
+ physx::intrinsics::memCopy(dest,source+1,cp.getSize()-1);
+ mReadPacketHeaderLoc = cp.getSize()-1;
+ }
+
+ }
+ }
+ }
+ return ret;
+ }
+
+ virtual int32_t getPendingReadSize(void) const // returns the number of bytes of data which is pending to be read.
+ {
+ return physx::shdfnd::atomicAdd(&mReadSize,0);
+ }
+
+ virtual bool isServer(void) const // return true if we are in server mode.
+ {
+ return mIsServer;
+ }
+
+ virtual bool hasClient(void) const // return true if a client connection is currently established
+ {
+ return mClientConnected;
+ }
+
+ int32_t getPendingSendSize(void) const
+ {
+ return physx::shdfnd::atomicAdd(&mTotalPendingSize,0);
+ }
+
+ physx::shdfnd::Socket *mSocket;
+ uint16_t mPortNumber;
+ bool mIsServer;
+ bool mConnected;
+ mutable int32_t mReadSize;
+ uint32_t mReadPacketHeaderLoc; // The current read location from the input stream for the current packet
+ uint32_t mReadPacketLoc;
+ CommPacket mReadPacketHeader; // The current packet we are reading header
+ CommPacketArray mReadPackets;
+ mutable int32_t mTotalPendingSize;
+ mutable int32_t mTotalPendingCount;
+ CommPacketArray mPendingSends;
+ bool mClientConnected;
+ physx::shdfnd::Mutex mReadPacketMutex; // Mutex to have thread safety on reads
+ physx::shdfnd::Mutex mSendMutex; // Mutex to have thread safety on sends
+ uint8_t *mSendData; // data being sent over the socket connection
+ uint32_t mSendDataLength; // The length of the data to send over the socket connection
+ uint32_t mSendLoc; // The current location of the data which has been sent so far.
+ bool mListenPending;
+ uint32_t mReadTimeOut;
+};
+
+} // end of namespace
+
+using namespace COMM_LAYER;
+
+
+CommLayer *createCommLayer(const char *ipaddress,uint16_t portNumber,bool isServer)
+{
+ CommLayerImp *c = PX_NEW(CommLayerImp)(ipaddress,portNumber,isServer);
+ if ( !c->isConnected() )
+ {
+ c->release();
+ c = NULL;
+ }
+ return static_cast< CommLayer *>(c);
+}
diff --git a/APEX_1.4/shared/general/RenderDebug/src/PsCommStream.cpp b/APEX_1.4/shared/general/RenderDebug/src/PsCommStream.cpp
new file mode 100644
index 00000000..491e62df
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/PsCommStream.cpp
@@ -0,0 +1,291 @@
+#include "PsCommStream.h"
+#include "PsUserAllocated.h"
+#include "RenderDebug.h"
+#include "PsString.h"
+#include "PxIntrinsics.h"
+#include "PsIntrinsics.h"
+#include <stdio.h>
+
+#define MAX_STREAM_RECORD (1024*1024*2047) // no more than one gig
+#define STREAM_VERSION_NUMBER 100
+static char magic[4] = { 'N', 'V', 'C', 'S' };
+
+class CommStreamImpl : public CommStream, public physx::shdfnd::UserAllocated
+{
+public:
+ CommStreamImpl(const char *streamFile,bool recordFile,CommLayer *c)
+ {
+ mCommLayer = c;
+ mIsRecord = recordFile;
+ mFirstFrame = true;
+ mIsValid = true;
+ mMaxPacketLength = (1024*1024)*16;
+ mPacketLength = 0;
+ mPacketLoc = 0;
+ mPacketData = static_cast<uint8_t *>(PX_ALLOC(mMaxPacketLength,"PacketData"));
+ mPacketBigEndian = false;
+ physx::shdfnd::strlcpy(mFilename,256,streamFile);
+ if ( mIsRecord )
+ {
+ mFph = NULL;
+ }
+ else
+ {
+ mFph = fopen(streamFile,"rb");
+ mIsValid = false;
+ if ( mFph )
+ {
+ char id[4] = { 0, 0, 0, 0};
+ uint32_t v1=0;
+ uint32_t v2=0;
+ uint32_t v3=0;
+ size_t res = fread(id,sizeof(id),1,mFph);
+ res = fread(&v1,sizeof(v1),1,mFph);
+ res = fread(&v2,sizeof(v2),1,mFph);
+ res = fread(&v3,sizeof(v3),1,mFph);
+ PX_UNUSED(res);
+ if ( id[0] == magic[0] &&
+ id[1] == magic[1] &&
+ id[2] == magic[2] &&
+ id[3] == magic[3] &&
+ v1 == STREAM_VERSION_NUMBER &&
+ v2 == RENDER_DEBUG_VERSION &&
+ v3 == RENDER_DEBUG_COMM_VERSION )
+ {
+ mIsValid = true;
+ readNextPacket();
+ }
+ }
+ }
+ }
+
+ virtual ~CommStreamImpl(void)
+ {
+ close();
+ }
+
+ void close(void)
+ {
+ PX_FREE(mPacketData);
+ mPacketData = NULL;
+ if ( mFph )
+ {
+ fclose(mFph);
+ mFph = NULL;
+ }
+ mPacketLength = 0;
+ mPacketLoc = 0;
+ mIsValid = false;
+ }
+
+ FILE *getFile(void)
+ {
+ if ( mFirstFrame )
+ {
+ mFph = fopen(mFilename,"wb");
+ if ( mFph )
+ {
+ uint32_t version = STREAM_VERSION_NUMBER;
+ fwrite(magic,sizeof(magic),1,mFph);
+ fwrite(&version,sizeof(version),1,mFph);
+ version = RENDER_DEBUG_VERSION;
+ fwrite(&version,sizeof(version),1,mFph);
+ version = RENDER_DEBUG_COMM_VERSION;
+ fwrite(&version,sizeof(version),1,mFph);
+ fflush(mFph);
+ }
+ mFirstFrame = false;
+ }
+ return mFph;
+ }
+
+ virtual void release(void)
+ {
+ delete this;
+ }
+
+ virtual CommLayer *getCommLayer(void)
+ {
+ return mCommLayer;
+ }
+
+ bool isValid(void) const
+ {
+ return mIsValid;
+ }
+
+ virtual bool isServer(void) const // return true if we are in server mode.
+ {
+ return mCommLayer->isServer();
+ }
+
+ virtual bool hasClient(void) const // return true if a client connection is currently established
+ {
+ bool ret = false;
+ if ( mIsRecord )
+ {
+ ret = mCommLayer->hasClient();
+ }
+ else
+ {
+ ret = mIsValid;
+ }
+ return ret;
+ }
+
+ virtual bool isConnected(void) const // return true if we are still connected to the server. The server is always in a 'connected' state.
+ {
+ return mCommLayer->isConnected();
+ }
+
+ virtual int32_t getPendingReadSize(void) const // returns the number of bytes of data which is pending to be read.
+ {
+ int32_t ret = 0;
+ if ( mIsRecord )
+ {
+ ret = mCommLayer->getPendingReadSize();
+ }
+ else
+ {
+ ret = int32_t(mPacketLength-mPacketLoc);
+ }
+ return ret;
+ }
+
+ virtual int32_t getPendingSendSize(void) const // return the number of bytes of data pending to be sent. This can be used for flow control
+ {
+ return mCommLayer->getPendingSendSize();
+ }
+
+ virtual bool sendMessage(const void *msg,uint32_t len)
+ {
+ bool ret = true;
+ if ( mIsRecord )
+ {
+ ret = mCommLayer->sendMessage(msg,len);
+ }
+ return ret;
+ }
+
+ virtual uint32_t peekMessage(bool &isBigEndianPacket) // return the length of the next pending message
+ {
+ uint32_t ret = 0;
+ if ( mIsRecord )
+ {
+ ret = mCommLayer->peekMessage(isBigEndianPacket);
+ }
+ else
+ {
+ ret = mPacketLength - mPacketLoc;
+ isBigEndianPacket = mPacketBigEndian;
+ }
+ return ret;
+ }
+
+ virtual uint32_t getMessage(void *msg,uint32_t maxLength,bool &isBigEndianPacket) // receives a pending message
+ {
+ uint32_t ret = 0;
+ if ( mIsRecord )
+ {
+ ret = mCommLayer->getMessage(msg,maxLength,isBigEndianPacket);
+ if ( ret && mIsRecord )
+ {
+ getFile();
+ if ( mFph )
+ {
+ uint32_t be = isBigEndianPacket ? 1U : 0U;
+ fwrite(&ret,sizeof(ret),1,mFph);
+ fwrite(&be,sizeof(be),1,mFph);
+ fwrite(msg,ret,1,mFph);
+ fflush(mFph);
+ size_t len = size_t(ftell(mFph));
+ if ( len > MAX_STREAM_RECORD )
+ {
+ fclose(mFph);
+ mFph = NULL;
+ }
+ }
+ }
+ }
+ else if ( mIsValid )
+ {
+ ret = mPacketLength - mPacketLoc;
+ if ( ret <= maxLength )
+ {
+ physx::intrinsics::memCopy(msg,&mPacketData[mPacketLoc],ret);
+ readNextPacket();
+ }
+ else
+ {
+ ret = maxLength;
+ physx::intrinsics::memCopy(msg,&mPacketData[mPacketLoc],ret);
+ mPacketLoc+=ret;
+ }
+ }
+ return ret;
+ }
+
+ void readNextPacket(void)
+ {
+ if ( mFph && !mIsRecord )
+ {
+ mPacketLoc = 0;
+ uint32_t be;
+ size_t r1 = fread(&mPacketLength,sizeof(mPacketLength),1,mFph);
+ size_t r2 = fread(&be,sizeof(be),1,mFph);
+ if ( r1 == 1 && r2 == 1 )
+ {
+ if ( mPacketLength > mMaxPacketLength )
+ {
+ mMaxPacketLength = mPacketLength + (1024*1024*10);
+ PX_FREE(mPacketData);
+ mPacketData = static_cast<uint8_t *>(PX_ALLOC(mMaxPacketLength,"PacketData"));
+ }
+ if ( mPacketData )
+ {
+ size_t r3 = fread(mPacketData,mPacketLength,1,mFph);
+ if ( r3 == 1 )
+ {
+ mPacketBigEndian = be ? true : false;
+ }
+ else
+ {
+ close();
+ }
+ }
+ else
+ {
+ close();
+ }
+ }
+ else
+ {
+ close();
+ }
+ }
+ }
+
+ uint32_t mMaxPacketLength;
+ uint32_t mPacketLoc;
+ uint32_t mPacketLength;
+ uint8_t *mPacketData;
+ bool mPacketBigEndian;
+
+ char mFilename[256];
+ FILE *mFph;
+ bool mFirstFrame;
+ bool mIsValid;
+ bool mIsRecord;
+ CommLayer *mCommLayer;
+};
+
+CommStream *createCommStream(const char *streamFile,bool recordFile,CommLayer *cl)
+{
+ CommStreamImpl *c = PX_NEW(CommStreamImpl)(streamFile,recordFile,cl);
+ if ( !c->isValid() )
+ {
+ c->release();
+ c = NULL;
+ }
+ return static_cast< CommStream *>(c);
+}
diff --git a/APEX_1.4/shared/general/RenderDebug/src/RenderDebug.cpp b/APEX_1.4/shared/general/RenderDebug/src/RenderDebug.cpp
new file mode 100644
index 00000000..03554c43
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/RenderDebug.cpp
@@ -0,0 +1,817 @@
+#include "RenderDebugTyped.h"
+
+
+#include "RenderDebugImpl.h"
+#include "ClientServer.h"
+#include "ProcessRenderDebug.h"
+#include "InternalRenderDebug.h"
+#include "FileRenderDebug.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "PsUserAllocated.h"
+#include "PsMutex.h"
+#include "PsString.h"
+#include "PxErrorCallback.h"
+#include "PxAllocatorCallback.h"
+#include "PsArray.h"
+#include "PsFoundation.h"
+
+namespace RENDER_DEBUG
+{
+class RenderDebugIImpl;
+void finalRelease(RenderDebugIImpl *nv);
+}
+
+#include "GetArgs.h"
+#include "PsFileBuffer.h"
+
+#if PX_WINDOWS_FAMILY
+#pragma warning(disable:4986)
+#endif
+
+#define SERVER_FILE_SIZE sizeof(ServerHeader)+(1024*1024)
+
+class EchoRemoteCommand
+{
+public:
+ char mCommand[16384];
+};
+
+typedef physx::shdfnd::Array< EchoRemoteCommand > EchoRemoteCommandVector;
+
+#ifdef USE_PX_FOUNDATION
+#else
+class DefaultErrorCallback : public physx::PxErrorCallback
+{
+public:
+ DefaultErrorCallback(void)
+ {
+ }
+
+ virtual void reportError(physx::PxErrorCode::Enum code, const char* message, const char* file, int line)
+ {
+ PX_UNUSED(code);
+ PX_UNUSED(file);
+ PX_UNUSED(line);
+ printf("PhysX: %s\r\n", message );
+ }
+private:
+};
+
+#if PX_WINDOWS_FAMILY
+// on win32 we only have 8-byte alignment guaranteed, but the CRT provides special aligned allocation
+// fns
+#include <malloc.h>
+#include <crtdbg.h>
+
+static void* platformAlignedAlloc(size_t size)
+{
+ return _aligned_malloc(size, 16);
+}
+
+static void platformAlignedFree(void* ptr)
+{
+ _aligned_free(ptr);
+}
+#elif PX_LINUX || PX_ANDROID
+static void* platformAlignedAlloc(size_t size)
+{
+ return ::memalign(16, size);
+}
+
+static void platformAlignedFree(void* ptr)
+{
+ ::free(ptr);
+}
+#elif PX_WIIU
+static void* platformAlignedAlloc(size_t size)
+{
+ size_t pad = 15 + sizeof(size_t); // store offset for delete.
+ uint8_t* base = (uint8_t*)::malloc(size+pad);
+ if(!base)
+ return NULL;
+
+ uint8_t* ptr = (uint8_t*)(size_t(base + pad) & ~(15)); // aligned pointer
+ ((size_t*)ptr)[-1] = ptr - base; // store offset
+
+ return ptr;
+}
+
+static void platformAlignedFree(void* ptr)
+{
+ if(ptr == NULL)
+ return;
+
+ uint8_t* base = ((uint8_t*)ptr) - ((size_t*)ptr)[-1];
+ ::free(base);
+}
+#else
+
+// on PS3, XBox and Win64 we get 16-byte alignment by default
+static void* platformAlignedAlloc(size_t size)
+{
+ void *ptr = ::malloc(size);
+ PX_ASSERT((reinterpret_cast<size_t>(ptr) & 15)==0);
+ return ptr;
+}
+
+static void platformAlignedFree(void* ptr)
+{
+ ::free(ptr);
+}
+#endif
+
+
+class DefaultAllocator : public physx::PxAllocatorCallback
+{
+public:
+ DefaultAllocator(void)
+ {
+ }
+
+ ~DefaultAllocator(void)
+ {
+ }
+
+
+ virtual void* allocate(size_t size, const char* typeName, const char* filename, int line)
+ {
+ PX_UNUSED(typeName);
+ PX_UNUSED(filename);
+ PX_UNUSED(line);
+ void *ret = platformAlignedAlloc(size);
+ return ret;
+ }
+
+ virtual void deallocate(void* ptr)
+ {
+ platformAlignedFree(ptr);
+ }
+private:
+};
+
+
+DefaultAllocator gDefaultAllocator;
+DefaultErrorCallback gDefaultErrorCallback;
+#endif
+
+#define RECORD_REMOTE_COMMANDS_VERSION 100
+
+static char magic[4] = { 'R', 'R', 'C', 'V' };
+
+static uint32_t isBigEndian(void)
+{
+ int32_t i = 1;
+ bool b = *(reinterpret_cast<char*>(&i))==0;
+ return b ? uint32_t(1) : uint32_t(0);
+}
+
+
+namespace RENDER_DEBUG
+{
+
+class PlaybackRemoteCommand
+{
+public:
+ PlaybackRemoteCommand(void)
+ {
+ mFrameNumber = 0;
+ mArgc = 0;
+ for (uint32_t i=0; i<256; i++)
+ {
+ mArgv[i] = NULL;
+ }
+ }
+ void release(void)
+ {
+ mFrameNumber = 0;
+ for (uint32_t i=0; i<mArgc; i++)
+ {
+ PX_FREE(static_cast<void *>(const_cast<char *>(mArgv[i])));
+ mArgv[i] = NULL;
+ }
+ mArgc = 0;
+ }
+ uint32_t mFrameNumber;
+ uint32_t mArgc;
+ const char *mArgv[256];
+};
+
+class RenderDebugIImpl : public physx::shdfnd::UserAllocated, public RenderDebugHook
+{
+ PX_NOCOPY(RenderDebugIImpl)
+public:
+ RenderDebugIImpl(RENDER_DEBUG::RenderDebug::Desc &desc) :
+ mEchoRemoteCommandBuffer(PX_DEBUG_EXP("PxRenderDebug::mEchoRemoteCommandBuffer"))
+ {
+ mEndianSwap = false;
+ mRecordRemoteCommands = NULL;
+ mPlaybackRemoteCommands = NULL;
+ mCurrentFrame = 0;
+ mMeshId = 0;
+ mFileRenderDebug = NULL;
+ mIsValid = true;
+ mApexRenderDebug = NULL;
+ mInternalProcessRenderDebug = NULL;
+ mRenderDebug = NULL;
+ mClientServer = NULL;
+ mReadNext = false;
+ switch ( desc.runMode )
+ {
+ case RenderDebug::RM_CLIENT:
+ case RenderDebug::RM_CLIENT_OR_FILE:
+ case RenderDebug::RM_SERVER:
+ {
+ if ( desc.runMode == RenderDebug::RM_SERVER ) // if running in server mode.
+ {
+ mClientServer = createClientServer(desc);
+ }
+ else
+ {
+ mClientServer = createClientServer(desc);
+ if ( mClientServer == NULL )
+ {
+ if ( desc.runMode != RenderDebug::RM_CLIENT_OR_FILE )
+ {
+ desc.errorCode = "Unable to locate server";
+ }
+ else
+ {
+ desc.errorCode = NULL;
+ }
+ }
+ }
+ }
+ break;
+ case RenderDebug::RM_LOCAL:
+ break;
+ case RenderDebug::RM_FILE:
+ break;
+ }
+
+ if ( desc.runMode == RenderDebug::RM_FILE || desc.runMode == RenderDebug::RM_CLIENT_OR_FILE || desc.runMode == RENDER_DEBUG::RenderDebug::RM_CLIENT )
+ {
+ if ( desc.echoFileLocally )
+ {
+ mInternalProcessRenderDebug = RENDER_DEBUG::createProcessRenderDebug();
+ }
+ mFileRenderDebug = RENDER_DEBUG::createFileRenderDebug(desc.recordFileName,false,desc.echoFileLocally ? mInternalProcessRenderDebug : NULL, mClientServer);
+ if ( mFileRenderDebug == NULL )
+ {
+ mIsValid = false;
+ desc.errorCode = "Failed to open recording file";
+ }
+ }
+ if ( mIsValid )
+ {
+ if ( mFileRenderDebug )
+ {
+ mMeshId = 1000000; //
+ mRenderDebug = RENDER_DEBUG::createInternalRenderDebug(mFileRenderDebug,this);
+ }
+ else
+ {
+ if ( mInternalProcessRenderDebug == NULL )
+ {
+ mInternalProcessRenderDebug = RENDER_DEBUG::createProcessRenderDebug();
+ }
+ mRenderDebug = RENDER_DEBUG::createInternalRenderDebug(mInternalProcessRenderDebug,this);
+ }
+ }
+ if ( desc.errorCode )
+ {
+ mIsValid = false;
+ }
+ if ( mIsValid && desc.recordRemoteCommands )
+ {
+ mRecordRemoteCommands = PX_NEW(physx::PsFileBuffer)(desc.recordRemoteCommands, physx::PsFileBuffer::OPEN_WRITE_ONLY);
+ if ( mRecordRemoteCommands->isOpen() )
+ {
+ mRecordRemoteCommands->write(magic, 4 );
+ mRecordRemoteCommands->storeDword(RECORD_REMOTE_COMMANDS_VERSION);
+ uint32_t bigEndian = isBigEndian();
+ mRecordRemoteCommands->storeDword(bigEndian);
+ mRecordRemoteCommands->flush();
+ }
+ else
+ {
+ delete mRecordRemoteCommands;
+ mRecordRemoteCommands = NULL;
+ }
+ }
+ if ( mIsValid && desc.playbackRemoteCommands )
+ {
+ mPlaybackRemoteCommands = PX_NEW(physx::PsFileBuffer)(desc.playbackRemoteCommands, physx::PsFileBuffer::OPEN_READ_ONLY);
+ if ( mPlaybackRemoteCommands->isOpen() )
+ {
+ char temp[4];
+ uint32_t r = mPlaybackRemoteCommands->read(temp,4);
+ uint32_t version = mPlaybackRemoteCommands->readDword();
+ uint32_t bigEndian = mPlaybackRemoteCommands->readDword();
+
+ if ( r == 4 && magic[0] == temp[0] && magic[1] == temp[1] && magic[2] == temp[2] && magic[3] == temp[3] && version == RECORD_REMOTE_COMMANDS_VERSION )
+ {
+ if ( bigEndian != isBigEndian() )
+ {
+ mEndianSwap = true;
+ }
+ mReadNext = true;
+ }
+ else
+ {
+ delete mPlaybackRemoteCommands;
+ mPlaybackRemoteCommands = NULL;
+ }
+ }
+ else
+ {
+ delete mPlaybackRemoteCommands;
+ mPlaybackRemoteCommands = NULL;
+ }
+ }
+ mDesc = desc;
+ }
+
+ virtual ~RenderDebugIImpl(void)
+ {
+ delete mRecordRemoteCommands;
+ delete mPlaybackRemoteCommands;
+ mPlaybackRemoteCommand.release();
+ if ( mFileRenderDebug )
+ {
+ mFileRenderDebug->release();
+ }
+ if ( mClientServer )
+ {
+ mClientServer->release();
+ }
+ if ( mRenderDebug )
+ {
+ mRenderDebug->releaseRenderDebug();
+ }
+ if ( mInternalProcessRenderDebug )
+ {
+ mInternalProcessRenderDebug->release();
+ }
+ }
+
+ virtual bool render(float dtime,RENDER_DEBUG::RenderDebugInterface *iface)
+ {
+ bool ret = true;
+
+ mCurrentFrame++;
+
+ mApexRenderDebug = iface;
+
+ if ( mFileRenderDebug && mFileRenderDebug->getFrameCount() )
+ {
+ mFileRenderDebug->processReadFrame(iface);
+ }
+
+ if ( mClientServer && mDesc.runMode == RENDER_DEBUG::RenderDebug::RM_SERVER )
+ {
+ mClientServer->processFrame(mInternalProcessRenderDebug,iface);
+ }
+
+ ret = mRenderDebug->renderImpl(dtime,iface);
+
+ return ret;
+ }
+
+
+ virtual void release(void)
+ {
+ finalRelease(this);
+ }
+
+ bool isValid(void) const
+ {
+ return mIsValid;
+ }
+
+ virtual uint32_t setFilePlayback(const char *fileName)
+ {
+ uint32_t ret = 0;
+
+ if ( mFileRenderDebug )
+ {
+ mFileRenderDebug->release();
+ mFileRenderDebug = NULL;
+ }
+
+ mFileRenderDebug = RENDER_DEBUG::createFileRenderDebug(fileName,true,mInternalProcessRenderDebug, NULL);
+
+ if ( mFileRenderDebug )
+ {
+ mFileRenderDebug->setFrame(0);
+ ret = mFileRenderDebug->getFrameCount();
+ }
+
+ return ret;
+ }
+
+ virtual bool setPlaybackFrame(uint32_t playbackFrame)
+ {
+ bool ret = false;
+
+ if ( mFileRenderDebug && playbackFrame < mFileRenderDebug->getFrameCount() )
+ {
+ ret = true;
+ mFileRenderDebug->setFrame(playbackFrame);
+ }
+
+ return ret;
+ }
+
+ virtual uint32_t getPlaybackFrameCount(void) const
+ {
+ uint32_t ret = 0;
+ if ( mFileRenderDebug )
+ {
+ ret = mFileRenderDebug->getFrameCount();
+ }
+ return ret;
+ }
+
+ virtual void stopPlayback(void)
+ {
+ if ( mFileRenderDebug )
+ {
+ mFileRenderDebug->release();
+ mFileRenderDebug = NULL;
+ }
+ }
+
+ virtual bool trylock(void)
+ {
+ return mMutex.trylock();
+ }
+
+ virtual void lock(void)
+ {
+ mMutex.lock();
+ }
+
+ virtual void unlock(void)
+ {
+ mMutex.unlock();
+ }
+
+ /**
+ \brief Convenience method to return a unique mesh id number (simply a global counter to avoid clashing with other ids
+ */
+ virtual uint32_t getMeshId(void)
+ {
+ mMeshId++;
+ return mMeshId;
+ }
+
+ /**
+ \brief Transmit an actual input event to the remote client
+
+ \param ev The input event data to transmit
+ */
+ virtual void sendInputEvent(const InputEvent &ev)
+ {
+ if ( mClientServer )
+ {
+ mClientServer->sendInputEvent(ev);
+ }
+ }
+
+
+ virtual bool sendRemoteCommand(const char *fmt,...)
+ {
+ bool ret = false;
+
+ EchoRemoteCommand c;
+ va_list arg;
+ va_start( arg, fmt );
+ physx::shdfnd::vsnprintf(c.mCommand,sizeof(c.mCommand)-1, fmt, arg);
+ va_end(arg);
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->sendCommand(c.mCommand);
+ }
+ else
+ {
+ mEchoRemoteCommandBuffer.pushBack(c);
+ }
+ return ret;
+ }
+
+ virtual const char ** getRemoteCommand(uint32_t &argc)
+ {
+ const char **ret = NULL;
+ argc = 0;
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->getCommand(argc);
+ }
+ else if ( !mEchoRemoteCommandBuffer.empty() )
+ {
+ mCurrentCommand = mEchoRemoteCommandBuffer[0];
+ mEchoRemoteCommandBuffer.remove(0);
+ ret = mParser.getArgs(mCurrentCommand.mCommand,argc);
+ }
+
+ if ( mReadNext )
+ {
+ readNextRemoteCommand();
+ mReadNext = false;
+ }
+
+ if ( mPlaybackRemoteCommands )
+ {
+ ret = NULL;
+ argc = 0;
+ if ( mPlaybackRemoteCommand.mFrameNumber == mCurrentFrame )
+ {
+ argc = mPlaybackRemoteCommand.mArgc;
+ ret = mPlaybackRemoteCommand.mArgv;
+ mReadNext = true;
+ }
+ }
+
+ if ( mRecordRemoteCommands && ret && argc < 256 )
+ {
+ mRecordRemoteCommands->storeDword(mCurrentFrame);
+ mRecordRemoteCommands->storeDword(argc);
+ for (uint32_t i=0; i<argc; i++)
+ {
+ const char *str = ret[i];
+ uint32_t len = uint32_t(strlen(str))+1;
+ mRecordRemoteCommands->storeDword(len);
+ mRecordRemoteCommands->write(str,len);
+ }
+ mRecordRemoteCommands->flush();
+ }
+
+ return ret;
+ }
+
+
+ /**
+ \brief Transmits an arbitrary block of binary data to the remote machine. The block of data can have a command and id associated with it.
+
+ It is important to note that due to the fact the RenderDebug system is synchronized every single frame, it is strongly recommended
+ that you only use this feature for relatively small data items; probably on the order of a few megabytes at most. If you try to do
+ a very large transfer, in theory it would work, but it might take a very long time to complete and look like a hang since it will
+ essentially be blocking.
+
+ \param command An arbitrary command associated with this data transfer, for example this could indicate a remote file request.
+ \param id An arbitrary id associated with this data transfer, for example the id could be the file name of a file transfer request.
+ \param data The block of binary data to transmit, you are responsible for maintaining endian correctness of the internal data if necessary.
+ \param dlen The length of the lock of data to transmit.
+
+ \return Returns true if the data was queued to be transmitted, false if it failed.
+ */
+ virtual bool sendRemoteResource(const char *command,
+ const char *id,
+ const void *data,
+ uint32_t dlen)
+ {
+ bool ret = false;
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->sendRemoteResource(command,id,data,dlen);
+ }
+
+ return ret;
+ }
+
+ /**
+ \brief This function allows you to request a file from the remote machine by name. If successful it will be returned via 'getRemoteData'
+
+ \param command The command field associated with this request which will be returned by 'getRemoteData'
+ \param fileName The filename being requested from the remote machine.
+
+ \return Returns true if the request was queued to be transmitted, false if it failed.
+ */
+ virtual bool requestRemoteResource(const char *command,
+ const char *fileName)
+ {
+ bool ret = false;
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->requestRemoteResource(command,fileName);
+ }
+
+ return ret;
+ }
+
+ /**
+ \brief Retrieves a block of remotely transmitted binary data.
+
+ \param command A a reference to a pointer which will store the arbitrary command associated with this data transfer, for example this could indicate a remote file request.
+ \param id A reference to a pointer which will store an arbitrary id associated with this data transfer, for example the id could be the file name of a file transfer request.
+ \param dlen A reference that will contain length of the lock of data received.
+ \param remoteIsBigEndian A reference to a boolean which will be set to true if the remote machine that sent this data is big endian format.
+
+ \retrun A pointer to the block of data received.
+ */
+ virtual const void * getRemoteResource(const char *&command,
+ const char *&id,
+ uint32_t &dlen,
+ bool &remoteIsBigEndian)
+ {
+ const void *ret = NULL;
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->getRemoteResource(command,id,dlen,remoteIsBigEndian);
+ }
+
+ return ret;
+ }
+
+
+ virtual RENDER_DEBUG::RenderDebug::RunMode getRunMode(void)
+ {
+ RENDER_DEBUG::RenderDebug::RunMode ret = RENDER_DEBUG::RenderDebug::RM_LOCAL;
+ if ( mClientServer )
+ {
+ if ( mClientServer->isServer() )
+ {
+ ret = RENDER_DEBUG::RenderDebug::RM_SERVER;
+ }
+ else
+ {
+ ret = RENDER_DEBUG::RenderDebug::RM_CLIENT;
+ }
+ }
+ else if ( mFileRenderDebug )
+ {
+ ret = RENDER_DEBUG::RenderDebug::RM_FILE;
+ }
+ return ret;
+ }
+
+ virtual bool isConnected(void) const
+ {
+ bool ret = false;
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->isConnected();
+ }
+
+ return ret;
+ }
+
+ virtual uint32_t getCommunicationsFrame(void) const
+ {
+ return mClientServer ? mClientServer->getCommunicationsFrame() : 0;
+ }
+
+ virtual const char *getRemoteApplicationName(void)
+ {
+ const char *ret = NULL;
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->getRemoteApplicationName();
+ }
+
+ return ret;
+ }
+
+ virtual RenderDebugTyped *getRenderDebugTyped(void)
+ {
+ return static_cast< RenderDebugTyped *>(mRenderDebug);
+ }
+
+ void readNextRemoteCommand(void)
+ {
+ if ( mPlaybackRemoteCommands == NULL ) return;
+ mPlaybackRemoteCommand.release(); // release previous command
+ mPlaybackRemoteCommand.mFrameNumber = mPlaybackRemoteCommands->readDword();
+ if ( mPlaybackRemoteCommand.mFrameNumber == 0 )
+ {
+ mPlaybackRemoteCommand.release();
+ delete mPlaybackRemoteCommands;
+ mPlaybackRemoteCommands = NULL;
+ }
+ else
+ {
+ mPlaybackRemoteCommand.mArgc = mPlaybackRemoteCommands->readDword();
+ for (uint32_t i=0; i<mPlaybackRemoteCommand.mArgc; i++)
+ {
+ uint32_t len = mPlaybackRemoteCommands->readDword();
+ mPlaybackRemoteCommand.mArgv[i] = static_cast<const char *>(PX_ALLOC(len,"PlaybackRemoteCommand"));
+ uint32_t rbytes = mPlaybackRemoteCommands->read(reinterpret_cast<void *>(const_cast<char*>(mPlaybackRemoteCommand.mArgv[i])),len);
+ if ( rbytes != len )
+ {
+ mPlaybackRemoteCommand.release();
+ delete mPlaybackRemoteCommands;
+ mPlaybackRemoteCommands = NULL;
+ }
+ }
+ }
+ }
+
+
+ /**
+ \brief Returns any incoming input event for processing purposes
+ */
+ virtual const InputEvent *getInputEvent(bool flush)
+ {
+ const InputEvent *ret = NULL;
+
+ if ( mClientServer )
+ {
+ ret = mClientServer->getInputEvent(flush);
+ }
+
+ return ret;
+ }
+
+ /**
+ \brief Set the base file name to record communications stream; or NULL to disable it.
+
+ \param fileName The base name of the file to record the communications channel stream to, or NULL to disable it.
+ */
+ virtual bool setStreamFilename(const char *fileName)
+ {
+ bool ret = false;
+ if ( mClientServer )
+ {
+ ret = mClientServer->setStreamFilename(fileName);
+ }
+ return ret;
+ }
+
+ /**
+ \brief Begin playing back a communications stream recording
+
+ \param fileName The name of the previously captured communications stream file
+ */
+ virtual bool setStreamPlayback(const char *fileName)
+ {
+ bool ret = false;
+ if ( mClientServer )
+ {
+ ret = mClientServer->setStreamPlayback(fileName);
+ }
+ return ret;
+ }
+
+ uint32_t mCurrentFrame;
+ uint32_t mMeshId;
+ physx::shdfnd::Mutex mMutex;
+ ClientServer *mClientServer;
+ RenderDebug::Desc mDesc;
+ bool mIsValid;
+ RENDER_DEBUG::RenderDebugInterface *mApexRenderDebug;
+ RENDER_DEBUG::RenderDebugImpl *mRenderDebug;
+ RENDER_DEBUG::FileRenderDebug *mFileRenderDebug;
+ RENDER_DEBUG::ProcessRenderDebug *mInternalProcessRenderDebug;
+ EchoRemoteCommand mCurrentCommand;
+ EchoRemoteCommandVector mEchoRemoteCommandBuffer;
+ GetArgs mParser;
+ physx::PsFileBuffer *mRecordRemoteCommands;
+ bool mEndianSwap;
+ physx::PsFileBuffer *mPlaybackRemoteCommands;
+ bool mReadNext;
+ PlaybackRemoteCommand mPlaybackRemoteCommand;
+};
+
+RENDER_DEBUG::RenderDebug *createRenderDebug(RENDER_DEBUG::RenderDebug::Desc &desc)
+{
+ RENDER_DEBUG::RenderDebug *ret = NULL;
+
+ if ( desc.versionNumber != RENDER_DEBUG_VERSION || desc.foundation == NULL)
+ {
+ return NULL;
+ }
+
+ RENDER_DEBUG::RenderDebugIImpl *c = PX_NEW(RENDER_DEBUG::RenderDebugIImpl)(desc);
+
+ if ( !c->isValid() )
+ {
+ c->release();
+ c = NULL;
+ }
+ else
+ {
+ ret = static_cast< RENDER_DEBUG::RenderDebug *>(c->getRenderDebugTyped());
+ }
+
+ return ret;
+}
+
+void finalRelease(RENDER_DEBUG::RenderDebugIImpl *nv)
+{
+ delete nv;
+}
+
+} // end of namespace
+
+
diff --git a/APEX_1.4/shared/general/RenderDebug/src/RenderDebugDLLMain.cpp b/APEX_1.4/shared/general/RenderDebug/src/RenderDebugDLLMain.cpp
new file mode 100644
index 00000000..ea60c43c
--- /dev/null
+++ b/APEX_1.4/shared/general/RenderDebug/src/RenderDebugDLLMain.cpp
@@ -0,0 +1,37 @@
+#include "RenderDebug.h"
+
+
+extern "C"
+#if PX_WINDOWS_FAMILY != 0
+__declspec(dllexport)
+#endif
+RENDER_DEBUG::RenderDebug* createRenderDebugExport(RENDER_DEBUG::RenderDebug::Desc &desc)
+{
+ return createRenderDebug(desc);
+}
+
+#if PX_WIN32 || PX_WIN64
+
+#include "windows/PsWindowsInclude.h"
+#pragma warning(disable:4100 4127)
+
+
+BOOL APIENTRY DllMain( HANDLE ,
+ DWORD ul_reason_for_call,
+ LPVOID )
+{
+ switch (ul_reason_for_call)
+ {
+ case DLL_PROCESS_ATTACH:
+ break;
+ case DLL_THREAD_ATTACH:
+ break;
+ case DLL_THREAD_DETACH:
+ break;
+ case DLL_PROCESS_DETACH:
+ break;
+ }
+ return TRUE;
+}
+#endif
+