Skip to content

Commit 29737c6

Browse files
Fixed friction and restitution usage
1 parent 2601cb5 commit 29737c6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/polyray/physics/PhysicsObject.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ public void update(double dt) {
4747
acc.y = 0.0d;
4848
acc.z = 0.0d;
4949
}
50+
51+
public void applyGround(double dt, double height, Vector3f normal) {
52+
if (pos.y < height) {
53+
Vector3f v = new Vector3f((float) (pos.x - prevPos.x), (float) (pos.y - prevPos.y), (float) (pos.z - prevPos.z));
54+
double diff = height - pos.y;
55+
Vector3f resolve = Vector3f.mul(normal, (float) diff);
56+
pos.x += resolve.x;
57+
pos.y += resolve.y;
58+
pos.z += resolve.z;
59+
if (Vector3f.dot(v, normal) > 0.0f) {
60+
return;
61+
}
62+
Vector3f vel = bounce(v, normal);
63+
prevPos.x = pos.x - vel.x;
64+
prevPos.y = pos.y - vel.y;
65+
prevPos.z = pos.z - vel.z;
66+
}
67+
}
5068

5169
protected Vector3f bounce(Vector3f v, Vector3f n) {
5270
float height = -Vector3f.dot(v, n);

0 commit comments

Comments
 (0)