You are on page 1of 8

Pregunta 4

Spacebrew:
Spacebrew.Event:

using UnityEngine;
using System;
using System.Collections;

public class SpacebrewEvents : MonoBehaviour


{

SpacebrewClient sbClient;
GameObject sbCubo;
// Use this for initialization
void Start()
{
print("Iniciando Programa");
GameObject go = GameObject.Find("SpacebrewObject");

sbCubo = GameObject.Find("cubo");

sbClient = go.GetComponent<SpacebrewClient>();
sbClient.addEventListener(this.gameObject, "rotacionX");
sbClient.addEventListener(this.gameObject, "rotacionY");
sbClient.addEventListener(this.gameObject, "rotacionZ");

// Update is called once per frame


void Update()
{
// if (Input.GetKeyDown("space"))
// {
// print("Sending Spacebrew Message");
// sbClient.sendMessage("mybool", "boolean", "true");
// }
}

public void OnSpacebrewEvent(SpacebrewClient.SpacebrewMessage _msg)


{
print("Received Spacebrew Message");
print(_msg.name);
print(_msg.value);

if (_msg.name == "rotacionY")
{
sbCubo.transform.rotation = Quaternion.Euler(0, Convert.ToInt32(_msg.value), 0);
}
if (_msg.name == "rotacionX")
{
sbCubo.transform.rotation = Quaternion.Euler(Convert.ToInt32(_msg.value), 0, 0);
}
if (_msg.name == "rotacionZ")
{
sbCubo.transform.rotation = Quaternion.Euler(Convert.ToInt32(_msg.value), 0, Convert.ToInt32(_msg.value));
}
}

}
Processing:

ControlP5 cp5;

Spacebrew sb;

PImage img;

String servidor="nidospacebrew.herokuapp.com";

String nombre="mateo";

String descripcion="aplicacion de Processing";

int puerto=80;

void setup(){

size(1000,500);

sb = new Spacebrew (this);

sb.addPublish("A0", "range", 200);

sb.addPublish("A1", "range", 200);

sb.addPublish("A2", "range", 200);

sb.addPublish("Pin13", "boolean", true);

sb.connect(servidor, puerto, nombre, descripcion);


cp5= new ControlP5(this);

cp5.addKnob("A2").setPosition(700,430).setRadius(30).setMin(0).setMax(1023).setDecimalPrecision(0);

cp5.addKnob("A1").setPosition(600,430).setRadius(30).setMin(0).setMax(1023).setDecimalPrecision(0);

cp5.addKnob("A0").setPosition(500,430).setRadius(30).setMin(0).setMax(1023).setDecimalPrecision(0);

cp5.addToggle("Pin13").setPosition(600,30).setSize(50,30);

void draw (){

background(255);

void A0(int value){

sb.send("A0", value);

println(value);

void A1(int value){

sb.send("A1", value);
println(value);

void A2(int value){

sb.send("A2", value);

println(value);

void Pin13(boolean value){

sb.send("Pin13", value);

println(value);

You might also like