游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4794|回复: 12

一个用来碰撞检测的方法

[复制链接]

14

主题

283

帖子

293

积分

中级会员

Rank: 3Rank: 3

积分
293
QQ
发表于 2004-8-5 10:23:00 | 显示全部楼层 |阅读模式
D3DXIntersectSubset Function  

--------------------------------------------------------------------------------


Intersects the specified ray with the given mesh subset. This provides similar functionality to D3DXIntersect.


Syntax

HRESULT D3DXIntersectSubset(          LPD3DXBASEMESH pMesh,
    DWORD AttribId,
    const D3DXVECTOR3 *pRayPos,
    const D3DXVECTOR3 *pRayDir,
    BOOL *pHit,
    DWORD *pFaceIndex,
    FLOAT *pU,
    FLOAT *pV,
    FLOAT *pDist,
    LPD3DXBUFFER *ppAllHits,
    DWORD *pCountOfHits
);
Parameters

pMesh
[in] Pointer to an ID3DXBaseMesh interface, representing the mesh to be tested. The mesh must be attribute sorted.
AttribId
[in] Attribute identifier of the subset to intersect with.
pRayPos
[in] Pointer to a D3DXVECTOR3 structure, specifying the origin coordinate of the ray.
pRayDir
[in] Pointer to a D3DXVECTOR3 structure, specifying the direction of the ray.
pHit
[out] Pointer to a BOOL. If the ray intersects a triangular face on the mesh, this value will be set to TRUE. Otherwise, this value is set to FALSE.
pFaceIndex
[out] Pointer to an index value of the face closest to the ray origin, if pHit is TRUE.
pU
[out] Pointer to a barycentric hit coordinate, U.
pV
[out] Pointer to a barycentric hit coordinate, V.
pDist
[out] Pointer to a ray intersection parameter distance.
ppAllHits
[out] Array of D3DXINTERSECTINFO structures, representing all hits, not just closest hits.
pCountOfHits
[out] Number of elements in the array returned from ppAllHits.
Return Value


If the function succeeds, the return value is D3D_OK.

If the function fails, the return value can be the following value.


E_OUTOFMEMORY Microsoft Direct3D could not allocate sufficient memory to complete the call.


Remarks

The D3DXIntersectSubset function provides a way to understand points in and around a triangle, independent of where the triangle is actually located. This function returns the resulting point by using the following equation: V1 + U(V2-V1) + V(V3-V1).

Any point in the plane V1V2V3 can be represented by the barycentric coordinate (U,V). The parameter U controls how much V2 gets weighted into the result and the parameter V controls how much V3 gets weighted into the result. Lastly, 1-U-V controls how much V1 gets weighted into the result.

Barycentric coordinates are a form of general coordinates. In this context, using barycentric coordinates represents a change in coordinate systems. What holds true for Cartesian coordinates holds true for barycentric coordinates.

Function Information

Header d3dx9mesh.h
Import library d3dx9.lib
Minimum operating systems Windows 98
以上是这个函数的介绍,E文好的请翻译下
此函数将从pRayPos引一条射线,至pRayDir,如果与指定网格的某个单元有碰撞(穿过),则isHit为真,并返回1个该单元的索引保存在pFaceIndex中,返回碰撞次数在pCountOfHits中,并返碰撞时pRayPos至碰撞点的直线距离在pDist中.
我们只要利用好pDist,判断碰撞的距离,就可以实现游戏中的碰撞检测.
具我判断,该函数应该是由GPU执行的,所以效率应该很高,速度很快.
关于碰撞检测,本来小弟还有个愚蠢的办法,但由于此法更精细,小弟也就舍弃了,不在次献丑了.
上面的函数介绍都是E文的,小弟也还有些参数没弄明白,有这几个参数也已经足够,其它的全都用NULL就行了.如果有哪位大哥有时间还请指点下其他参数,最好还能翻译下哈,很多人像小弟一样E问单词认识的少啊
还有个类似功能的函数D3DXIntersect,大家可以查MSDN,基本一样,少个参数,其实用D3DXIntersectSubset()应该更好.

14

主题

283

帖子

293

积分

中级会员

Rank: 3Rank: 3

积分
293
QQ
 楼主| 发表于 2004-8-5 13:27:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

顶下,这个很有用啊,我也不容易啊

33

主题

445

帖子

446

积分

中级会员

Rank: 3Rank: 3

积分
446
发表于 2004-8-5 13:47:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

支持,DX封装的够多了,是不是连碰撞检测也由函数调用。

14

主题

283

帖子

293

积分

中级会员

Rank: 3Rank: 3

积分
293
QQ
 楼主| 发表于 2004-8-6 00:28:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

这个其实是用在内部处理光线,阴影的函数吧,但是用来做碰撞检测以不错啊

20

主题

473

帖子

502

积分

高级会员

Rank: 4

积分
502
发表于 2004-8-6 10:22:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

hehe,
如果collision也能用gpu来做的话,大概整个图形硬件的体系都要换
这个函数速度不快,因为它里面没有用aabb,可能主要还是穷举,所以求方便可以用,但视为了效率,还是别用为好

35

主题

340

帖子

350

积分

中级会员

Rank: 3Rank: 3

积分
350
发表于 2004-8-6 13:42:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

有没有专讲碰撞检测的文章
最好不是E文的

14

主题

283

帖子

293

积分

中级会员

Rank: 3Rank: 3

积分
293
QQ
 楼主| 发表于 2004-8-7 00:47:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

那应该用什么方法做碰撞检测啊?我想知道

50

主题

992

帖子

1012

积分

金牌会员

Rank: 6Rank: 6

积分
1012
发表于 2004-8-7 16:10:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

按对象来做的话还不慢死才怪,可能你开一枪对手N分钟后才能倒-夸张的说法下:),一般碰撞检测要和引擎里的场景组织联系起来。

8

主题

553

帖子

560

积分

高级会员

Rank: 4

积分
560
发表于 2004-8-7 18:17:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

先用AABB“粗选”一遍,再使用这个函数求的精确碰撞点,用这种方法做不算太复杂的场景速度还算能接受,但也只能做几个demo而已。
在游戏里,除了要和场景信息联系起来以外,也可以使用些小伎俩,比如可以使用代理(proxy)mesh来做一个相对比较复杂的mesh的碰撞检测,最典型的入max payne和farcry里面的人,同样用过reactor也可以知道它的好处:-)

14

主题

283

帖子

293

积分

中级会员

Rank: 3Rank: 3

积分
293
QQ
 楼主| 发表于 2004-8-8 23:33:00 | 显示全部楼层

Re:一个用来碰撞检测的方法

5楼的大哥哥说的穷举,是不是指pMesh是穷举出来的?
如果是pMesh已知的呢?这个函数效率高吗?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-8-16 13:49

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表