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
| ///*********CALCUL DE LA MATRICE DE PROJECTION**********
D3DXMATRIX matProjection;
//Bords de l'écran
D3DXVECTOR3 pa(- mmWIDTH / 2.0f,-mmHEIGHT/2.0f,0.0f);
D3DXVECTOR3 pb(mmWIDTH / 2.0f,-mmHEIGHT/2.0f,0.0f);
D3DXVECTOR3 pc(- mmWIDTH / 2.0f,mmHEIGHT/2.0f,0.0f);
//Position des yeux
D3DXVECTOR3 pe(0.0f,0.0f,-50.0f);
//Base orthonormée pour l'écran
D3DXVECTOR3 vr; D3DXVECTOR3 nvr;
D3DXVECTOR3 vu; D3DXVECTOR3 nvu;
D3DXVECTOR3 vn; D3DXVECTOR3 nvn;
D3DXVECTOR3 va;
D3DXVECTOR3 vb;
D3DXVECTOR3 vc;
D3DXVec3Subtract(&vr, &pb, &pa);
D3DXVec3Subtract(&vu,&pc,&pa);
D3DXVec3Normalize(&nvr,&vr);
D3DXVec3Normalize(&nvu,&vu);
D3DXVec3Cross(&vn, &nvr, &nvu);
D3DXVec3Normalize(&nvn, &vn);
//Détermine les vecteurs des coins de l'écran
D3DXVec3Subtract(&va, &pa, &pe);
D3DXVec3Subtract(&vb,&pb,&pe);
D3DXVec3Subtract(&vc, &pc, &pe);
//Distance yeux/plan de l'écran
float d = - D3DXVec3Dot(&va,&vn);
//Plan near, plan far
float n = 1.0f, f = 20000.0f;
//Extrémités du frustum de vue
float l = D3DXVec3Dot(&nvr,&va) * n / d;
float r = D3DXVec3Dot(&nvr,&vb) * n / d;
float b = D3DXVec3Dot(&nvu,&va) * n / d;
float t = D3DXVec3Dot(&nvu,&vc) * n / d;
//D3DXMatrixPerspectiveOffCenterLH(&matProjection, l, r, b, t, n, f);
//équivalent de glFrustum
myFrustum(&matProjection, l, r, b, t, n, f);
d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);
//Rotation de la projection pour qu'elle soit non-perpendiculaire
D3DXMATRIX M;
M._11 = vr.x; M._21 = vr.y; M._31 = vr.z;
M._12 = vu.x; M._22 = vu.y; M._32 = vu.z;
M._13 = vn.x; M._23 = vn.y; M._33 = vn.z;
M._44 = 1.0f;
d3ddev->MultiplyTransform(D3DTS_PROJECTION, &M);
D3DXMATRIX eyeTranslation;
D3DXMatrixTranslation(&eyeTranslation, -pe.x, -pe.y, -pe.z);
d3ddev->MultiplyTransform(D3DTS_PROJECTION, &eyeTranslation); |
Partager