Arcball

From Processing

Jump to: navigation, search
Versions: 1.0+
Contributors: tomc
Started: 2006-02-06


An arcball is an interface for manipulating a 3D world in an intuitive way, and can be thought of as a virtual trackball. This snippet presents a simple arcball library which automatically attaches itself to your sketch and allows you to freely rotate the world in 3D dimensions about a specified point. Extensions to this library might change the way the mouse movements are interpreted, add a zoom control, and so on. This arcball library is adapted from code by Simon Greenwold for Yale's Model Based Design class. The arcball method of interaction was introduced by Ken Shoemake in his 1985 SIGGRAPH paper "Animating rotations with quaternion curves".

To install the library, unzip the archive and place the arcball folder into your Processing libraries folder, then restart Processing.

At the top of your sketch, type:

import com.processinghacks.arcball.*;

Then inside setup(), for a default arcball centered on width/2, height/2, -min(width/2,height/2) with radius min(width/2,height/2) do:

ArcBall arcball = new ArcBall(this);

Or, to specify center x/y/z and radius yourself, do:

ArcBall arcball = new ArcBall(100,100,0,50,this);

Source Code

/**
arcball taken from http://processinghacks.com/hacks:arcball
@author Tom Carden
*/
 
import com.processinghacks.arcball.*;
 
void setup() {
  size(600,400,P3D);
  ArcBall arcball = new ArcBall(this);
}
 
void draw() {
  background(255);
 
  translate(width/2,height/2,-height/2);
  fill(255,0,0,40);
  noStroke();
  for (int i = 1; i <= 5; i++) {
    box(60*i);
  }
  stroke(100,0,0);
  noFill();
  box(300);
}

Downloads

Related Links

Personal tools