Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
recreated as an independent repo
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed Jan 8, 2014
0 parents commit ddf6d32
Show file tree
Hide file tree
Showing 26 changed files with 2,398 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The planetarium library is intended to project 3D Processing sketches on spherical domes, with minimal changes in the code of the sketch.

It is based on the FullDomeTemplate code from Christopher Warnow, available at https://github.com/mphasize/FullDome

### Overview

A brief descrition of how it works: a 360° view of the scene is generated by rendering the scene 6 times from each direction: positive x, negative x, and so on. The output of each rendering is stored inside a cube map texture, which is then applied on a sphere representing the dome. Hence, the library calls the draw() method 6 times per frame in order to update the corresponding side of the cube map texture (in reality, only 5 times since the bottom side of the cube map is not invisible on the dome).

So, it is important to keep in mind that if you need to perform some calculation only one time per frame, then the code for that calculation should be put inside the pre() method. Similarly, calculations that should performed only once after the rendering is concluded should be put in the post() method.

The library currently assumes that the the projector is placed in the center of the dome, the output will be incorrect if the projector is not centered. Multiple projectors are not currently supported.
7 changes: 7 additions & 0 deletions data/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
the data folder:
If your library is using files like images, sound files,
any data file, etc., put them into the data folder.
When coding your library you can use processing's internal loading
functions like loadImage(), loadStrings(), etc. to load files
located inside the data folder into your library.

1 change: 1 addition & 0 deletions data/cubeMapFrag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uniform samplerCube cubemap;varying vec3 reflectDir;void main() { vec3 color = vec3(textureCube(cubemap, reflectDir)); gl_FragColor = vec4(color, 1.0); }
Expand Down
1 change: 1 addition & 0 deletions data/cubeMapVert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uniform mat4 transform;uniform mat4 modelview;uniform mat3 normalMatrix;attribute vec4 vertex;attribute vec3 normal;varying vec3 reflectDir;void main() { gl_Position = transform * vertex; vec3 ecNormal = normalize(normalMatrix * normal); // Vertex in eye coordinates vec3 ecVertex = vec3(modelview * vertex); // Normal vector in eye coordinates vec3 eyeDir = ecVertex.xyz; reflectDir = reflect(eyeDir, ecNormal);}
Expand Down
64 changes: 64 additions & 0 deletions examples/Basic/Basic.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// The planetarium library is designed to create real-time projections on
// spherical domes. It is based on the FullDome project by Christopher
// Warnow (ch.warnow@gmx.de):
// https://github.com/mphasize/FullDome
//
// A brief descrition on how it works: a 360° view of the scene is generated
// by rendering the scene 6 times from each direction: positive x, negative x,
// positive y, and so on. The output of each rendering is stored inside a cube map
// texture, which is then applied on a sphere representing the dome.
// Hence, the library calls the draw() method 6 times per frame in order to update
// the corresponding side of the cube map texture (in reality, only 5 times since
// the bottom side of the cube map is not invisible on the dome).
// So, it is important to keep in mind that if you need to perform some calculation
// only one time per frame, then the code for those calculations should be put inside
// the pre() method.

import codeanticode.planetarium.*;

float cubeX, cubeY, cubeZ;

void setup() {
// For the time being, only use square windows
size(600, 600, Dome.RENDERER);
}

// Called one time per frame.
void pre() {
// The dome projection is centered at (0, 0), so the mouse coordinates
// need to be offset by (width/2, height/2)
cubeX += ((mouseX - width * 0.5) - cubeX) * 0.2;
cubeY += ((mouseY - height * 0.5) - cubeY) * 0.2;
}

// Called five times per frame.
void draw() {
background(0);

pushMatrix();
translate(width/2, height/2, 300);

lights();

stroke(0);
fill(150);
pushMatrix();
translate(cubeX, cubeY, cubeZ);
box(50);
popMatrix();

stroke(255);
int linesAmount = 10;
for (int i = 0; i < linesAmount;i++) {
float ratio = (float)i/(linesAmount-1);
line(0, 0, cos(ratio*TWO_PI) * 50, sin(ratio*TWO_PI) * 50);
}
popMatrix();
}

void keyPressed() {
if (key == CODED) {
if (keyCode == UP) cubeZ -= 5;
else if (keyCode == DOWN) cubeZ += 5;
}
}
92 changes: 92 additions & 0 deletions examples/Calibrate/Calibrate.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import codeanticode.planetarium.*;

DomeCamera camera;
float cubeX, cubeY;
float domeZ = 0;
float domeScale = 1;
boolean dome = true;
boolean grid = false;

void setup() {
// For the time being, only use square windows
size(600, 600, Dome.RENDERER);
camera = new DomeCamera(this);
}

// Called one time per frame.
void pre() {
// The dome projection is centered at (0, 0), so the mouse coordinates
// need to be offset by (width/2, height/2)
cubeX += ((mouseX - width * 0.5) - cubeX) * 0.2;
cubeY += ((mouseY - height * 0.5) - cubeY) * 0.2;
}

// Called five times per frame.
void draw() {
int face = camera.getFace();
if (face == DomeCamera.POSITIVE_X) {
background(240, 59, 31);
} else if (face == DomeCamera.NEGATIVE_X) {
background(240, 146, 31);
} else if (face == DomeCamera.POSITIVE_Y) {
background(30, 245, 0);
} else if (face == DomeCamera.NEGATIVE_Y) {
background(30, 232, 156);
} else if (face == DomeCamera.POSITIVE_Z) {
background(52, 148, 206);
} else if (face == DomeCamera.NEGATIVE_Z) {
background(183, 115, 13);
}

pushMatrix();
translate(width/2, height/2, 300);

stroke(255);
noFill();

pushMatrix();
translate(cubeX, cubeY, 0);
sphereDetail(8);
sphere(30);
popMatrix();

int linesAmount = 10;
for (int i = 0; i < linesAmount;i++) {
float ratio = (float)i/(linesAmount-1);
line(0, 0, cos(ratio*TWO_PI) * 50, sin(ratio*TWO_PI) * 50);
}

popMatrix();
}

void keyPressed() {
if (key == CODED) {
if (keyCode == UP) {
domeZ += 1;
println("Dome Z : " + domeZ);
camera.translate(0, 0, domeZ);
} else if (keyCode == DOWN) {
domeZ -= 1;
println("Dome Z : " + domeZ);
camera.translate(0, 0, domeZ);
} else if (keyCode == LEFT) {
domeScale -= 0.05;
println("Dome scale: " + domeScale);
camera.scale(domeScale);
} else if (keyCode == RIGHT) {
domeScale += 0.05;
println("Dome scale: " + domeScale);
camera.scale(domeScale);
}
} else {
if (key == 'g') {
grid = !grid;
if (grid) camera.setMode(Dome.GRID);
else camera.setMode(Dome.NORMAL);
} else if (key == ' ') {
dome = !dome;
if (dome) camera.enable();
else camera.disable();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Gravitational Attraction (3D)
* by Daniel Shiffman.
*
* Adapted for dome projection by Andres Colubri
*
* Simulating gravitational attraction
* G ---> universal gravitational constant
* m1 --> mass of object #1
* m2 --> mass of object #2
* d ---> distance between objects
* F = (G*m1*m2)/(d*d)
*
* For the basics of working with PVector, see
* http://processing.org/learning/pvector/
* as well as examples in Topics/Vectors/
*
*/

import codeanticode.planetarium.*;

// A bunch of planets
Planet[] planets = new Planet[10];
// One sun (note sun is not attracted to planets (violation of Newton's 3rd Law)
Sun s;

// An angle to rotate around the scene
float angle = 0;

void setup() {
size(800, 800, Dome.RENDERER);
smooth();
// Some random planets
for (int i = 0; i < planets.length; i++) {
planets[i] = new Planet(random(0.1, 2), random(-width/2, width/2), random(-height/2, height/2), random(-100, 100));
}
// A single sun
s = new Sun();
}

void pre() {
for (int i = 0; i < planets.length; i++) {
// Sun attracts Planets
PVector force = s.attract(planets[i]);
planets[i].applyForce(force);
// Update and draw Planets
planets[i].update();
}
}

void draw() {
background(0);

// Setup the scene
lights();

translate(width/2, height/2, 300);

rotateY(angle);

// Display the Sun
s.display();

// All the Planets
for (int i = 0; i < planets.length; i++) {
planets[i].display();
}
}

// Called after rendering all the faces, but before the dome sphere,
// so it can be used to draw stuff on the corners of the screen.
void border() {
perspective();
camera();
background(255);
fill(0);
text("FPS: " + frameRate, 20, 20);
}

void post() {
// Rotate around the scene
angle += 0.003;
}
45 changes: 45 additions & 0 deletions examples/GravitationalAttractionDome/Planet.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Gravitational Attraction (3D)
// Daniel Shiffman <http://www.shiffman.net>

// A class for an orbiting Planet

class Planet {

// Basic physics model (location, velocity, acceleration, mass)
PVector location;
PVector velocity;
PVector acceleration;
float mass;
PShape sphere;

Planet(float m, float x, float y, float z) {
mass = m;
location = new PVector(x,y,z);
velocity = new PVector(1,0); // Arbitrary starting velocity
acceleration = new PVector(0,0);
sphere = createShape(SPHERE, mass*8, 20);
sphere.setStroke(false);
sphere.setFill(color(255));
}

// Newton's 2nd Law (F = M*A) applied
void applyForce(PVector force) {
PVector f = PVector.div(force,mass);
acceleration.add(f);
}

// Our motion algorithm (aka Euler Integration)
void update() {
velocity.add(acceleration); // Velocity changes according to acceleration
location.add(velocity); // Location changes according to velocity
acceleration.mult(0);
}

// Draw the Planet
void display() {
pushMatrix();
translate(location.x,location.y,location.z);
shape(sphere);
popMatrix();
}
}
38 changes: 38 additions & 0 deletions examples/GravitationalAttractionDome/Sun.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Gravitational Attraction (3D)
// Daniel Shiffman <http://www.shiffman.net>

// A class for an attractive body in our world

class Sun {
float mass; // Mass, tied to size
PVector location; // Location
float G; // Universal gravitational constant (arbitrary value)
PShape sphere;

Sun() {
location = new PVector(0,0);
mass = 20;
G = 0.4;
sphere = createShape(SPHERE, mass*2, 20);
sphere.setFill(false);
sphere.setStroke(color(255));
}


PVector attract(Planet m) {
PVector force = PVector.sub(location,m.location); // Calculate direction of force
float d = force.mag(); // Distance between objects
d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude
force.setMag(strength); // Get force vector --> magnitude * direction
return force;
}

// Draw Sun
void display() {
pushMatrix();
translate(location.x,location.y,location.z);
shape(sphere);
popMatrix();
}
}
1 change: 1 addition & 0 deletions examples/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add examples for your library here.
6 changes: 6 additions & 0 deletions lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The lib folder:
In case your library requires 3rd party libraries, which need to be
added to the distribution, put them into the lib folder.
These 3rd party libraries will be added to your distribution and are
located next to your library's jar file.
This does not apply to .jar files that are considered core processing libraries.
20 changes: 20 additions & 0 deletions license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
A code template to build libraries for the Processing programming environment.

Part of the Processing project - http://processing.org

Copyright (c) 2011-12 Elie Zananiri
Copyright (c) 2008-11 Andreas Schlegel

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Loading

0 comments on commit ddf6d32

Please sign in to comment.