Arcball: A Virtual 3D Trackball Interface

versions0095+
contributorstomc
started on2006-02-06 11:19

An arcball is an interface for manipulating a 3D world in an intuitive way, and can be thought of as a virtual trackball. This hack 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.

Installation

Unzip the archive and place the arcball folder into your Processing libraries folder, then restart Processing.

Usage

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);

Example

Here's a very basic example showing the use of the Arcball library with default settings. The rotation occurs around the point (300,200,-200) with a radius of 200.

/**
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);
 
}

Credits

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”.

Downloads

Related Links

hacks/arcball.txt · Last modified: 2007-07-13 02:12 (external edit)