Processing

Component: User/Artist’s Sketch
POV-BlockDiagram-Processing


Figure A: Display Component Block Diagram

 

Quick Start Guide
  1. Download Processing (Version 1.5.1 was used for Testing)
  2. Download Library from this Link: Pov3D-0.1.5.zip
    (Full source Library Source Code at GitHub )
  3. Install Library instructions are here
  4. Copy and Paste the Code Below, of find it in the Library examples.
  5. Join the Same WIFI as the POV Display is on.
  6. Press “Play” in Processing.
/* 
 * Classic Bouncing Ball Sample for POV 3D Display
 * Brady Marks 2015
 */

// CONSTANTS
String BEAGLE_IP = "10.10.2.99"; // WIFI IP of Display
int BEAGLE_PORT = 0x1A0A; // 6666
int SLICES = 90; // 90 - 150, more slice makes a denser render on the display

// LIBRARIES / IMPORTS
import Pov3D.library.*;
import Pov3D.display.*;
import Pov3D.util.*;
import Pov3D.shape.*;

// GLOBALS

POVDisplay g_display = null; // Display "Sigleton"
int g_last = 0;

Sphere sphere = null; // Our Ball
PVector center = null; // the Center Point of the Ball
PVector velocity; // Speed and Direction of Ball
int maxSpeed = 5; // Max Magnitude of velocity
int size = 12; // 7 - 12 Work Nicely

void setup() {
 size(640, 480, P3D);
 fill(204);
 frameRate(12); // fps

 println("setup");
 Pov3DLibrary lib = new Pov3DLibrary(this); 
 ProcessingObject.setPApplet(this);
 g_display = new POVDisplay(BEAGLE_IP, SLICES /* number of slices */ );
 POVObject.setDisplay(g_display); // sets the display for all the POV Objects 
 // like sphere and line

 center = new PVector();
 
 velocity = new PVector(random(-1, 1), random(-1, 1), random(-1, 1));

 velocity.normalize(); // make random vector 'unity' size (i.e. having magnitude of 1)
 velocity.mult(maxSpeed); // scale up to maxSpeed magnitude

 sphere = new Sphere(center, size, Sphere.DrawMode.OUTLINE);
}

void Animate() {
 boolean bounce = false; // remember if we bounced or not
 center.add(velocity); // move center by adding 'velocity' vector to current possition
 sphere.setSize(size);


 /* lazy bouncing, we bounce against a cube, not a cylinder, this is bad form and results
 in the ball going outside of the display in the "corners", which is instuctional but silly
 */
 
 if (center.y - size <= POVDisplay.MIN || center.y + size >= POVDisplay.MAX) {
 velocity.y *= -1; // flip direction of velocity vector, on Y plane
 bounce = true;
 }

 if (center.z -size <= POVDisplay.SAFE_MIN || center.z + size >= POVDisplay.SAFE_MAX) {
 velocity.z *= -1; // flip direction of velocity vector, on Z plane
 bounce = true;
 }

 if (center.x - size <= POVDisplay.SAFE_MIN || center.x + size >= POVDisplay.SAFE_MAX) {
 velocity.x *= -1; // flip direction of velocity vector, on X plane
 bounce = true;
 }

 if (bounce == true) {
    // if we bounced we went too far, so come back in
    center.add(velocity);
 }
 sphere.setCenter(center); // update position
}

void draw() { 
 lights();
 background(0);

 // Camera Move on mouse position
 float cameraTopBotAngle = (float)Util.linearmap(mouseY, 0, height, -Math.PI/4, Math.PI/4);
 camera(Util.linearmap(mouseX, 0, width, 150, -150), // eye X
 sin(cameraTopBotAngle)*220f, // eye Y
 cos(cameraTopBotAngle)*220, // eye Z
 0.0f, 0.0f, 0.0f, // centerX, centerY, centerZ
 0.0f, 1.0f, 0.0f); // upX, upY, upZ

 Animate(); // Move the Ball

 g_display.clear(); // Clear the Volume, like bacground(0), but the POV version

 // Draw Static Cursor Points (in Processing, NOT on the POV Display)
 stroke(255, 0, 0);

 point(-50, -50, 50); point(-50, 50, 50);
 point( 50, -50, 50); point( 50, 50, 50);

 point(-50, -50, -50); point(-50, 50, -50);
 point( 50, -50, -50); point( 50, 50, -50);
 
 stroke(255);
 sphere.draw(); // draw the sphere in the POV Display Volume
 g_display.export(); // Send Current Volume to POV Display
}

Leave a Reply

I'm a human because I know: