Hi there,
I have written a class that scales and rotates a box in 3D. At the moment there is a variable called 'angle' that simply gets incremented in my 'update' method:
Code:
angle += 0.01;
if(angle > TWO_PI) {
angle = 0.0;
}
Then in my 'render' method, I use that variable to rotate the box:
Code:
void render() {
rectMode(CENTER);
noStroke();
fill(153,75);
pushMatrix();
// position object
translate(x, y, -200);
pushMatrix();
// rotate object using 'angle' variable
rotateX(angle);
rotateY(angle);
rotateZ(90);
// draw box using location vectors
box(loc.x,loc.y,loc.z);
popMatrix();
popMatrix();
}
That all seems to work fine. However, what I am trying to do is get the box to rotate in response to the mouse x/y position, so that the direction of rotation shifts in the opposite direction of the mouse. Kind of like Yugo's 'Rosebox' piece (done in Director): http://yugop.com/ver3/index.asp?id=30
Does anyone know how to do this? I'm sure it involves using mouseX and mouseY in relation to the 'angle' variable - but I can't get it to work. Any help would be much appreciated as always :)
cheers,
Matt