Ich spiele nur ein bisschen in der Verarbeitung herum, da ich es besser kenne als jede andere Sprache und stolperte auf dieser Website benutzerdefinierte 2D -Physik -Engine. So weit, ist es gut. Ich bin an dem Punkt, an dem ich 2 Rechtecke kollidieren und die Kollision lösen muss. Nach dem Papier sollte ich den Code verwenden: < /p>
void ResolveCollision( Object A, Object B )
{
// Calculate relative velocity
Vec2 rv = B.velocity - A.velocity
// Calculate relative velocity in terms of the normal direction
float velAlongNormal = DotProduct( rv, normal )
// Do not resolve if velocities are separating
if(velAlongNormal > 0)
return;
// Calculate restitution
float e = min( A.restitution, B.restitution)
// Calculate impulse scalar
float j = -(1 + e) * velAlongNormal
j /= 1 / A.mass + 1 / B.mass
// Apply impulse
Vec2 impulse = j * normal
A.velocity -= 1 / A.mass * impulse
B.velocity += 1 / B.mass * impulse
}
< /code>
Dies ist in C ++ geschrieben, daher müsste ich es auf Java portieren. Und hier bleibe ich auf zwei Dingen. 1: Was bedeutet der Autor mit "normal"? Wie bekomme ich das "normale"? Sache 2 sind diese 3 Codezeilen: < /p>
Vec2 impulse = j * normal
A.velocity -= 1 / A.mass * impulse
B.velocity += 1 / B.mass * impulse
< /code>
Er erstellt einen Vektor, der nur 1 Zahl hat? J * Normal?
Ich habe kein klares Bild darüber, was genau passiert, was mir nicht wirklich zugute kommt. < /p>
Versuchen Sie, eine Physik -Engine in Java aus Dokumentarfilm zu erstellen, die C ++ verwendet ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Ausgabe in Bezug auf die Schulung Physik informiertes neuronales Netzwerk
by Anonymous » » in Python - 0 Replies
- 28 Views
-
Last post by Anonymous
-
-
-
Anwendung der Physik auf nur eines von zwei kollidierenden Objekten (Einheit)
by Anonymous » » in C# - 0 Replies
- 6 Views
-
Last post by Anonymous
-