View Javadoc

1   /*
2    * Copyright 2008 motej
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License. 
15   */
16  package motejx.adapters;
17  
18  import motejx.extensions.balanceboard.BalanceBoardEvent;
19  import motejx.extensions.balanceboard.BalanceBoardListener;
20  
21  /**
22   * 
23   * <p>
24   * @author <a href="mailto:vfritzsch@users.sourceforge.net">Volker Fritzsch</a>
25   */
26  public abstract class BalanceBoardDirectionAdapter implements BalanceBoardListener {
27  
28  	/* (non-Javadoc)
29  	 * @see motejx.extensions.balanceboard.BalanceBoardListener#balanceBoardChanged(motejx.extensions.balanceboard.BalanceBoardEvent)
30  	 */
31  	public void balanceBoardChanged(BalanceBoardEvent evt) {
32  		float left = evt.getTopLeftInterpolated() + evt.getBottomLeftInterpolated();
33  		float right = evt.getTopRightInterpolated() + evt.getBottomRightInterpolated();
34  		float top = evt.getTopLeftInterpolated() + evt.getTopRightInterpolated();
35  		float bottom = evt.getBottomLeftInterpolated() + evt.getBottomRightInterpolated();
36  		float total = top + bottom;
37  		if (total != 0) {		
38  			float x = (right - left) / total;
39  			float y = (top - bottom) / total;
40  			directionChanged(x,y);
41  		}
42  	}
43  
44  	public abstract void directionChanged(float x, float y);
45  	
46  }