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;
}
}
这里我使用的是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;
}
}
相关文章推荐
- CocoaPods第三方库管理 iOS
- poj-2367 Genealogical tree
- 6174问题
- hdu5024
- 进程间通信的方式
- 排序算法整理
- 第四天:内存管理-property参数
- android调用httpclient.excute报android.os.NetworkOnMainThreadException 异常处理
- Html5 Canvas笔记(1)-CanvasAppTemplate代码
- android学习之Service的笔记,里面service里有监听用户通话状态的实例
- Hibernate的一对多增改级联操作
- iOS_UIImage中 + imageNamed: 和 + imageWithContentsOfFile:两个方法的区别
- Number of 1 Bits
- 算法的时间复杂度
- hdu 1002 A + B Problem II(大正整数相加)
- 112 Path Sum
- java通过JDBC链接SQLServer2012
- hadoop论坛实战项目
- 并发技巧
- 使用Nexus配置Maven私有仓库