We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Rotation of a cube
Page Index Toggle Pages: 1
Rotation of a cube (Read 446 times)
Rotation of a cube
Jun 30th, 2006, 3:32pm
 
How do I rotate a cube around the center of the cube when the mouse is dragged.
The cube is a 3D cube.
Re: Rotation of a cube
Reply #1 - Jul 16th, 2006, 3:48am
 
You may want to take a look at the ArcBall library.

http://www.processinghacks.com/hacks/arcball

I hacked up the code found at http://processing.org/learning/examples/rotate3d.html a little bit and came up with this... maybe more along what you were thinking of...

Quote:


float a = 0.0;
float b = 0;

void setup()
{
 size(200, 200, P3D);
 noStroke();
 fill(204, 204);
 framerate(30);
}

void draw()
{
 background(0);
 pointLight(100, 156, 200, 35, 40, 50);
 translate(width/2, height/2);
 if(mouseX != pmouseX && mousePressed){
   b += mouseX-pmouseX;
 }
 if(mouseY != pmouseY && mousePressed){
   a -= mouseY-pmouseY;
 }
 rotateX(radians(a));
 rotateY(radians(b));
 box(width/4);
}


Page Index Toggle Pages: 1