PImage src, img; //src: the source panoramic image, img: the image that is displayed float pitch, yaw, vAngle; //angles of the camera. int panoramaIndex; String[] panoramaList; float[] fov; //FieldOfView: an array with 3D coordinates for 3 corners of the viewscreen //0,1,2: coordinates for top left corner //3,4,5: vector from top left to top right corner //6,7,8: vector from top left to bottom left corner //the camera is presumed to be at (0,0,0); //------------------------------------------------ void setup() { panoramaList = new String[] { "trees.jpg", "ocean.jpg", "red.jpg" }; panoramaIndex = 0; src = loadImage(panoramaList[panoramaIndex]); pitch = 0; yaw = 0; vAngle = 1.8; size(200,130); setFov(vAngle,width,height); updatePanorama(); } //------------------------------------------------ void setFov(float fovAngle, int fWidth, int fHeight) { float screenHeight = fHeight/(float)fWidth; float screenDist = 1 / tan( fovAngle/2 ); fov = new float[] { -0.5, -screenHeight/2, screenDist, 1f, 0f, 0f, 0f, screenHeight, 0f}; } //------------------------------------------------ void draw(){ if(keyPressed){ if(key == 'c'){ panoramaIndex = (panoramaIndex+1) % panoramaList.length; src = loadImage(panoramaList[panoramaIndex]); } if(key == 's') pitch = constrain( pitch-0.05, -HALF_PI, HALF_PI); if(key == 'a') yaw -= 0.05; if(key == 'w') pitch = constrain( pitch+0.05, -HALF_PI, HALF_PI); if(key == 'd') yaw += 0.05; if(key == 'z') vAngle = constrain( vAngle+0.05, 0.2, 2.8); if(key == 'x') vAngle = constrain( vAngle-0.05, 0.2, 28); setFov(vAngle,width,height); updatePanorama(); } } //------------------------------------------------ void updatePanorama() { img = new PImage(width, height); loadPixels(); float[] ang, cang; int pixNr; int halfW = width/2; for (int x=0; x