#include "DrawStars.h"
#include "math.h"
CDrawStars::CDrawStars(LPDIRECT3DDEVICE9 pD3DDevice)
{
m_pd3dDevice = pD3DDevice;
m_pLight = new CD3DLight(m_pd3dDevice);
}
CDrawStars::~CDrawStars()
{
Clearup();
}
HRESULT CDrawStars::InitVB()
{
if(FAILED(m_pd3dDevice->CreateVertexBuffer(32*sizeof(VERTEX)
,0
,D3DFVF_VERTEX
,D3DPOOL_DEFAULT
,&m_pBufferVex
,NULL)))
{
return E_FAIL;
}
VERTEX* pVertices1;
if(FAILED(m_pBufferVex->Lock(0, 32*sizeof(VERTEX),(void**)&pVertices1,
0)))
{
return E_FAIL;
}
//初始化光晕的顶点缓冲区
//=============================================================
pVertices1->position = D3DXVECTOR3(8.0f, -8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-8.0f, -8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(8.0f, 8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 1.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-8.0f, 8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 1.0f;
pVertices1++;
//=============================================================
pVertices1->position = D3DXVECTOR3(3.0f, -3.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-3.0f, -3.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(3.0f, 3.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 1.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-3.0f, 3.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 1.0f;
pVertices1++;
//=============================================================
pVertices1->position = D3DXVECTOR3(8.0f, -8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-8.0f, -8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(8.0f, 8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 1.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-8.0f, 8.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 1.0f;
pVertices1++;
//=============================================================
pVertices1->position = D3DXVECTOR3(4.0f, -4.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-4.0f, -4.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 0.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(4.0f, 4.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 1.0f;
pVertices1->tv = 1.0f;
pVertices1++;
pVertices1->position = D3DXVECTOR3(-4.0f, 4.0f, 0.0f);
pVertices1->color = D3DCOLOR_XRGB(0,0,255);
pVertices1->tu = 0.0f;
pVertices1->tv = 1.0f;
pVertices1++;
m_pBufferVex->Unlock();
///////////////////////////////////////////////////////////////////////////////////////////////////////
/*
if(FAILED(D3DXCreateSphere(m_pd3dDevice, 3.96, 24, 24, &g_sphere, NULL)))
return S_FALSE;
if (FAILED(g_sphere->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_LIGHTVERTEX,m_pd3dDevice,&g_sun)))
{
return false ;
}
LIGHTVERTEX* pVerts ;
//
//
// int numVerts1 = 0 ;
//
// if (SUCCEEDED(g_sun->LockVertexBuffer(0, (void **)&pVerts)))
// {
// numVerts1 = g_sun->GetNumVertices() ;
// }
// // pVerts++;
// // pVerts->pos = pVerts[1].pos;
// // pVerts->normal = pVerts[1].normal;
// // pVerts++;
// // pVerts->pos = pVerts[2].pos;
// // pVerts->normal = pVerts[2].normal;
// // pVerts++;
// // pVerts->pos = pVerts[3].pos;
// // pVerts->normal = pVerts[3].normal;
// // numVerts = g_sun->GetNumVertices() ;
//
// for(int i =0;i<numVerts1;i++)
// {
// pVerts++;
// }
//
// for(int i =0;i<3;i++)
// {
// pVerts->pos = pVerts[i*25+25].pos;
// pVerts->normal = pVerts[i*25+25].normal;
// pVerts++;
// }
// numVerts1 = g_sun->GetNumVertices() ;
//
// g_sun->UnlockVertexBuffer() ;
if (SUCCEEDED(g_sun->LockVertexBuffer(0, (void **)&pVerts)))
{
// Get vertex count
int numVerts = g_sun->GetNumVertices() ;
for (int i = 0; i < numVerts; ++i)
{
// Calculates texture coordinates
if(pVerts->normal.x >=0)
pVerts->tu = (asinf(pVerts->normal.y/sqrt( pow(pVerts->normal.x,2) + pow(pVerts->normal.y,2) )) / D3DX_PI )/2 ;
else
pVerts->tu = -1.0f*(asinf(pVerts->normal.y/sqrt( pow(pVerts->normal.x,2) + pow(pVerts->normal.y,2) )) / D3DX_PI )/2 +0.5 ;
pVerts->tv = asinf(pVerts->normal.z) / D3DX_PI + 0.5f ;
++pVerts ;
}
// Unlock the vertex buffer
g_sun->UnlockVertexBuffer() ;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(FAILED(D3DXCreateSphere(m_pd3dDevice, 0.24, 25, 25,
&g_sphere, NULL))) return false;
if (FAILED(g_sphere->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_LIGHTVERTEX,m_pd3dDevice,&g_mercury)))
{
return false ;
}
if (SUCCEEDED(g_mercury->LockVertexBuffer(0, (void **)&pVerts)))
{
// Get vertex count
int numVerts = g_mercury->GetNumVertices() ;
for (int i = 0; i < numVerts; ++i)
{
// Calculates texture coordinates
if(pVerts->normal.x >=0)
pVerts->tu = (asinf(pVerts->normal.y/sqrt( pow(pVerts->normal.x,2) + pow(pVerts->normal.y,2) )) / D3DX_PI )/2 ;
else
pVerts->tu = -1.0f*(asinf(pVerts->normal.y/sqrt( pow(pVerts->normal.x,2) + pow(pVerts->normal.y,2) )) / D3DX_PI )/2 +0.5 ;
pVerts->tv = asinf(pVerts->normal.z) / D3DX_PI + 0.5f ;
++pVerts ;
}
// Unlock the vertex buffer
g_mercury->UnlockVertexBuffer() ;
}
////////////////////////////////////////////////////////////////////
if(FAILED(D3DXCreateSphere(m_pd3dDevice, 0.61, 25, 25,
&g_sphere, NULL))) return false;
if (FAILED(g_sphere->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_LIGHTVERTEX,m_pd3dDevice,&g_venus)))
{
return false ;
}
if (SUCCEEDED(g_venus->LockVertexBuffer(0, (void **)&pVerts)))
{
// Get vertex count
int numVerts = g_venus->GetNumVertices() ;
for (int i = 0; i < numVerts; ++i)
{
// Calculates texture coordinates
if(pVerts->normal.x >=0)
pVerts->tu = (asinf(pVerts->normal.y/sqrt( pow(pVerts->normal.x,2) + pow(pVerts->normal.y,2) )) / D3DX_PI )/2 ;
else
pVerts->tu = -1.0f*(asinf(pVerts->normal.y/sqrt( pow(pVerts->normal.x,2) + pow(pVerts->normal.y,2) )) / D3DX_PI )/2 +0.5 ;
pVerts->tv = asinf(pVerts->normal.z) / D3DX_PI + 0.5f ;
++pVerts ;
}
// Unlock the vertex buffer
g_venus->UnlockVertexBuffer() ;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(FAILED(D3DXCreateSphere(m_pd3dDevice, 0.64, 25, 25,
&g_sphere, NULL))) return false;
if (FAILED(g_sphere->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_LIGHTVERTEX,m_pd3dDevice,&g_earth)))
{
r
- 1
- 2
前往页