Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

11.1 Rotation

24. November 2011

 

import processing.serial.*;  // Import the Processing Serial Library for communicating with arduino
Serial myPort;               // The used Serial Port

int xnewVal, ynewVal, znewVal; // fourthValue, fifthValue, ... // add more if needed
int xPosition;
float xRotation, yRotation;

void setup()
{
size(500, 500, P3D);
background(0);
println(Serial.list()); // Prints the list of serial available devices (Arduino should be on top of the list)
myPort = new Serial(this, Serial.list()[0], 9600); // Open a new port and connect with Arduino at 9600 baud
}

void draw()
{
background(0);

float xValCorrected = float(xnewVal)/64;
float yValCorrected = float(ynewVal)/64;
float zValCorrected = float(znewVal)/64;

float normalVector = sqrt(sq(xValCorrected)+sq(yValCorrected)+sq(zValCorrected));

translate(width/2,height/2);

if(zValCorrected>0)
{
xRotation = radians(map(xnewVal, -64, 64, 0, 180));
yRotation = radians(map(ynewVal, -64, 64, 180, 0));
}
else
{
xRotation = radians(map(xnewVal, -64, 64, 180, 0));
yRotation = radians(map(ynewVal, -64, 64, 0, 180));
}

rotateX(xRotation);
rotateY(yRotation);

float qcolor = map(xnewVal,-64, 64, 0, 255);
float anzahl = map(ynewVal,-64, 64, 0, 20);

for (int x=0; x <= anzahl; x++)
{
pushMatrix();
//translate(20*x,0);
rotateX(radians(x));
rotateY(radians(x*20));
stroke(22);
fill(qcolor);
box(qcolor);
translate(100,0);
fill(255);
box(50);
popMatrix();
}
//println(xValCorrected+"\t"+yValCorrected+"\t"+zValCorrected+"\t"+normalVector);

println(qcolor);
println(ynewVal+"\t"+xnewVal+"\t"+znewVal+"\t");
//println(xValCorrected+"\t"+yValCorrected+"\t"+zValCorrected+"\t");
//println(xRotation+"\t"+yRotation);

}

void serialEvent(Serial myPort) // Is called everytime there is new data to read
{
if (myPort.available() > 0)
{
String completeString = myPort.readStringUntil(10); // Read the Serial port until there is a linefeed/carriage return
if (completeString != null) // If there is valid data insode the String
{
trim(completeString); // Remove whitespace characters at the beginning and end of the string
String seperateValues[] = split(completeString, "\t"); // Split the string everytime a delimiter is received
xnewVal = int(seperateValues[0]);
ynewVal = int(seperateValues[1]);
znewVal = int(seperateValues[2]);
}
}
}