Fiduciales y dedos: posición y rotacion

En este ejemplo de programa HOST se pinta en el tabletop 1, un circulo rojo debajo del fiducial 1, un circulo azul debajo del fiducial 10, y un circulo blanco debajo de un dedo (fiducial -1). Además, en el caso del fiducial 1 y 10, rotando el fiducial se regula la intensidad del color del circulo.

Fichero displays.xml

<xml >
<virtualDisplay width="3840" height="1368"> 
 <display id="1" x="0" y="0" width="1280" height="768" />
 <display id="2" x="1280" y="0" width="1280" height="768" />
 <display id="3" x="2560" y="0" width="1280" height="768" />
 <display id="4" x="0" y="1000" width="800" height="600" />
 <display id="5" x="1000" y="1000" width="800" height="600" />
 <display id="6" x="2000" y="1000" width="800" height="600" />
 <display id="7" x="3000" y="1000" width="800" height="600" />
</virtualDisplay>
</xml>

Fichero TUIML.xml
<juguemos>
 <token name="tabletop1">
 <constraint name="todo" type= "2D" list_vertex="0.0,0.0,1.0,0.0,1.0,1.0,0.0,1.0,0.0,0.0">
 <tac subtoken="1,10,-1"/>
 </constraint>
 <subtoken idG="1,10,-1"/>
 </token>
</juguemos>

Codigo Host en Proccessing

int ANCHO=1600;
int ALTO=1200;
int opcion = 0;
boolean verb = true;

TACAPI miAPI;
DisplaysHost displaysClient;

float f1x=0;
float f1y=0;
float f1r=0;
float f10x=0;
float f10y=0;
float f10r=0;
float fx=0;
float fy=0;

void setup() { 
 // Keystone will only work with P3D or OPENGL renderers, 
 // since it relies on texture mapping to deform
 //fullScreen( P3D);
 size(600, 400, P3D); 
 frameRate(16);
 miAPI = new TACAPI();
 
 //virtual screens
 displaysClient = new DisplaysHost("host"); 
}

void draw() {

 displaysClient.beginDraw();
 if(f1x>0 &&f1y>0) displaysClient.elipse(f1x,f1y,200,200,(int)f1r,0,0,255);
 if(f10x>0 &&f10y>0) displaysClient.elipse(f10x,f10y,200,200,0,0,(int)f10r,255);
 if(fx>0 &&fy>0) displaysClient.elipse(fx,fy,30,30,255,255,255,255);
 displaysClient.endDraw();
}

void eventoTAC(TAC ta) {
 ta.info();
 if (ta.getManipulacion().equals("move") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("1")) { 
 f1x=ta.valores.get(0)*800;
 f1y=1000+ta.valores.get(1)*600; 
 }
 if (ta.getManipulacion().equals("rotate") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("1")) { 
 f1r=map(ta.valores.get(0), 0,2*PI, 0,255); 
 }
 if (ta.getManipulacion().equals("move") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("10")) { 
 f10x=ta.valores.get(0)*800;
 f10y=1000+ta.valores.get(1)*600; 
 }
 if (ta.getManipulacion().equals("rotate") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("10")) { 
 f10r=map(ta.valores.get(0), 0,2*PI, 0,255); 
 }
 if(ta.getManipulacion().equals("add") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("1")) {
 if (ta.getValores().get(0)==0) {
 f1x=0;
 f1y=0;
 }
 }
 if(ta.getManipulacion().equals("add") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("10")) {
 if (ta.getValores().get(0)==0) {
 f10x=0;
 f10y=0;
 }
 }
 
 if (ta.getManipulacion().equals("move") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("-1")) { 
 fx=ta.valores.get(0)*800;
 fy=1000+ta.valores.get(1)*600; 
 }
 if(ta.getManipulacion().equals("add") && ta.getTokenName().equals("tabletop1") && ta.getSubtokenName().equals("-1")) {
 if (ta.getValores().get(0)==0) {
 fx=0;
 fy=0;
 }
 }
}

void mensajeRecibido(OscMessage theOscMessage) {
}

void keyPressed() {
 switch(key) { 
 case ESC: 
 displaysClient.disconnect();
 super.stop();
 break;
 } 
}

Retos de aprendizaje


Documentación

  • elipse

Este método permite dibujar una elipse del color especificado, con o sin contorno ( del color que se indique) y del tamaño que se desee. Los parámetros que recibe son los siguientes:

float x: posición del centro de la elipse en el eje X (2D).

float y: posición del centro de la elipse en el eje Y (2D).

int ancho: anchura de la elipse que se va a dibujar.

int alto: altura de la elipse que se va a dibujar.

int rrell: valor de la componente rojo del color con el que se pintará el relleno de la elipse. Valores: 0-255.

int grell: valor de la componente verde del color con el que se pintará el relleno de la elipse. Valores: 0-255.

int brell: valor de la componente azul del color con el que se pintará el relleno de la elipse. Valores: 0-255.

int alpharell: opacidad del relleno de la elipse que se va a dibujar. Valores: 0 (transparente) – 255 (opaco)

int grosor (OPCIONAL): grosor del contorno de la elipse a dibujar.

int rcon (OPCIONAL): valor de la componente rojo del color con el que se pintará el contorno de la elipse. Valores: 0-255.

int gcon (OPCIONAL): valor de la componente verde del color con el que se pintará el contorno de la elipse. Valores: 0-255.

int bcon (OPCIONAL): valor de la componente azul del color con el que se pintará el contorno de la elipse. Valores: 0-255.

int alphacon (OPCIONAL): opacidad del contorno de la elipse a dibujar. Valores: 0 (transparente) – 255 (opaco).

  • Clase TAC

A continuación se presenta la clase TAC con sus diversas funciones:

ATRIBUTOS

String tokenName: Token al que pertenece el tac. Si el token es un sensor, <tokenName> es el nombre del sensor (tabletop, kinect…). Si el token es un objeto con áreas asociadas, <tokenName> = idG_Objeto + “_” + idS_Objeto

String consName: Nombre del constraint

String manipulación: Valor: “add”

String idG: id general del subtoken

String idS: id de sesión del subtoken

String idSToken: id de sesión del Token. Si el Token es un sensor y no un objeto, su valor es “–”.

ArrayList<Float> valores: 1 valor

MÉTODOS

String getTokenName() // devuelve el nombre del token

String getManipulacion()  // devuelve la manipulacion

ArrayList<Float> getValores() //devuelve la lista de valores:  1 valor (0 = remove, 1 = add)

String getConstraintName() // devuelve el nombre del constraint

String getSubtokenName() // devuelve el ID general

String getSubtokenIDS() // devuelve el ID de sesión

String getIDSToken() // devuelve el ID de sesión del Token

void info()  // escribe por pantalla la información del TAC