Convert Figma logo to code with AI

NVIDIAGameWorks logoPhysX

NVIDIA PhysX SDK

3,152
796
3,152
321

Top Related Projects

12,540

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

8,069

Box2D is a 2D physics engine for games

2D physics engine for games

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.

Quick Overview

NVIDIA PhysX is an open-source real-time physics engine used in various applications, including video games, simulations, and robotics. It provides a robust set of tools for simulating rigid body dynamics, fluid dynamics, cloth, and particle systems, allowing developers to create realistic and interactive physical environments.

Pros

  • High performance and optimized for GPU acceleration
  • Cross-platform support (Windows, Linux, macOS, and game consoles)
  • Extensive feature set covering various physics simulations
  • Active development and support from NVIDIA

Cons

  • Steep learning curve for beginners
  • Documentation can be overwhelming due to the extensive feature set
  • Some advanced features may require NVIDIA hardware for optimal performance
  • Large codebase can be challenging to navigate and modify

Code Examples

  1. Creating a basic rigid body:
PxRigidDynamic* createDynamic(const PxTransform& t, const PxGeometry& geometry, const PxVec3& velocity=PxVec3(0))
{
    PxRigidDynamic* dynamic = PxCreateDynamic(*gPhysics, t, geometry, *gMaterial, 10.0f);
    dynamic->setAngularDamping(0.5f);
    dynamic->setLinearVelocity(velocity);
    gScene->addActor(*dynamic);
    return dynamic;
}
  1. Applying force to a rigid body:
void applyForce(PxRigidBody* body, const PxVec3& force)
{
    body->addForce(force);
}
  1. Creating a joint between two rigid bodies:
PxRevoluteJoint* createRevoluteJoint(PxRigidActor* actor0, const PxTransform& localFrame0, 
                                     PxRigidActor* actor1, const PxTransform& localFrame1)
{
    return PxRevoluteJointCreate(*gPhysics, actor0, localFrame0, actor1, localFrame1);
}

Getting Started

To get started with PhysX, follow these steps:

  1. Clone the repository:

    git clone https://github.com/NVIDIAGameWorks/PhysX.git
    
  2. Build the project using CMake:

    cd PhysX
    mkdir build && cd build
    cmake ..
    cmake --build .
    
  3. Include PhysX in your project and initialize it:

#include "PxPhysicsAPI.h"

using namespace physx;

PxDefaultAllocator gAllocator;
PxDefaultErrorCallback gErrorCallback;
PxFoundation* gFoundation = NULL;
PxPhysics* gPhysics = NULL;

void initPhysX()
{
    gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
    gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale());
}

Competitor Comparisons

12,540

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Pros of Bullet

  • Open-source and free for commercial use
  • More flexible and customizable
  • Supports a wider range of platforms and programming languages

Cons of Bullet

  • Less optimized for high-performance scenarios
  • Smaller community and less documentation compared to PhysX
  • Fewer advanced features out-of-the-box

Code Comparison

Bullet

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);

PhysX

PxDefaultAllocator allocator;
PxDefaultErrorCallback errorCallback;
PxFoundation* foundation = PxCreateFoundation(PX_PHYSICS_VERSION, allocator, errorCallback);
PxPhysics* physics = PxCreatePhysics(PX_PHYSICS_VERSION, *foundation, PxTolerancesScale());
PxScene* scene = physics->createScene(PxSceneDesc(physics->getTolerancesScale()));

Both libraries offer similar functionality, but PhysX provides a more streamlined API with fewer lines of code required for basic setup. Bullet offers more granular control over the simulation components, which can be beneficial for advanced users but may require more initial setup.

8,069

Box2D is a 2D physics engine for games

Pros of Box2D

  • Lightweight and easy to integrate into smaller projects
  • Simpler API, making it more accessible for beginners
  • Open-source with a permissive license (zlib)

Cons of Box2D

  • Limited to 2D physics simulations
  • Less advanced features compared to PhysX
  • Smaller community and fewer resources available

Code Comparison

Box2D:

b2World world(gravity);
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
b2Body* body = world.CreateBody(&bodyDef);
world.Step(timeStep, velocityIterations, positionIterations);

PhysX:

PxPhysics* physics = PxCreatePhysics(PX_PHYSICS_VERSION, *foundation, PxTolerancesScale());
PxScene* scene = physics->createScene(sceneDesc);
PxRigidDynamic* body = physics->createRigidDynamic(PxTransform(PxVec3(0, 0, 0)));
scene->addActor(*body);
scene->simulate(timeStep);

Box2D is more straightforward and requires less setup, while PhysX offers more advanced features and 3D capabilities. Box2D is ideal for 2D games and simpler projects, whereas PhysX is better suited for complex 3D simulations and AAA game development.

2D physics engine for games

Pros of LiquidFun

  • Specialized for fluid and soft body simulations
  • Lightweight and optimized for mobile devices
  • Open-source with a permissive Apache 2.0 license

Cons of LiquidFun

  • Limited feature set compared to PhysX
  • Less active development and community support
  • Primarily focused on 2D physics

Code Comparison

LiquidFun:

b2World world(gravity);
b2ParticleSystemDef particleSystemDef;
b2ParticleSystem* particleSystem = world.CreateParticleSystem(&particleSystemDef);
b2ParticleGroupDef pd;
pd.flags = b2_waterParticle;
particleSystem->CreateParticleGroup(pd);

PhysX:

PxPhysics* physics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale());
PxScene* scene = physics->createScene(sceneDesc);
PxRigidDynamic* body = physics->createRigidDynamic(PxTransform(PxVec3(0, 0, 0)));
scene->addActor(*body);

Summary

LiquidFun excels in fluid simulations and mobile optimization but has a narrower focus. PhysX offers a more comprehensive physics engine with broader platform support and features. The choice depends on specific project requirements and target platforms.

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.

Pros of JoltPhysics

  • Better performance, especially for large-scale simulations
  • More modern codebase with C++17 support
  • Easier to integrate and use in projects

Cons of JoltPhysics

  • Less mature and battle-tested compared to PhysX
  • Smaller community and ecosystem
  • Fewer advanced features and specialized solvers

Code Comparison

JoltPhysics:

JPH::BodyInterface &body_interface = physics_system.GetBodyInterface();
JPH::Body *body = body_interface.CreateAndAddBody(body_creation_settings, JPH::EActivation::Activate);

PhysX:

PxRigidDynamic* body = PxCreateDynamic(*gPhysics, transform, geometry, *gMaterial, 10.0f);
gScene->addActor(*body);

Both libraries offer similar functionality for creating and adding physics bodies, but JoltPhysics uses a more modern C++ approach with its interface design. PhysX relies more on global objects and pointers, while JoltPhysics uses references and a more object-oriented style.

JoltPhysics generally requires less boilerplate code and has a more intuitive API, which can lead to cleaner and more maintainable physics implementations in game projects.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

NVIDIA PhysX SDK 4.1

Copyright (c) 2021 NVIDIA Corporation. All rights reserved.

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.

PhysX 5 Now Available

The NVIDIA PhysX SDK version 5 is now available here. This repository will continue to be available to support legacy users. We encourage all new projects to start on the new release.

Introduction

Welcome to the NVIDIA PhysX SDK source code repository. This depot includes the PhysX SDK and the Kapla Demo application.

The NVIDIA PhysX SDK is a scalable multi-platform physics solution supporting a wide range of devices, from smartphones to high-end multicore CPUs and GPUs. PhysX is already integrated into some of the most popular game engines, including Unreal Engine, and Unity3D. PhysX SDK on developer.nvidia.com.

Documentation

Please see Release Notes for updates pertaining to the latest version.

The full set of documentation can also be found in the repository under physx/documentation or online at http://gameworksdocs.nvidia.com/simulation.html

Platform specific information can be found here:

Quick Start Instructions

Requirements:

  • Python 2.7.6 or later
  • CMake 3.12 or later

To begin, clone this repository onto your local drive. Then change directory to physx/, run ./generate_projects.[bat|sh] and follow on-screen prompts. This will let you select a platform specific solution to build. You can then open the generated solution file with your IDE and kick off one or more configuration builds.

To build and run the Kapla Demo see kaplademo/README.md.

Acknowledgements

This depot contains external third party open source software copyright their respective owners. See kaplademo/README.md and externals/README.md for details.