We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
360 video (Read 757 times)
360 video
Dec 5th, 2009, 8:59am
 
Hi

Im new to processing, and i would like to know if it would be possible to do a 360 video panorama player in processing.

In Flex or AS3 i have seen some explames like:

http://www.cornflex.org/?p=1

http://www.villmer.com/


I have seen the examples of a plane with texture video, but i dont know how to do an sphere or a cilinder, put the camera inside and rotate the point of view.

Is possible to do that in processing, can someone give me an approach of how to do that  Roll Eyes


Thanks for your help
Re: 360 video
Reply #1 - Dec 5th, 2009, 9:24am
 
You might make a start here.
http://processing.org/learning/3d/texturedsphere.html

The 2 examples you link to both use a 3600 panoramic camera to get the images and unless you have one the reults are never going to be as impressive.
Re: 360 video
Reply #2 - Dec 6th, 2009, 9:21am
 
Thanks for the link.

I have access to a ladybug camera so the 360 pano vide file will not be an issue.


I tried the code in the example but when i try to replace the image texture with a video it doesn´t work.

So whats wrong with that code


import processing.video.*;
import processing.opengl.*;



PImage bg;
//PImage texmap;
Movie texmap;

int sDetail = 100;  //Sphere detail setting
float rotationX = 0;
float rotationY = 0;
float velocityX = 0;
float velocityY = 0;
float globeRadius = 500;
float pushBack = 0;

float[] cx,cz,sphereX,sphereY,sphereZ;
float sinLUT[];
float cosLUT[];
float SINCOS_PRECISION = 0.5f;
int SINCOS_LENGTH = int(360.0 / SINCOS_PRECISION);


void setup()
{
 size(640, 480, OPENGL);  
// texmap = loadImage("pano.png");    
 texmap = new Movie(this, "pano.mov");
 texmap.loop();
 initializeSphere(sDetail);
}

void draw()
{    
 background(0);            
 renderGlobe();
}
void movieEvent(Movie texmap) {
 texmap.read();
}


void renderGlobe()
{
 pushMatrix();
 translate(width/2.0, height/2.0, pushBack);
 pushMatrix();
 noFill();
 stroke(255,200);
 strokeWeight(2);
 smooth();
 popMatrix();
 lights();    
 pushMatrix();
 rotateX( radians(-rotationX) );  
 rotateY( radians(270 - rotationY) );
 fill(200);
 noStroke();
 textureMode(IMAGE);  
 texturedSphere(globeRadius, texmap);
 popMatrix();  
 popMatrix();
 rotationX += velocityX;
 rotationY += velocityY;
 velocityX *= 0.95;
 velocityY *= 0.95;
 
 // Implements mouse control (interaction will be inverse when sphere is  upside down)
 if(mousePressed){
   velocityX += (mouseY-pmouseY) * 0.01;
   velocityY -= (mouseX-pmouseX) * 0.01;
 }
}

void initializeSphere(int res)
{
 sinLUT = new float[SINCOS_LENGTH];
 cosLUT = new float[SINCOS_LENGTH];

 for (int i = 0; i < SINCOS_LENGTH; i++) {
   sinLUT[i] = (float) Math.sin(i * DEG_TO_RAD * SINCOS_PRECISION);
   cosLUT[i] = (float) Math.cos(i * DEG_TO_RAD * SINCOS_PRECISION);
 }

 float delta = (float)SINCOS_LENGTH/res;
 float[] cx = new float[res];
 float[] cz = new float[res];
 
 // Calc unit circle in XZ plane
 for (int i = 0; i < res; i++) {
   cx[i] = -cosLUT[(int) (i*delta) % SINCOS_LENGTH];
   cz[i] = sinLUT[(int) (i*delta) % SINCOS_LENGTH];
 }
 
 // Computing vertexlist vertexlist starts at south pole
 int vertCount = res * (res-1) + 2;
 int currVert = 0;
 
 // Re-init arrays to store vertices
 sphereX = new float[vertCount];
 sphereY = new float[vertCount];
 sphereZ = new float[vertCount];
 float angle_step = (SINCOS_LENGTH*0.5f)/res;
 float angle = angle_step;
 
 // Step along Y axis
 for (int i = 1; i < res; i++) {
   float curradius = sinLUT[(int) angle % SINCOS_LENGTH];
   float currY = -cosLUT[(int) angle % SINCOS_LENGTH];
   for (int j = 0; j < res; j++) {
     sphereX[currVert] = cx[j] * curradius;
     sphereY[currVert] = currY;
     sphereZ[currVert++] = cz[j] * curradius;
   }
   angle += angle_step;
 }
 sDetail = res;
}

// Generic routine to draw textured sphere
void texturedSphere(float r, PImage t)
{
 int v1,v11,v2;
 r = (r + 240 ) * 0.33;
 beginShape(TRIANGLE_STRIP);
 texture(t);
 float iu=(float)(t.width-1)/(sDetail);
 float iv=(float)(t.height-1)/(sDetail);
 float u=0,v=iv;
 for (int i = 0; i < sDetail; i++) {
   vertex(0, -r, 0,u,0);
   vertex(sphereX[i]*r, sphereY[i]*r, sphereZ[i]*r, u, v);
   u+=iu;
 }
 vertex(0, -r, 0,u,0);
 vertex(sphereX[0]*r, sphereY[0]*r, sphereZ[0]*r, u, v);
 endShape();  
 
 // Middle rings
 int voff = 0;
 for(int i = 2; i < sDetail; i++) {
   v1=v11=voff;
   voff += sDetail;
   v2=voff;
   u=0;
   beginShape(TRIANGLE_STRIP);
   texture(t);
   for (int j = 0; j < sDetail; j++) {
     vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1++]*r, u, v);
     vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2++]*r, u, v+iv);
     u+=iu;
   }
 
   // Close each ring
   v1=v11;
   v2=voff;
   vertex(sphereX[v1]*r, sphereY[v1]*r, sphereZ[v1]*r, u, v);
   vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v+iv);
   endShape();
   v+=iv;
 }
 u=0;
 
 // Add the northern cap
 beginShape(TRIANGLE_STRIP);
 texture(t);
 for (int i = 0; i < sDetail; i++) {
   v2 = voff + i;
   vertex(sphereX[v2]*r, sphereY[v2]*r, sphereZ[v2]*r, u, v);
   vertex(0, r, 0,u,v+iv);    
   u+=iu;
 }
 vertex(0, r, 0,u, v+iv);
 vertex(sphereX[voff]*r, sphereY[voff]*r, sphereZ[voff]*r, u, v);
 endShape();
 
}



Also to get the effect (testing with a panoramic image) i have to draw a sphere with a bigger diameter and then it renders slow and choppy  Angry
Page Index Toggle Pages: 1