001 /*
002 *
003 * Created: Jun 7 2006
004 *
005 * Copyright (C) 1999-2000 Fabien Sanglard
006 *
007 * This program is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU General Public License
009 * as published by the Free Software Foundation; either version 2
010 * of the License, or (at your option) any later version.
011 *
012 * This program is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015 * GNU General Public License for more details.
016 *
017 * You should have received a copy of the GNU General Public License
018 * along with this program; if not, write to the Free Software
019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020 */
021
022 package renderer.modelers;
023
024 import java.awt.Image;
025 import java.awt.Toolkit;
026 import java.awt.image.PixelGrabber;
027 import renderer.Modeler;
028 import renderer.Renderer;
029
030 public class Tunnel implements Modeler
031 {
032 private int scrWidth ;
033 private int scrHeight;
034
035 private static final int TEXTUREWIDTH = 256;
036 private static final int TEXTUREHEIGHT = 256;
037
038 private static int texture[] ;
039 private static int distances[][] ;
040 private static int angles[][] ;
041
042 private Renderer renderer;
043
044 public Tunnel(Renderer r)
045 {
046 this.renderer = r ;
047 texture = new int[TEXTUREHEIGHT * TEXTUREHEIGHT];
048 this.scrWidth = renderer.getRenderedWidth();
049 this.scrHeight = renderer.getRenderedHeight();
050
051 //Image textureImage = renderer.getToolkit().getImage(this.getClass().getResource("/tex99.jpg"));
052 java.awt.Image textureImage = renderer.getImage(renderer.getCodeBase(), "tex99.jpg");
053
054 PixelGrabber pixelgrabber = new PixelGrabber(textureImage, 0, 0, TEXTUREWIDTH, TEXTUREHEIGHT, texture, 0, TEXTUREWIDTH);
055 try
056 {
057 pixelgrabber.grabPixels();
058 }
059 catch(InterruptedException interruptedexception) {
060 interruptedexception.printStackTrace(System.out);
061
062 }
063
064 distances = new int[scrWidth][scrHeight];
065 angles = new int[scrWidth][scrHeight];
066
067
068 // Pregenerating the mapping pixel/coordinate.
069 for(int x = 0; x < scrWidth; x++)
070 for(int y = 0; y < scrHeight; y++)
071 {
072 distances[x][y] = (int)( (30.0 * TEXTUREHEIGHT / Math.sqrt(
073 (x - scrWidth /2.0) * (x - scrWidth /2.0) + (y - scrHeight /2.0) * (y - scrHeight /2.0)
074 )
075 ) % TEXTUREHEIGHT);
076
077 angles[x][y] = (int)(0.5* TEXTUREWIDTH * Math.atan2(y - scrHeight /2.0, x - scrWidth /2.0) / Math.PI);
078 }
079 }
080
081
082 static int shiftX=0;
083 static int shiftY=0;
084
085 static double movement = 0.1;
086 static double animation = 0;
087
088 public void drawOffScreen(){
089 // Java timer sucks ! Don't try to make the animation platform independant (Renderer.tick) :( !
090 animation += 3;
091 movement += 1;//movement + (int)Renderer.tick * 100 / 10000.0;
092
093 //calculate the shift values out of the animation value
094 shiftX = (int)(TEXTUREWIDTH + animation);
095 shiftY = (int)(TEXTUREHEIGHT +movement);// / rotation);
096
097 for(int y = 0,cursor=0; y < scrHeight; y++)
098 for(int x = 0; x < scrWidth; x++,cursor++)
099 {
100 renderer.offScreenRaster[cursor] =// texture[23543];
101
102 texture[(distances[x][y] + shiftX) % TEXTUREWIDTH +
103 (((angles[x][y] + shiftY) % TEXTUREHEIGHT) * TEXTUREWIDTH)];
104 }
105 }
106
107 }
|