-
Notifications
You must be signed in to change notification settings - Fork 0
/
ResetBodyStrategy.java
37 lines (32 loc) · 1.3 KB
/
ResetBodyStrategy.java
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
package sk.yin.yngine.main;
import com.bulletphysics.linearmath.MotionState;
import com.bulletphysics.linearmath.Transform;
import javax.vecmath.Vector3f;
import sk.yin.yngine.scene.attributes.PhysicsAttribute;
import sk.yin.yngine.util.Log;
/**
* If an object falls off the ground and reaches certain distance from
* center of the scene, this strategy moves it back to position at start
* of animation.
*/
class ResetBodyStrategy implements IGLRendererStrategy {
GLRenderer outer;
public ResetBodyStrategy(GLRenderer outer) {
this.outer = outer;
}
public void applyStrategy() {
Transform t = new Transform();
for (int i = 0; i < GLRenderer.MODEL_NUM; i++) {
MotionState ms = outer.motionState[i];
ms.getWorldTransform(t);
if (t.origin.lengthSquared() > GLRenderer.WORLD_RADIUS_SQUARED) {
if (ms instanceof PhysicsAttribute) {
Log.log(this.getClass().getName() + " => body resetOrigin");
((PhysicsAttribute) ms).resetToStartOrigin(outer.rigidBodies[i]);
outer.rigidBodies[i].setAngularVelocity(new Vector3f(0.0f, 0.0f, 0.0f));
outer.rigidBodies[i].setLinearVelocity(new Vector3f(0.0f, 0.0f, 0.0f));
}
}
}
}
}