Bonjour à tous, j'ai un petit problème avec mon sweep test de deux spheres.
Pour le faire je me suis grandement inspiré du code de M.Gomez sur Gamasutra : http://www.gamasutra.com/view/featur...mes.php?page=2
Voici mon code :et le code de la formule quadratic :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 bool Sweep::SweepSphereSphere( const float _radiusS1, const D3DXVECTOR3 &_C0S1, const D3DXVECTOR3 &_C1S1, const float _radiusS2, const D3DXVECTOR3 &_C0S2, const D3DXVECTOR3 &_C1S2, D3DXVECTOR3 &_CiS1, D3DXVECTOR3 &_CiS2) { float fTime1 = 0, fTime2 = 0 ; const D3DXVECTOR3 vA = _C1S1 - _C0S1 ; const D3DXVECTOR3 vB = _C1S2 - _C0S2 ; const D3DXVECTOR3 AB = _C0S2 - _C0S1 ; const D3DXVECTOR3 vAB= vB - vA ; const float fRadiusAB = _radiusS1 + _radiusS2 ; const float fA = D3DXVec3Dot(&vAB, &vAB) ; const float fB = 2 * D3DXVec3Dot(&vAB, &AB) ; const float fC = D3DXVec3Dot(&AB, &AB) - (fRadiusAB * fRadiusAB) ; // Check if they're overlapping if(D3DXVec3Dot(&AB, &AB) <= fRadiusAB * fRadiusAB) { _CiS1 = _C0S1 ; _CiS2 = _C0S2 ; return true ; } if(QuadraticFormula(fA, -fB, fC, fTime1, fTime2)) { if( fTime1 > fTime2 ) { float fTmp = fTime1; fTime1 = fTime2; fTime2 = fTmp; } _CiS1 = (1-fTime1)* _C0S1 + fTime1 * _C1S1 ; _CiS2 = (1-fTime2)* _C0S2 + fTime2 * _C1S2 ; return true; } return false; }
Mon problème est que _CiS1 semble me donner de mauvaises valeurs (_CiS2 ne bouge pas, la sphere est immobile).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 bool Sweep::QuadraticFormula(const float _a, const float _b, const float _c, float& _r1, float& _r2) { if((_a >= 0) && (_b >= 0) && (_c >= 0)) { float a = sqrt(_a) ; float b = sqrt(_b) ; float c = sqrt(_c) ; const float q = b*b - 4*a*c; if( q > 0 ) { const float sq = sqrt(q); const float d = 1 / (2*a); _r1 = ( -b + sq ) * d; _r2 = ( -b - sq ) * d; return true;//real roots } else { return false;//complex roots } } else { return false ; } }
Lorsque je replace ma sphere avec ses valeurs ma sphere est mal replacée (parfois meme plus eloignée que le point d'origine).
Pourriez vous m'aider svp ?
Partager