加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Bullet cocos2d-x Creating a project from scratch

发布时间:2020-12-14 20:09:01 所属栏目:百科 来源:网络整理
导读:Creating a project from scratch Contents [hide] 1 Creating a project from scratch using Visual Studio (any version) 1.1 Download and install Bullet 1.2 Download and install cmake 1.3 Run CMake-gui 1.4 Create a new Visual Studio project 1.4

Creating a project from scratch

Contents

[hide]
  • 1 Creating a project from scratch using Visual Studio (any version)
    • 1.1 Download and install Bullet
    • 1.2 Download and install cmake
    • 1.3 Run CMake-gui
    • 1.4 Create a new Visual Studio project
      • 1.4.1 Alternative,manual method
  • 2 Creating a project from scratch using XCode
  • 3 Unix,Linux,MinGW etc
  • 4 Link order for libraries

Creating a project from scratch using Visual Studio (any version)

Download and install Bullet

  • Download the Bullet source code from http://code.google.com/p/bullet/downloads/list and unzip the archive somewhere,say c:develop,so the root of Bullet is in c:developbullet-2.76

Download and install cmake

  • The recommended way to start a new project from scratch is using cmake. Download cmake from http://cmake.org and install it.

Run CMake-gui

  • Start CMake-gui
  • Choose the location where you unzipped the Bullet source code,and where you build the binaries for your own project and press Configure
  • Choose the compiler,such as Microsoft Visual Studio 2008
  • Review the settings and press Configure again
  • Make sure the Run-time library is the same as your project (by default it is set to Run-time library DLL) and press Generate
  • Optionally,you could open the generated project solution (in our case C:developtutorialBulletBuildBULLET_PHYSICS.sln) and build the library and demos,but this is not necessary

Create a new Visual Studio project

  • Now create your new project,say a Win32 Console Application in c:develop called BulletTestApp,located in c:developBulletTestApp:
  • Hit Finish
  • Just try to build it without any change
  • Now add the generated projectfiles for the Bullet libraries,BulletCollision,BulletDynamics and LinearMath:
  • Browse to the folder where you selected CMake-gui to build the binaries,then select src/BulletCollision/BulletCollision.vcproj,and same for src/BulletDynamics/BulletDynamics.vcproj and src/LinearMath/LinearMath.vcproj:
  • Make sure to make your program dependent on the Bullet libraries,right click on your project,select 'Dependencies'
  • and select the Bullet libraries:
  • Now set the header include path to the 'src' folder within Bullet source code,for example c:developbullet-2.76src in our case. Right click on your project,select 'Properties'
  • Goto C/C++,Additional Include Directories,and type/browse to the Bullet/src folder,in our case c:developbullet-2.76src
  • Repeat those steps for all configurations (Debug,Release etc),and start programming
  • You might need to enable the Link Library Dependencies setting for all projects,in the linker settings (see below for Visual Studio 2010 and newer):
  • Visual Studio 2010: the above does not apply,use referencing instead. Go to your project's property pages. In the left panel,select Common Properties->Framework and References. Hit the Add New Reference button a few times and add all the bullet libraries you need (in this case,at least BulletCollision,BulletDynamics and LinearMath). When you get the error The project file has been moved renamed or not on your computer,check the References for the newly added project. Removes references to 'ZERO_CHECK'.
  • From here,you could try out the Hello World tutorial


Alternative,manual method

If you do not want to use cmake,here is another simple method. Assuming you have unzipped Bullet in C:bullet-2.75,adjust all pathnames if necessary:

  • Create a new,empty C++ project (File > New > Project: Choose Project types > Visual C++ > General > Empty Project)
  • Add a new C++ file (e.g. "main.cpp") to your project and copy the code from the Hello World page into it and save it.
  • Open the properties of your project (in the Solution Explorer right-click the project name and select Properties,or in the Property Manager double-click Debug|Win32):
  • In Configuration Properties > C/C++ > General > Additional Include Directories add:

    highlight: Unknown source file extension "dos".

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

4gl,a4c,abp, ada,agda,ampl,amtrix,applescript,arc,arm,as,asm,asp,aspect,au3,avenue,awk, bat,bb,bib,bms,boo,c,cb,cfc,clipper,clp,cob,cs,css,d,diff,dot,dylan,e,erl,euphoria,exp,f77,f90,flx,frink,haskell,hcl,httpd,icn, idl,ini,inp,io,j, java,js,jsp,lbn,ldif,lgt,lisp,lotos,ls,lsl,lua,ly,m,make,mel,mib,miranda,ml,mo,mod3,mpl,ms,mssql,n,nas,nice,nsi,nut,oberon, objc,octave,oorexx,os,pas,php,pike,pl,pl1,pov,pro,progress,ps,ps1, psl,py,pyx,q,qu, r,rb,rexx,rnc,s, sas,sc,scala,scilab,sh,sma,smalltalk,sml,snobol, spec,spn,sql,sybase,tcl,tcsh,test_re,tex,ttcn3, txt,vb,verilog,vhd,xml,xpp,y

  • Recursively add all .cpp files from the Bullet/src folder to your project
  • Build and debug your project.

Creating a project from scratch using XCode

Assume we downloaded bullet-2.x.tgz and unzipped it into a folder /Users/name/develop,we will have for example: /Users/name/develop/bullet-2.76

  • Create a new C++ console application,using XCode:
  • put it in next to bullet-2.x,in the develop folder:

  • Open the main.cpp file and add #include "btBulletDynamicsCommon.h":

  • Edit the project settings for All Configurations

  • Add the bullet-2.x/src folder:

  • Now build the project:

  • Update 12/17/2010: If you are having trouble with the following build errors:
 "btTypedConstraint::serialize(void*,btSerializer*) const",referenced from:
 "btAlignedFreeInternal(void*)",referenced from:

then you have to include the Bullet frameworks in your Xcode project. Make sure they are built and installed like this (This is without Xcode,maybe there is some way to make them in Xcode too,I don't know):

   cmake . -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON 
    -DFRAMEWORK=ON  -DCMAKE_OSX_ARCHITECTURES='i386;x86_64' 
    -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/Library/Frameworks 
    -DCMAKE_INSTALL_NAME_DIR=/Library/Frameworks -DBUILD_DEMOS:BOOL=OFF
   make -j4
   sudo make install

This will put the Bullet frameworks in /Library/Frameworks. Navigate there in the finder and then drag the frameworks into your Xcode project. You need at least LinearMath.framework and BulletDynamics.framework. (Those two will fix the above linking errors.) But you probably also want BulletCollision.framework and maybe others.

If you have set up the frameworks like this,you don't have to change the header search path as above. Instead you can put this include line and Xcode will find the headers inside the framework:

  #include <BulletDynamics/btBulletDynamicsCommon.h>
  • From here,continue to the Hello World tutorial.

Unix,MinGW etc

Follow the generic make recipe from the installation guide making sure the .a files are built. From there,when creating a Makefile,in the gcc arguments,make sure you add in a -I bullet_dir for the headers and also add in libBulletDynamics.a,libBulletCollision.a and libLinearMath.a or whatever you're using.

For example (assuming the src dir is in the folder bullet):

gcc myprogram.cpp -lGL -lGLU -I ./bullet/ ./bullet/BulletDynamics/libBulletDynamics.a ./bullet/BulletCollision/libBulletCollision.a ./bullet/LinearMath/libLinearMath.a

Link order for libraries

Note that many compilers the link order matters,so make sure to use the following order of libraries:

  • BulletMultiThreaded (optional)
  • MiniCL (optional)
  • BulletWorldImporter (optional)
  • BulletSoftBody (optional)
  • BulletDynamics
  • BulletCollision
  • LinearMath

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读