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

Commit ddf6d32

Browse files
committed
recreated as an independent repo
0 parents  commit ddf6d32

26 files changed

+2398
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The planetarium library is intended to project 3D Processing sketches on spherical domes, with minimal changes in the code of the sketch.
2+
3+
It is based on the FullDomeTemplate code from Christopher Warnow, available at https://github.com/mphasize/FullDome
4+
5+
### Overview
6+
7+
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).
8+
9+
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.
10+
11+
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.

data/README

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
the data folder:
2+
If your library is using files like images, sound files,
3+
any data file, etc., put them into the data folder.
4+
When coding your library you can use processing's internal loading
5+
functions like loadImage(), loadStrings(), etc. to load files
6+
located inside the data folder into your library.
7+

data/cubeMapFrag.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uniform samplerCube cubemap;varying vec3 reflectDir;void main() { vec3 color = vec3(textureCube(cubemap, reflectDir)); gl_FragColor = vec4(color, 1.0); }

data/cubeMapVert.glsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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);}

examples/Basic/Basic.pde

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// The planetarium library is designed to create real-time projections on
2+
// spherical domes. It is based on the FullDome project by Christopher
3+
// Warnow (ch.warnow@gmx.de):
4+
// https://github.com/mphasize/FullDome
5+
//
6+
// A brief descrition on how it works: a 360° view of the scene is generated
7+
// by rendering the scene 6 times from each direction: positive x, negative x,
8+
// positive y, and so on. The output of each rendering is stored inside a cube map
9+
// texture, which is then applied on a sphere representing the dome.
10+
// Hence, the library calls the draw() method 6 times per frame in order to update
11+
// the corresponding side of the cube map texture (in reality, only 5 times since
12+
// the bottom side of the cube map is not invisible on the dome).
13+
// So, it is important to keep in mind that if you need to perform some calculation
14+
// only one time per frame, then the code for those calculations should be put inside
15+
// the pre() method.
16+
17+
import codeanticode.planetarium.*;
18+
19+
float cubeX, cubeY, cubeZ;
20+
21+
void setup() {
22+
// For the time being, only use square windows
23+
size(600, 600, Dome.RENDERER);
24+
}
25+
26+
// Called one time per frame.
27+
void pre() {
28+
// The dome projection is centered at (0, 0), so the mouse coordinates
29+
// need to be offset by (width/2, height/2)
30+
cubeX += ((mouseX - width * 0.5) - cubeX) * 0.2;
31+
cubeY += ((mouseY - height * 0.5) - cubeY) * 0.2;
32+
}
33+
34+
// Called five times per frame.
35+
void draw() {
36+
background(0);
37+
38+
pushMatrix();
39+
translate(width/2, height/2, 300);
40+
41+
lights();
42+
43+
stroke(0);
44+
fill(150);
45+
pushMatrix();
46+
translate(cubeX, cubeY, cubeZ);
47+
box(50);
48+
popMatrix();
49+
50+
stroke(255);
51+
int linesAmount = 10;
52+
for (int i = 0; i < linesAmount;i++) {
53+
float ratio = (float)i/(linesAmount-1);
54+
line(0, 0, cos(ratio*TWO_PI) * 50, sin(ratio*TWO_PI) * 50);
55+
}
56+
popMatrix();
57+
}
58+
59+
void keyPressed() {
60+
if (key == CODED) {
61+
if (keyCode == UP) cubeZ -= 5;
62+
else if (keyCode == DOWN) cubeZ += 5;
63+
}
64+
}

examples/Calibrate/Calibrate.pde

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import codeanticode.planetarium.*;
2+
3+
DomeCamera camera;
4+
float cubeX, cubeY;
5+
float domeZ = 0;
6+
float domeScale = 1;
7+
boolean dome = true;
8+
boolean grid = false;
9+
10+
void setup() {
11+
// For the time being, only use square windows
12+
size(600, 600, Dome.RENDERER);
13+
camera = new DomeCamera(this);
14+
}
15+
16+
// Called one time per frame.
17+
void pre() {
18+
// The dome projection is centered at (0, 0), so the mouse coordinates
19+
// need to be offset by (width/2, height/2)
20+
cubeX += ((mouseX - width * 0.5) - cubeX) * 0.2;
21+
cubeY += ((mouseY - height * 0.5) - cubeY) * 0.2;
22+
}
23+
24+
// Called five times per frame.
25+
void draw() {
26+
int face = camera.getFace();
27+
if (face == DomeCamera.POSITIVE_X) {
28+
background(240, 59, 31);
29+
} else if (face == DomeCamera.NEGATIVE_X) {
30+
background(240, 146, 31);
31+
} else if (face == DomeCamera.POSITIVE_Y) {
32+
background(30, 245, 0);
33+
} else if (face == DomeCamera.NEGATIVE_Y) {
34+
background(30, 232, 156);
35+
} else if (face == DomeCamera.POSITIVE_Z) {
36+
background(52, 148, 206);
37+
} else if (face == DomeCamera.NEGATIVE_Z) {
38+
background(183, 115, 13);
39+
}
40+
41+
pushMatrix();
42+
translate(width/2, height/2, 300);
43+
44+
stroke(255);
45+
noFill();
46+
47+
pushMatrix();
48+
translate(cubeX, cubeY, 0);
49+
sphereDetail(8);
50+
sphere(30);
51+
popMatrix();
52+
53+
int linesAmount = 10;
54+
for (int i = 0; i < linesAmount;i++) {
55+
float ratio = (float)i/(linesAmount-1);
56+
line(0, 0, cos(ratio*TWO_PI) * 50, sin(ratio*TWO_PI) * 50);
57+
}
58+
59+
popMatrix();
60+
}
61+
62+
void keyPressed() {
63+
if (key == CODED) {
64+
if (keyCode == UP) {
65+
domeZ += 1;
66+
println("Dome Z : " + domeZ);
67+
camera.translate(0, 0, domeZ);
68+
} else if (keyCode == DOWN) {
69+
domeZ -= 1;
70+
println("Dome Z : " + domeZ);
71+
camera.translate(0, 0, domeZ);
72+
} else if (keyCode == LEFT) {
73+
domeScale -= 0.05;
74+
println("Dome scale: " + domeScale);
75+
camera.scale(domeScale);
76+
} else if (keyCode == RIGHT) {
77+
domeScale += 0.05;
78+
println("Dome scale: " + domeScale);
79+
camera.scale(domeScale);
80+
}
81+
} else {
82+
if (key == 'g') {
83+
grid = !grid;
84+
if (grid) camera.setMode(Dome.GRID);
85+
else camera.setMode(Dome.NORMAL);
86+
} else if (key == ' ') {
87+
dome = !dome;
88+
if (dome) camera.enable();
89+
else camera.disable();
90+
}
91+
}
92+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Gravitational Attraction (3D)
3+
* by Daniel Shiffman.
4+
*
5+
* Adapted for dome projection by Andres Colubri
6+
*
7+
* Simulating gravitational attraction
8+
* G ---> universal gravitational constant
9+
* m1 --> mass of object #1
10+
* m2 --> mass of object #2
11+
* d ---> distance between objects
12+
* F = (G*m1*m2)/(d*d)
13+
*
14+
* For the basics of working with PVector, see
15+
* http://processing.org/learning/pvector/
16+
* as well as examples in Topics/Vectors/
17+
*
18+
*/
19+
20+
import codeanticode.planetarium.*;
21+
22+
// A bunch of planets
23+
Planet[] planets = new Planet[10];
24+
// One sun (note sun is not attracted to planets (violation of Newton's 3rd Law)
25+
Sun s;
26+
27+
// An angle to rotate around the scene
28+
float angle = 0;
29+
30+
void setup() {
31+
size(800, 800, Dome.RENDERER);
32+
smooth();
33+
// Some random planets
34+
for (int i = 0; i < planets.length; i++) {
35+
planets[i] = new Planet(random(0.1, 2), random(-width/2, width/2), random(-height/2, height/2), random(-100, 100));
36+
}
37+
// A single sun
38+
s = new Sun();
39+
}
40+
41+
void pre() {
42+
for (int i = 0; i < planets.length; i++) {
43+
// Sun attracts Planets
44+
PVector force = s.attract(planets[i]);
45+
planets[i].applyForce(force);
46+
// Update and draw Planets
47+
planets[i].update();
48+
}
49+
}
50+
51+
void draw() {
52+
background(0);
53+
54+
// Setup the scene
55+
lights();
56+
57+
translate(width/2, height/2, 300);
58+
59+
rotateY(angle);
60+
61+
// Display the Sun
62+
s.display();
63+
64+
// All the Planets
65+
for (int i = 0; i < planets.length; i++) {
66+
planets[i].display();
67+
}
68+
}
69+
70+
// Called after rendering all the faces, but before the dome sphere,
71+
// so it can be used to draw stuff on the corners of the screen.
72+
void border() {
73+
perspective();
74+
camera();
75+
background(255);
76+
fill(0);
77+
text("FPS: " + frameRate, 20, 20);
78+
}
79+
80+
void post() {
81+
// Rotate around the scene
82+
angle += 0.003;
83+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Gravitational Attraction (3D)
2+
// Daniel Shiffman <http://www.shiffman.net>
3+
4+
// A class for an orbiting Planet
5+
6+
class Planet {
7+
8+
// Basic physics model (location, velocity, acceleration, mass)
9+
PVector location;
10+
PVector velocity;
11+
PVector acceleration;
12+
float mass;
13+
PShape sphere;
14+
15+
Planet(float m, float x, float y, float z) {
16+
mass = m;
17+
location = new PVector(x,y,z);
18+
velocity = new PVector(1,0); // Arbitrary starting velocity
19+
acceleration = new PVector(0,0);
20+
sphere = createShape(SPHERE, mass*8, 20);
21+
sphere.setStroke(false);
22+
sphere.setFill(color(255));
23+
}
24+
25+
// Newton's 2nd Law (F = M*A) applied
26+
void applyForce(PVector force) {
27+
PVector f = PVector.div(force,mass);
28+
acceleration.add(f);
29+
}
30+
31+
// Our motion algorithm (aka Euler Integration)
32+
void update() {
33+
velocity.add(acceleration); // Velocity changes according to acceleration
34+
location.add(velocity); // Location changes according to velocity
35+
acceleration.mult(0);
36+
}
37+
38+
// Draw the Planet
39+
void display() {
40+
pushMatrix();
41+
translate(location.x,location.y,location.z);
42+
shape(sphere);
43+
popMatrix();
44+
}
45+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Gravitational Attraction (3D)
2+
// Daniel Shiffman <http://www.shiffman.net>
3+
4+
// A class for an attractive body in our world
5+
6+
class Sun {
7+
float mass; // Mass, tied to size
8+
PVector location; // Location
9+
float G; // Universal gravitational constant (arbitrary value)
10+
PShape sphere;
11+
12+
Sun() {
13+
location = new PVector(0,0);
14+
mass = 20;
15+
G = 0.4;
16+
sphere = createShape(SPHERE, mass*2, 20);
17+
sphere.setFill(false);
18+
sphere.setStroke(color(255));
19+
}
20+
21+
22+
PVector attract(Planet m) {
23+
PVector force = PVector.sub(location,m.location); // Calculate direction of force
24+
float d = force.mag(); // Distance between objects
25+
d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
26+
float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude
27+
force.setMag(strength); // Get force vector --> magnitude * direction
28+
return force;
29+
}
30+
31+
// Draw Sun
32+
void display() {
33+
pushMatrix();
34+
translate(location.x,location.y,location.z);
35+
shape(sphere);
36+
popMatrix();
37+
}
38+
}

examples/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add examples for your library here.

0 commit comments

Comments
 (0)