Bonjour, je cherche à calculer l'impulsion générée par OBB1 sur OBB2.
J'ai le point P, le plus proche du centre de masse OBB1 sur l'axe d'OBB2 où a eu lieu la collision.
Je le calcule comme suit :
Code Java : 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
41
42
43
44
45
46
47
48
49
50
51
52
53 void ClosestPtPointOBB(Vector2 p, RotatedRectangle other, out Vector2 q)//, out Vector2 axis) { List<Vector2> Other_Axis = new List<Vector2>(); Other_Axis.Add((other.Center_X_Axis() - other.CenterOfMass()) ); Other_Axis.Add((other.Center_Y_Axis() - other.CenterOfMass())); Vector2 aAxis0 = Other_Axis[0]; Vector2 aAxis1 = Other_Axis[1]; List<float> Other_Edge = new List<float>(); Other_Edge.Add((other.Width / 2)); Other_Edge.Add(( other.Height/2)); Vector2 d = p - other.CenterOfMass(); // Start result at center of box; make steps from there q = other.CenterOfMass(); TheAxis = other.CenterOfMass(); for (int i =0;i<2;i++) { Other_Axis[i].Normalize(); } for (int i =0;i<2;i++) { aAxis0.Normalize(); aAxis1.Normalize(); Other_Axis[0] = aAxis0; Other_Axis[1] = aAxis1; float dist = Vector2.Dot(d, Other_Axis[i]); // If distance farther than the box extents, clamp to the box // Step that distance along the axis to get world coordinate if (dist > Other_Edge[i]) { dist = Other_Edge[i]; } if (dist < -Other_Edge[i]) { dist = -Other_Edge[i]; } q += Other_Axis[i]*dist; //Ce qui me pose problème, récupérer l'axe en collision pour calculer la normale TheAxis += Other_Axis[i]; } }
Je me sert de ce petit tuto
http://www.myphysicslab.com/collision.html
et voilà comment j'ai mis en place le calcul de mon impulsion
Code Java : 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 public void Inertie_Momentum(RotatedRectangle other, out float j) { Vector2 normale = new Vector2(other.UpperLeftCorner().X - PointQ.X, other.UpperLeftCorner().Y - PointQ.Y); /*if (inverse == 0) normale = new Vector2(normale.Y, -normale.X); else*/ normale = new Vector2(-normale.Y, normale.X); j = -((1 + 1) * (Vector2.Dot(velocity, normale))) / ( 2+ (((((this.Rp.X * normale.X) + (this.Rp.Y * normale.Y) )*( (this.Rp.X * normale.X )+ (this.Rp.Y * normale.Y))) / inertieRotat) + ((((other.Rp.X * normale.X) + (other.Rp.Y * normale.Y) )* ((other.Rp.X * normale.X) + (other.Rp.Y * normale.Y))) / other.inertieRotat))); }
Mais cela ne fonctionne pas comme je le voudrais, à un certain moment la rotation change de sens alors que je suis toujours en collision sur la même face.
Le test actuel repose sur le fait que je vient toujours entrer en collision sur la même face, coté gauche, au plus prés de du coin supérieur.
Je prépare une vidéo pour plus de compréhension.
Si quelqu'un voit d'où vient le problème, un peu d'aide serait la bien venue.
Merci
Partager