1 package net.sf.josceleton.motion.impl.gesture.hitwall;
2
3 import net.sf.josceleton.core.api.entity.Coordinate;
4 import net.sf.josceleton.core.api.entity.XyzDirection;
5 import net.sf.josceleton.core.api.entity.joint.Joint;
6 import net.sf.josceleton.core.api.entity.joint.Skeleton;
7 import net.sf.josceleton.motion.api.gesture.hitwall.HitWallConfig;
8 import net.sf.josceleton.motion.api.gesture.hitwall.HitWallGesture;
9 import net.sf.josceleton.motion.api.gesture.hitwall.HitWallListener;
10 import net.sf.josceleton.motion.impl.gesture.AbstractJointableGesture;
11
12 import com.google.inject.Inject;
13 import com.google.inject.assistedinject.Assisted;
14
15
16
17
18 class HitWallGestureImpl extends AbstractJointableGesture<HitWallConfig, HitWallListener> implements HitWallGesture {
19
20 private final HitWallConfig configuration;
21
22 private final XyzDirection configDirecton;
23
24 private final boolean triggerLower;
25
26 private final float coordinateValue;
27
28
29 private boolean wasYetTriggered = false;
30
31
32 @Inject HitWallGestureImpl(@Assisted final HitWallConfig configuration) {
33 super(configuration);
34 this.configuration = configuration;
35 this.configDirecton = this.configuration.getDirection();
36 this.triggerLower = this.configuration.getTriggerOnLower();
37 this.coordinateValue = this.configuration.getCoordinate();
38 }
39
40
41 @Override protected final void onMovedRelevantJoint(
42 final Joint movedJoint,
43 final Coordinate updatedCoordinate,
44 final Skeleton skeleton) {
45
46 final float actualCoordinate = this.configDirecton.extractValue(updatedCoordinate);
47
48 if(this.wasYetTriggered == false) {
49 final boolean shouldTrigger = this.checkTrigger(actualCoordinate);
50 if(shouldTrigger == true) {
51 this.dispatchGestureDetected(skeleton);
52 this.wasYetTriggered = true;
53 }
54
55 } else {
56 final boolean shouldUntrigger = this.checkUntrigger(actualCoordinate);
57 if(shouldUntrigger == true) {
58 this.wasYetTriggered = false;
59 }
60 }
61 }
62
63 private boolean checkTrigger(final float actualCoordinate) {
64 if(this.triggerLower == true) {
65 return actualCoordinate < this.coordinateValue;
66 }
67 return actualCoordinate > this.coordinateValue;
68 }
69
70 private boolean checkUntrigger(final float actualCoordinate) {
71 if(this.triggerLower == true) {
72 return actualCoordinate > this.coordinateValue;
73 }
74 return actualCoordinate < this.coordinateValue;
75 }
76
77 }