图形学实验
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
天津理工大学实验报告学院(系)名称:计算机与通信工程学院
class CRole:public CActiveObj游戏中的人物
virtual void EndRender(void);渲染后操作
virtual void OnRender(void)渲染人物
说明类的继承关系
功能函数的流程图
这里主要列举了几个功能的流程图:
1.声音播放函数:
Play(DWORD loop)
{
if( bEnable==FALSE || !DSSoundFX )
return;
DWORD *Status1=NULL;
if( (DSSoundFX->GetStatus(Status1))!=DS_OK )
goto _next;
if( (*Status1 & DSBSTATUS_PLAYING) == DSBSTA TUS_PLAYING )
return;
_next:
DSSoundFX->SetCurrentPosition(0);
if( loop==-1 )
loop=DSBPLAY_LOOPING; //循环播放
DSSoundFX->Play(0,0,loop);
}
声音播放功能函数的流程图:
2.用鼠标实现输入功能的函数:
Update(){
if (FAILED(m_pDIDev->GetDeviceState(sizeof(DIMOUSESTATE), &m_state)))
{
if (FAILED(m_pDIDev->Acquire()))
{
return FALSE;
}
if (FAILED(m_pDIDev->GetDeviceState(sizeof(DIMOUSESTA TE), &m_state)))
{
return FALSE;
}
}
m_sMousePos.x+=m_state.lX;
m_sMousePos.y-=m_state.lY;
if(m_sMousePos.x<0)m_sMousePos.x=0;
if(m_sMousePos.x>m_iWidth)m_sMousePos.x=m_iWidth;
if(m_sMousePos.y<0)m_sMousePos.y=0;
if(m_sMousePos.y>m_iHeight)m_sMousePos.y=m_iHeight;
return TRUE;
}
用鼠标实现输入功能的流程图:
3. 3d图片文件的显示功能的函数:
Render()
{
glEnable(GL_TEXTURE_2D);
glColor3f(1.f,1.f,1.f);
int triangleIndex;
int index;
for (unsigned short i = 0; i < m_numMeshes; ++i )
{
m_pTexture[m_pMeshes[i].m_textureIndex].Bind(0);
glBegin( GL_TRIANGLES );
for (unsigned short j = 0; j < m_pMeshes[i].m_numTriangles; ++j )
{
triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];
for (unsigned int k = 0; k < 3; ++k )
{
index = m_pTriangles[triangleIndex].m_vertexIndices[k];
glNormal3fv( m_pTriangles[triangleIndex].m_normal );
glTexCoord2f( m_pTriangles[triangleIndex].m_u[k], m_pTriangles[triangleIndex].m_v[k] );
glVertex3fv( m_pVertices[index].m_location );
}
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
}
3d图片文件的显示功能的流程图:
4.游戏场景天空的场景显示函数:
Render()
{
CCamera::GetCameraPointer()->GetCameraPos(&m_sCameraPos);
texture.Bind(0);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glTranslatef(m_sCameraPos.x,-40,m_sCameraPos.z-CCamera::GetCameraPointer()->GetDestToRole());
glRotatef(yrot,0.f,1.f,0.f);
glColor3f(1.f,1.f,1.f);
glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(0.5,0.5);
glVertex3f(0,300,0);
glTexCoord2f(0,0);
glVertex3f(-300,0, 300);
glTexCoord2f(1,0);
glVertex3f(-300,0,-300);
glTexCoord2f(1,1);
glVertex3f( 300,0,-300);
glTexCoord2f(0,1);
glVertex3f( 300,0, 300);
glTexCoord2f(0,0);
glVertex3f(-300,0, 300);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
yrot += 0.04f;
if(yrot > 360.0f)yrot -= 360.0f;
}
游戏场景天空的场景显示的流程图:
5.消息处理功能函数:
Run()
{
if(GetMsgNum()<=0)return;
switch(m_dQueue[0].msg)
{
case MSG_PLAY_MUSIC:
if(CMusic::GetSysMusic()->IsPlay())CMusic::GetSysMusic()->Stop();
CMusic::GetSysMusic()->LoadMusic(m_dQueue[0].str1);