반응형
Bullet을 Direct3D로 연동시키기 위해서는 Vector, Quaternion, Matrix 값들을 각자에 맞게 연결시켜줘야 한다.
Bullet 엔진을 통해서 물리 연산을 한 뒤 해당 객체의 위치와 회전값을 얻어와서 Direct3D에 적용해 렌더링 해줘야 하고 클라이언트에서 특정 값을 적용시킬때 사용된다.
편하게 사용하기 위해서 만든 툴킷 객체이다.
#pragma once
#pragma warning(push)
#pragma warning(disable : 4127)
#include "btBulletDynamicsCommon.h"
#pragma warning(pop)
class CMSBulletHelper
{
public:
static D3DXVECTOR3 BT_TO_DX_VECTOR3(const btVector3& vector);
static D3DXQUATERNION BT_TO_DX_QUATERNION(const btQuaternion& quaternion);
static D3DXMATRIX BT_TO_DX_MATRIX(const btMotionState& motionState);
static D3DXMATRIX BT_TO_DX_MATRIX(const btTransform& transform);
static btVector3 DX_TO_BT_VECTOR3(const D3DXVECTOR3& vector);
static btQuaternion DX_TO_BT_QUATERNION(const D3DXQUATERNION& quaternion);
static btTransform DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXVECTOR3& rot);
static btTransform DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXQUATERNION& rot);
};
#pragma warning(push)
#pragma warning(disable : 4127)
#include "btBulletDynamicsCommon.h"
#pragma warning(pop)
class CMSBulletHelper
{
public:
static D3DXVECTOR3 BT_TO_DX_VECTOR3(const btVector3& vector);
static D3DXQUATERNION BT_TO_DX_QUATERNION(const btQuaternion& quaternion);
static D3DXMATRIX BT_TO_DX_MATRIX(const btMotionState& motionState);
static D3DXMATRIX BT_TO_DX_MATRIX(const btTransform& transform);
static btVector3 DX_TO_BT_VECTOR3(const D3DXVECTOR3& vector);
static btQuaternion DX_TO_BT_QUATERNION(const D3DXQUATERNION& quaternion);
static btTransform DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXVECTOR3& rot);
static btTransform DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXQUATERNION& rot);
};
#include "DXUT.h"
#include "MSBulletHelper.h"
D3DXVECTOR3 CMSBulletHelper::BT_TO_DX_VECTOR3(const btVector3& vector)
{
return D3DXVECTOR3(vector.x(), vector.y(), vector.z());
}
D3DXQUATERNION CMSBulletHelper::BT_TO_DX_QUATERNION(const btQuaternion& quaternion)
{
return D3DXQUATERNION(quaternion.x(), quaternion.y(), quaternion.z(), quaternion.w());
}
D3DXMATRIX CMSBulletHelper::BT_TO_DX_MATRIX(const btMotionState& motionState)
{
btTransform worldTransform;
motionState.getWorldTransform(worldTransform);
return BT_TO_DX_MATRIX(worldTransform);
}
D3DXMATRIX CMSBulletHelper::BT_TO_DX_MATRIX(const btTransform& transform)
{
btQuaternion rotation = transform.getRotation();
btVector3 origin = transform.getOrigin();
D3DXQUATERNION rot = BT_TO_DX_QUATERNION(rotation);
D3DXMATRIX matTrans;
D3DXMATRIX matRot;
D3DXMATRIX matWorld;
D3DXMatrixTranslation(&matTrans, origin.x(), origin.y(), origin.z());
D3DXMatrixRotationQuaternion(&matRot, &rot);
D3DXMatrixMultiply(&matWorld, &matRot, &matTrans);
return matWorld;
}
btVector3 CMSBulletHelper::DX_TO_BT_VECTOR3(const D3DXVECTOR3& vector)
{
return btVector3(vector.x, vector.y, vector.z);
}
btQuaternion CMSBulletHelper::DX_TO_BT_QUATERNION(const D3DXQUATERNION& quaternion)
{
return btQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
}
btTransform CMSBulletHelper::DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXVECTOR3& rot)
{
btVector3 origin = DX_TO_BT_VECTOR3(pos);
btTransform transform;
transform.setIdentity();
transform.getBasis().setEulerZYX(rot.x, rot.y, rot.z);
transform.setOrigin(origin);
return transform;
}
btTransform CMSBulletHelper::DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXQUATERNION& rot)
{
btVector3 origin = DX_TO_BT_VECTOR3(pos);
btQuaternion rotation = DX_TO_BT_QUATERNION(rot);
btTransform transform;
transform.setIdentity();
transform.getBasis().setRotation(rotation);
transform.setOrigin(origin);
return transform;
}
#include "MSBulletHelper.h"
D3DXVECTOR3 CMSBulletHelper::BT_TO_DX_VECTOR3(const btVector3& vector)
{
return D3DXVECTOR3(vector.x(), vector.y(), vector.z());
}
D3DXQUATERNION CMSBulletHelper::BT_TO_DX_QUATERNION(const btQuaternion& quaternion)
{
return D3DXQUATERNION(quaternion.x(), quaternion.y(), quaternion.z(), quaternion.w());
}
D3DXMATRIX CMSBulletHelper::BT_TO_DX_MATRIX(const btMotionState& motionState)
{
btTransform worldTransform;
motionState.getWorldTransform(worldTransform);
return BT_TO_DX_MATRIX(worldTransform);
}
D3DXMATRIX CMSBulletHelper::BT_TO_DX_MATRIX(const btTransform& transform)
{
btQuaternion rotation = transform.getRotation();
btVector3 origin = transform.getOrigin();
D3DXQUATERNION rot = BT_TO_DX_QUATERNION(rotation);
D3DXMATRIX matTrans;
D3DXMATRIX matRot;
D3DXMATRIX matWorld;
D3DXMatrixTranslation(&matTrans, origin.x(), origin.y(), origin.z());
D3DXMatrixRotationQuaternion(&matRot, &rot);
D3DXMatrixMultiply(&matWorld, &matRot, &matTrans);
return matWorld;
}
btVector3 CMSBulletHelper::DX_TO_BT_VECTOR3(const D3DXVECTOR3& vector)
{
return btVector3(vector.x, vector.y, vector.z);
}
btQuaternion CMSBulletHelper::DX_TO_BT_QUATERNION(const D3DXQUATERNION& quaternion)
{
return btQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
}
btTransform CMSBulletHelper::DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXVECTOR3& rot)
{
btVector3 origin = DX_TO_BT_VECTOR3(pos);
btTransform transform;
transform.setIdentity();
transform.getBasis().setEulerZYX(rot.x, rot.y, rot.z);
transform.setOrigin(origin);
return transform;
}
btTransform CMSBulletHelper::DX_TO_BT_TRANSFORM(const D3DXVECTOR3& pos, const D3DXQUATERNION& rot)
{
btVector3 origin = DX_TO_BT_VECTOR3(pos);
btQuaternion rotation = DX_TO_BT_QUATERNION(rot);
btTransform transform;
transform.setIdentity();
transform.getBasis().setRotation(rotation);
transform.setOrigin(origin);
return transform;
}
반응형
'프로그래밍' 카테고리의 다른 글
Breakpoint Condition 기능 활용 (0) | 2013.08.27 |
---|---|
SQL 명령어 정리(스키마 분석하면서..) (0) | 2013.04.05 |
warning LNK4099 해결방법 (0) | 2012.10.06 |
Visual Studio Property Sheets를 이용해서 공통된 속성 관리하기 (0) | 2012.10.04 |
윈도우창 관련 메시지 정리 (0) | 2012.09.28 |