您的位置:首页 > 其它

HAVOK只碰撞一个shape的一面

2015-08-14 21:42 302 查看
这里我只针对hkpTriangleShape, 当然这包括包含这类型的shape集合

这里我使用的是hkpContactListener,对反面的碰撞使用枚举hkContactPointMaterial::CONTACT_IS_DISABLED,去除相关的碰撞

重载contactPointCallback( const hkpContactPointEvent& event )

一般要遍历得对应的shape后,用weld的构造方向求法线(默认是反时钟方向),再点积下碰撞法线就好了

例如:

[cpp] view
plaincopy





hkpShapeKeyPath path( event, 1 - event.m_source );

hkpShapeKeyPath::Iterator it = path.getIterator();

while (it.isValid()){

const hkpShape* curShape = it.getShape();

if( curShape ->getType() == hkcdShapeType::TRIANGLE ){

hkpShapeKey* key = event.getShapeKeys( 1 -event.m_source );

const hkpTriangleShape* triangle = static_cast<const hkpTriangleShape*>( curShape );

hkVector4 a, b, n;

a.setSub( triangle->getVertex(1), triangle->getVertex(0) );

b.setSub( triangle->getVertex(2), triangle->getVertex(1) );

n.setCross( a, b );

if( n.dot3(event.m_contactPoint ->getNormal()) < .0f ){

event.m_contactPointProperties->m_flags |= hkContactPointMaterial::CONTACT_IS_DISABLED;

return;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: