DirectX9 and Bullet

Post Reply
EnlightenedOne
Posts: 37
Joined: Wed Sep 08, 2010 2:57 pm

DirectX9 and Bullet

Post by EnlightenedOne »

After I got Bullet to compile I was keen to link it to DirectX9 so I could figure out how scaling was going to work and see how I was going to debug the collisions.

Unfortunately when I use both libraries together I get a new linker problem.

Heres are my includes.

#include <windows.h> //Ruled out by adding to hello world bullet program
#include <mmsystem.h> //Ruled out by adding to hello world bullet program
#include <d3d9.h>
#include <d3dx9.h>
#include <btBulletDynamicsCommon.h>

Here is the error that my application gets, all the Bullet programs complete their compilation fine.

4>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)
4>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)
4>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __wassert already defined in LIBCMTD.lib(wassert.obj)
4>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _printf already defined in LIBCMTD.lib(printf.obj)
4>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
4>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
4>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
4>Debug\HLSLDiffusePointLight.exe : fatal error LNK1169: one or more multiply defined symbols found

It appear DX does not want to share. Has anyone met and overcome this issue or got a suggestion as to how to proceed? I tried many combinations of /NODEFAULTLIB but when I switch that on anywhere no one wants to compile.

When I get rid of these annoying Linker teething problems I promise not to be a pain :D
Dominik
Posts: 32
Joined: Fri Dec 19, 2008 2:51 pm

Re: DirectX9 and Bullet

Post by Dominik »

The problem is that you are mixing different of code generation settings.
If you check MSVC in the project settings under C/C++>Code Generation>Runtime Library, you can set either Multithreaded/MultithreadedDebug, or MultithreadedDLL/MultithreadedDebugDLL. This setting has to be the same also for the linked libraries. If you are trying to link your program to a library that was built with a different setting, your linker errors pop up.
EnlightenedOne
Posts: 37
Joined: Wed Sep 08, 2010 2:57 pm

Re: DirectX9 and Bullet

Post by EnlightenedOne »

That was a perfect explanation worked straight off the bat, Bullet was on multi threaded debug DLL and my program was on the none dll version. Thank you very much!

Now I have to figure out how to visually represent collision stuff via DX decently. Might have to build my own helper function for it. With all the teething problems sorted I will go away and ponder on physics!
Skuzz
Posts: 11
Joined: Wed Aug 25, 2010 12:57 am

Re: DirectX9 and Bullet

Post by Skuzz »

Regarding DirectX, try this.

Code: Select all

void BT_GetD3DMatrix( D3DMATRIX *m, btRigidBody * rb)
{
        // assumes m is an identity matrix, and you're using btMotionStates. No scaling is taken into account here.
	btTransform t;
	rb->getMotionState()->getWorldTransform(t);

	btMatrix3x3 bm = t.getBasis().transpose(); // transpose needed
	btVector3 p[4];

	p[0] = bm.getRow(0);
	p[1] = bm.getRow(1);
	p[2] = bm.getRow(2);
	p[3] = t.getOrigin();

	m->_11 = p[0].getX(); m->_12 = p[0].getY(); m->_13 = p[0].getZ(); // X axis
	m->_21 = p[1].getX(); m->_22 = p[1].getY(); m->_23 = p[1].getZ(); // Y axis
	m->_31 = p[2].getX(); m->_32 = p[2].getY(); m->_33 = p[2].getZ(); // Z axis
	
	m->_41 = p[3].getX(); // position
	m->_42 = p[3].getY();
	m->_43 = p[3].getZ();
}
EnlightenedOne
Posts: 37
Joined: Wed Sep 08, 2010 2:57 pm

Re: DirectX9 and Bullet

Post by EnlightenedOne »

That is much appreciated but I had already found and put into use that function :p I had to to get my teapot to fall to the floor in my second experiment in DX when scaling the worlds! I am now stuck trying to actually make one of the demos for stuff like the "vehicle demo" run properly I can't seem to find a linker value for glut that is required after adding all of the openGL demo folder to my code. I am desperate to get a vehicle driving along a mesh of terrain.
Post Reply