下载

1下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 三维编程实验十二、圆柱体和球的创建

三维编程实验十二、圆柱体和球的创建.doc

三维编程实验十二、圆柱体和球的创建

hlphlp
2018-09-11 0人阅读 举报 0 0 暂无简介

简介:本文档为《三维编程实验十二、圆柱体和球的创建doc》,可适用于IT/计算机领域

实验十二、圆柱体和球的创建、实验目的、掌握DD的圆柱体和球的创建、实验步骤、打开vsnet打开ftp上的Ddemo项目执行并观看结果。、定义四个全局变量intiSegment=intiSpherePointNums=LPDIRECTDVERTEXBUFFERgpVBSphere=LPDIRECTDVERTEXBUFFERgpVBCylinder=、修改顶点函数HRESULTInitVertexBuffer(){VOID*pVerticesiSegment=圆柱体分段数该值越大越圆floatfRadius=f圆柱体切面半径floatfHeight=f圆柱体高度floatfDelta=DDXPIiSegment*f圆柱体顶点角度floatfTheta,fPhi球的经度纬度floatfSphereRadius=f球半径floatiLongSeg=floatiLatSeg=iSpherePointNums=iLongSeg*iLatSeg*fTheta=DDXPIiLongSeg*fPhi=DDXPIiLatSeg*CUSTOMVERTEX*pVertex为DD设备创建顶点缓冲if(FAILED(gpDDDevice>CreateVertexBuffer(((iSegment)*(iSegment)*)*sizeof(CUSTOMVERTEX),,DDFVFCUSTOMVERTEX,DDPOOLDEFAULT,gpVBCylinder,))){returnEFAIL}if(FAILED(gpDDDevice>CreateVertexBuffer(iSpherePointNums*sizeof(CUSTOMVERTEX),,DDFVFCUSTOMVERTEX,DDPOOLDEFAULT,gpVBSphere,))){returnEFAIL}获得指向顶点缓冲的指针并且锁定准备写入数据if(FAILED(gpVBCylinder>Lock(,,(void**)pVertex,))){returnEFAIL}floatx,zinti=sidefor(i=i<=iSegmenti){x=fRadius*cosf(fDelta*i)z=fRadius*sinf(fDelta*i)pVertex>x=xpVertex>y=fHeightfpVertex>z=zpVertex>nx=xpVertex>ny=pVertex>nz=zpVertex>u=(float)iiSegmentpVertex>v=fpVertexpVertex>x=xpVertex>y=fHeightfpVertex>z=zpVertex>nx=xpVertex>ny=pVertex>nz=zpVertex>u=(float)iiSegmentpVertex>v=fpVertex}toppVertex>x=fpVertex>y=fHeightfpVertex>z=fpVertex>nx=pVertex>ny=pVertex>nz=pVertex>u=fpVertex>v=fpVertexfor(i=iSegmenti>=i){x=fRadius*cosf(fDelta*i)z=fRadius*sinf(fDelta*i)pVertex>x=xpVertex>y=fHeightfpVertex>z=zpVertex>nx=pVertex>ny=pVertex>nz=pVertex>u=*cosf(fDelta*i)pVertex>v=*sinf(fDelta*i)pVertex}bottompVertex>x=fpVertex>y=fHeightfpVertex>z=fpVertex>nx=pVertex>ny=pVertex>nz=pVertex>u=fpVertex>v=fpVertexfor(i=i<=iSegmenti){x=fRadius*cosf(fDelta*i)z=fRadius*sinf(fDelta*i)pVertex>x=xpVertex>y=fHeightfpVertex>z=zpVertex>nx=pVertex>ny=pVertex>nz=pVertex>u=*cosf(fDelta*i)pVertex>v=*sinf(fDelta*i)pVertex}解锁gpVBCylinder>Unlock()floatx,y,z获得指向顶点缓冲的指针并且锁定准备写入数据if(FAILED(gpVBSphere>Lock(,,(void**)pVertex,))){returnEFAIL}for(floati=DDXPIi<DDXPIfPhii=fPhi)纬度{for(floatj=j<DDXPI*j=fTheta)经度{x=fRadius*cosf(i)*cosf(j)z=fRadius*cosf(i)*sinf(j)y=fRadius*sinf(i)pVertex>x=xpVertex>y=ypVertex>z=zpVertex>nx=xpVertex>ny=ypVertex>nz=zpVertex>u=j(DDXPI*)pVertex>v=(DDXPIi)DDXPIpVertexx=fRadius*cosf(ifPhi)*cosf(j)z=fRadius*cosf(ifPhi)*sinf(j)y=fRadius*sinf(ifPhi)pVertex>x=xpVertex>y=ypVertex>z=zpVertex>nx=xpVertex>ny=ypVertex>nz=zpVertex>u=j(DDXPI*)pVertex>v=(DDXPIifPhi)DDXPIpVertexx=fRadius*cosf(i)*cosf(jfTheta)z=fRadius*cosf(i)*sinf(jfTheta)y=fRadius*sinf(i)pVertex>x=xpVertex>y=ypVertex>z=zpVertex>nx=xpVertex>ny=ypVertex>nz=zpVertex>u=(jfTheta)(DDXPI*)pVertex>v=(DDXPIi)DDXPIpVertexx=fRadius*cosf(ifPhi)*cosf(jfTheta)z=fRadius*cosf(ifPhi)*sinf(jfTheta)y=fRadius*sinf(ifPhi)pVertex>x=xpVertex>y=ypVertex>z=zpVertex>nx=xpVertex>ny=ypVertex>nz=zpVertex>u=(jfTheta)(DDXPI*)pVertex>v=(DDXPIifPhi)DDXPIpVertex}}解锁gpVBSphere>Unlock()returnSOK}、渲染函数的渲染图元函数改为gpDDDevice>SetStreamSource(,gpVertexBuffer,,sizeof(CUSTOMVERTEX))上面这条指定原有的顶点缓冲的语句注释掉gpDDDevice>SetStreamSource(,gpVBCylinder,,sizeof(CUSTOMVERTEX))objRecz=SetupRotation()gpDDDevice>DrawPrimitive(DDPTTRIANGLESTRIP,,iSegment*)sidegpDDDevice>DrawPrimitive(DDPTTRIANGLEFAN,(iSegment)*,iSegment)topgpDDDevice>DrawPrimitive(DDPTTRIANGLEFAN,(iSegment)*,iSegment)bottomgpDDDevice>SetStreamSource(,gpVBSphere,,sizeof(CUSTOMVERTEX))objRecz=SetupRotation()gpDDDevice>SetRenderState(DDRSALPHABLENDENABLE,true)gpDDDevice>DrawPrimitive(DDPTTRIANGLESTRIP,,iSpherePointNums)

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/6

三维编程实验十二、圆柱体和球的创建

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利