Here I have simplified and commented the code to make it easy for me to understand what each bit does.
/*
RGB Cube Mod
Here are some edits to get a framework
for understanding RGB Cube and starting
on the next step.
*/
float xmag, ymag = 0; //starting variables to define X and Y rotation
float newXmag, newYmag = 0; //Same but used to define new variables as the mouse moves
void setup() {
//Setting up the 'field' at 800X400 with OpenGL (P3D)
size(800, 400, P3D);
// Setting colour values to simplify RGB, 0=0, 1=255
colorMode(RGB, 1); }
void draw()
{ //sets grey value for background
background(0.5, 0.5, 0.45);
//From what I can tell this is a procedure call in a matrix
pushMatrix();
//Moving the draw function to the center of the form
translate(width/2, height/2, -30);
//This bit converts the mouse movement into 3d Rotation.
//Later I plan to freeze and hide the mouse for infinite free movement
//Converting mouse x and y into a value between 0 and PI
newXmag = mouseX/float(width) * TWO_PI;
newYmag = mouseY/float(height) * TWO_PI;
//making x/y mag = the new mouse x and y with a small amount of easing
float diff = xmag-newXmag;
if (abs(diff) > 0.01) {
xmag -= diff/4.0;
}
diff = ymag-newYmag;
if (abs(diff) > 0.01) {
ymag -= diff/4.0;
}
//the actual rotate functions
rotateX(-ymag);
rotateY(-xmag);
rotateZ(50);
//making the vertex (1,1,0) actually = (50,50,0) using scale
scale(50);
//Finally, drawing the shape!
//Note how easy it is to use 1 instead of 50 or 255 here.
beginShape(QUADS);
fill(0, 1, 1);
vertex(-1, 1, 0);
fill(1, 1, 1);
vertex( 1, 1, 0);
fill(1, 0, 1);
vertex( 1, -1, 0);
fill(0, 0, 0);
vertex(-1, -1, 0);
endShape();
//Close procedure
popMatrix();
}
Labels:
Input Device,
Semester 2
Subscribe to:
Post Comments (Atom)
0 comments: