A small data-oriented and SIMD-optimized 3D rigid body physics library.

Overview

nudge

Nudge is a small data-oriented and SIMD-optimized 3D rigid body physics library.

For more information, see: http://rasmusbarr.github.io/blog/dod-physics.html

FAQ

The sample application is crashing. Why?

Most likely, your CPU doesn't support AVX2 and/or FMA. The project files are set to compile with AVX2 and FMA support and you need to disable it in build settings.

Xcode: Set "Enable Additional Vector Extensions" to your supported level. Remove -mfma and -mno-fma4 from "Other C Flags".

Visual Studio: Set "Enable Enhanced Instruction Set" under code generation to your supported level. Remove __FMA__ from the preprocessor definitions.

Comments
  • Adding Linux support

    Adding Linux support

    Hi @rasmusbarr ! Wonderful project! Coding a mini physic engine in a single .cpp file must be a tough challenge!

    However, I posted this just to say that I've compiled it for Linux (I'm using Ubuntu 16.04 LTS 64bits), with the following changes to main.cpp:

    #ifdef __APPLE__
    #include <GLUT/GLUT.h>
    #include <OpenGL/gl.h>
    #elif _MSC_VER
    #include <GLUT/glut.h>
    #include <gl/gl.h>
    #else // linux
    #include <GL/glut.h>
    #include <GL/gl.h>
    #endif
    // Not sure about mingw (if it's like linux or like _MSC_VER)
    

    I just used this command line from the example folder::

    g++ --std=c++11 main.cpp -o main -I"./" -I"../" ../nudge.cpp -lglut -lGL
    # Or:
    # clang++ --std=c++11 main.cpp -o main -I"./" -I"../" ../nudge.cpp -lglut -lGL
    #  optionally use --march=haswell (Using 8-wide AVX FMA: Enabled)
    

    Without --std=c++11, g++ produces a lot of errors. Strangely, using clang It compiles with only the following warnings:

    ../nudge.cpp:2928:41: warning: default template arguments for a function
          template are a C++11 extension [-Wc++11-extensions]
    template<unsigned data_stride, unsigned index_stride = 1, class T>
                                            ^              ~
    ../nudge.cpp:2973:41: warning: default template arguments for a function
          template are a C++11 extension [-Wc++11-extensions]
    template<unsigned data_stride, unsigned index_stride = 1, class T>
                                            ^              ~
    ../nudge.cpp:3030:41: warning: default template arguments for a function
          template are a C++11 extension [-Wc++11-extensions]
    template<unsigned data_stride, unsigned index_stride = 1, class T>
    

    However these are just details. Thank you for this project!

    opened by Flix01 10
  • [Question] Assertion `count <= (1 << 13)' failed.

    [Question] Assertion `count <= (1 << 13)' failed.

    Hi again.

    Today I'm playing a bit with the nudge demo, and I've hit the assertion in the title when I increase the total number of bodies. The comment in nudge.cpp says:

    // Too many colliders. 2^13 is currently the maximum.
    

    The question is: Is it related to the number of bodies or to the number of collisions between bodies?

    Basically my settings are:

    #define NUM_BOXES 1024*4
    #define NUM_SPHERES 1024*4 //1024*3 works fine
    #define MAX_BODY_COUNT (NUM_BOXES+NUM_SPHERES+1) // +1 = ground box
    static const unsigned max_body_count = MAX_BODY_COUNT;
    static const unsigned max_box_count = NUM_BOXES+1;      // +1 = ground box
    static const unsigned max_sphere_count = NUM_SPHERES;
    #define ARENA_SIZE (32*MAX_BODY_COUNT*MAX_BODY_COUNT/4)
    

    P.S. However if I use 1024*4 boxes and 1024*3 spheres it works perfectly. This is a .gif with:

    #   define NUM_SIMULATION_STEPS 1
    #   define NUM_SIMULATION_ITERATIONS 5 // These seem to be enough to me...
    // I've also doubled all the body masses
    

    nudge This single .cpp physics library seems really powerful :+1: !

    opened by Flix01 2
  • Possible copy-paste error

    Possible copy-paste error

    Hey,

    Skimming through your code and found something that seemed a bit strange, though I don't understand the structure well enough yet to say its an error for sure. But in the loop around line 3778, I saw this:

    		a -= colliders.boxes.count;
    		b -= colliders.boxes.count;
    		
    		SphereCollider box = colliders.spheres.data[a];
    		SphereCollider sphere = colliders.spheres.data[b];
    

    I'd imagine it should be sphere in place of box in those lines?

    opened by Srekel 1
  • Build fails when using GCC 8

    Build fails when using GCC 8

    Compiling with GCC 8 causes a compile error:

    ../../nudge.cpp:454:56: error: cannot convert ‘nudge::simd8_float {aka __vector(8) float}’ to ‘__m256i {aka __vector(4) long long int}’ for argument ‘1’ to ‘__m256i _mm256_permute2x128_si256(__m256i, __m256i, int)’ return _mm256_permute2x128_si256(x, x, i0 | (i1 << 4));

    Using clang/LLVM 5 works just fine. Not yet sure if this is a bug in gcc or not.

    opened by Ristovski 1
  • Any intent to develop this library further?

    Any intent to develop this library further?

    @rasmusbarr in case it's not, would you like to give some pointers regarding the convex collisions, cache information about the previous contacts and other issues listed in your blog post under the "Future work" section?

    opened by ompadu 0
  • boxCollider size

    boxCollider size

    It is not bug but I think it is somewhat misleading that boxCollider's real extent seem to be size*2. So it is analogous to sphere's radius. I have checked ODE box create gets real side lengths. Bullet's box collider gets halfExtent. https://github.com/rasmusbarr/nudge/blob/master/nudge.h#L57

    opened by attilaz 0
  • Interesting lib design

    Interesting lib design

    This is not an issue, I just didn't manage to add a comment on your article with a twitter account...

    I really like this lean and mean API design. Probably needs a higher level interface for adding removing bodies/colliders etc but it is very easy to add on top of this. And I think an interface like this is way better than traditional OO interfaces like bullet3d with a hundred .h files and tons of classes with public functions and of course ( with private/protected stuffz that a user didn't really care about)

    About the multithreading, how about an interface like this?

    generateJobs(JobsData* j); bool doJob(JobsData* j, int processJobCount); void waitForJobs(JobsData* j)

    threads could call doJob so JobsData needs to be thread-safe, I think an atomic int could be enough for stepping. JobsData could also store number of finished jobs with atomic int for waiting, or could implementing with some higher level multithreading primitive to avoid spinning.

    or instead of the two fuction ( doJob, waitForJobs) maybe bool doJob(JobsData* j, int processJobCount, bool waitForFinish);

    opened by attilaz 2
Owner
null
An object oriented C++ wrapper for CURL (libcurl)

curlcpp An object-oriented C++ wrapper for cURL tool If you want to know a bit more about cURL and libcurl, you should go on the official website http

Giuseppe Persico 549 Jan 9, 2023
H2O - the optimized HTTP/1, HTTP/2, HTTP/3 server

H2O - an optimized HTTP server with support for HTTP/1.x, HTTP/2 and HTTP/3 (experimental) Copyright (c) 2014-2019 DeNA Co., Ltd., Kazuho Oku, Tatsuhi

H2O 10.2k Dec 30, 2022
An optimized Webcash mining daemon.

Webminer An experimental vector-accelerated CPU miner for the Webcash electronic payment network. Webminer is tested and known to work on recent versi

Mark Friedenbach 20 Nov 30, 2022
Warp speed Data Transfer (WDT) is an embeddedable library (and command line tool) aiming to transfer data between 2 systems as fast as possible over multiple TCP paths.

WDT Warp speed Data Transfer Design philosophy/Overview Goal: Lowest possible total transfer time - to be only hardware limited (disc or network bandw

Facebook 2.7k Dec 31, 2022
Small and fast cross-platform networking library, with support for messaging, IPv6, HTTP, SSL and WebSocket.

frnetlib Frnetlib, is a cross-platform, small and fast networking library written in C++. There are no library dependencies (unless you want to use SS

Fred Nicolson 23 Nov 25, 2022
Simple and small reliable UDP networking library for games

libquicknet Simple and small reliable UDP networking library for games ❗ libquicknet is under development and not suitable for production code ❗ The m

null 25 Oct 26, 2022
A small, minimal HTTP library written in C.

trail - A small, minimal HTTP library written in C. trail is a small, minimal, and easy-to-use HTTP library written in C that supports GET and POST re

null 7 Nov 20, 2022
This is a small library that allows to stream a Dear ImGui scene to multiple WebSocket clients at once

imgui-ws Dear ImGui over WebSockets This is a small library that allows to stream a Dear ImGui scene to multiple WebSocket clients at once. This is ac

Georgi Gerganov 327 Dec 30, 2022
Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.

Graphical small-internet client for windows, linux, MacOS X and BSDs. Supports gemini, http, https, gopher, finger.

Felix Queißner 569 Dec 30, 2022
Simple, small, C++ embeddable webserver with WebSockets support

Seasocks - A tiny embeddable C++ HTTP and WebSocket server for Linux Features Simple C++ API Serves static content from disk API for building WebSocke

Matt Godbolt 624 Jan 3, 2023
Open source file system for small embedded systems

STORfs Open Source File System Release Version 1.0.2 Created by: KrauseGLOBAL Solutions, LLC What is STORfs? STORfs is an open source flash file syste

null 17 Jul 26, 2022
A small C utility that encodes bytes into whitespace characters.

Whitespacer - a whitespace encoder/decoder What is it? Whitespacer is an encoder and decoder that encodes bytes into whitespace characters

Greg Foletta 27 Aug 27, 2022
Small utility that leverages eBPF to dump the traffic of a unix domain socket

UnixDump UnixDump is a small eBPF powered utility that can be used to dump unix socket traffic. System requirements This project was developed on a Ub

Guillaume Fournier 8 Nov 19, 2022
A software C library designed to extract data attributes from network packets, server logs, and from structured events in general, in order to make them available for analysis

MMT-DPI A software C library desinged to extract data attributes from network packets, server logs, and from structured events in general, in odrder t

Montimage 3 Nov 9, 2022
Steve's Persistent Unreal Data library

SPUD: Steve's Persistent Unreal Data library What is it? SPUD is a save game and streaming level persistence solution for Unreal Engine 4. The 2 main

Steve Streeting 167 Jan 6, 2023
Realtime Client/Server app for Linux allowing joystick (and other HID) data to be transferred over a local network

netstick What is it? Netstick enables HID devices to be remotely connected between a "client" and "server" over a network connection. It allows the ke

null 33 Nov 6, 2022
Data Plane Development Kit

DPDK is a set of libraries and drivers for fast packet processing. It supports many processor architectures and both FreeBSD and Linux. The DPDK uses

DPDK 2.2k Dec 29, 2022
Steve's Unreal Quest System: data-driven quest system for UE4

Steve's Unreal Quest System (SUQS) What Is It? SUQS is a simple, data-driven quest system for UE4. It helps you define quest structures for your game,

Steve Streeting 66 Dec 11, 2022
Upload arbitrary data via Apple's Find My network.

Send My allows you to to upload abritrary data from devices without an internet connection by (ab)using Apple's Find My network. The data is broadcasted via Bluetooth Low Energy and forwarded by nearby Apple devices.

Positive Security 1.5k Jan 2, 2023