• PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 441KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 10 积分
    下载积分
  • 484
    下载次数
  • 2006-07-31 10:11
    上传日期
用directx9.0做的一个3D坦克游戏,最主要的地方是加进了先进的物理碰撞检测
3D_Tank.rar
  • GameClass
  • res
  • Sound
  • fire.wav
    19.9KB
  • Model
  • tank_console.x
    6.6KB
  • tank_gun.x
    6.5KB
  • sky.x
    56.5KB
  • tank_body.x
    13.1KB
  • Texture
  • fire.dds
    64.1KB
  • Sky.jpg
    54.1KB
  • tank.jpg
    359.6KB
  • minimap.dds
    64.1KB
  • ground.bmp
    12.1KB
  • redpoint.dds
    192B
  • terrain.raw
    16KB
  • Sound.h
    1.3KB
  • D3DInit.suo
    8.5KB
  • Camera.h
    991B
  • Arithmetic.h
    1.1KB
  • Particle.h
    2KB
  • GameFont.cpp
    724B
  • Sky.h
    796B
  • DXInput.h
    763B
  • Sound.cpp
    5.6KB
  • Sky.cpp
    2.1KB
  • Input.cpp
    1.2KB
  • D3DInit.sln
    903B
  • Input.h
    458B
  • Error.h
    160B
  • ComPtr.h
    1.9KB
  • TerrainInfo.h
    871B
  • d3dUtility.cpp
    3.3KB
  • Camera.cpp
    2.9KB
  • TerrainInfo.cpp
    3.6KB
  • Error.cpp
    377B
  • Sprite.h
    711B
  • Sprite.cpp
    1.1KB
  • Particle.cpp
    5.4KB
  • DXInput.cpp
    20B
  • Terrain.h
    1.3KB
  • GameObject.h
    2KB
  • d3dUtility.h
    707B
  • d3dInit.cpp
    6.6KB
  • Terrain.cpp
    3.6KB
  • GameObject.cpp
    8.3KB
  • GameFont.h
    474B
  • D3DInit.vcproj
    5.1KB
  • Arithmetic.cpp
    4.4KB
  • www.pudn.com.txt
    218B
内容介绍
#include "GameObject.h" Tank::Tank() { m_vMoveDirection = D3DXVECTOR3(0, 0, 1); m_pCamera = NULL; m_fGunYaw = 0; m_fGunPitch = 0; m_bAttackMode = FALSE; m_fFireColdTime = 0; m_fChangeModeColdTime = 0; } Tank::~Tank() {} D3DXVECTOR3 & Tank::GetMoveDirection(D3DXVECTOR3 *direction) { *direction = m_vMoveDirection; return m_vMoveDirection; } D3DXVECTOR3 & Tank::GetPosition(D3DXVECTOR3 *position) { *position = m_vPosition; return m_vPosition; } float Tank::GetYaw() { return m_fYaw; } VOID Tank::SetPosition(float x, float y, float z) { m_vPosition = D3DXVECTOR3(x, y, z); CameraUpdate(); } VOID Tank::SetPitchRoll(float pitch, float roll) { m_fPitch = pitch; m_fRoll = roll; } VOID Tank::SetCamera(CCamera *camera) { m_pCamera = camera; } VOID Tank::SetParticle(CParticleSystem *particle) { m_pParticle = particle; } VOID Tank::ChangeMode() { if (m_fChangeModeColdTime == 0) { m_bAttackMode = !m_bAttackMode; m_fChangeModeColdTime = 0.5f; } } VOID Tank::InitObject(const CComPtr<IDirect3DDevice9> &device) { HRESULT hr; m_pDevice = device; IDirect3DTexture9 *tex = 0; hr =D3DXCreateTextureFromFile(m_pDevice.Get(), ".\\res\\Texture\\tank.jpg", &tex); m_pTexture.Reset(tex); ID3DXMesh *meshBody = 0; ID3DXBuffer *mtrlBody = 0; DWORD dwBodyMtrl = 0; hr = D3DXLoadMeshFromX(".\\res\\Model\\tank_body.x", D3DXMESH_MANAGED, m_pDevice.Get(), 0, &mtrlBody, 0, &dwBodyMtrl, &meshBody); if (FAILED(hr)) { HrError(hr);} m_pBodyMesh.Reset(meshBody); if (mtrlBody != 0 && dwBodyMtrl != 0) { D3DXMATERIAL *mtrl = (D3DXMATERIAL*)mtrlBody->GetBufferPointer(); for (DWORD dw = 0; dw < dwBodyMtrl; ++dw) { mtrl[dw].MatD3D.Ambient = mtrl[dw].MatD3D.Diffuse; m_vecBodyMaterial.push_back(mtrl[dw].MatD3D); } } mtrlBody->Release(); ID3DXMesh *meshConsole = 0; ID3DXBuffer *mtrlConsole = 0; DWORD dwConsoleMtrl = 0; hr = D3DXLoadMeshFromX(".\\res\\Model\\tank_console.x", D3DXMESH_MANAGED, m_pDevice.Get(), 0, &mtrlConsole,0, &dwConsoleMtrl, &meshConsole); if (FAILED(hr)) { HrError(hr);} m_pConsoleMesh.Reset(meshConsole); if (mtrlConsole != 0 && dwConsoleMtrl != 0) { D3DXMATERIAL * mtrl = (D3DXMATERIAL *)mtrlConsole->GetBufferPointer(); for (DWORD dw = 0; dw < dwConsoleMtrl; ++dw) { mtrl[dw].MatD3D.Ambient = mtrl[dw].MatD3D.Diffuse; m_vecConsoleMaterial.push_back(mtrl[dw].MatD3D); } } mtrlConsole->Release(); ID3DXMesh *meshGun = 0; ID3DXBuffer *mtrlGun = 0; DWORD dwGunMtrl = 0; hr = D3DXLoadMeshFromX(".\\res\\Model\\tank_gun.x", D3DXMESH_MANAGED, m_pDevice.Get(), 0, &mtrlGun, 0, &dwGunMtrl, &meshGun); if (FAILED(hr)) { HrError(hr);} m_pGunMesh.Reset(meshGun); if (mtrlGun != 0 && dwGunMtrl != 0) { D3DXMATERIAL * mtrl = (D3DXMATERIAL *)mtrlGun->GetBufferPointer(); for (DWORD dw = 0; dw < dwGunMtrl; ++dw) { mtrl[dw].MatD3D.Ambient = mtrl[dw].MatD3D.Diffuse; m_vecGunMaterial.push_back(mtrl[dw].MatD3D); } } mtrlGun->Release(); } VOID Tank::PrepareBodyRenderState() { D3DXMATRIX matTranslation; GenerateTranslationMatrix(&matTranslation, m_vPosition, m_fYaw - 90, m_fPitch, m_fRoll); m_pDevice->SetTransform(D3DTS_WORLD, &matTranslation); GenerateTranslationMatrix(&matTranslation, m_vPosition, m_fYaw, 0, 0); D3DXVECTOR3 look, up, right; GetThreeDirFromMatrix(&matTranslation, &right, &up, &look); } VOID Tank::Render() { PrepareBodyRenderState(); m_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE); HRESULT hr = m_pDevice->SetTexture(0, m_pTexture.Get()); if (FAILED(hr)) { HrError(hr);} m_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); for (UINT i = 0; i < m_vecBodyMaterial.size(); ++i) { m_pDevice->SetMaterial(&m_vecBodyMaterial[i]); m_pBodyMesh->DrawSubset(i); } ResetRenderState(); PrepareConsoleRenderState(); for (UINT i = 0; i < m_vecConsoleMaterial.size(); ++i) { m_pDevice->SetMaterial(&m_vecConsoleMaterial[i]); m_pConsoleMesh->DrawSubset(i); } ResetRenderState(); PrepareGunRenderState(); for (UINT i = 0; i < m_vecGunMaterial.size(); ++i) { m_pDevice->SetMaterial(&m_vecGunMaterial[i]); m_pGunMesh->DrawSubset(i); } ResetRenderState(); } VOID Tank::ResetRenderState() { D3DXMATRIX I; D3DXMatrixIdentity(&I); m_pDevice->SetTransform(D3DTS_WORLD, &I); } VOID Tank::PrepareConsoleRenderState() { D3DXMATRIX matTranslation; GenerateTranslationMatrix(&matTranslation, m_vPosition, m_fYaw + m_fGunYaw - 90, m_fPitch, m_fRoll); m_pDevice->SetTransform(D3DTS_WORLD, &matTranslation); } VOID Tank::PrepareGunRenderState() { D3DXMATRIX matTranslation; D3DXVECTOR3 pos; pos.x = 0; pos.y = 0; pos.z = 0; GenerateTranslationMatrix(&matTranslation, pos, m_fYaw + m_fGunYaw - 90, m_fPitch, m_fRoll); D3DXVECTOR3 look, up, right; GetThreeDirFromMatrix(&matTranslation, &right, &up, &look); D3DXMATRIX matPitch; D3DXMatrixRotationAxis(&matPitch, &look, D3DXToRadian(-m_fGunPitch)); D3DXVec3TransformNormal(&right, &right, &matPitch); D3DXVec3TransformNormal(&up, &up, &matPitch); GenerateMatrix(&matTranslation, right, up, look, m_vPosition); m_pDevice->SetTransform(D3DTS_WORLD, &matTranslation); } VOID Tank::Walk(float length) { m_vPosition += m_vMoveDirection * length; CameraUpdate(); } VOID Tank::BodyYaw(float angle) { m_fYaw += angle; D3DXMATRIX T; D3DXVECTOR3 up(0, 1, 0); D3DXMatrixRotationAxis(&T, &up, D3DXToRadian(angle)); D3DXVec3TransformNormal(&m_vMoveDirection, &m_vMoveDirection, &T); } VOID Tank::GunYaw(float angle) { m_fGunYaw += angle; if (m_fGunYaw > 90) { m_fGunYaw = 90;} if (m_fGunYaw < -90) { m_fGunYaw = -90;} CameraUpdate(); } VOID Tank::GunPitch(float angle) { m_fGunPitch += angle; if (m_fGunPitch > 0) { m_fGunPitch = 0;} if (m_fGunPitch < -30) { m_fGunPitch = -30;} CameraUpdate(); } VOID Tank::Fire() { if (m_fFireColdTime == 0) { D3DXMATRIX matTranslation; D3DXVECTOR3 pos; pos.x = 0; pos.y = 0; pos.z = 0; GenerateTranslationMatrix(&matTranslation, pos, m_fYaw + m_fGunYaw, m_fPitch, m_fRoll); D3DXVECTOR3 look, up, right; GetThreeDirFromMatrix(&matTranslation, &right, &up, &look); D3DXMATRIX matPitch; D3DXMatrixRotationAxis(&matPitch, &right, D3DXToRadian(m_fGunPitch)); D3DXVec3TransformNormal(&look, &look, &matPitch); D3DXVec3TransformNormal(&up, &up, &matPitch); D3DXVECTOR3 vFireDir = m_vPosition + up * 2.5f + look * 10; m_pParticle->SetOrigin(vFireDir); m_pParticle->SetVelocity(look * 200); m_pParticle->AddPartile(); m_fFireColdTime = 0.5f; m_pSound->Play(".\\res\\Sound\\fire.wav"); } } VOID Tank::TimeElapse(float time) { if (m_fFireColdTime > 0) { m_fFireColdTime -= time; if (m_fFireColdTime < 0) { m_fFireColdTime = 0;} } if (m_fChangeModeColdTime > 0) { m_fChangeModeColdTime -= time; if (m_fChangeModeColdTime < 0) { m_fChangeModeColdTime = 0;} } } VOID Tank::CameraUpdate() { if (m_pCamera != NULL && m_bAttackMode == TRUE) { D3DXMATRIX matTranslation; D3DXVECTOR3 pos; pos.x = 0; pos.y = 0; pos.z = 0; GenerateTranslationMatrix(&matTranslation, pos, m_fYaw + m_fGunYaw, m_fPitch, m_fRoll); D3DXVECTOR3 look, up, right; GetThreeDirFromMatrix(&matTranslation, &right, &up, &look); D3DXMATRIX matPitch; D3DXMatrixRotationAxis(&matPitch, &right, D3DXToRadian(m_fGunPitch)); D3DXVec3TransformNormal(&look, &look, &matPitch); D3DXVec3TransformNormal(&up, &up, &matPitch); m_pCamera->SetDirection(look, up, right); m_pCamera->SetPosition(m_vPosition + look * 5.0f + up * 4.0f); } if (m_pCamera != NULL && m_bAttackMode == FALSE)
评论
  • PUDN用户 2008-01-19 18:58:31
    少一个文件 不能用
相关推荐
  • 干涉碰撞检测.zip
    该压缩包了有三个文件,分别有三个程序,其主要用于干涉碰撞检测
  • Ogre碰撞检测
    Ogre碰撞检测技术,包括AABB,球查询等等
  • OpenGL碰撞检测
    用OpenGL开放图形库写的一个碰撞检测系统,算法比较简单,比较基础,基于MFC框架的
  • AndEngine 碰撞检测
    基于Andengine游戏引擎CollisionDetection 实体碰撞检测例子
  • OgreOpcode碰撞检测
    OgreOpcode实现有关Ogre碰撞检测技术
  • 碰撞检测应用
    本位币详细阐述了与碰撞检测问题相关的高效解决方案及相应的数据结构和算法,主要包括:碰撞检测系统中的设计问题、数学和几何学入门、包围体、基本图元测试、层次包围体技术、空间划分、BSP树层次结构、凸体算法、...
  • 碰撞检测算法
    实时碰撞检测算法技术实时碰撞检测算法技术实时碰撞检测算法技术实时碰撞检测算法技术
  • 碰撞检测AABB
    利用AABB算法实现物体与物体之间的碰撞检测
  • 小球碰撞检测
    先绘制立方体,让后球体,计算机3D数学小球碰撞检测
  • AndEngine 碰撞检测
    基于Andengine游戏引擎CollisionDetection 实体碰撞检测例子 修复了原作者的错误,可以正常运行。