Processing with tangible user interface

Asked By 7060 points N/A Posted on -
qa-featured

Hi i am new to processing and I'm trying to figure out how to make the sphere move from left to right using a marker instead of the mouse.

Can you help me please?

I can use the marker to shoot but i cant move the sphere by shooting. Import TUIO.*;

TuioProcessing tuioClient;
HashMap symbols=new HashMap();
PFont fontA;
int sphereDiameter = 50;
boolean shoot = false;
float obj_size = 60;
int randx()
{
return int(random(600));
}
int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
int[] sphereYCoords = { 0, 0, 0, 0, 0 };
void setup()
{
size(1000,700);
tuioClient = new TuioProcessing(this);
}
void draw()
{
Vector tuioObjectList =tuioClient.getTuioObjects();
Collections.sort(tuioObjectList, comp);
for (TuioObject tobj:tuioObjectList) {
fill(50, 50, 100);
int id = tobj.getSymbolID();
int x = tobj.getScreenX(width);
int y = tobj.getScreenY(height);
rect(x, y, obj_size, obj_size);
String txt="?";
if (symbols.containsKey(id)) {// if it's one in symbols, then look it up
txt = (String)symbols.get(id);
}
fill(255);
text(txt, x, y);
}
int[] sphereXCoords = { randx(), randx(), randx(), randx(), randx() };
fill(100, 0, 0);
// draw the answer box
// ellipse(answerX, answerY, obj_size, obj_size);
fill(255);
// write the answer text
// text("" answer, answerX, answerY);
background(1);
fill(color(255,255,0));
stroke(color(0,255,0));
triangle(mouseX-8, 580, mouseX 8, 580, mouseX, 565);
fill(color(255,0,0));
stroke(color(255,0,0));
if(shoot==true)
{
sphereKiller( mouseX);
shoot = false;
}
sphereDropper();
//gameEnder();
}
Comparator comp = new Comparator() {
// Comparator object to compare two TuioObjects on the basis of their x position
// Returns -1 if o1 left of o2; 0 if they have same x pos; 1 if o1 right of o2
public int compare(TuioObject o1, TuioObject o2) {
if (o1.getX() return -1;
}
else if (o1.getX()>o2.getX()) {
return 1;
}
else {
return 0;
}
}
};
void mousePressed()
{
shoot = true;
}
void sphereDropper()
{
stroke(255);
fill(255);
for (int i=0; i<5; i )
{
ellipse(sphereXCoords[i], sphereYCoords[i] ,
sphereDiameter, sphereDiameter);
}
}
void sphereKiller(int shotX)
{
boolean hit = false;
for (int i = 0; i < 5; i )
{
if((shotX >= (sphereXCoords[i]-sphereDiameter/2))
SHARE
Answered By 0 points N/A #195169

Processing with tangible user interface

qa-featured

Hello ,

I have known about the matter .But it will be better if the programming language you using is known.

However I am giving the code attached to this solution for moving object .Here a bullet type variable is used which is only for calculation. Here ba#=ATan2(bey-bpy,bex) is used to calculate from 'coordinate system relative ' to player relative position.

Here the bullet angle is defined as calculation return to system relative cords .

This is implemented by the declaration : bba#=-b

The bullet can be updated according to calculated angle by declaration:bba#=bbx+Cos(bba)*bbs*.1

Regards

Shifflett Laurel

Related Questions