1. 程式人生 > >bullet物理引擎-配置

bullet物理引擎-配置

Bullet物理引擎-配置

如下圖:

選擇第一個bullet2.82-r2704(這個是sdk)。

下載後解壓,如圖:

此時lib資料夾下只有一個readme.txt。

進入build資料夾下,如圖:

        

執行vs2010.bat,會在當前目錄下生成一個vs2010資料夾,結果如下:


進入vs2010資料夾,問價如下:


第一個檔案格式為.sln,表示是vs工程,可以用vs2010開啟。

開啟後如圖:

分別在debug和release模式下生成全部解決方案。完成後可以檢視demo執行情況。

生成成功後,bullet資料夾下會顯示如下:


說明debug和release模式下生成的檔案都存在到了bullet主目錄下,而此時的lib資料夾中存在如下檔案:


Vs2010工程。

新建一個空白的vs2010控制檯工程,新增一個main.cpp檔案。拷貝如下內容:

#include <iostream>


#include <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;


system("pause");
return 0;
}

儲存。

在解決方案上右鍵—屬性,如下:


配置如下:

附加包含目錄--新增bullet資料夾下的src資料夾:


附加庫目錄--下新增bullet資料夾中的lib資料夾:


在debug模式下新增lib檔案中的debug模式生成的lib檔案。(有debug字元):


同樣的,在release模式下新增lib資料夾中的release模式生成的lib檔案(無debug字元)。

然後生成解決方案,執行後如圖:


配置成功。