3
* This file is part of jReality. jReality is open source software, made
4
* available under a BSD license:
6
* Copyright (c) 2003-2006, jReality Group: Charles Gunn, Tim Hoffmann, Markus
7
* Schmies, Steffen Weissmann.
11
* Redistribution and use in source and binary forms, with or without
12
* modification, are permitted provided that the following conditions are met:
14
* - Redistributions of source code must retain the above copyright notice, this
15
* list of conditions and the following disclaimer.
17
* - Redistributions in binary form must reproduce the above copyright notice,
18
* this list of conditions and the following disclaimer in the documentation
19
* and/or other materials provided with the distribution.
21
* - Neither the name of jReality nor the names of its contributors nor the
22
* names of their associated organizations may be used to endorse or promote
23
* products derived from this software without specific prior written
26
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
* POSSIBILITY OF SUCH DAMAGE.
41
package opencog.spacetime.toolsystem.virtual;
43
import java.util.List;
46
import opencog.spacetime.scene.tool.AxisState;
47
import opencog.spacetime.scene.tool.InputSlot;
48
import opencog.spacetime.toolsystem.MissingSlotException;
49
import opencog.spacetime.toolsystem.ToolEvent;
50
import opencog.spacetime.toolsystem.VirtualDevice;
51
import opencog.spacetime.toolsystem.VirtualDeviceContext;
55
* changed the state of its output axis from ORIGIN to
56
* PRESSED whenever the switch (first) axis is PRESSED.
57
* inverts its current state as long as the invert axis is pressed
62
public class VirtualSwitchAndInvertAxis implements VirtualDevice {
73
public ToolEvent process(VirtualDeviceContext context)
74
throws MissingSlotException {
76
invert = context.getAxisState(invertIS).isPressed();
77
value = Boolean.valueOf(context.getAxisState(switchIS).isPressed());
78
lastVal = value.booleanValue();
79
if (invert) lastVal = !lastVal;
80
return new ToolEvent(this, context.getEvent().getTimeStamp(), out, lastVal ? AxisState.PRESSED : AxisState.ORIGIN);
83
if (context.getEvent().getInputSlot() == switchIS && context.getAxisState(switchIS).isPressed())
84
value = Boolean.valueOf(!value.booleanValue());
86
if (context.getEvent().getInputSlot() == invertIS)
87
invert = context.getAxisState(invertIS).isPressed();
89
boolean newVal = value.booleanValue();
90
if (invert) newVal = !newVal;
91
if (newVal != lastVal) {
93
return new ToolEvent(this, context.getEvent().getTimeStamp(), out, lastVal ? AxisState.PRESSED : AxisState.ORIGIN);
98
public void initialize(List inputSlots, InputSlot result,
100
switchIS = (InputSlot) inputSlots.get(0);
101
invertIS = (InputSlot) inputSlots.get(1);
105
public void dispose() {
106
// TODO Auto-generated method stub
110
public String getName() {
114
public String toString() {
115
return "Virtual Device: "+getName();