From d4cca4d0e4d658fbcd50e170a8ed4cd6181b7dbc Mon Sep 17 00:00:00 2001 From: Stefan Medack Date: Mon, 2 Jul 2012 14:25:42 +0200 Subject: [PATCH] Added "undo" to the voice interaction --- .classpath | 27 ++++--- src/de/tub/mubix/main/Cube.java | 24 ++++++ src/de/tub/mubix/main/Mubix.java | 14 +--- .../mubix/speechControl/SpeechControl.java | 76 ++++++++++--------- src/de/tub/mubix/speechControl/speech.gram | 2 +- 5 files changed, 83 insertions(+), 60 deletions(-) diff --git a/.classpath b/.classpath index 8c18f66..0a143d7 100644 --- a/.classpath +++ b/.classpath @@ -1,11 +1,16 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/src/de/tub/mubix/main/Cube.java b/src/de/tub/mubix/main/Cube.java index 53303b1..677afa2 100644 --- a/src/de/tub/mubix/main/Cube.java +++ b/src/de/tub/mubix/main/Cube.java @@ -1,6 +1,7 @@ package de.tub.mubix.main; import java.util.ArrayList; +import java.util.LinkedList; import processing.core.PApplet; import processing.core.PVector; @@ -17,8 +18,18 @@ public class Cube { public int clock = 0; public int faceTurn = 0; + public int getFaceTurn() { + return faceTurn; + } + + public void setFaceTurn(int faceTurn) { + this.faceTurn = faceTurn; + this.pushMove(faceTurn); + } + public boolean mixCube = false; public boolean reverseRotation = false; + private LinkedList moveList = null; ArrayList listNumOfSiteRotation; int numOfSiteRotation = 0; @@ -41,6 +52,7 @@ public class Cube { public Cube(PApplet parent) {// The points for each square on the face this.parent = parent; + moveList = new LinkedList(); squareMatrix = new PVector[6][9][4]; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) { @@ -626,4 +638,16 @@ public void singleTwist() { faceTurn = 0; } } + + public void undoLastMove() { + if (!moveList.isEmpty()) { + reverseRotation = true; + faceTurn = moveList.getLast(); + moveList.removeLast(); + } + } + + public void pushMove(int faceTurn) { + moveList.add(faceTurn); + } } \ No newline at end of file diff --git a/src/de/tub/mubix/main/Mubix.java b/src/de/tub/mubix/main/Mubix.java index aca45fe..df7c8d4 100644 --- a/src/de/tub/mubix/main/Mubix.java +++ b/src/de/tub/mubix/main/Mubix.java @@ -1,7 +1,5 @@ package de.tub.mubix.main; -import java.util.LinkedList; - import peasy.PeasyCam; import processing.core.PApplet; import processing.core.PVector; @@ -26,8 +24,6 @@ public class Mubix extends PApplet { final boolean enableMultimodal = true; boolean showDepth = false; - private LinkedList moveList = null; - // int clock = 0; // int ith = 0; // int faceTurn = 0; @@ -66,8 +62,6 @@ public void setup() { cam.setActive(false); // deactivate mouse rotation theCube = new Cube(this); - moveList = new LinkedList(); - // bkg_img = loadImage("cube_black_1024_640.jpg"); // bkg_img.filter(OPAQUE); @@ -393,11 +387,7 @@ public void keyPressed() { theCube.mixCube = false; } if ((key == 'ö') || (key == 'Ö') || (key == ',')) { - if (!moveList.isEmpty()) { - theCube.reverseRotation = true; - theCube.faceTurn = moveList.getLast(); - moveList.removeLast(); - } + theCube.undoLastMove(); } if ((key == 'd') || (key == 'D')) { this.showDepth = !this.showDepth; @@ -421,7 +411,7 @@ public void keyPressed() { } public void setMoveReminder(int faceTurn) { - moveList.add(faceTurn); + theCube.pushMove(faceTurn); } // mm mehtods diff --git a/src/de/tub/mubix/speechControl/SpeechControl.java b/src/de/tub/mubix/speechControl/SpeechControl.java index d977286..d3108f5 100644 --- a/src/de/tub/mubix/speechControl/SpeechControl.java +++ b/src/de/tub/mubix/speechControl/SpeechControl.java @@ -49,111 +49,115 @@ private void extractCommand(Result result) { } if (s != "" && this.cube.clock == 0) { + if(s.contains("undo")){ + this.cube.undoLastMove(); + } + if (trackpad.getFocusX() == 0 && trackpad.getFocusY() == 0) { if (s.contains("up")) { - this.cube.faceTurn = 11; + this.cube.setFaceTurn(11); } else if (s.contains("down")) { - this.cube.faceTurn = 12; + this.cube.setFaceTurn(12); } else if (s.contains("right")) { - this.cube.faceTurn = 41; + this.cube.setFaceTurn(41); } else if (s.contains("left")) { - this.cube.faceTurn = 42; + this.cube.setFaceTurn(42); } } if (trackpad.getFocusX() == 0 && trackpad.getFocusY() == 1) { if (s.contains("up")) { - this.cube.faceTurn = 11; + this.cube.setFaceTurn(11); } else if (s.contains("down")) { - this.cube.faceTurn = 12; + this.cube.setFaceTurn(12); } else if (s.contains("right")) { - this.cube.faceTurn = 51; + this.cube.setFaceTurn(51); } else if (s.contains("left")) { - this.cube.faceTurn = 52; + this.cube.setFaceTurn(52); } } if (trackpad.getFocusX() == 0 && trackpad.getFocusY() == 2) { if (s.contains("up")) { - this.cube.faceTurn = 11; + this.cube.setFaceTurn(11); } else if (s.contains("down")) { - this.cube.faceTurn = 12; + this.cube.setFaceTurn(12); } else if (s.contains("right")) { - this.cube.faceTurn = 61; + this.cube.setFaceTurn(61); } else if (s.contains("left")) { - this.cube.faceTurn = 62; + this.cube.setFaceTurn(62); } } if (trackpad.getFocusX() == 1 && trackpad.getFocusY() == 0) { if (s.contains("up")) { - this.cube.faceTurn = 21; + this.cube.setFaceTurn(21); } else if (s.contains("down")) { - this.cube.faceTurn = 22; + this.cube.setFaceTurn(22); } else if (s.contains("right")) { - this.cube.faceTurn = 41; + this.cube.setFaceTurn(41); } else if (s.contains("left")) { - this.cube.faceTurn = 42; + this.cube.setFaceTurn(42); } } if (trackpad.getFocusX() == 1 && trackpad.getFocusY() == 1) { if (s.contains("up")) { - this.cube.faceTurn = 101; + this.cube.setFaceTurn(101); } else if (s.contains("down")) { - this.cube.faceTurn = 102; + this.cube.setFaceTurn(102); } else if (s.contains("right")) { - this.cube.faceTurn = 104; + this.cube.setFaceTurn(104); } else if (s.contains("left")) { - this.cube.faceTurn = 103; + this.cube.setFaceTurn(103); } } if (trackpad.getFocusX() == 1 && trackpad.getFocusY() == 2) { if (s.contains("up")) { - this.cube.faceTurn = 21; + this.cube.setFaceTurn(21); } else if (s.contains("down")) { - this.cube.faceTurn = 22; + this.cube.setFaceTurn(22); } else if (s.contains("right")) { - this.cube.faceTurn = 61; + this.cube.setFaceTurn(61); } else if (s.contains("left")) { - this.cube.faceTurn = 62; + this.cube.setFaceTurn(62); } } if (trackpad.getFocusX() == 2 && trackpad.getFocusY() == 0) { if (s.contains("up")) { - this.cube.faceTurn = 31; + this.cube.setFaceTurn(31); } else if (s.contains("down")) { - this.cube.faceTurn = 32; + this.cube.setFaceTurn(32); } else if (s.contains("right")) { - this.cube.faceTurn = 41; + this.cube.setFaceTurn(41); } else if (s.contains("left")) { - this.cube.faceTurn = 42; + this.cube.setFaceTurn(42); } } if (trackpad.getFocusX() == 2 && trackpad.getFocusY() == 1) { if (s.contains("up")) { - this.cube.faceTurn = 31; + this.cube.setFaceTurn(31); } else if (s.contains("down")) { - this.cube.faceTurn = 32; + this.cube.setFaceTurn(32); } else if (s.contains("right")) { - this.cube.faceTurn = 51; + this.cube.setFaceTurn(51); } else if (s.contains("left")) { - this.cube.faceTurn = 52; + this.cube.setFaceTurn(52); } } if (trackpad.getFocusX() == 2 && trackpad.getFocusY() == 2) { if (s.contains("up")) { - this.cube.faceTurn = 31; + this.cube.setFaceTurn(31); } else if (s.contains("down")) { - this.cube.faceTurn = 32; + this.cube.setFaceTurn(32); } else if (s.contains("right")) { - this.cube.faceTurn = 61; + this.cube.setFaceTurn(61); } else if (s.contains("left")) { - this.cube.faceTurn = 62; + this.cube.setFaceTurn(62); } } diff --git a/src/de/tub/mubix/speechControl/speech.gram b/src/de/tub/mubix/speechControl/speech.gram index bb68763..c6e7ea8 100644 --- a/src/de/tub/mubix/speechControl/speech.gram +++ b/src/de/tub/mubix/speechControl/speech.gram @@ -6,4 +6,4 @@ grammar hello; -public = ( up | down | left | right ); +public = ( up | down | left | right | undo);