This presentation is the property of its rightful owner.
Sponsored Links
1 / 19

网络游戏脚本编程 PowerPoint PPT Presentation


  • 87 Views
  • Uploaded on
  • Presentation posted in: General

网络游戏脚本编程. 专业教程 北京汇众益智科技有限公司. 鼠标拾取. 什么是拾取,拾取能做什么?. 拾取操作指当我们在屏幕上用鼠标点击某个图元,应用程序能返回该图元的一个标志或某些相关信息。 有这些信息就得到该图元的控制权,我们可以删除,可以编辑,可以任意对待该图元. 拾取操作的原理. 拾取算法的思想很简单:得到鼠标点击处的屏幕坐标,通过投影矩阵和观察矩阵把该坐标转换为通过视点和鼠标点击点的一条射入场景的光线,该光线如果与场景模型的三角形相交(本文只处理三角形图元),则获取该相交三角形的信息。.

Download Presentation

网络游戏脚本编程

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


4588311


4588311


4588311


4588311

d3d:


4588311

Windows APIGetCursorPosScreenToClient()POINT screenPt


4588311

view project

viewproject

view

viewview frustum


4588311

viewx

y = z * tan(fov/2)


4588311

projectprojectxoyzview port640*480


4588311

projectx[-1,1], y[-1,1], z[0,1]


4588311

projectx

y=1


4588311

ProjMatrix =

=


4588311

screenPtprojPt

screenWidth,screenHeight,

projPt.x = (screenPt.x-screenWidth/2)/screenWidth*2;

projPt.y = (screenPt.y-screenHeight/2)/screenHeight*2;

projPt.z =0;0

projPt(view space),

(projPt.xprojPt.yprojPt.z)

(projPt.x*projPt.wprojPt.y*projPt.wprojPt.z*projPt.wprojPt.w)


4588311

GetTransform(D3DTS_PROJECTION,&ProjMatrix)ProjMatrix,

(projPt.x*projPt.wprojPt.y*projPt.wprojPt.z*projPt.wprojPt.w)

= (viewPt.xviewPt.yviewPt.z, 1)*pProjMatrx;

ProjMatrix =

=

,

(projPt.x*projPt.wprojPt.y*projPt.wprojPt.z*projPt.wprojPt.w)

= ( viewPt.x*ProjMatrix._m11, viewPt.y*ProjMatrix._m22,viewPt.z*Q-QZn,viewPt.z)

projPt.x*projPt.w = viewPt.x*ProjMatrix._m11

projPt.y*projPt.w = viewPt.y*ProjMatrix._m22

projPt.z*projPt.w = viewPt.z*Q-QZn projPt.z = 0

projPt.w = viewPt.z;

viewPt.x = projPt.x*Zn/ ProjMatrix._m11;

viewPt.y = projPt.y*Zn/ ProjMatrix._m22;

viewPt.z = Zn;


4588311

zZn

DIRview = (projPt.x/projMatrix._m11,projPt.y/projMatrix._m22,1)

projPt.x = (screenPt.x-screenWidth/2)/screenWidth*2;

projPt.y = (screenPt.y-screenHeight/2)/screenHeight*2;

projPt.z =0;

DIRview.x = (2*screenPt.x/screenWidth-1)/projMatrix._m11;

DIRview.y = (2*screenPt.y/screenHeight-1)/projMatrix._m22;

DIRview.z = 1;


4588311

Dir

DIRviewDIRworld

DIRview = DIRworld*ViewMatrix;

ViewMatrixD3DGetTransform( D3DTS_VIEW, &ViewMatrix )

DIRworld = DIRview * inverse_ViewMatrix,inverse_ViewMatrix

ViewMatrix


4588311

:

D3DD3DXIntersect


4588311

D3D

D3D SDK

HRESULTD3DXIntersect(

LPD3DXBASEMESHpMesh,

CONST D3DXVECTOR3*pRayPos,

CONST D3DXVECTOR3*pRayDir,

BOOL*pHit,

DWORD*pFaceIndex,

FLOAT*pU,

FLOAT*pV,

FLOAT*pDist,

LPD3DXBUFFER*ppAllHits,

DWORD*pCountOfHits

);

l pMeshID3DXBaseMesh.xdirect9 SDK

l pRayPos

l pRayDir

l pHit true,

l pU U

l pVV

l pDist

l ppAllHits

l pCountOfHits


4588311

pUpVV1(x1,y1,z1),V2(x2,y2,z2),V3(x3,y3,z3), pV = V1 + U(V2-V1) + V(V3-V1),(U,V) UV2VV31UVV1


  • Login