#include "DrawRound.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDrawRound::CDrawRound(LPDIRECT3DDEVICE9 pD3DDevice)
{
m_pd3dDevice = pD3DDevice;
m_Sun = InitVB(pD3DDevice, 3.0f, 30, 30);
m_Mercury = InitVB(pD3DDevice,0.38f,20,20);
m_Venus = InitVB(pD3DDevice,0.95f,20,20);
m_Moon = InitVB(pD3DDevice,0.2f,20,20);
m_Earth = InitVB(pD3DDevice,1.0f,20,20);
m_Mars = InitVB(pD3DDevice,0.53f,20,20);
m_Jupiter= InitVB(pD3DDevice,1.3f,20,20);
m_Saturn= InitVB(pD3DDevice,1.2f,20,20);
m_Uranus= InitVB(pD3DDevice,1.1f,20,20);
m_Neptune= InitVB(pD3DDevice,1.05f,20,20);
}
#define FVF_VERTEX D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1
CDrawRound::~CDrawRound()
{
m_Sun ->Release();
m_Earth ->Release();
m_Moon ->Release();
m_Sun = NULL;
m_Earth = NULL;
m_Moon = NULL;
}
LPD3DXMESH CDrawRound::InitVB(LPDIRECT3DDEVICE9 pd3dDevice, float fRad,
UINT slices,UINT stacks)
{
//D3DXCreateSphere(m_pD3dDevice,0.5f,50,50,&mesh,NULL);
CUSTOMVERTEX g_Vertices[37] ;
float r=5;
for(int i=0;i<37;i++)
{
float x = r*cos(i*10*3.14/180);
float z = r*sin(i*10*3.14/180);
g_Vertices[i].x=x;
g_Vertices[i].z=z;
g_Vertices[i].y=0.0f;
g_Vertices[i].color=D3DCOLOR_XRGB(0,255,255);
}
if(FAILED(m_pd3dDevice->CreateVertexBuffer(sizeof(g_Vertices)
,0
,D3DFVF_CUSTOMVETEX
,D3DPOOL_MANAGED
,&m_pBufferRec
,NULL)))
{
return NULL;
}
VOID* pVertices;
if(FAILED(m_pBufferRec->Lock(0,
sizeof(g_Vertices),(void**)&pVertices,
0)))
{
return NULL;
}
memcpy(pVertices,g_Vertices,sizeof(g_Vertices));
m_pBufferRec->Unlock();
LPD3DXMESH mesh;
if (FAILED(D3DXCreateSphere(pd3dDevice, fRad, slices, stacks,&mesh,NULL)))
return NULL;
// create a copy of the mesh with texture coordinates,
// since the D3DX function doesn't include them
LPD3DXMESH texMesh;
if (FAILED(mesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM,FVF_VERTEX,m_pd3dDevice,&texMesh)))
// failed, return un-textured mesh
return mesh;
// finished with the original mesh, release it
mesh->Release();
// lock the vertex buffer
LPVERTEX pVerts;
if (SUCCEEDED(texMesh->LockVertexBuffer(0,(LPVOID*) &pVerts))) {
// get vertex count
int numVerts = texMesh->GetNumVertices();
// loop through the vertices
for (int i=0;i<numVerts;i++) {
// calculate texture coordinates
pVerts->tu=asinf(pVerts->norm.x)/D3DX_PI+0.5f;
pVerts->tv=asinf(pVerts->norm.y)/D3DX_PI+0.5f;
// go to next vertex
pVerts++;
}
// unlock the vertex buffer
texMesh->UnlockVertexBuffer();
}
// return pointer to caller
return texMesh;
return S_OK;
}
void CDrawRound::Render()
{
m_pd3dDevice ->SetRenderState(D3DRS_LIGHTING,false);
m_pd3dDevice ->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
D3DXMATRIX matWorld,mScale;
/*太阳*/
D3DXMATRIX m_SunWorld;
D3DXMATRIX m_suntrans;//平移矩阵
D3DXMATRIX mSunRotationself;//自转矩阵
D3DXMatrixTranslation(&m_suntrans,0,0,0);//返回的是平移矩阵,由于为零,所以这里太阳的世界坐标相当于没变
D3DXMatrixIdentity(&m_SunWorld);
D3DXMatrixTranslation(&m_suntrans,0,0,0);//平移
D3DXMatrixRotationY(&m_SunWorld,timeGetTime()/5000.0f);//太阳自转
D3DXMatrixMultiply(&m_SunWorld,&m_suntrans,&m_SunWorld );//m_SunWorld=mSunRotationself*m_SunWorld平移变换得到太阳的世界坐标;
m_pd3dDevice->SetTransform(D3DTS_WORLD,&m_SunWorld);
//m_pd3dDevice->SetMaterial(&Yellowmtrl);
m_pd3dDevice ->SetTexture(0,m_pTexture[0]);
m_Sun->DrawSubset(0);
/***********/
/*(水星)Mercury*/
D3DXMATRIX m_MercuryWorld,m_MercuryRound;
D3DXMATRIX m_mercurytrans;//平移矩阵
D3DXMATRIX m_mercuryRotationself;//自转矩阵
D3DXMATRIX m_mercuryRotationpublic;//公转矩阵
D3DXMatrixTranslation(&m_mercurytrans,5,0,0);//平移
D3DXMatrixRotationY(&m_mercuryRotationself,timeGetTime()/1000.0f);//水星自转
D3DXMatrixRotationY(&m_mercuryRotationpublic,timeGetTime()/3000.0f);//水星公转
D3DXMatrixMultiply(&m_MercuryWorld,&m_mercuryRotationself,&(m_mercurytrans*m_mercuryRotationpublic) );
D3DXMatrixMultiply(&m_MercuryWorld,&m_MercuryWorld,&m_SunWorld );
m_pd3dDevice->SetTransform(D3DTS_WORLD,&m_MercuryWorld);
m_pd3dDevice ->SetTexture(0,m_pTexture[1]);
m_Mercury->DrawSubset(0);
m_pd3dDevice->SetStreamSource(0, m_pBufferRec,0,sizeof(CUSTOMVERTEX));
m_pd3dDevice->SetFVF(D3DFVF_CUSTOMVETEX);
D3DXMatrixTranslation(&m_MercuryRound, 0, 0, 0);
m_pd3dDevice->SetTransform(D3DTS_WORLD, &m_MercuryRound);
m_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP ,0,36);//轨迹
/***********/
/*(金星)Venus*/
D3DXMATRIX m_VenusWorld,m_VenusRound;
D3DXMATRIX m_venustrans;//平移矩阵
D3DXMATRIX m_venusRotationself;//自转矩阵
D3DXMATRIX m_venusRotationpublic;//公转矩阵
D3DXMatrixTranslation(&m_venustrans,-7,0,0);//平移
D3DXMatrixRotationY(&m_venusRotationself,timeGetTime()/1000.0f);//金星自转
D3DXMatrixRotationY(&m_venusRotationpublic,timeGetTime()/4000.0f);//金星公转
D3DXMatrixMultiply(&m_VenusWorld,&m_venusRotationself,&(m_venustrans*m_venusRotationpublic) );
D3DXMatrixMultiply(&m_VenusWorld,&m_VenusWorld,&m_SunWorld );
m_pd3dDevice->SetTransform(D3DTS_WORLD,&m_VenusWorld);
m_pd3dDevice ->SetTexture(0,m_pTexture[2]);
m_Venus->DrawSubset(0);
m_pd3dDevice->SetStreamSource(0, m_pBufferRec,0,sizeof(CUSTOMVERTEX));
m_pd3dDevice->SetFVF(D3DFVF_CUSTOMVETEX);
D3DXMatrixTranslation(&m_VenusRound, 0, 0, 0);
D3DXMatrixScaling(&mScale,1.4,0,1.4);
D3DXMatrixMultiply(&m_VenusRound,&m_VenusRound,&mScale );
m_pd3dDevice->SetTransform(D3DTS_WORLD, &m_VenusRound);
m_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP ,0,36);//轨迹
/***********/
/*地球*/
D3DXMATRIX m_EarthWorld,m_EarthRound;
D3DXMATRIX m_earthtrans;//平移矩阵
D3DXMATRIX m_earthRotationself;//自转矩阵
D3DXMATRIX m_earthRotationpublic;//公转矩阵
D3DXMatrixTranslation(&m_earthtrans,10,0,0);//平移
D3DXMatrixRotationY(&m_earthRotationself,timeGetTime()/1000.0f);//地球自转
D3DXMatrixRotationY(&m_earthRotationpublic,timeGetTime()/5000.0f);//地球公转
//m_EarthWorld=m_earthRotationself*(m_earthtrans*m_earthRotationpublic)*m_SunWorld;//先平移,再旋转!!!
D3DXMatrixMultiply(&m_EarthWorld,&m_earthRotationself,&(m_earthtrans*m_earthRotationpublic) );
D3DXMatrixMultiply(&m_EarthWorld,&m_EarthWorld,&m_SunWorld );
m_pd3dDevice->SetTransform(D3DTS_WORLD,&m_EarthWorld);
m_pd3dDevice ->SetTexture(0,m_pTexture[3]);
m_Earth->DrawSubset(0);
m_pd3dDevice->SetStreamSource(0, m_pBufferRec,0,sizeof(CUSTOMVERTEX));
m_pd3dDevice->SetFVF(D3DFVF_CUSTOMVETEX);
D3DXMatrixTranslation(&m_EarthRound, 0, 0, 0);
D3DXMatrixScaling(&mScale,2,0,2);
D3DXMatrixMultiply(&m_EarthRound,&m_EarthRound,&mScale );
m_pd3dDevice->SetTransform(D3DTS_WORLD, &m_EarthRound);
m_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP ,0,36);//轨迹
/***********/
/*月球*/
D3DXMATRIX m_MoonWorld,m_MoonRound;
D3DXMATRIX m_moontrans;//平移矩阵
D3DXMATRIX m_moonRotationSelf;//自转矩阵
D3DXMATRIX m_moonRotationpublic;//公转矩阵
D3DXMatrixTranslation(&m_moontrans,2,0,0);//平移
D3DXMatrixRotationY(&m_moonRotationSelf,timeGetTime()/1000.0f);//月球自转
D3DXMatrixRotationY(&m_moonRotationpublic,timeGetTime()/1000.0f);//月球公转
//m_MoonWorld=m_moonRotationSelf*(m_moontrans*m_moonRotationpublic)*(m_earthtrans*m_earthRotationpublic)*m_SunWorld;
D3DXMatrixMultiply(&m_MoonWorld,&m_moonRotationSelf,&(m_moontrans*m_moonRotationpublic) );
D3DXMatrixMultiply(&m_MoonWorld,&m_MoonWorld,&(m_earthtrans*m_earthRotationpublic) );
D3DXMatrixMultiply(&m_MoonWorld,&m_MoonWorld,&m_SunWorld );
m_pd3dDevice->SetTransform(D3DTS_WORLD,&m_MoonWorld);
m_p
没有合适的资源?快使用搜索试试~ 我知道了~
D3D太阳系(轨道自转公转)
共109个文件
tlog:50个
jpg:16个
h:10个
需积分: 9 27 下载量 67 浏览量
2013-04-08
10:34:01
上传
评论
收藏 14.2MB RAR 举报
温馨提示
Direct 9.0出来的太阳系,visualC++10下检测通过,带有摄像机,自转公转,轨道,以及纹理贴图,天空盒
资源推荐
资源详情
资源评论
收起资源包目录
D3D太阳系(轨道自转公转) (109个子文件)
DrawRound.cpp 14KB
D3DBox.cpp 5KB
D3DBox.cpp 5KB
D3DInit.cpp 5KB
DrawRound.cpp 4KB
CreateWindows.cpp 3KB
CreateWindows.cpp 3KB
Camera.cpp 2KB
Camera.cpp 1KB
D3DSphere.exe 66KB
D3DSphere.vcxproj.filters 2KB
DrawRound.h 1KB
DrawRound.h 979B
D3DBox.h 563B
D3DBox.h 563B
D3DInit.h 536B
D3DInit.h 536B
header.h 392B
header.h 392B
Camera.h 245B
Camera.h 245B
vc100.idb 579KB
D3DSphere.ilk 564KB
d3dsphere-d83634ae.ipch 35.56MB
top.jpg 131KB
Venus.jpg 120KB
Sun.jpg 78KB
黑洞.jpg 61KB
飞船.jpg 60KB
银河.jpg 57KB
Earth.jpg 50KB
Mars.jpg 39KB
Jupiter.jpg 35KB
Moon.jpg 27KB
1.jpg 19KB
Uranus.jpg 9KB
Neptune.jpg 8KB
Saturn.jpg 6KB
Mercury.jpg 3KB
preview.jpg 2KB
D3DSphere.lastbuildstate 100B
D3DSphere.log 5KB
D3DSphere.exe.embed.manifest 406B
D3DSphere.exe.intermediate.manifest 381B
DrawRound.obj 68KB
D3DBox.obj 47KB
D3DInit.obj 45KB
Camera.obj 40KB
CreateWindows.obj 37KB
D3DSphere.pdb 819KB
vc100.pdb 268KB
太阳系.psd 689KB
D3DSphere_manifest.rc 208B
D3DSphere.exe.embed.manifest.res 472B
D3DSphere.sdf 30.52MB
D3DSphere.sln 894B
D3DSphere.suo 20KB
CL.read.1.tlog 83KB
CL.write.1.tlog 7KB
link.read.1.tlog 5KB
cl.command.1.tlog 4KB
link.command.1.tlog 3KB
link.write.1.tlog 2KB
rc.command.1.tlog 692B
mt.read.1.tlog 470B
mt.write.1.tlog 470B
mt.command.1.tlog 468B
rc.write.1.tlog 450B
rc.read.1.tlog 442B
link.4240-cvtres.read.1.tlog 2B
link.2720.read.1.tlog 2B
link.7020.write.1.tlog 2B
link.6416.write.1.tlog 2B
link.6416-cvtres.write.1.tlog 2B
link.2720-cvtres.write.1.tlog 2B
link.1732-cvtres.write.1.tlog 2B
link.4764-cvtres.read.1.tlog 2B
link.3000-cvtres.read.1.tlog 2B
link.1732-cvtres.read.1.tlog 2B
link.7020.read.1.tlog 2B
link.2720-cvtres.read.1.tlog 2B
link.3404.read.1.tlog 2B
link-cvtres.write.1.tlog 2B
link.3000.read.1.tlog 2B
link.1732.read.1.tlog 2B
link.3404-cvtres.write.1.tlog 2B
link.6416-cvtres.read.1.tlog 2B
link.3000.write.1.tlog 2B
link.4764.write.1.tlog 2B
link.4764-cvtres.write.1.tlog 2B
link.4240.read.1.tlog 2B
link-cvtres.read.1.tlog 2B
link.3404-cvtres.read.1.tlog 2B
link.2124-cvtres.read.1.tlog 2B
link.2124.read.1.tlog 2B
link.7020-cvtres.read.1.tlog 2B
link.3000-cvtres.write.1.tlog 2B
link.1732.write.1.tlog 2B
link.2124-cvtres.write.1.tlog 2B
link.2124.write.1.tlog 2B
共 109 条
- 1
- 2
资源评论
xuqiang0088
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功