Skip to content

Commit 4ab457e

Browse files
committed
OpenGL texture, POSIX benchmark
1 parent f734a2e commit 4ab457e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1144
-197
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ C and C++ minimal examples. Asserts used wherever possible. Cheatsheets, tutoria
3636
1. [Linting tools](linting-tools.md)
3737
1. [Frama-C](frama-c/)
3838
1. [Boost](boost/)
39-
1. [CMake](cmake.md)
39+
1. [Build systems](build-systems.md)
40+
1. [CMake](cmake.md)
4041
1. [Flex and Bison](flex-bison/)
4142
1. [glibc](glibc/)
4243
1. [hello_world_cpp.cpp](hello_world_cpp.cpp)
@@ -52,6 +53,7 @@ C and C++ minimal examples. Asserts used wherever possible. Cheatsheets, tutoria
5253
1. [LAPACK](lapack/)
5354
1. [OpenCV](opencv/)
5455
1. [PLplot](plplot/)
56+
1. [Bullet physics](bullet/)
5557
1. [CONTRIBUTING](CONTRIBUTING.md)
5658
1. [TODO](TODO.md)
5759
1. [Bibliography](bibliography.md)

build-systems.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Build systems
2+
3+
- premake:

bullet.md

-17
This file was deleted.

bullet/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Makefile_many

bullet/Makefile_params

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# TODO get rid of this. Bullet headers are horribly coded for Linux:
2+
# the toplevel include all btBulletDynamicsCommon.h uses #include "subdir"
3+
# instead of the better #include "bullet/subdir".
4+
# So we are forced to add it to the search path.
5+
# Maybe some cmake magic would prevent that?
6+
I := -I/usr/include/bullet -I/usr/local/include/bullet
7+
LIBS := \
8+
-lBullet2FileLoader \
9+
-lBullet3Collision \
10+
-lBullet3Common \
11+
-lBullet3Dynamics \
12+
-lBullet3Geometry \
13+
-lBullet3OpenCL_clew \
14+
-lBulletCollision \
15+
-lBulletDynamics \
16+
-lBulletSoftBody \
17+
-lLinearMath

bullet/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Bullet
2+
3+
1. [Introduction](introduction.md)
4+
1. [Concepts](concepts.md)
5+
1. [Build](build.md)
6+
1. [Users](users.md)
7+
1. Examples
8+
1. [Hello world](hello_world.cpp)
9+
1. [TODO](TODO.md)

bullet/TODO.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TODO
2+
3+
- Stairs physics: http://gamedev.stackexchange.com/questions/74794/make-the-player-run-onto-stairs-smoothly

bullet/alternatives.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Alternatives
2+
3+
2009 comparison: <http://physxinfo.com/articles/?page_id=154>
4+
5+
Open source:
6+
7+
- ODE
8+
- Newton
9+
10+
Proprietary:
11+
12+
- PhysX: bought by NVIDIA from a Swiss company. NVIDIA GPU acceleration.
13+
- 2015 Flex demo with lots of water / cloth: <https://www.youtube.com/watch?v=pfonMfP__Ks>
14+
- Havoc: first bought by Intel from an Irish company, then Microsoft.
15+
- Has GPU support.
16+
- Used by Assassin's Creed (Ubisoft)
17+
- Havoc destruction
18+
- car demo 2015: https://www.youtube.com/watch?v=iiRR6DtR1z8
19+
- 2010 demo: https://www.youtube.com/watch?v=cIcg5eotZlY
20+
21+
2D:
22+
23+
- Box2D
24+
25+
## Fluids
26+
27+
- https://github.com/rchoetzlein/fluids3
28+
- https://github.com/erwincoumans/fluids_v3
29+
- https://en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics
30+
- Windows focused build, https://github.com/erwincoumans/fluids_v3/pull/2 might port it to Linux

bullet/build.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Build
2+
3+
Tested on Ubuntu 2.83.5 in Ubuntu 15.10.
4+
5+
Just forget that `premake` build, use the much more popular CMake and be done with it! Why both exist: <https://github.com/bulletphysics/bullet3/issues/600>
6+
7+
git clone https://github.com/bulletphysics/bullet3
8+
git checkout 2.83.5
9+
mkdir -p build
10+
cd build
11+
cmake .. -DBUILD_SHARED_LIBS=ON
12+
make
13+
sudo make install
14+
15+
Run examples:
16+
17+
cd build/examples
18+
./ExampleBrowser/App_ExampleBrowser
19+
./HelloWorld/App_HelloWorld
20+
21+
If you don't use:
22+
23+
-DBUILD_SHARED_LIBS=ON
24+
25+
only the static `.a` files are generated, and you will get link errors if you try to use them with `-lBulletSomething`.
26+
27+
The example browser allows you to:
28+
29+
- view simulations OpenGL
30+
- mouse drag objects around
31+
- move camera with mouse wheel or Ctrl + mouse drag
32+
33+
Make dynamic libraries: <https://github.com/bulletphysics/bullet3/issues/447>
34+
35+
TODO: compile examples without the example browser.

bullet/concepts.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Concepts
2+
3+
- acceleration: continuous speed change, ignores mass
4+
- force: continuous speed change, considers mass
5+
- impulse: instantaneous speed change, considers mass
6+
- velocity change: instantaneous speed change, ignores mass
7+
- rag doll physics: https://www.youtube.com/watch?v=XKuleYcVF-U
8+
- https://en.wikipedia.org/wiki/Ragdoll_physics
9+
- http://www.havok.com/physics/
10+
I distinctly remember sing that on a CS:GO game in 2016-04-15, when a dead body fell from a platform
11+
- AABB axis-aligned bounding-box http://www.gamasutra.com/view/feature/131833/when_two_hearts_collide_.php

bullet/configure

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
sudo apt-get update
3+
sudo apt-get install -y libbullet-dev

bullet/hello_world.cpp

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include <btBulletDynamicsCommon.h>
5+
6+
int main() {
7+
int i, j;
8+
9+
btDefaultCollisionConfiguration* collisionConfiguration
10+
= new btDefaultCollisionConfiguration();
11+
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
12+
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
13+
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
14+
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(
15+
dispatcher, overlappingPairCache, solver, collisionConfiguration);
16+
17+
dynamicsWorld->setGravity(btVector3(0, -10, 0));
18+
btCollisionShape* groundShape = new btBoxShape(
19+
btVector3(btScalar(50.0), btScalar(50.0), btScalar(50.0)));
20+
btAlignedObjectArray<btCollisionShape*> collisionShapes;
21+
collisionShapes.push_back(groundShape);
22+
btTransform groundTransform;
23+
groundTransform.setIdentity();
24+
groundTransform.setOrigin(btVector3(0, 0, 0));
25+
26+
// Shpere at position 0, 10, 0.
27+
{
28+
btCollisionShape *colShape = new btSphereShape(btScalar(1.0));
29+
collisionShapes.push_back(colShape);
30+
btTransform startTransform;
31+
startTransform.setIdentity();
32+
startTransform.setOrigin(btVector3(0, 10, 0));
33+
btVector3 localInertia(0, 0, 0);
34+
btScalar mass(1.0f);
35+
colShape->calculateLocalInertia(mass, localInertia);
36+
btDefaultMotionState *myMotionState = new btDefaultMotionState(startTransform);
37+
btRigidBody *body = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(
38+
mass, myMotionState, colShape, localInertia));
39+
dynamicsWorld->addRigidBody(body);
40+
}
41+
42+
// Main loop. Update state and print it.
43+
for (i = 0; i < 100; ++i) {
44+
dynamicsWorld->stepSimulation(1.0f / 60.0f, 10);
45+
for (j = dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; --j) {
46+
btCollisionObject *obj = dynamicsWorld->getCollisionObjectArray()[j];
47+
btRigidBody *body = btRigidBody::upcast(obj);
48+
btTransform trans;
49+
if (body && body->getMotionState()) {
50+
body->getMotionState()->getWorldTransform(trans);
51+
} else {
52+
trans = obj->getWorldTransform();
53+
}
54+
printf("%d = %7.3f, %7.3f, %7.3f\n",
55+
j,
56+
float(trans.getOrigin().getX()),
57+
float(trans.getOrigin().getY()),
58+
float(trans.getOrigin().getZ()));
59+
}
60+
}
61+
62+
// Cleanup.
63+
for (i = dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; --i) {
64+
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];
65+
btRigidBody* body = btRigidBody::upcast(obj);
66+
if (body && body->getMotionState()) {
67+
delete body->getMotionState();
68+
}
69+
dynamicsWorld->removeCollisionObject( obj );
70+
delete obj;
71+
}
72+
for (i = 0; i < collisionShapes.size(); ++i) {
73+
btCollisionShape* shape = collisionShapes[i];
74+
collisionShapes[i] = 0;
75+
delete shape;
76+
}
77+
delete dynamicsWorld;
78+
delete solver;
79+
delete overlappingPairCache;
80+
delete dispatcher;
81+
delete collisionConfiguration;
82+
collisionShapes.clear();
83+
}

bullet/introduction.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Introduction
2+
3+
## C API
4+
5+
Bullet is written in C++, and exposes only a C++ API.
6+
7+
A C API has been somewhat considered: <https://github.com/bulletphysics/bullet3/issues/130>
8+
9+
## Android
10+
11+
- <http://stackoverflow.com/questions/6004381/ideas-for-physics-for-rolling-dice>
12+
- <http://stackoverflow.com/questions/1034253/are-there-any-decent-physics-engines-for-android>
13+
14+
## 2D
15+
16+
TODO: efficient compared to say, Box2D?
17+
18+
- official example classified under experiments in the example browser <https://github.com/bulletphysics/bullet3/blob/2.83/examples/Planar2D/Planar2D.cpp>
19+
- <http://gamedev.stackexchange.com/questions/6130/is-it-worth-it-to-use-bullet-for-2d-physics-instead-of-box2d-for-the-sake-of-lea>
20+
- 2D demo https://www.youtube.com/watch?v=CsPgMmgsU7E
21+
22+
## History
23+
24+
Library creator worked at:
25+
26+
- Havok
27+
- Sony
28+
- AMD (on Bullet)
29+
- Google (on Bullet)
30+
31+
<https://www.linkedin.com/in/erwincoumans>
32+
33+
<https://twitter.com/erwincoumans>

bullet/users.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Users
2+
3+
Notables who uses Bullet.
4+
5+
- Blender <https://wiki.blender.org/index.php/User:Sculptorjim/Game_Engine/Physics>
6+
- libgdx: <https://github.com/libgdx/libgdx/wiki/Bullet-physics>

c-vs-cpp.md

+26-7
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,35 @@ All of those features allow to:
2121

2222
at the cost of:
2323

24-
- adding huge complexity to the language (probably at least doubles the complexity).
24+
- adding huge complexity to the language.
2525

26-
The problem is that individual features sometimes interact in ways which are not obvious to understand, so the complexity growth is exponential per feature.
26+
The C++ standards have twice as many pages as the C standards.
2727

28-
- making it harder to track what assembly code is generated thus:
28+
- harder to track what assembly code is generated thus:
2929

30-
- making it harder to write very efficient code
30+
- harder to write very efficient code
3131

32-
- generating executables that are very large
32+
- generated executables are very large and compilation is slow
3333

34-
For exmple, at one point I had a 7k line C file whose assembly was 8k lines, but a 7k C++ file generated 55k assembly code lines!!
34+
For exmple, at one point I had a 7k line C file whose assembly was 8k lines, but a 7k C++ file generated 55k assembly code lines!
3535

36-
All things considered, C++ offers huge productivity boosts over C *once you learn it*... It should be used on any new project, except if code efficiency is absolutelly crucial, and even in those cases it might be worth it to have a C++ project that use C only features for the 20% critical sections.
36+
- harder to interface with other languages because of name mangling.
37+
38+
`extern C` reduces the pain a bit: http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c/30526795#30526795
39+
40+
All things considered, C++ offers huge productivity boosts over C *once you learn it*...
41+
42+
It should be used on any new project, except if code efficiency is absolutely crucial, and even in those cases it might be worth it to have a C++ project that use C only features for the 20% critical sections.
43+
44+
## C++11 N3337 standard draft Annex C
45+
46+
Not all behaviour changes in C++ from C are new features!
47+
48+
Some are just deprecation of archaic C ugliness.
49+
50+
This section of the C++ standard lists those differences.
51+
52+
Some examples:
53+
54+
- `static struct` definitions deprecated: <http://stackoverflow.com/questions/7259830/why-and-when-to-use-static-structures-in-c-programming>
55+
- char literals `a` are... chars, not int: <http://stackoverflow.com/questions/433895/why-are-c-character-literals-ints-instead-of-chars>

c/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1. [main function](main_function.c)
1818
1. Data
1919
1. [Identifier](identifier.c)
20+
1. [Uninitialized variable](uninitialized_variable.c)
2021
1. [Types](types.c)
2122
1. [Basic types](basic_types.md)
2223
1. [Incomplete types](incomplete_type.c)

c/interactive/timespec_get.c

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1+
/*
2+
C11 for clock_gettime
3+
http://stackoverflow.com/questions/361363/how-to-measure-time-in-milliseconds-using-ansi-c/36095407#36095407
4+
5+
Vs clock: http://stackoverflow.com/questions/12392278/measure-time-in-linux-getrusage-vs-clock-gettime-vs-clock-vs-gettimeofday
6+
All we know about the clock output is that dividing it by
7+
*/
8+
19
#include <stdio.h>
210
#include <stdlib.h>
311
#include <time.h>
412

5-
static long get_nanos() {
13+
/*
14+
We use double because time_t can be either floating point or integer.
15+
POSIX guarantees that it is an integer, we could use uintmax_t then.
16+
*/
17+
static long double get_nanos(void) {
618
struct timespec ts;
719
timespec_get(&ts, TIME_UTC);
8-
return (long)ts.tv_sec * 1000000000L + ts.tv_nsec;
20+
return ts.tv_sec * 1e9 + ts.tv_nsec;
921
}
1022

11-
int main() {
12-
long nanos;
13-
long last_nanos;
14-
long start;
23+
int main(void) {
24+
long double last_nanos;
25+
long double nanos;
26+
long double start;
1527
nanos = get_nanos();
1628
last_nanos = nanos;
1729
start = nanos;
1830
while (1) {
1931
nanos = get_nanos();
20-
if (nanos - last_nanos > 1000000L) {
21-
printf("current nanos: %ld\n", nanos - start);
32+
if (nanos - last_nanos > 1e7) {
33+
printf("%Lf\n", nanos - start);
2234
last_nanos = nanos;
2335
}
2436
}

0 commit comments

Comments
 (0)