-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 32384b7
Showing
5 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import com.github.sarxos.webcam.Webcam; | ||
import java.awt.image.BufferedImage; | ||
import java.util.List; | ||
import java.awt.Dimension; | ||
|
||
class PCapture { | ||
Webcam webcam; | ||
int width = 0; | ||
int height = 0; | ||
|
||
public PCapture(int id, int w, int h) { | ||
super(); | ||
List<Webcam> webcams = Webcam.getWebcams(); | ||
webcam = webcams.get(id); | ||
|
||
Dimension size = new Dimension( w, h ); | ||
webcam.setCustomViewSizes(new Dimension[] { | ||
size | ||
} | ||
); | ||
|
||
webcam.setViewSize(size); | ||
webcam.open(); | ||
|
||
width = webcam.getImage().getWidth(); | ||
height = webcam.getImage().getHeight(); | ||
|
||
} | ||
|
||
PImage getImage() { | ||
BufferedImage bImg = webcam.getImage(); | ||
PImage pImg = createImage(bImg.getWidth(), bImg.getHeight(), ARGB); | ||
|
||
for (int y = 0; y < pImg.height; y++) { | ||
for (int x = 0; x < pImg.width; x++) { | ||
pImg.pixels[y * pImg.width + x] = bImg.getRGB(x, y); | ||
} | ||
} | ||
return pImg; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// CAUTION! | ||
// This is very dirty code. It needs refactoring. | ||
|
||
PCapture cam; | ||
PImage img; | ||
|
||
PVector[][] vertex; | ||
PVector[][] t_vertex1; | ||
PVector[][] t_vertex2; | ||
|
||
void setup() { | ||
size(800, 600, P3D); | ||
cam = new PCapture( 1, 1280, 720 ); | ||
|
||
int k_div = 20; | ||
int s_div = 50; | ||
int R = 300; | ||
|
||
vertex = new PVector[k_div+1][s_div]; | ||
t_vertex1 = new PVector[k_div+1][s_div]; | ||
t_vertex2 = new PVector[k_div+1][s_div]; | ||
|
||
for (int k=1; k<=k_div; k++) { | ||
for (int s=0; s<s_div; s++) { | ||
vertex[k][s] = getPoint3D( k, s, R, k_div, s_div ); | ||
t_vertex1[k][s] = getPoint2D( k, s, R, 310, 320, k_div, s_div ); | ||
t_vertex2[k][s] = getPoint2D( k, s, R, 960, 320, k_div, s_div ); | ||
} | ||
} | ||
} | ||
|
||
|
||
void draw() { | ||
background(0); | ||
img = cam.getImage(); | ||
|
||
translate( width/2, height/2, 600 ); | ||
rotateY( radians( frameCount*5) ); | ||
|
||
noStroke(); | ||
drawHalfSphere( vertex, t_vertex1, 20, 50, 500, 300, 310, 320 ); | ||
rotateY(PI); | ||
drawHalfSphere( vertex, t_vertex2, 20, 50, 500, 300, 960, 320 ); | ||
} | ||
|
||
|
||
void drawHalfSphere(PVector[][] vertex, PVector[][] t_vertex, int k_div, int s_div, int R, int img_R, int xc, int yc) { | ||
|
||
for (int k=1; k<=k_div; k++) { | ||
for (int s=0; s<s_div; s++) { | ||
int s2 = (s+1==s_div) ? 0 : s+1; // next | ||
if ( k==1 ) { | ||
PVector p1 = vertex[k][s]; | ||
PVector p2 = vertex[k][s2]; | ||
PVector t1 = t_vertex[k][s]; | ||
PVector t2 = t_vertex[k][s2]; | ||
beginShape(); | ||
texture(img); | ||
vertex( p1.x, p1.y, p1.z, t1.x, t1.y ); | ||
vertex( p2.x, p2.y, p2.z, t2.x, t2.y ); | ||
vertex( 0, 0, R, xc, yc ); | ||
endShape(TRIANGLE); | ||
} else { | ||
PVector p1 = vertex[k][s]; | ||
PVector p2 = vertex[k-1][s]; | ||
PVector p3 = vertex[k][s2]; | ||
PVector p4 = vertex[k-1][s2]; | ||
|
||
PVector t1 = t_vertex[k][s]; | ||
PVector t2 = t_vertex[k-1][s]; | ||
PVector t3 = t_vertex[k][s2]; | ||
PVector t4 = t_vertex[k-1][s2]; | ||
|
||
beginShape(); | ||
texture(img); | ||
vertex( p1.x, p1.y, p1.z, t1.x, t1.y ); | ||
vertex( p3.x, p3.y, p3.z, t3.x, t3.y ); | ||
vertex( p2.x, p2.y, p2.z, t2.x, t2.y ); | ||
endShape(TRIANGLE); | ||
|
||
beginShape(); | ||
texture(img); | ||
vertex( p2.x, p2.y, p2.z, t2.x, t2.y ); | ||
vertex( p3.x, p3.y, p3.z, t3.x, t3.y ); | ||
vertex( p4.x, p4.y, p4.z, t4.x, t4.y ); | ||
endShape(TRIANGLE); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
PVector getPoint3D(int k, int s, int R, int k_div, int s_div ) { | ||
float theta_k = (PI/2)/k_div * k; | ||
float r = R*sin( theta_k ); | ||
float theta_s = (2*PI)/s_div * s; | ||
float x = r*cos(theta_s); | ||
float y = r*sin(theta_s); | ||
float z = R * cos(theta_k); | ||
PVector vec = new PVector(x, y, z); | ||
return vec; | ||
} | ||
|
||
PVector getPoint2D(int k, int s, int R, int xc, int yc, int k_div, int s_div ) { | ||
float theta_k = (PI/2)/k_div * k; | ||
float r = R*sin( theta_k ); | ||
float theta_s = (2*PI)/s_div * s; | ||
float x = r*cos(theta_s) + xc; | ||
float y = r*sin(theta_s) + yc; | ||
PVector vec = new PVector(x, y); | ||
return vec; | ||
} | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.