1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| bool CWinStars2View::resize(int width, int height)
{
D3DXMATRIX m;
float aspect = (float)width / (float)height;
float fov = 0.847197f;
D3DXMatrixPerspectiveFovLH(
&m,
fov,
aspect,
1.0f,
1e30f);
if( _device )
_device->SetTransform(D3DTS_PROJECTION, &m);
return true;
}
bool CWinStars2View::update(float timeDelta)
{
//on éloigne la planéte d'un facteur 1.000001 sur l'axe des x pour créer une petite animation
Planete[2][18]*=1.000001;
return true;
}
bool CWinStars2View::render()
{
D3DXMATRIX mat2,mat,mat3;
char chaine[40];
if( _device )
{
_device->Clear(0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L);
if (!FAILED(_device->BeginScene()))
{
D3DXMatrixIdentity(&mat);
//Soleil
D3DXMatrixScaling( &mat2, 696000.0, 696000.0, 696000.0 );
_device->SetTransform( D3DTS_WORLD, &mat2);
Soleil->Render(_device,TRUE,FALSE);
//Terre
D3DXMatrixScaling( &mat2, 6384.0, 6384.0, 6384.0 );
D3DXMatrixTranslation(&mat3,Planete[2][18],Planete[2][19],Planete[2][20]);
mat2*=mat;
mat2*=mat3;
_device->SetTransform( D3DTS_WORLD, &mat2 );
Terre->Render(_device,TRUE,TRUE);
_device->EndScene();
_device->Present(NULL, NULL, NULL, NULL);
}
}
return true;
}
void CWinStars2View::OnMouseMove(UINT nFlags, CPoint point)
{
static CPoint pointAnc;
//on peut tourner autour de la terre si on appuie sur le bouton droit de la souris
if (nFlags==MK_RBUTTON )
{
Deplacx-=(point.x-pointAnc.x);
Deplacy-=(point.y-pointAnc.y);
xob=Planete[2][18]+20000.0*cos(Deplacy)*sin(Deplacx);
yob=Planete[2][19]+20000.0*cos(Deplacy)*cos(Deplacx);
zob=Planete[2][20]+20000.0*sin(Deplacy);
D3DXMATRIX m;
D3DXVECTOR3 eye(xob,yob, zob);
D3DXVECTOR3 to(Planete[2][18], Planete[2][19], Planete[2][20]);
D3DXVECTOR3 look(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&m, &eye, &to, &look);
_device->SetTransform(D3DTS_VIEW,&m);
}
pointAnc.x=point.x;
pointAnc.y=point.y;
CView::OnMouseMove(nFlags, point);
} |
Partager