feat(physics): wire physx sdk into build

This commit is contained in:
2026-04-15 12:22:15 +08:00
parent 5bf258df6d
commit 31f40e2cbb
2044 changed files with 752623 additions and 1 deletions

View File

@@ -0,0 +1,129 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#include "SnippetCamera.h"
#include <ctype.h>
#include "foundation/PxMat33.h"
using namespace physx;
namespace Snippets
{
Camera::Camera(const PxVec3& eye, const PxVec3& dir) : mMouseX(0), mMouseY(0), mSpeed(2.0f)
{
mEye = eye;
mDir = dir.getNormalized();
}
void Camera::handleMouse(int button, int state, int x, int y)
{
PX_UNUSED(state);
PX_UNUSED(button);
mMouseX = x;
mMouseY = y;
}
bool Camera::handleKey(unsigned char key, int x, int y, float speed)
{
PX_UNUSED(x);
PX_UNUSED(y);
const PxVec3 viewY = mDir.cross(PxVec3(0,1,0)).getNormalized();
switch(toupper(key))
{
case 'W': mEye += mDir*mSpeed*speed; break;
case 'S': mEye -= mDir*mSpeed*speed; break;
case 'A': mEye -= viewY*mSpeed*speed; break;
case 'D': mEye += viewY*mSpeed*speed; break;
default: return false;
}
return true;
}
void Camera::handleAnalogMove(float x, float y)
{
PxVec3 viewY = mDir.cross(PxVec3(0,1,0)).getNormalized();
mEye += mDir*y;
mEye += viewY*x;
}
void Camera::handleMotion(int x, int y)
{
const int dx = mMouseX - x;
const int dy = mMouseY - y;
const PxVec3 viewY = mDir.cross(PxVec3(0,1,0)).getNormalized();
const float Sensitivity = PxPi * 0.5f / 180.0f;
const PxQuat qx(Sensitivity * dx, PxVec3(0,1,0));
mDir = qx.rotate(mDir);
const PxQuat qy(Sensitivity * dy, viewY);
mDir = qy.rotate(mDir);
mDir.normalize();
mMouseX = x;
mMouseY = y;
}
PxTransform Camera::getTransform() const
{
PxVec3 viewY = mDir.cross(PxVec3(0,1,0));
if(viewY.normalize()<1e-6f)
return PxTransform(mEye);
const PxMat33 m(mDir.cross(viewY), viewY, -mDir);
return PxTransform(mEye, PxQuat(m));
}
PxVec3 Camera::getEye() const
{
return mEye;
}
PxVec3 Camera::getDir() const
{
return mDir;
}
void Camera::setPose(const PxVec3& eye, const PxVec3& dir)
{
mEye = eye;
mDir = dir;
}
void Camera::setSpeed(float speed)
{
mSpeed = speed;
}
}

View File

@@ -0,0 +1,62 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PHYSX_SNIPPET_CAMERA_H
#define PHYSX_SNIPPET_CAMERA_H
#include "foundation/PxTransform.h"
namespace Snippets
{
class Camera
{
public:
Camera(const physx::PxVec3& eye, const physx::PxVec3& dir);
void handleMouse(int button, int state, int x, int y);
bool handleKey(unsigned char key, int x, int y, float speed = 0.5f);
void handleMotion(int x, int y);
void handleAnalogMove(float x, float y);
physx::PxVec3 getEye() const;
physx::PxVec3 getDir() const;
physx::PxTransform getTransform() const;
void setPose(const physx::PxVec3& eye, const physx::PxVec3& dir);
void setSpeed(float speed);
private:
physx::PxVec3 mEye;
physx::PxVec3 mDir;
int mMouseX;
int mMouseY;
float mSpeed;
};
}
#endif //PHYSX_SNIPPET_CAMERA_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,282 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#include "SnippetFontData.h"
#include "SnippetFontRenderer.h"
#include "SnippetRender.h"
bool GLFontRenderer::m_isInit=false;
unsigned int GLFontRenderer::m_textureObject=0;
int GLFontRenderer::m_screenWidth=640;
int GLFontRenderer::m_screenHeight=480;
float GLFontRenderer::m_color[4]={1.0f, 1.0f, 1.0f, 1.0f};
namespace
{
struct RGBAPixel
{
unsigned char R,G,B,A;
};
#define PIXEL_OPAQUE 0xff
}
bool GLFontRenderer::init()
{
glGenTextures(1, (GLuint*)&m_textureObject);
if(!m_textureObject)
return false;
glBindTexture(GL_TEXTURE_2D, m_textureObject);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// expand to rgba
RGBAPixel* P = new RGBAPixel[OGL_FONT_TEXTURE_WIDTH*OGL_FONT_TEXTURE_HEIGHT];
for(int i=0;i<OGL_FONT_TEXTURE_WIDTH*OGL_FONT_TEXTURE_HEIGHT;i++)
{
if(1)
{
P[i].R = PIXEL_OPAQUE;
P[i].G = PIXEL_OPAQUE;
P[i].B = PIXEL_OPAQUE;
P[i].A = OGLFontData[i];
}
else
{
P[i].R = OGLFontData[i];
P[i].G = OGLFontData[i];
P[i].B = OGLFontData[i];
P[i].A = PIXEL_OPAQUE;
}
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, OGL_FONT_TEXTURE_WIDTH, OGL_FONT_TEXTURE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, P);
delete [] P;
m_isInit = true;
return true;
}
void GLFontRenderer::print(float x, float y, float fontSize, const char* pString, bool forceMonoSpace, int monoSpaceWidth, bool doOrthoProj)
{
if(1)
{
const float Saved0 = m_color[0];
const float Saved1 = m_color[1];
const float Saved2 = m_color[2];
m_color[0] = 0.0f;
m_color[1] = 0.0f;
m_color[2] = 0.0f;
// const float Offset = fontSize * 0.05f;
// const float Offset = fontSize * 0.075f;
const float Offset = fontSize * 0.1f;
print_(x+Offset, y-Offset, fontSize, pString, forceMonoSpace, monoSpaceWidth, doOrthoProj);
//print_(x-Offset, y-Offset, fontSize, pString, forceMonoSpace, monoSpaceWidth, doOrthoProj);
//print_(x+Offset, y+Offset, fontSize, pString, forceMonoSpace, monoSpaceWidth, doOrthoProj);
//print_(x-Offset, y+Offset, fontSize, pString, forceMonoSpace, monoSpaceWidth, doOrthoProj);
m_color[0] = Saved0;
m_color[1] = Saved1;
m_color[2] = Saved2;
}
print_(x, y, fontSize, pString, forceMonoSpace, monoSpaceWidth, doOrthoProj);
}
void GLFontRenderer::print_(float x, float y, float fontSize, const char* pString, bool forceMonoSpace, int monoSpaceWidth, bool doOrthoProj)
{
x = x*m_screenWidth;
y = y*m_screenHeight;
fontSize = fontSize*m_screenHeight;
if(!m_isInit)
m_isInit = init();
unsigned int num = (unsigned int)(strlen(pString));
if(m_isInit && num > 0)
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_textureObject);
if(doOrthoProj)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, m_screenWidth, 0, m_screenHeight, -1, 1);
}
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnable(GL_BLEND);
glDisable(GL_CULL_FACE);
glColor4f(m_color[0], m_color[1], m_color[2], m_color[3]);
const float glyphHeightUV = ((float)OGL_FONT_CHARS_PER_COL)/OGL_FONT_TEXTURE_HEIGHT*2 - 1.0f/128.0f;
//const float glyphHeightUV = ((float)OGL_FONT_CHARS_PER_COL)/OGL_FONT_TEXTURE_HEIGHT*2;
float translate = 0.0f;
float* pVertList = new float[num*3*6];
float* pTextureCoordList = new float[num*2*6];
int vertIndex = 0;
int textureCoordIndex = 0;
float translateDown = 0.0f;
unsigned int count = 0;
for(unsigned int i=0;i<num; i++)
{
const float glyphWidthUV = ((float)OGL_FONT_CHARS_PER_ROW)/OGL_FONT_TEXTURE_WIDTH;
if (pString[i] == '\n')
{
translateDown-=0.005f*m_screenHeight+fontSize;
translate = 0.0f;
continue;
}
int c = pString[i]-OGL_FONT_CHAR_BASE;
if (c < OGL_FONT_CHARS_PER_ROW*OGL_FONT_CHARS_PER_COL)
{
count++;
float glyphWidth = (float)GLFontGlyphWidth[c]+1;
if(forceMonoSpace)
glyphWidth = (float)monoSpaceWidth;
glyphWidth = glyphWidth*(fontSize/(((float)OGL_FONT_TEXTURE_WIDTH)/OGL_FONT_CHARS_PER_ROW))-0.01f;
const float cxUV = float((c)%OGL_FONT_CHARS_PER_ROW)/OGL_FONT_CHARS_PER_ROW+0.008f;
const float cyUV = float((c)/OGL_FONT_CHARS_PER_ROW)/OGL_FONT_CHARS_PER_COL+0.008f;
pTextureCoordList[textureCoordIndex++] = cxUV;
pTextureCoordList[textureCoordIndex++] = cyUV+glyphHeightUV;
pVertList[vertIndex++] = x+0+translate;
pVertList[vertIndex++] = y+0+translateDown;
pVertList[vertIndex++] = 0;
pTextureCoordList[textureCoordIndex++] = cxUV+glyphWidthUV;
pTextureCoordList[textureCoordIndex++] = cyUV;
pVertList[vertIndex++] = x+fontSize+translate;
pVertList[vertIndex++] = y+fontSize+translateDown;
pVertList[vertIndex++] = 0;
pTextureCoordList[textureCoordIndex++] = cxUV;
pTextureCoordList[textureCoordIndex++] = cyUV;
pVertList[vertIndex++] = x+0+translate;
pVertList[vertIndex++] = y+fontSize+translateDown;
pVertList[vertIndex++] = 0;
pTextureCoordList[textureCoordIndex++] = cxUV;
pTextureCoordList[textureCoordIndex++] = cyUV+glyphHeightUV;
pVertList[vertIndex++] = x+0+translate;
pVertList[vertIndex++] = y+0+translateDown;
pVertList[vertIndex++] = 0;
pTextureCoordList[textureCoordIndex++] = cxUV+glyphWidthUV;
pTextureCoordList[textureCoordIndex++] = cyUV+glyphHeightUV;
pVertList[vertIndex++] = x+fontSize+translate;
pVertList[vertIndex++] = y+0+translateDown;
pVertList[vertIndex++] = 0;
pTextureCoordList[textureCoordIndex++] = cxUV+glyphWidthUV;
pTextureCoordList[textureCoordIndex++] = cyUV;
pVertList[vertIndex++] = x+fontSize+translate;
pVertList[vertIndex++] = y+fontSize+translateDown;
pVertList[vertIndex++] = 0;
translate+=glyphWidth;
}
}
glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, num*6, pVertList);
glVertexPointer(3, GL_FLOAT, 3*4, pVertList);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// glTexCoordPointer(2, GL_FLOAT, num*6, pTextureCoordList);
glTexCoordPointer(2, GL_FLOAT, 2*4, pTextureCoordList);
glDrawArrays(GL_TRIANGLES, 0, count*6);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
delete[] pVertList;
delete[] pTextureCoordList;
// glMatrixMode(GL_MODELVIEW);
// glPopMatrix();
if(doOrthoProj)
{
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
}
}
void GLFontRenderer::setScreenResolution(int screenWidth, int screenHeight)
{
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
}
void GLFontRenderer::setColor(float r, float g, float b, float a)
{
m_color[0] = r;
m_color[1] = g;
m_color[2] = b;
m_color[3] = a;
}

View File

@@ -0,0 +1,51 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef SNIPPET_FONT_RENDERER_H
#define SNIPPET_FONT_RENDERER_H
class GLFontRenderer
{
private:
static bool m_isInit;
static unsigned int m_textureObject;
static int m_screenWidth;
static int m_screenHeight;
static float m_color[4];
public:
static bool init();
static void print(float x, float y, float fontSize, const char* pString, bool forceMonoSpace=false, int monoSpaceWidth=11, bool doOrthoProj=true);
static void print_(float x, float y, float fontSize, const char* pString, bool forceMonoSpace=false, int monoSpaceWidth=11, bool doOrthoProj=true);
static void setScreenResolution(int screenWidth, int screenHeight);
static void setColor(float r, float g, float b, float a);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,143 @@
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2025 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PHYSX_SNIPPET_RENDER_H
#define PHYSX_SNIPPET_RENDER_H
#include "PxPhysicsAPI.h"
#include "foundation/PxPreprocessor.h"
#if PX_WINDOWS
#include <windows.h>
#pragma warning(disable: 4505)
#include <GL/glew.h>
#include <GL/freeglut.h>
#elif PX_LINUX_FAMILY
#if PX_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-identifier"
#endif
#include <GL/glew.h>
#include <GL/freeglut.h>
#if PX_CLANG
#pragma clang diagnostic pop
#endif
#elif PX_OSX
#include <GL/glew.h>
#include <GLUT/glut.h>
#else
#error platform not supported.
#endif
typedef void (*KeyboardCallback) (unsigned char key, const physx::PxTransform& camera);
typedef void (*RenderCallback) ();
typedef void (*ExitCallback) ();
namespace Snippets
{
class Camera;
void setupDefault(const char* name, Camera* camera, KeyboardCallback kbcb, RenderCallback rdcb, ExitCallback excb);
Camera* getCamera();
physx::PxVec3 computeWorldRayF(float xs, float ys, const physx::PxVec3& camDir);
PX_FORCE_INLINE physx::PxVec3 computeWorldRay(int xs, int ys, const physx::PxVec3& camDir)
{
return computeWorldRayF(float(xs), float(ys), camDir);
}
physx::PxU32 getScreenWidth();
physx::PxU32 getScreenHeight();
void enableVSync(bool vsync);
void startRender(const Camera* camera, float nearClip = 1.0f, float farClip = 10000.0f, float fov=60.0f, bool setupLighting=true);
void finishRender();
void print(const char* text);
class TriggerRender
{
public:
virtual bool isTrigger(physx::PxShape*) const = 0;
};
#if PX_SUPPORT_GPU_PHYSX
class SharedGLBuffer
{
public:
SharedGLBuffer();
~SharedGLBuffer();
void initialize(physx::PxCudaContextManager* contextManager);
void allocate(physx::PxU32 sizeInBytes);
void release();
void* map();
void unmap();
private:
physx::PxCudaContextManager* cudaContextManager;
void* vbo_res;
void* devicePointer;
public:
GLuint vbo; //Opengl vertex buffer object
physx::PxU32 size;
};
#endif
void initFPS();
void showFPS(int updateIntervalMS = 30, const char* info = NULL);
void renderDeformableVolume(physx::PxDeformableVolume* deformableVolume, const physx::PxVec4* deformedPositionsInvMass, bool shadows, const physx::PxVec3& color = physx::PxVec3(0.0f, 0.75f, 0.0f));
void renderActors(physx::PxRigidActor** actors, const physx::PxU32 numActors, bool shadows = false, const physx::PxVec3& color = physx::PxVec3(0.0f, 0.75f, 0.0f), TriggerRender* cb = NULL, bool changeColorForSleepingActors = true, bool wireframePass=true);
// void renderGeoms(const physx::PxU32 nbGeoms, const physx::PxGeometry* geoms, const physx::PxTransform* poses, bool shadows, const physx::PxVec3& color);
void renderGeoms(const physx::PxU32 nbGeoms, const physx::PxGeometryHolder* geoms, const physx::PxTransform* poses, bool shadows, const physx::PxVec3& color);
void renderMesh(physx::PxU32 nbVerts, const physx::PxVec3* verts, physx::PxU32 nbTris, const physx::PxU32* indices, const physx::PxVec3& color, const physx::PxVec3* normals = NULL, bool flipFaceOrientation = false);
void renderMesh(physx::PxU32 nbVerts, const physx::PxVec4* verts, physx::PxU32 nbTris, const physx::PxU32* indices, const physx::PxVec3& color, const physx::PxVec4* normals = NULL, bool flipFaceOrientation = false);
void renderMesh(physx::PxU32 nbVerts, const physx::PxVec4* verts, physx::PxU32 nbTris, const void* indices, bool hasSixteenBitIndices, const physx::PxVec3& color, const physx::PxVec4* normals = NULL, bool flipFaceOrientation = false, bool enableBackFaceCulling = true);
void DrawLine(const physx::PxVec3& p0, const physx::PxVec3& p1, const physx::PxVec3& color);
void DrawPoints(const physx::PxArray<physx::PxVec3>& pts, const physx::PxVec3& color, float scale);
void DrawPoints(const physx::PxArray<physx::PxVec3>& pts, const physx::PxArray<physx::PxVec3>& colors, float scale);
void DrawPoints(const physx::PxArray<physx::PxVec4>& pts, const physx::PxVec3& color, float scale);
void DrawPoints(const physx::PxArray<physx::PxVec4>& pts, const physx::PxArray<physx::PxVec3>& colors, float scale);
void DrawPoints(GLuint vbo, physx::PxU32 numPoints, const physx::PxVec3& color, float scale, physx::PxU32 coordinatesPerPoint = 3, physx::PxU32 stride = 4 * sizeof(float), size_t offset = 0);
void DrawLines(GLuint vbo, physx::PxU32 numPoints, const physx::PxVec3& color, float scale, physx::PxU32 coordinatesPerPoint = 3, physx::PxU32 stride = 4 * sizeof(float), size_t offset = 0);
void DrawIcosahedraPoints(const physx::PxArray<physx::PxVec3>& pts, const physx::PxVec3& color, float radius);
void DrawFrame(const physx::PxVec3& pt, float scale=1.0f);
void DrawBounds(const physx::PxBounds3& box);
void DrawBounds(const physx::PxBounds3& box, const physx::PxVec3& color);
void DrawMeshIndexedNoNormals(GLuint vbo, GLuint elementbuffer, GLuint numTriangles, const physx::PxVec3& color, physx::PxU32 stride = 4 * sizeof(float));
void DrawMeshIndexed(GLuint vbo, GLuint elementbuffer, GLuint numTriangles, const physx::PxVec3& color, physx::PxU32 stride = 6 * sizeof(float));
GLuint CreateTexture(physx::PxU32 width, physx::PxU32 height, const GLubyte* buffer, bool createMipmaps);
void UpdateTexture(GLuint texId, physx::PxU32 width, physx::PxU32 height, const GLubyte* buffer, bool createMipmaps);
void ReleaseTexture(GLuint texId);
void DrawRectangle(float x_start, float x_end, float y_start, float y_end, const physx::PxVec3& color_top, const physx::PxVec3& color_bottom, float alpha, physx::PxU32 screen_width, physx::PxU32 screen_height, bool draw_outline, bool texturing);
void DisplayTexture(GLuint texId, physx::PxU32 size, physx::PxU32 margin);
}
#endif //PHYSX_SNIPPET_RENDER_H