这里我只针对hkpTriangleShape, 当然这包括包含这类型的shape集合
这里我使用的是hkpContactListener,对反面的碰撞使用枚举hkContactPointMaterial::CONTACT_IS_DISABLED,去除相关的碰撞
重载contactPointCallback( const hkpContactPointEvent& event )
一般要遍历得对应的shape后,用weld的构造方向求法线(默认是反时钟方向),再点积下碰撞法线就好了
例如:
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;
}
}