ÇϺ¹À» ¾Æ·¡ ½ÎÀÌÆ®·Î °¡¼ ´Ù¿î ¹Þ´Â´Ù. http://software.intel.com/sites/havok/
ÇϺ¹ ¹öÀü: Havok_Physics_Animation_2010-2-0_PC_XS_win32_VS2005_keycode_perpetual_20101115.zip
Ãß°¡ Æ÷ÇÔ µð·ºÅ͸®: ../hk2010_2_0_r1/Source
Ãß°¡ ¶óÀ̺귯¸® µð·ºÅ͸®: µð¹ö±×¿ë - ../hk2010_2_0_r1/Lib/win32_net_8-0/debug_multithreaded_dll ¸±¸®Áî¿ë - ../hk2010_2_0_r1/Lib/win32_net_8-0/release_multithreaded_dll < 1. ÇϺ¹ ÃʱâÈ >
//ÇϺ¹ ¸Þ¸ð¸® ÃʱâÈ
hkMallocAllocator baseMalloc;
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault( &baseMalloc, hkMemorySystem::FrameInfo(1024 * 1024) );
hkBaseSystem::init(memoryRouter, HavokErrorReportFunction);
hkpWorldCinfo info;
info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;
info.m_collisionTolerance = 0.001f;
info.setBroadPhaseWorldSize( 10000.0f );
info.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_8ITERS_HARD );
info.m_gravity = hkVector4(0.0f, -9.8f, 0.0f);
hkpWorld *world = new hkpWorld(info);
hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() );
|
ÇϺ¹ ¸Þ¸ð¸®¸¦ ÃʱâÈ ÇÏ°í Á¾·á½Ã¿¡¼´Â quitÀ» È£ÃâÇØÁØ´Ù.
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault( &baseMalloc, hkMemorySystem::FrameInfo(1024 * 1024) );
hkBaseSystem::init(memoryRouter, HavokErrorReportFunction);
............
............
hkBaseSystem::quit();
hkMemoryInitUtil::quit();
|
ÇϺ¹ ½Ã¹Ä·¹ÀÌ¼Ç Å¸ÀÔÀ» Á¤ÇÑ´Ù. ¸ÖƼ¾²·¹µå ¹°¸® ½Ã¹Ä·¹À̼ÇÀ» ÇÑ´Ù¸é SIMULATION_TYPE_MULTITHREADEDÀ» »ç¿ëÇÑ´Ù.
info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;
|
Ãæµ¹ ¿ÀÂ÷¸¦ ÁöÁ¤ÇÑ´Ù.
info.m_collisionTolerance = 0.001f;
|
Ãæµ¹ ¿ùµå »çÀÌÁ ÁöÁ¤ÇÑ´Ù.
info.setBroadPhaseWorldSize( 10000.0f );
|
ÀÌ ¿É¼ÇÀº Á¤È®ÇÏ°Ô ¹¹Çϴ°ÇÁö ¸ð¸¥´Ù. µðÆúÆ® °ªÀº SOLVER_TYPE_4ITERS_MEDIUMÀÌ´Ù.
info.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_8ITERS_HARD );
|
Áß·Â ¹æÇâÀ» ¼³Á¤ÇÑ´Ù.
info.m_gravity = hkVector4(0.0f, -9.8f, 0.0f);
|
< 2. Ãæµ¹ ¹Ù´Ú ¸¸µé±â >
const float groundHalfH = 2.0f;
const hkVector4 halfExtents( 2000.0f, groundHalfH, 2000.0f );
hkpBoxShape* groundShape = new hkpBoxShape(halfExtents);
hkpRigidBodyCinfo bodyInfo;
bodyInfo.m_mass = 0.0f;
bodyInfo.m_shape = groundShape;
bodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
bodyInfo.m_position.set(0.0f, -groundHalfH, 0.0f);
hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);
groundShape->removeReference();
world->addEntity(groundBody);
groundBody->removeReference();
|
¹ÝÁö¸§ x = 2000, y = 2, z = 2000 hkBoxShape¸¦ »ý¼ºÇÑ´Ù.
hkpBoxShape* groundShape = new hkpBoxShape(halfExtents)
|
¹Ù´ÚÀº ¿òÁ÷ÀÌ ¾Ê´Â Á¤ÀûÀÎ ¹°Ã¼À̹ǷΠÁú·®À» 0À¸·Î ¼ÂÆÃÇÑ´Ù. ¸ð¼Ç ŸÀÔÀ» MOTION_FIXED·Î ÇÏ¸é ¿òÁ÷ÀÌÁö ¾Ê´Â °ÔÀÓÀÇ ¹è°æ°ú °°Àº Á¤ÀûÀΠŸÀÔÀÌ´Ù.
hkpRigidBody »ý¼ºÈÄ groundShape Á¤º¸´Â ´õ ÀÌ»ó ÇÊ¿äÇÏÁö ¾ÊÀ¸¹Ç·Î »èÁ¦ÇÑ´Ù.
hkpRigidBody* groundBody = new hkpRigidBody(bodyInfo);
groundShape->removeReference();
|
ÇϺ¹ ¿ùµå¿¡ Rigid BodyÃß°¡ÈÄ groundBodyÁ¤º¸´Â ´õ ÀÌ»ó ÇÊ¿äÇÏÁö ¾ÊÀ¸¹Ç·Î »èÁ¦ÇÑ´Ù.
world->addEntity(groundBody);
groundBody->removeReference();
|
< 3. Ãæµ¹ ¹Ú½º ¸¸µé±â >
const float bx = 1.0f, by = 2.0f, bz = 1.0f;
const int nx = 2, ny = 2, nz = 2;
const int NUM_BODIES = nx * ny * nz;
hkpRigidBody *bodies[NUM_BODIES];
{
const hkVector4 halfExtents(bx, by, bz);
hkpShape* shape = new hkpBoxShape(halfExtents, 0.0f);
hkpMassProperties massProperties;
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, 5.0f, massProperties);
hkpRigidBodyCinfo bodyInfo;
bodyInfo.m_mass = massProperties.m_mass;
bodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
bodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
bodyInfo.m_shape = shape;
bodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
int i = 0;
for(int x = 0; x < nx; x++)
for(int y = 0; y < ny; y++)
for(int z = 0; z < nz; z++) {
hkpRigidBody *body = new hkpRigidBody(bodyInfo);
body->setPosition(hkVector4(x * bx * 2, 100.0f + y * by * 2, z * bz * 2));
bodies[i] = body;
world->addEntity(body);
body->removeReference();
i++;
}
shape->removeReference();
}
|
°ü¼º ÅÙ¼¿Í hkpShapeÀÇ ÁÖ¾îÁø ÃÑ Áú·®ÀÇ Áß½ÉÀ» °è»êÇÑ´Ù. ¸ðµç Åë°úÇÏ´Â ÀÚ½Ä ¼ÎÀÌÇÁ´Â º¼·ýÀ» °¡Áö°í ÀÖ¾î¾ß ÇÑ´Ù. »ï°¢ÇüÀÇ ÃÖ¼Ò µÎ²²´Â 0.01fÀÌ´Ù.
hkpInertiaTensorComputer::computeShapeVolumeMassProperties(shape, 5.0f, massProperties);
hkpRigidBodyCinfo bodyInfo;
bodyInfo.m_mass = massProperties.m_mass;
bodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
bodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
¹Ú½ºÀÇ ¿òÁ÷ÀÓÀ̹ǷΠMOTION_BOX_INERTIA·Î ¼³Á¤ÇÑ´Ù.
bodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA
|
hkpRigidBody()À» »ý¼ºÈÄ setPosition()À¸·Î À̵¿ÇÑ´Ù.
hkpRigidBody *body = new hkpRigidBody(bodyInfo)
body->setPosition(hkVector4(x * bx * 2, 100.0f + y * by * 2, z * bz * 2))
|
< 4. ÇϺ¹ ·çÇÁ >
ÇϺ¹ ½Ã¹Ä·¹ÀÌ¼Ç °£°ÝÀ» 60ÇÁ·¹ÀÓÀ¸·Î ¼³Á¤ÇÑ´Ù.
world->stepDeltaTime(1.0f/60.0f)
|
Ä«¸Þ¶ó´Â ù ¹ø° ¹Ú½º¸¦ µû¶ó¼ ¿òÁ÷ÀÔ´Ï´Ù. ù ¹ø° hkpRigidBodyÀÎ bodies[0]·ÎºÎÅÍ TransformÀ¸·Î À§Ä¡¸¦ ±¸Çؼ Ä«¸Þ¶ó ºä¸¦ ¼³Á¤ÇÑ´Ù.
hkVector4 pos = bodies[0]->getPosition();
{
const hkTransform &trans = bodies[0]->getTransform();
const hkVector4 &t = trans.getTranslation();
D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 50.0f, -25.0f),
&D3DXVECTOR3(t(0), t(1), t(2)), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
g_pD3DDev->SetTransform(D3DTS_VIEW, &view);
}
|
¹Ù´ÚÀ̳ª ¹Ú½º¸¦ ±×¸±¶§, ¿À¸¥¼Õ ÁÂÇ¥°è¿¡¼ ¿Þ¼Õ ÁÂÇ¥°è·Î Çà·Ä º¯È¯À» ÇÑ´Ù.
D3DXMATRIX transMat(
t(0,0), t(1,0), t(2,0), 0.0f,
t(0,1), t(1,1), t(2,1), 0.0f,
t(0,2), t(1,2), t(2,2), 0.0f,
t(0,3), t(1,3), t(2,3), 1.0f);
|
< 5. ÇϺ¹ Á¾·á >
delete world;
hkBaseSystem::quit();
hkMemoryInitUtil::quit();
|
ÀÌ»ó Âü°í ½ÎÀÌÆ®ÀÇ ¼Ò½º¸¦ °¡Á®¿Í¼ »õ·Î¿î ÇϺ¹¹öÀü¿¡¼ ºôµå µÇµµ·Ï ¼öÁ¤ÇÏ°í ¼Ò½º¸¦ ºÐ¼® ÇÏ¿´´Ù.
ÇÁ·ÎÁ§Æ®: havok_start.zip
Âü°í ½ÎÀÌÆ®: http://marupeke296.com/COL_HVK_No2_Integration.html
|