Bonjour à tous,
Je suis en train d'essayer de faire rebondir une bille sur un terrain plat. Pour cela j'utilise cette fonction :
Le problème : ce code est tiré d'un autre projet qui fonctionne très bien, mais la la bille rebondit correctement en y mais ne bouge pas en x et z (elle rebondit sur place, malgré sa vitesse initiale en x et z).
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 bool PlaneSphereResolution(D3DXVECTOR3& _PrevQ, D3DXVECTOR3& _Q, D3DXVECTOR3& _vInit, float _fFrame, float _fRadius) { D3DXMATRIX transMat; D3DXVECTOR3 P1(_PrevQ), P2(_Q), P3; D3DXVECTOR3 V1in; D3DXVECTOR3 vUp(0, 1, 0) ; // Restitution coefficient float fRebound = 0.6f; // Compute velocity V1in = P2 - P1; float distP1P2 = D3DXVec3Length(&V1in); float fVCurrent = distP1P2/_fFrame ; // Compute Q float k; _Q.y = _fRadius ; k = (_Q.y - P1.y) / (P2.y - P1.y); _Q.x = k*(P2.x-P1.x)+P1.x; _Q.z = k*(P2.z-P1.z)+P1.z; // Rebound D3DXVECTOR3 Vout, P2Q = P2 - _Q; D3DXVec3Normalize(&P2Q, &P2Q); P3 = P2 - (1+fRebound) * D3DXVec3Dot(&P2Q, &vUp) * vUp; // Reinitialise motion parameters Vout = P3-_Q; D3DXVec3Normalize(&Vout, &Vout); _vInit = fRebound * fVCurrent * Vout; return true ; }
Pourriez vous m'aider à régler ce problème svp ?
Partager