Directx

Mr.Newb
Posts: 9
Joined: Sat Nov 10, 2007 7:28 am

Directx

Post by Mr.Newb »

Does anyone know where I can find some examples of using bullet with Directx(c++)? I'm not very familiar with opengl/bullet and the combination of the two are confusing the hell out of me.
dreamtheater39
Posts: 13
Joined: Sat Nov 10, 2007 8:39 pm

Re: Directx

Post by dreamtheater39 »

Using it with directx is just the same. Bullet is more of a physics computation engine, and does not depend on the graphics driver...

I'm currently using it with DX with no problems, i suggest you start integrating it, by referring to one of the samples....you should be on your way!

If you get stuck in any point, post in ;)

Cheers,
San
Mr.Newb
Posts: 9
Joined: Sat Nov 10, 2007 7:28 am

Re: Directx

Post by Mr.Newb »

dreamtheater39 wrote:Using it with directx is just the same. Bullet is more of a physics computation engine, and does not depend on the graphics driver...
Are there any problems with the the left-handed coordinate system used by Direct3D?
dreamtheater39 wrote: I'm currently using it with DX with no problems, i suggest you start integrating it, by referring to one of the samples....you should be on your way!
Are there any pitfalls(opengl -> directx) I should watchout for?
dreamtheater39 wrote: If you get stuck in any point, post in ;)

Cheers,
San
Thx for your response.
dreamtheater39
Posts: 13
Joined: Sat Nov 10, 2007 8:39 pm

Re: Directx

Post by dreamtheater39 »

Mr.Newb wrote:
dreamtheater39 wrote:Using it with directx is just the same. Bullet is more of a physics computation engine, and does not depend on the graphics driver...
Are there any problems with the the left-handed coordinate system used by Direct3D?
dreamtheater39 wrote: I'm currently using it with DX with no problems, i suggest you start integrating it, by referring to one of the samples....you should be on your way!
Are there any pitfalls(opengl -> directx) I should watchout for?
dreamtheater39 wrote: If you get stuck in any point, post in ;)

Cheers,
San
Thx for your response.
Assume the physics engine is built for DX coordinate system and go ahead and setup everything. In fact all the examples assume dx style coordinate system if you take a closer look. Bullet then converts to "Opengl style" matrices to render them eventually.

Here is some code for setting up a d3d matrix to render objects...

Code: Select all

	btTransform trn = m_SphereBody->getWorldTransform();

	D3DXMATRIX world;
	btVector3 R = trn.getBasis().getColumn(0);
	btVector3 U = trn.getBasis().getColumn(1);
	btVector3 L = trn.getBasis().getColumn(2);
	btVector3 P = m_SphereBody->getWorldTransform().getOrigin();

	D3DXVECTOR3 vR, vU, vL, vP;
	vR.x = R.x();vR.y = R.y();vR.z = R.z();
	vU.x = U.x();vU.y = U.y();vU.z = U.z();
	vL.x = L.x();vL.y = L.y();vL.z = L.z();
	vP.x = P.x();vP.y = P.y();vP.z = P.z();

	g_MathUtilityManager.XPrepareMatrixFromRULP( world, &vR, &vU, &vL, &vP );

Code: Select all

	void XPrepareMatrixFromRULP( D3DXMATRIX &matOutput, D3DXVECTOR3 *R, D3DXVECTOR3 *U, D3DXVECTOR3 *L, D3DXVECTOR3 *P )
	{
		matOutput._11 = R->x;matOutput._12 = R->y;matOutput._13 = R->z;matOutput._14 = 0.f;
		matOutput._21 = U->x;matOutput._22 = U->y;matOutput._23 = U->z;matOutput._24 = 0.f;
		matOutput._31 = L->x;matOutput._32 = L->y;matOutput._33 = L->z;matOutput._34 = 0.f;
		matOutput._41 = P->x;matOutput._42 = P->y;matOutput._43 = P->z;matOutput._44 = 1.f;
	}

cheers,
San
dreamtheater39
Posts: 13
Joined: Sat Nov 10, 2007 8:39 pm

Re: Directx

Post by dreamtheater39 »

Cleaner functions you could use -

Code: Select all

D3DXMATRIX XPhysicsManager::XConvertBulletTransform( btTransform *bulletTransformMatrix )
{
	D3DXMATRIX world;
	btVector3 R = bulletTransformMatrix->getBasis().getColumn(0);
	btVector3 U = bulletTransformMatrix->getBasis().getColumn(1);
	btVector3 L = bulletTransformMatrix->getBasis().getColumn(2);
	btVector3 P = bulletTransformMatrix->getOrigin();

	D3DXVECTOR3 vR, vU, vL, vP;
	vR.x = R.x();vR.y = R.y();vR.z = R.z();
	vU.x = U.x();vU.y = U.y();vU.z = U.z();
	vL.x = L.x();vL.y = L.y();vL.z = L.z();
	vP.x = P.x();vP.y = P.y();vP.z = P.z();

	g_MathUtilityManager.XPrepareMatrixFromRULP( world, &vR, &vU, &vL, &vP );
	return world;
}

btTransform XPhysicsManager::XConvertD3DXMatrix( D3DXMATRIX *d3dMatrix )
{
	btTransform bulletTransformMatrix;
	btVector3 R,U,L,P;
	R.setX( d3dMatrix->_11 ); R.setY( d3dMatrix->_12 ); R.setZ( d3dMatrix->_13 );
	U.setX( d3dMatrix->_21 ); U.setY( d3dMatrix->_22 ); U.setZ( d3dMatrix->_23 );
	L.setX( d3dMatrix->_31 ); L.setY( d3dMatrix->_32 ); L.setZ( d3dMatrix->_33 );
	P.setX( d3dMatrix->_41 ); P.setY( d3dMatrix->_42 ); P.setZ( d3dMatrix->_43 );

	bulletTransformMatrix.getBasis().setValue( R.x(), U.x(), L.x(), 
											   R.y(), U.y(), L.y(), 
											   R.z(), U.z(), L.z() );
	bulletTransformMatrix.setOrigin( P );
	return bulletTransformMatrix;
}

Code: Select all

	void XPrepareMatrixFromRULP( D3DXMATRIX &matOutput, D3DXVECTOR3 *R, D3DXVECTOR3 *U, D3DXVECTOR3 *L, D3DXVECTOR3 *P )
	{
		matOutput._11 = R->x;matOutput._12 = R->y;matOutput._13 = R->z;matOutput._14 = 0.f;
		matOutput._21 = U->x;matOutput._22 = U->y;matOutput._23 = U->z;matOutput._24 = 0.f;
		matOutput._31 = L->x;matOutput._32 = L->y;matOutput._33 = L->z;matOutput._34 = 0.f;
		matOutput._41 = P->x;matOutput._42 = P->y;matOutput._43 = P->z;matOutput._44 = 1.f;
	}
Mr.Newb
Posts: 9
Joined: Sat Nov 10, 2007 7:28 am

Re: Directx

Post by Mr.Newb »

Thx.