Incomplete bullet physical engine guide in Linux

Source: Internet
Author: User
Document directory
  • Basic items
  • Merging item
  • Physical item
Bullet Introduction

Bullet homepage. Download the latest version. For a brief Chinese introduction, see Baidu encyclopedia. Some stories that may prompt you to choose bullet are mentioned in previous articles. Refer to the beginning here-Why choose bullet.

Main features:

* The code is built in C ++ and complies with the zlib open-source protocol. It can be used for various commercial purposes for free. Cross-platform support, including PS3, Xbox 360...

* Discrete or continuous collision detection. Collision models include irregular objects and basic graphs;

* Fast and stable solving of Rigid Body Dynamics constraints, slide and comparative simulation;

* Simulation of soft objects such as clothes and ropes, supporting constraints;

* Rich plug-in support, including Maya, blender...

Environment: ubuntu12.04 gcc4.6

Install

First, use git to clone the code.

Git clone SVN checkout http://bullet.googlecode.com/svn/trunk/

Then CD the terminal to the directory, or the set:

./Configure

Make

Sudo make install

After the execution, demos is compiled and the terminal is running.

./Allbulletdemos/appallbulletdemos



You can click Next scene on the right to switch the demo.

Hello World

Refer to the helloworld tutorial on the official wiki to create main. cpp.

#include <iostream> #include <bullet/btBulletDynamicsCommon.h> int main (void){         btBroadphaseInterface* broadphase = new btDbvtBroadphase();         btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();        btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);         btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;         btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);         dynamicsWorld->setGravity(btVector3(0,-10,0));          btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);         btCollisionShape* fallShape = new btSphereShape(1);          btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));        btRigidBody::btRigidBodyConstructionInfo                groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));        btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);        dynamicsWorld->addRigidBody(groundRigidBody);          btDefaultMotionState* fallMotionState =                new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));        btScalar mass = 1;        btVector3 fallInertia(0,0,0);        fallShape->calculateLocalInertia(mass,fallInertia);        btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);        btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);        dynamicsWorld->addRigidBody(fallRigidBody);          for (int i=0 ; i<300 ; i++) {                dynamicsWorld->stepSimulation(1/60.f,10);                 btTransform trans;                fallRigidBody->getMotionState()->getWorldTransform(trans);                 std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;        }         dynamicsWorld->removeRigidBody(fallRigidBody);        delete fallRigidBody->getMotionState();        delete fallRigidBody;         dynamicsWorld->removeRigidBody(groundRigidBody);        delete groundRigidBody->getMotionState();        delete groundRigidBody;          delete fallShape;         delete groundShape;          delete dynamicsWorld;        delete solver;        delete collisionConfiguration;        delete dispatcher;        delete broadphase;         return 0;}

Create cmakelists.txt

cmake_minimum_required(VERSION 2.8)PROJECT (HELLO)SET(SRC_LIST main.cpp)INCLUDE_DIRECTORIES(/usr/local/include/bullet)LINK_LIBRARIES(BulletDynamics    BulletCollision    LinearMath    )ADD_EXECUTABLE(hello ${SRC_LIST})

Terminal execution

Cmake.

Make

The running effect is as follows:

It can be seen from the Wiki that this is a parabolic simulation of a sphere.

Note that bullet is only responsible for computing! (It is said that the latest bullet has used opencl to place computing tasks to the GPU), while graphics rendering requires other rendering engines, such as OpenGL and ogre.

Glossary

The following table is also the official wiki from bullet.

Basic items

Scalar

A single volume is actually a number, a linear value. For example, 1.0,. A single volume can be used to form other items.

For example, the distance between two points is a single volume, and the speed is also a single volume.

Vector, 3-dimensional vector, 4-dimensional vector-Vector

A vector is a distance with a direction.

Based on the spatial dimension, vectors can be divided into 2, 3, and 4 dimensions.

The length of a three-dimensional vector can be used for computation based on the hook theorem. It corresponds to the lengh method of the vector. The root algorithm consumes a lot of complexity, so the Vector class has leng22 (), the result is that there is no root.

For example:

#define THRESHOLD 20#define THRESHOLD_SQ THRESHOLD*THRESHOLD // Your compiler will optimise this out laterVector3 a(12,14,20);if(THRESHOLD > a.length()) { do_something; } // This one is much slowerif(THRESHOLD_SQ > a.length2()) {do_something; } // Use this version if you can

Euler's coordinate-Euler co-ordinates

It is a three-dimensional coordinate. vector3 (x, y, z) represents a point in a three-dimensional space.

Polar Coordinates-polar co-ordinates

Take a fixed point O in the plane, called the pole, and lead a ray ox, called the polar axis. then select a length unit and the positive direction of the angle (usually counterclockwise ). For any M point in the plane, P indicates the length of the OM of the line segment. θ indicates the angle from ox to Om, the ordered number pair (p, θ) is called the polar coordinate of the point M, and the created coordinate system is called the polar coordinate system.

The polar expression of the circle in the plane is:

X = P Cos (θ); y = P Sin (θ)

The polar expression of the space sphere is:

Ouarla-Euler angle

The Euclidean angle is mainly used to describe a rotation. The rotation of a point in space can usually be described as follows: First rotate an angle around X, then rotate an angle around Y axis, and then rotate an angle around Z axis, finally, the final coordinates are obtained.

Because computers are linear computing monsters ~ It may be a very painful situation when you use the ouarla corner to rotate-Halloween lock YouTube
Video explaining gimbal lock

To avoid Halloween locks, you can set the rotation sequence of the rotation axis.

Another method is to use tuples.

Quad-Quaternion

The following table lists the general definitions of the four elements:
Q = W + Xi + YJ + ZK

Where V = (x, y, z) is a vector, W is a scalar, although V is a vector, it cannot be simply understood as a vector of 3D space, it is a vector in a 4-dimensional space and is not easy to imagine.
In general, quaternion describes a rotation axis and a rotation angle. The rotation axis and the angle can be obtained through quaternion: toangleaxis conversion. Of course, you can also specify an angle and a rotation axis to construct a quaternion. This angle is relative to the unit Quaternary, or relative to the initial direction of the object.
When we multiply a vector by a single element, the vector is actually the vector generated by rotating the angle described by this element around the rotation axis described by this element.

Axisangle

It is also used to describe a rotation.

The rotation axis angle represents a parameterized rotation with two values: An axis or vector, and an angle describing the amount of rotation around this axis. It is also called the exponential coordinate of rotation.
Sometimes it is also called the rotation vector representation, because the two parameters (axis and angle) can be expressed by a vector of the rotation angle on this axis.

Merging item

Transform-Transform

A transform is a displacement plus a rotation.

Matrix-Matrix

All transformations can be implemented using matrix operations. However, make sure that the implementation of the matrix algorithm in the rendering system is the same as that in bullet.

Physical item

Rigid Body-Rigid Body

A rigid body has fixed quality, size, and other physical attributes. It is the most basic item in physical simulation.

Node constraint-joint, constraint

The node constraint is used to connect two objects. There are many connection methods. One is simple connection, where the connection can be rotated, and the other is twisted, which can only be one-way motion.

World-world

All objects, all rigid bodies, and software are in the world, and the whole simulation system is a world.

Reference

Bullet physical engine not complete guide-http://blog.csdn.net/vagrxie/article/details/5952310

Bullet tutorial article-http://bulletphysics.org/mediawiki-1.5.8/index.php/Tutorial_Articles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.