diff options
Diffstat (limited to 'demos/GLLandScape')
-rw-r--r-- | demos/GLLandScape/GLLandScape-readme.txt | 58 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1-big.html | 14 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1-big_plugin13.html | 46 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1.html | 14 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1.java | 714 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1Applet.java | 399 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1_plugin13.html | 46 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1w1-big.html | 14 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1w1-big_plugin13.html | 46 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1w1.html | 14 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1w1.java | 781 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1w1Applet$SpeedTimer | bin | 0 -> 1521 bytes | |||
-rwxr-xr-x | demos/GLLandScape/GLLandScape1w1Applet.java | 416 | ||||
-rw-r--r-- | demos/GLLandScape/GLLandScape1w1_plugin13.html | 46 | ||||
-rw-r--r-- | demos/GLLandScape/GlutPlaneObj.java | 112 | ||||
-rw-r--r-- | demos/GLLandScape/LICENSE.txt | 36 | ||||
-rw-r--r-- | demos/GLLandScape/index.html | 52 |
17 files changed, 2808 insertions, 0 deletions
diff --git a/demos/GLLandScape/GLLandScape-readme.txt b/demos/GLLandScape/GLLandScape-readme.txt new file mode 100644 index 0000000..7ceb26f --- /dev/null +++ b/demos/GLLandScape/GLLandScape-readme.txt @@ -0,0 +1,58 @@ +GLLandScape V 1.1 (for JDK 1.1.X + GL4Java) +=========================================== + +you need to have: +================= + + o jdk 1.1.X or java2 + o GL4Java V 2.X.X (http://www.jausoft.com/gl4java.html) + +ABOUT +===== + +GLLandScape is another demonstration and test for GL4Java. + +The landscape algorythms are taken from +Nicholas Anderson's Landscape V1.0 ! + http://www.fortunecity.com/skyscraper/online/263 + mailto:[email protected] + +A landscape will be generated, where you can walk through :-) + +FUTURE +====== + +I ported Nicholas Anderson's Landscape V1.0, +because i am thinking that this is a fine virtual-world, +to create a game :-) + +CHANGES +======= + +Now using display lists for the world -> faster ! + +INSTALL +======= + +be sure to have GL4Java correctly installed +(check the manuals at http://www.jausoft.com/gl4java.html ! + +extract the GLLandScape.zip file ! + +generate the classes with: �javac *.java� + +run GLLandScape with: 'java GLLandScapeFrame' + +thats it :-) + +THANXS +====== + +Thanxs to Nicholas Anderson for his source code of +Landscape V1.0, which was written in ANSI-C and uses +OpenGL GLU and GLUT ! + +Sven Goethel + + + diff --git a/demos/GLLandScape/GLLandScape1-big.html b/demos/GLLandScape/GLLandScape1-big.html new file mode 100644 index 0000000..06dcdf4 --- /dev/null +++ b/demos/GLLandScape/GLLandScape1-big.html @@ -0,0 +1,14 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<applet code="GLLandScape1Applet.class" width=800 height=600>
+<param name=frames value="55">
+</applet>
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GLLandScape1-big_plugin13.html b/demos/GLLandScape/GLLandScape1-big_plugin13.html new file mode 100644 index 0000000..1cb8f63 --- /dev/null +++ b/demos/GLLandScape/GLLandScape1-big_plugin13.html @@ -0,0 +1,46 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<!--"CONVERTED_APPLET"-->
+<!-- CONVERTER VERSION 1.3 --> +<SCRIPT LANGUAGE="JavaScript"><!-- + var _info = navigator.userAgent; var _ns = false; + var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0); +//--></SCRIPT> +<COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!-- + var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0))); +//--></SCRIPT></COMMENT> + +<SCRIPT LANGUAGE="JavaScript"><!-- + if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 800 HEIGHT = 600 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"><NOEMBED><XMP>'); + else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.3" CODE = "GLLandScape1Applet.class" WIDTH = 800 HEIGHT = 600 frames = "55" scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED><XMP>'); +//--></SCRIPT> +<APPLET CODE = "GLLandScape1Applet.class" WIDTH = 800 HEIGHT = 600></XMP> +<PARAM NAME = CODE VALUE = "GLLandScape1Applet.class" >
+ +<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3"> +<PARAM NAME="scriptable" VALUE="false"> +<PARAM NAME = frames VALUE ="55">
+ +</APPLET> + +</NOEMBED></EMBED></OBJECT> + + +<!-- +<APPLET CODE = "GLLandScape1Applet.class" WIDTH = 800 HEIGHT = 600>
+<PARAM NAME = frames VALUE ="55">
+
+
+</APPLET> +--> +<!--"END_CONVERTED_APPLET"-->
+
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GLLandScape1.html b/demos/GLLandScape/GLLandScape1.html new file mode 100644 index 0000000..5521afd --- /dev/null +++ b/demos/GLLandScape/GLLandScape1.html @@ -0,0 +1,14 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<applet code="GLLandScape1Applet.class" width=500 height=300>
+<param name=frames value="55">
+</applet>
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GLLandScape1.java b/demos/GLLandScape/GLLandScape1.java new file mode 100644 index 0000000..209f6db --- /dev/null +++ b/demos/GLLandScape/GLLandScape1.java @@ -0,0 +1,714 @@ +/** + * @(#) GLLandScape1.java + */ +import gl4java.GLContext; +import gl4java.awt.GLAnimCanvas; +import java.awt.*; +import java.awt.event.*; +import java.lang.*; +import java.util.*; + +/** + * This is meant as an skellekton for porting/writing + * OpenGL to gl4java + * + * If you are interessting in further Documentation and/or + * the history of gl4java follow the following link. + * + * <pre> + <a href="gl4java.html#_top_">The gl4java Documentation</a> + * </pre> + * <p> + * + * This NEW dummy code uses repaint(), + * the std. java thread, and sleep to suspend with a given + * Frames per secounds value !! + * (of course - sDisplay is still avaiable, + * but i guess it is not that reliable ... comments welcome ) + * + * + * @see WinDataAccess + * @version 1.1, 3. MAI 1999 + * @author Sven Goethel + * + */ +class GLLandScape1 extends GLAnimCanvas +{ + /** + * Variables for the LandScape + */ + class COLOUR + { + public float r, g, b; + + public COLOUR() + { + r = 0.0f; + g = 0.0f; + b = 0.0f; + } + + } + + /* The constant MAP is used throughout the program and represents the MAP of + the matrix/landscape. */ + static final int MAP = 256; + + /* This is the holding space for the landscape. */ + float y[/*MAP+2*/][/*MAP+2*/]; + + char object[/*MAP+1*/][/*MAP+1*/]; + + /* This is the holding space for the landscape colours. */ + COLOUR c[/*MAP+1*/][/*MAP+1*/]; + + public static final int FORWARD = 1; + + public static final int UP = 2; + + public static final int TURNLEFT = 3; + + public static final int STRAFELEFT = 4; + + public static final int LOOKUP = 5; + + public static final int LOOKSET = 6; + + static final int TRUE = 1; + + static final int FALSE = 0; + + static final int WIDTH = 32; + + /* The width of the texture map. */ + byte texImg[/*WIDTH * WIDTH * 4*/]; + + int texName[/*1*/] = {0}; + + short comp = 32; + + /* Scale modifier. */ + short temp, texture_mapping = FALSE, land_fogging = TRUE, + flat_shading = FALSE; + + /* Initial eye position and vector of sight. */ + float posx, posy, posz; + + float lookx, looky, lookz; + + float mySpeed = 0; + + int myDir = FORWARD; + + // the display list for the land .. + int theLand; + + + public GLLandScape1(int w, int h) + { + super(w,h); + } + + public void init_pos() + { + posx = 4500.0f; + posy = 256.0f; + posz = 4500.0f; + lookx = 4096.0f; + looky = 0.0f; + lookz = 4096.0f; + mySpeed = 0; + System.out.println("init_pos"); + } + + public void init() + { + int i, j; + /* here we should add and initialize our JAVA components */ + texImg = new byte[WIDTH * WIDTH * 4]; + y = new float[MAP + 2][MAP + 2]; + object = new char[MAP + 1][MAP + 1]; + c = new COLOUR[MAP + 1][MAP + 1]; + for(i = 0;i <= MAP;i++) + { + for(j = 0;j <= MAP;j++) + { + c[i][j] = new COLOUR(); + } + } + float fogColor[] = {0.75f, 0.75f, 1.0f, 1.0f}; + init_pos(); + // srand(224); + + create_fractal(); + genLand(); + + // srand((unsigned)time(NULL)); + makeTexture(); + /* ... and furthet OpenGL init's - like you want to */ + gl.glPixelStorei(GL_UNPACK_ALIGNMENT,1); + if(texture_mapping == TRUE) + gl.glEnable(GL_TEXTURE_2D); + gl.glGenTextures(1,texName); + gl.glBindTexture(GL_TEXTURE_2D,texName[0]); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + gl.glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,WIDTH,WIDTH,0,GL_RGBA,GL_UNSIGNED_BYTE,texImg); + gl.glEnable(GL_DEPTH_TEST); + if(flat_shading == FALSE) + gl.glShadeModel(GL_SMOOTH); + else + gl.glShadeModel(GL_FLAT); + if(land_fogging == TRUE) + gl.glEnable(GL_FOG); + else + gl.glDisable(GL_FOG); + gl.glFogi(GL_FOG_MODE,GL_LINEAR); + gl.glFogfv(GL_FOG_COLOR,fogColor); + gl.glFogf(GL_FOG_DENSITY,0.4f); + gl.glFogf(GL_FOG_START,800.0f); + gl.glFogf(GL_FOG_END,1000.0f); + gl.glClearColor(0.75f,0.75f,1.0f,1.0f); + // FreeConsole(); + glj.gljCheckGL(); + + + Dimension dim = getSize(); + reshape(dim.width,dim.height); + myMove(FORWARD,mySpeed,true); + check_height(); + repaint(); + /* and start our working thread ... */ + start(); + } + + public void display() + { + int i; + /* Standard gl4java Init */ + if(!cvsIsInit() || glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + // ... just render it + + gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + gl.glCallList(theLand); + + myMove(FORWARD,mySpeed,true); + check_height(); + + setSuspended(mySpeed==0); + + /* For your animation dutys ;-) */ + glj.gljSwap(); + glj.gljCheckGL(); + glj.gljFree(); + } + + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + void create_fractal() + { + int bsize, csize; + int x, z, i; + int r = 256; + /* The maximum random value. */ + float gradient, shadow = 0.5f, n; + /* Make the matrix flat. */ + for(x = 0;x < MAP + 2;x++) + for(z = 0;z < MAP + 2;z++) + y[x][z] = 0L; + bsize = MAP; + for(i = 0;i < 8;i++) + { + for(x = 0;x < MAP;x += bsize) + for(z = 0;z < MAP;z += bsize) + y[x][z] += (Math.random() * r - r / 2); + if(i > 4) + r = r / 2; + csize = bsize / 2; + if(csize > 0) + { + for(x = 0;x < MAP;x += bsize) + for(z = 0;z < MAP;z += bsize) + { + if(x < MAP) + y[x + csize][z] = (y[x + bsize][z] + y[x][z]) / 2; + if(z < MAP) + y[x][z + csize] = (y[x][z + bsize] + y[x][z]) / 2; + if(x < MAP && z < MAP) + y[x + csize][z + csize] = (y[x][z] + y[x + bsize][z] + y[x][z + bsize] + y[x + bsize][z + bsize]) / 4; + } + } + bsize = csize; + } + for(x = 0;x < MAP;x++) + { + for(z = 0;z < MAP;z++) + { + y[x][z] = y[x][z] + y[x + 1][z] + y[x + 1][z + 1] + y[x][z + 1]; + y[x][z] /= 4.0f; + } + } + for(x = MAP;x > 0;x--) + { + for(z = 0;z < MAP;z++) + { + y[x][z] = y[x][z] + y[x - 1][z] + y[x - 1][z + 1] + y[x][z + 1]; + y[x][z] /= 4.0f; + } + } + /* put trees in various places on grassland. */ + for(x = 0;x < MAP;x++) + { + for(z = 0;z < MAP;z++) + { + if(((int)(Math.random() * 256.0f)) % 8 == 0 && y[x][z] > 0 && y[x][z] < 64) + { + object[x][z] = 't'; + } + else + { + object[x][z] = 'n'; + } + } + } + for(x = 0;x < MAP;x++) + for(z = 0;z < MAP;z++) + if(y[x][z] > 8) + { + n = y[x][z]; + y[x][z] *= n; + y[x][z] /= 256.0f; + } + for(x = 0;x <= MAP;x++) + { + for(z = 0;z <= MAP;z++) + { + gradient = ((float)(y[x][z] - y[x + 1][z])) / 100.0f; + if(y[x][z] > 64) + { + if((y[x][z] - y[x][z + 1]) < 8 && (y[x][z] - y[x][z + 1]) > -8 && (y[x][z] - y[x + 1][z]) < 8 && (y[x][z] - y[x + 1][z]) > -8) + { + c[x][z].g = gradient + 0.75f; + c[x][z].r = c[x][z].g; + c[x][z].b = c[x][z].g; + } + else + { + c[x][z].r = gradient + 0.75f; + c[x][z].g = c[x][z].r * 0.8f; + c[x][z].b = c[x][z].r * 0.5f; + } + } + else + if(y[x][z] > 0) + { + c[x][z].g = gradient + 0.75f; + c[x][z].r = c[x][z].g * 0.6f; + c[x][z].b = 0.0f; + } + else + { + c[x][z].r = gradient + 1.0f; + c[x][z].g = c[x][z].r * 0.75f; + c[x][z].b = c[x][z].r * 0.5f; + } + } + } + for(x = 0;x <= MAP;x++) + for(z = 0;z <= MAP;z++) + { + if(y[x][z] < 0) + y[x][z] /= 4.0f; + } + + } + + void makeTexture() + { + int i, j, h, c; + for(i = 0;i < WIDTH;i++) + { + for(j = 0;j < WIDTH;j++) + { + c = (int)(Math.random() * 15 + 240); + h = i * WIDTH * 4 + j * 4; + texImg[h + 0] = (byte)c; + texImg[h + 1] = (byte)c; + texImg[h + 2] = (byte)c; + texImg[h + 3] = (byte)255; + } + } + } + + void check_height() + { + float x0, x1, lx, lz, x, z, midpoint; + int fx, fz; + x = (posx / (comp * 1.0f)); + z = (posz / (comp * 1.0f)); + fx = (int)(x); + fz = (int)(z); + lx = x - fx; + lz = z - fz; + if(fx >= MAP + 2 || fz >= MAP + 2 || fx < 0 || fz < 0) + { + init_pos(); + return; + } + x0 = y[fx][fz] + (y[fx][fz + 1] - y[fx][fz]) * lz; + x1 = y[fx + 1][fz] + (y[fx + 1][fz + 1] - y[fx + 1][fz]) * lz; + midpoint = x0 + (x1 - x0) * lx; + posy = midpoint + 16.0f; + } + + /* Function that moves the eye / turns the angle of sight. */ + /* Updates scene if update. */ + void myMove(int dir, float amount, boolean update) + { + float diff = (float)Math.sqrt(lookx * lookx + lookz * lookz); + /* + float alpha = (float) + Math.atan(Math.abs(lookz)/Math.abs(lookx)); + if(lookx<0&&lookz>=0) + alpha+=(float)(Math.PI/2.0); + else if(lookx>=0&&lookz>=0) + alpha+=0; + else if(lookx<0&&lookz<0) + alpha+=(float)Math.PI; + else if(lookx>=0&&lookz<0) + alpha+=(float)((3.0*Math.PI)/2.0); + float _alpha = (float) (alpha*180f/Math.PI ); + */ + boolean do_repaint = false; + lookx /= diff; + lookz /= diff; + //myDir=dir; + switch(dir) + { + case FORWARD: + posx += lookx * amount; + posz += lookz * amount; + break; + case TURNLEFT: + lookx = lookx * (float)Math.cos(amount) + lookz * (float)Math.sin(amount); + lookz = lookz * (float)Math.cos(amount) - lookx * (float)Math.sin(amount); + // lookx^2 + lookz^2 != 1 for some reason. Fix. + lookx /= diff; + lookz /= diff; + do_repaint = true; + break; + case STRAFELEFT: + posx += lookz * amount; + posz -= lookx * amount; + break; + case UP: + posy += amount; + do_repaint = true; + break; + case LOOKUP: + looky += amount; + do_repaint = true; + break; + case LOOKSET: + looky = amount; + do_repaint = true; + break; + } + int x = (int)(posx / (comp * 1.0f)); + int z = (int)(posz / (comp * 1.0f)); + if(x > MAP) + posx = 0; + if(z > MAP) + posz = 0; + if(posx < 0) + posx = MAP * comp; + if(posz < 0) + posz = MAP * comp; + if (update) + { + gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); + glu.gluLookAt(posx, posy, posz, + posx+lookx, posy+looky, + posz+lookz, 0.0f,1.0f,0.0f); + if( do_repaint ) + repaint(); + } + } + + void draw_tree(int x, int z) + { + int x1, y1, z1; + y1 = (int)y[x][z]; + x1 = x * comp; + z1 = z * comp; + gl.glBegin(GL_POLYGON); + gl.glColor3f(0.6f,0.4f,0.0f); + gl.glVertex3f(x1 - 2,y1 + 5,z1); + gl.glVertex3f(x1 + 2,y1 + 5,z1); + gl.glVertex3f(x1 + 2,y1,z1); + gl.glVertex3f(x1 - 2,y1,z1); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glVertex3f(x1,y1 + 5,z1 - 2); + gl.glVertex3f(x1,y1 + 5,z1 + 2); + gl.glVertex3f(x1,y1,z1 + 2); + gl.glVertex3f(x1,y1,z1 - 2); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glColor3f(0.35f,0.7f,0.0f); + gl.glTexCoord2f(0.0f,0.0f); + gl.glVertex3f(x1 - 10,y1 + 5,z1); + gl.glTexCoord2f(0.5f,1.0f); + gl.glVertex3f(x1,y1 + 25,z1); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x1 + 10,y1 + 5,z1); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glColor3f(0.4f,0.8f,0.0f); + gl.glTexCoord2f(0.0f,0.0f); + gl.glVertex3f(x1,y1 + 5,z1 - 10); + gl.glTexCoord2f(0.5f,1.0f); + gl.glVertex3f(x1,y1 + 25,z1); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x1,y1 + 5,z1 + 10); + gl.glEnd(); + } + + void genLand() + { + int x, z, position_x, position_z; + float x1, x2, z1, z2; + + theLand = gl.glGenLists(1); + gl.glNewList(theLand, GL_COMPILE); + + position_x = (int)(posx / comp); + position_z = (int)(posz / comp); + for(x = position_x - 16;x < position_x + 17;x++) + for(z = position_z - 16;z < position_z + 17;z++) + { + if(x > 0 && x < MAP && z > 0 && z < MAP) + { + x1 = x * comp; + x2 = x * comp + comp; + z1 = z * comp; + z2 = z * comp + comp; + gl.glBegin(GL_POLYGON); + gl.glColor3f(c[x][z].r,c[x][z].g,c[x][z].b); + gl.glTexCoord2f(0.0f,0.0f); + gl.glVertex3f(x1,y[x][z],z1); + gl.glColor3f(c[x + 1][z].r,c[x + 1][z].g,c[x + 1][z].b); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x2,y[x + 1][z],z1); + gl.glColor3f(c[x][z + 1].r,c[x][z + 1].g,c[x][z + 1].b); + gl.glTexCoord2f(0.0f,1.0f); + gl.glVertex3f(x1,y[x][z + 1],z2); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glColor3f(c[x + 1][z + 1].r,c[x + 1][z + 1].g,c[x + 1][z + 1].b); + gl.glTexCoord2f(1.0f,1.0f); + gl.glVertex3f(x2,y[x + 1][z + 1],z2); + gl.glColor3f(c[x][z + 1].r,c[x][z + 1].g,c[x][z + 1].b); + gl.glTexCoord2f(0.0f,1.0f); + gl.glVertex3f(x1,y[x][z + 1],z2); + gl.glColor3f(c[x + 1][z].r,c[x + 1][z].g,c[x + 1][z].b); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x2,y[x + 1][z],z1); + gl.glEnd(); + if(object[x][z] == 't') + draw_tree(x,z); + } + } + gl.glEndList(); + glj.gljCheckGL(); + } + + public void reshape(int w, int h) + { + glj.gljResize(w,h); + gl.glViewport(0,0,w,h); + gl.glMatrixMode(GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(60.0,(double)w / (double)h,1.0,1000.0); + gl.glMatrixMode(GL_MODELVIEW); + gl.glLoadIdentity(); + glu.gluLookAt(posx,posy,posz,posx + lookx,posy + looky,posz + lookz,0.0,1.0,0.0); + } + + public float getMySpeed() + { + return mySpeed; + } + + public void setMySpeed(float s) + { + mySpeed = s; + setSuspended(false); + } + + public boolean getTextureState() + { + return texture_mapping == TRUE; + } + + public void setTexture(boolean t) + { + if(t) + { + if(texture_mapping == FALSE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glEnable(GL_TEXTURE_2D); + texture_mapping = TRUE; + glj.gljCheckGL(); + repaint(); + } + } + } + else + { + if(texture_mapping == TRUE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glDisable(GL_TEXTURE_2D); + texture_mapping = FALSE; + glj.gljCheckGL(); + repaint(); + } + } + } + setSuspended(false); + } + + public boolean getFogState() + { + return land_fogging == TRUE; + } + + public void setFog(boolean t) + { + if(t) + { + if(land_fogging == FALSE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glEnable(GL_FOG); + land_fogging = TRUE; + glj.gljCheckGL(); + repaint(); + } + } + } + else + { + if(land_fogging == TRUE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glDisable(GL_FOG); + land_fogging = FALSE; + glj.gljCheckGL(); + repaint(); + } + } + } + setSuspended(false); + } + + public boolean getFlatShadeState() + { + return flat_shading == TRUE; + } + + public void setFlatShading(boolean t) + { + if(t) + { + if(flat_shading == FALSE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glShadeModel(GL_FLAT); + flat_shading = TRUE; + glj.gljCheckGL(); + repaint(); + } + } + } + else + { + if(flat_shading == TRUE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glShadeModel(GL_SMOOTH); + flat_shading = FALSE; + glj.gljCheckGL(); + repaint(); + } + } + } + setSuspended(false); + } + + public void newFractal() + { + create_fractal(); + if(!cvsIsInit() || glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glFinish(); + gl.glDeleteLists(theLand, 1); + genLand(); + check_height(); + repaint(); + setSuspended(false); + } + +} + diff --git a/demos/GLLandScape/GLLandScape1Applet.java b/demos/GLLandScape/GLLandScape1Applet.java new file mode 100644 index 0000000..155f934 --- /dev/null +++ b/demos/GLLandScape/GLLandScape1Applet.java @@ -0,0 +1,399 @@ + +import gl4java.GLContext; +import java.awt.*; +import java.applet.*; +import java.awt.event.*; + +public class GLLandScape1Applet extends Applet + implements MouseListener, KeyListener, ActionListener +{ + GLLandScape1 landScape = null; + + Button bTexture = null; + Button bShading = null; + Button bFog = null; + Button bNewFractal = null; + Button bInfo = null; + + Button bFps; TextField tFps; + + boolean gameOn = true; + + SpeedTimer tMySpeed = null; + + public void init() + { + init(0,0); + } + + public void init(int w, int h) + { + super.init(); + + setLayout(new BorderLayout()); + + Panel glFeatures = new Panel(); + glFeatures.setLayout(new GridLayout(6,1)); + glFeatures.add(bTexture =new Button("Texture")); + glFeatures.add(bShading =new Button("Shading")); + glFeatures.add(bFog =new Button("Fogging")); + glFeatures.add(bNewFractal =new Button("Fractal")); + bTexture.addMouseListener(this); + bShading.addMouseListener(this); + bFog.addMouseListener(this); + bNewFractal.addMouseListener(this); + add("East", glFeatures); + + Panel pFps = new Panel(); + pFps.setLayout(new GridLayout(1,3)); + pFps.add(bInfo =new Button("info")); + pFps.add(bFps =new Button("get fps")); + pFps.add(tFps =new TextField()); + bInfo.addMouseListener(this); + bFps.addMouseListener(this); + tFps.addActionListener(this); + add("South", pFps); + + if(w==0 && h==0) + { + Dimension d = getSize(); + landScape= new GLLandScape1(d.width, d.height); + } else { + landScape= new GLLandScape1(w, h); + } + landScape.setAnimateFps(30.0); + landScape.addMouseListener(this); + landScape.addKeyListener(this); + + tMySpeed = new SpeedTimer(landScape, 200); + + landScape.requestFocus(); + landScape.setMySpeed(0); + + add("Center", landScape); + } + + public void destroy() + { + landScape.stop(); + landScape.cvsDispose(); + landScape.removeMouseListener(this); + landScape.removeKeyListener(this); + } + + public void start() + { + landScape.start(); + } + + public void stop() + { + landScape.stop(); + } + + public static void main( String args[] ) { + String gljLib=null; + String glLib=null; + String gluLib=null; + + if(args.length>0) + gljLib = args[0]; + if(args.length>1) + glLib = args[1]; + if(args.length>2) + gluLib = args[2]; + + if(GLContext.loadNativeLibraries(gljLib, glLib, gluLib)==false) + System.out.println("GLCanvasV2 could not load native libs:"+ + gljLib + ", " + glLib + ", " + gluLib); + + GLContext.gljNativeDebug = false; + GLContext.gljClassDebug = false; + + GLLandScape1Applet window = + new GLLandScape1Applet(); + + Frame f = new Frame(); + f.add(window); + window.init(500,300); + f.pack(); + f.setVisible(true); + + f.addWindowListener( new WindowAdapter() + { + public void windowClosed(WindowEvent e) + { + System.exit(0); + } + public void windowClosing(WindowEvent e) + { + System.exit(0); + } + } + ); + + + window.start(); + } + + // Methods required for the implementation of MouseListener + public void mouseEntered( MouseEvent evt ) + { + Component comp = evt.getComponent(); + if( comp.equals(landScape ) ) + { + landScape.requestFocus(); + } + } + + public void mouseExited( MouseEvent evt ) + { + } + + public void mousePressed( MouseEvent evt ) + { + } + public void mouseReleased( MouseEvent evt ) { + } + + public void mouseClicked( MouseEvent evt ) + { + Component comp = evt.getComponent(); + + if( comp.equals(bTexture ) ) + landScape.setTexture( ! landScape.getTextureState()); + else if( comp.equals(bNewFractal ) ) + landScape.newFractal(); + else if( comp.equals(bShading ) ) + landScape.setFlatShading(!landScape.getFlatShadeState()); + else if( comp.equals(bFog ) ) + landScape.setFog( ! landScape.getFogState()); + else if( comp.equals(landScape) ) + landScape.setSuspended(false); + else if( comp.equals(bFps) ) + { + double fps = 0; + + landScape.stopFpsCounter(); + fps=landScape.getFps(); + tFps.setText(String.valueOf(fps)); + landScape.resetFpsCounter(); + } + else if( comp.equals(bInfo) ) + { + InfoWin iw = new InfoWin(); + } + } + + + public void keyTyped(KeyEvent e) + { + } + + public void keyPressed(KeyEvent e) + { + int key = e.getKeyCode(); + + if( gameOn==true ) + { + if ( key==KeyEvent.VK_LEFT ) + { + landScape.myMove(landScape.TURNLEFT, 0.1f, true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_RIGHT ) + { + landScape.myMove(landScape.TURNLEFT, -0.1f, true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_UP ) + { + float v = tMySpeed.getSpeed(); + + if ( e.isShiftDown() ) + { + tMySpeed.setSpeed(v+2.0f); + } + else { + tMySpeed.setSpeed(v+1.0f); + } + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_DOWN ) + { + float v = tMySpeed.getSpeed(); + + if ( e.isShiftDown() ) + tMySpeed.setSpeed(v/2.0f); + else + tMySpeed.setSpeed(v-1.0f); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_PAGE_UP ) + { + landScape.myMove(landScape.LOOKUP, 0.1f, true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_PAGE_DOWN ) + { + landScape.myMove(landScape.LOOKUP, -0.1f, true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_END ) + { + landScape.myMove(landScape.LOOKSET, 0f, true); + tMySpeed.start(); + } + } + } + + public void keyReleased(KeyEvent e) + { + int key = e.getKeyCode(); + + if( gameOn==true && + ( key==KeyEvent.VK_UP || + key==KeyEvent.VK_DOWN + ) + ) + { + //ts.start(); + } + else if( gameOn==true && + ( key==KeyEvent.VK_LEFT || + key==KeyEvent.VK_RIGHT + ) + ) + { + //landScape.noMySpeed(); + } + } + + public void actionPerformed(ActionEvent event) + { + Object source = event.getSource(); + + if ( source == tFps ) + { + try { + double FramesPerSec= + Double.valueOf(tFps.getText()).doubleValue(); + landScape.setAnimateFps(FramesPerSec); + landScape.setSuspended(false); + } catch (NumberFormatException s) { + System.out.println("wrong fps format, use float .."); + } + + } + } + + class SpeedTimer implements Runnable { + protected Thread me = null; + protected boolean to=false, started=false; + protected int _t; + + protected float speed = 0.0f; + protected GLLandScape1 _ls; + + public SpeedTimer(GLLandScape1 ls, int t) + { _ls=ls; _t=t; } + + public void start() + { + if(me!=null) stop(); + to=false; + started=true; + + me = new Thread(this); + me.start(); + } + + public void stop() { + if(me!=null) + { + me.stop(); + me=null; + started=false; + to=false; + } + } + + public void run() { + if(me!=null) + { + try {me.sleep(_t,0);} catch (InterruptedException e){} + to=true; + while(speed>1.0f) + { + speed/=2.0f; + _ls.setMySpeed(speed); + try {me.sleep(_t,0);} catch (InterruptedException e){} + } + speed = 0.0f; + _ls.setMySpeed(0f); + } + } + + public boolean isActive() { return to; } + public boolean isStarted() { return started; } + + public float getSpeed() { return speed; } + public void setSpeed(float v) + { speed=v; + _ls.setMySpeed(speed); + } + + } + + class InfoWin extends Frame + implements ActionListener + { + protected Button DismissButton; + + String text = + "GLLandScape1 V 1.2\n"+ + "by Sven Goethel\n"+ + "\thttp://www.jausoft.com/gl4java.html\n"+ + "\tmailto:[email protected]\n\n"+ + "The original sources for the lanscape algorythms,\n"+ + "are taken from Nicholas Anderson's Landscape V1.0 !\n"+ + "\thttp://www.fortunecity.com/skyscraper/online/263\n"+ + "\tmailto:[email protected]\n\n"+ + "usage:\n"+ + "\t ARROW-UP : accelerate\n"+ + "\t ARROW-UP + SHIFT : accelerate fast \n"+ + "\t ARROW-DOWN : de-accelerate\n"+ + "\t ARROW-DOWN + SHIFT : de-accelerate fast\n"+ + "\t ARROW-LEFT : turn left\n"+ + "\t ARROW-right : turn right\n"+ + "\t PAGE-UP : look-up\n"+ + "\t PAGE-DOWN : look-down\n"+ + "\t END : look normal\n\n"+ + "Have a lot of fun - Sven Goethel\n"; + + public InfoWin() + { + setTitle("INFO"); + setName("INFO"); + + setLayout(new BorderLayout()); + add("Center", new TextArea(text, 25, 50)); + + add("South", DismissButton = new Button("dismiss")); + DismissButton.addActionListener(this); + + pack(); + setVisible(true); + + toFront(); + } + + public void actionPerformed(ActionEvent event) { + if ( event.getSource() == DismissButton) + { + setVisible(false); + dispose(); + } + } + } +} diff --git a/demos/GLLandScape/GLLandScape1_plugin13.html b/demos/GLLandScape/GLLandScape1_plugin13.html new file mode 100644 index 0000000..a3f188b --- /dev/null +++ b/demos/GLLandScape/GLLandScape1_plugin13.html @@ -0,0 +1,46 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<!--"CONVERTED_APPLET"-->
+<!-- CONVERTER VERSION 1.3 --> +<SCRIPT LANGUAGE="JavaScript"><!-- + var _info = navigator.userAgent; var _ns = false; + var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0); +//--></SCRIPT> +<COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!-- + var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0))); +//--></SCRIPT></COMMENT> + +<SCRIPT LANGUAGE="JavaScript"><!-- + if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 500 HEIGHT = 300 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"><NOEMBED><XMP>'); + else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.3" CODE = "GLLandScape1Applet.class" WIDTH = 500 HEIGHT = 300 frames = "55" scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED><XMP>'); +//--></SCRIPT> +<APPLET CODE = "GLLandScape1Applet.class" WIDTH = 500 HEIGHT = 300></XMP> +<PARAM NAME = CODE VALUE = "GLLandScape1Applet.class" >
+ +<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3"> +<PARAM NAME="scriptable" VALUE="false"> +<PARAM NAME = frames VALUE ="55">
+ +</APPLET> + +</NOEMBED></EMBED></OBJECT> + + +<!-- +<APPLET CODE = "GLLandScape1Applet.class" WIDTH = 500 HEIGHT = 300>
+<PARAM NAME = frames VALUE ="55">
+
+
+</APPLET> +--> +<!--"END_CONVERTED_APPLET"-->
+
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GLLandScape1w1-big.html b/demos/GLLandScape/GLLandScape1w1-big.html new file mode 100644 index 0000000..7e5eae0 --- /dev/null +++ b/demos/GLLandScape/GLLandScape1w1-big.html @@ -0,0 +1,14 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<applet code="GLLandScape1w1Applet.class" width=800 height=600>
+<param name=frames value="55">
+</applet>
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GLLandScape1w1-big_plugin13.html b/demos/GLLandScape/GLLandScape1w1-big_plugin13.html new file mode 100644 index 0000000..1dc35f8 --- /dev/null +++ b/demos/GLLandScape/GLLandScape1w1-big_plugin13.html @@ -0,0 +1,46 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<!--"CONVERTED_APPLET"-->
+<!-- CONVERTER VERSION 1.3 --> +<SCRIPT LANGUAGE="JavaScript"><!-- + var _info = navigator.userAgent; var _ns = false; + var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0); +//--></SCRIPT> +<COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!-- + var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0))); +//--></SCRIPT></COMMENT> + +<SCRIPT LANGUAGE="JavaScript"><!-- + if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 800 HEIGHT = 600 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"><NOEMBED><XMP>'); + else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.3" CODE = "GLLandScape1w1Applet.class" WIDTH = 800 HEIGHT = 600 frames = "55" scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED><XMP>'); +//--></SCRIPT> +<APPLET CODE = "GLLandScape1w1Applet.class" WIDTH = 800 HEIGHT = 600></XMP> +<PARAM NAME = CODE VALUE = "GLLandScape1w1Applet.class" >
+ +<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3"> +<PARAM NAME="scriptable" VALUE="false"> +<PARAM NAME = frames VALUE ="55">
+ +</APPLET> + +</NOEMBED></EMBED></OBJECT> + + +<!-- +<APPLET CODE = "GLLandScape1w1Applet.class" WIDTH = 800 HEIGHT = 600>
+<PARAM NAME = frames VALUE ="55">
+
+
+</APPLET> +--> +<!--"END_CONVERTED_APPLET"-->
+
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GLLandScape1w1.html b/demos/GLLandScape/GLLandScape1w1.html new file mode 100644 index 0000000..074a19e --- /dev/null +++ b/demos/GLLandScape/GLLandScape1w1.html @@ -0,0 +1,14 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<applet code="GLLandScape1w1Applet.class" width=500 height=300>
+<param name=frames value="55">
+</applet>
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GLLandScape1w1.java b/demos/GLLandScape/GLLandScape1w1.java new file mode 100644 index 0000000..9f6f1a3 --- /dev/null +++ b/demos/GLLandScape/GLLandScape1w1.java @@ -0,0 +1,781 @@ +/** + * @(#) GLLandScape1w1.java + */ +import gl4java.GLContext; +import gl4java.awt.GLAnimCanvas; +import java.awt.*; +import java.awt.event.*; +import java.lang.*; +import java.util.*; + +/** + * This is meant as an skellekton for porting/writing + * OpenGL to gl4java + * + * If you are interessting in further Documentation and/or + * the history of gl4java follow the following link. + * + * <pre> + <a href="gl4java.html#_top_">The gl4java Documentation</a> + * </pre> + * <p> + * + * This NEW dummy code uses repaint(), + * the std. java thread, and sleep to suspend with a given + * Frames per secounds value !! + * (of course - sDisplay is still avaiable, + * but i guess it is not that reliable ... comments welcome ) + * + * + * @see WinDataAccess + * @version 1.1, 3. MAI 1999 + * @author Sven Goethel + * + */ +class GLLandScape1w1 extends GLAnimCanvas +{ + /** + * Variables for the LandScape + */ + class COLOUR + { + public float r, g, b; + + public COLOUR() + { + r = 0.0f; + g = 0.0f; + b = 0.0f; + } + + } + + /* The constant MAP is used throughout the program and represents the MAP of + the matrix/landscape. */ + static final int MAP = 256; + + /* This is the holding space for the landscape. */ + float y[/*MAP+2*/][/*MAP+2*/]; + + char object[/*MAP+1*/][/*MAP+1*/]; + + /* This is the holding space for the landscape colours. */ + COLOUR c[/*MAP+1*/][/*MAP+1*/]; + + public static final int FORWARD = 1; + + public static final int UP = 2; + + public static final int TURNLEFT = 3; + + public static final int STRAFELEFT = 4; + + public static final int LOOKUP = 5; + + public static final int LOOKSET = 6; + + static final int TRUE = 1; + + static final int FALSE = 0; + + static final int WIDTH = 32; + + /* The width of the texture map. */ + byte texImg[/*WIDTH * WIDTH * 4*/]; + + int texName[/*1*/] = {0}; + + short comp = 32; + + /* Scale modifier. */ + short temp, texture_mapping = FALSE, land_fogging = TRUE, + flat_shading = FALSE; + + /* Initial eye position and vector of sight. */ + float posx, posy, posz; + + float lookx, looky, lookz; + + float mySpeed = 0; + + int myDir = FORWARD; + + // the display list for the land .. + int theLand; + + + final int MAX_PLANES = 15; + GlutPlaneObj planes[] = null; + Random random = null; + + + public GLLandScape1w1(int w, int h) + { + super(w,h); + } + + public void init_pos() + { + posx = 4500.0f; + posy = 256.0f; + posz = 4500.0f; + lookx = 4096.0f; + looky = 0.0f; + lookz = 4096.0f; + mySpeed = 0; + System.out.println("init_pos"); + } + + public void init() + { + int i, j; + /* here we should add and initialize our JAVA components */ + texImg = new byte[WIDTH * WIDTH * 4]; + y = new float[MAP + 2][MAP + 2]; + object = new char[MAP + 1][MAP + 1]; + c = new COLOUR[MAP + 1][MAP + 1]; + for(i = 0;i <= MAP;i++) + { + for(j = 0;j <= MAP;j++) + { + c[i][j] = new COLOUR(); + } + } + float fogColor[] = {0.75f, 0.75f, 1.0f, 1.0f}; + init_pos(); + // srand(224); + + create_fractal(); + genLand(); + + random = new Random(System.currentTimeMillis()); + planes = new GlutPlaneObj[MAX_PLANES]; + for (i = 0; i < MAX_PLANES; i++) + planes[i] = new GlutPlaneObj(gl, glu); + + // srand((unsigned)time(NULL)); + makeTexture(); + /* ... and furthet OpenGL init's - like you want to */ + gl.glPixelStorei(GL_UNPACK_ALIGNMENT,1); + if(texture_mapping == TRUE) + gl.glEnable(GL_TEXTURE_2D); + gl.glGenTextures(1,texName); + gl.glBindTexture(GL_TEXTURE_2D,texName[0]); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); + gl.glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + gl.glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,WIDTH,WIDTH,0,GL_RGBA,GL_UNSIGNED_BYTE,texImg); + gl.glEnable(GL_DEPTH_TEST); + if(flat_shading == FALSE) + gl.glShadeModel(GL_SMOOTH); + else + gl.glShadeModel(GL_FLAT); + if(land_fogging == TRUE) + gl.glEnable(GL_FOG); + else + gl.glDisable(GL_FOG); + gl.glFogi(GL_FOG_MODE,GL_LINEAR); + gl.glFogfv(GL_FOG_COLOR,fogColor); + gl.glFogf(GL_FOG_DENSITY,0.4f); + gl.glFogf(GL_FOG_START,800.0f); + gl.glFogf(GL_FOG_END,1000.0f); + gl.glClearColor(0.75f,0.75f,1.0f,1.0f); + // FreeConsole(); + glj.gljCheckGL(); + + + Dimension dim = getSize(); + reshape(dim.width,dim.height); + myMove(FORWARD,mySpeed,true,false); + check_height(); + repaint(); + /* and start our working thread ... */ + start(); + } + + public void display() + { + int i; + /* Standard gl4java Init */ + if(!cvsIsInit() || glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + // ... just render it + + gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + gl.glCallList(theLand); + + gl.glShadeModel(GL_FLAT); + for (i = 0; i < MAX_PLANES; i++) + { + planes[i].display(); + } + if(flat_shading == FALSE) + gl.glShadeModel(GL_SMOOTH); + + myMove(FORWARD,mySpeed,true,false); + check_height(); + + + /* For your animation dutys ;-) */ + glj.gljSwap(); + glj.gljCheckGL(); + glj.gljFree(); + } + + public void addPlane() + { + for (int i = 0; i < MAX_PLANES; i++) + { + if (planes[i].speed == 0.0f) + { + int c = random.nextInt() & 0x07; + while (c == 0) c = random.nextInt() & 0x07; + float r = (float)((c >> 2) & 0x01); + float g = (float)((c >> 1) & 0x01); + float b = (float)(c & 0x01); + // Blue fades into the background; lighten it up. + if (c == 0x01) r = g = 0.4f; + planes[i].setColor(r,g,b); + planes[i].speed = + ((float)(random.nextInt() % 20)) * 0.001f + 0.02f; + if ((random.nextInt() & 0x01) != 0) + planes[i].speed *= -1.0f; + planes[i].theta = + ((float)(random.nextInt() % 257))*0.1111f; + planes[i].tick(); + if (isSuspended()) repaint(); + System.out.println("plane added"); + return; + } + } + } + + public void removePlane() + { + for (int i = MAX_PLANES - 1; i >= 0; i--) + { + if (planes[i].speed != 0.0f) + { + planes[i].speed = 0.0f; + if (isSuspended()) repaint(); + System.out.println("plane removed"); + return; + } + } + } + + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + /*************************************************************/ + void create_fractal() + { + int bsize, csize; + int x, z, i; + int r = 256; + /* The maximum random value. */ + float gradient, shadow = 0.5f, n; + /* Make the matrix flat. */ + for(x = 0;x < MAP + 2;x++) + for(z = 0;z < MAP + 2;z++) + y[x][z] = 0L; + bsize = MAP; + for(i = 0;i < 8;i++) + { + for(x = 0;x < MAP;x += bsize) + for(z = 0;z < MAP;z += bsize) + y[x][z] += (Math.random() * r - r / 2); + if(i > 4) + r = r / 2; + csize = bsize / 2; + if(csize > 0) + { + for(x = 0;x < MAP;x += bsize) + for(z = 0;z < MAP;z += bsize) + { + if(x < MAP) + y[x + csize][z] = (y[x + bsize][z] + y[x][z]) / 2; + if(z < MAP) + y[x][z + csize] = (y[x][z + bsize] + y[x][z]) / 2; + if(x < MAP && z < MAP) + y[x + csize][z + csize] = (y[x][z] + y[x + bsize][z] + y[x][z + bsize] + y[x + bsize][z + bsize]) / 4; + } + } + bsize = csize; + } + for(x = 0;x < MAP;x++) + { + for(z = 0;z < MAP;z++) + { + y[x][z] = y[x][z] + y[x + 1][z] + y[x + 1][z + 1] + y[x][z + 1]; + y[x][z] /= 4.0f; + } + } + for(x = MAP;x > 0;x--) + { + for(z = 0;z < MAP;z++) + { + y[x][z] = y[x][z] + y[x - 1][z] + y[x - 1][z + 1] + y[x][z + 1]; + y[x][z] /= 4.0f; + } + } + /* put trees in various places on grassland. */ + for(x = 0;x < MAP;x++) + { + for(z = 0;z < MAP;z++) + { + if(((int)(Math.random() * 256.0f)) % 8 == 0 && y[x][z] > 0 && y[x][z] < 64) + { + object[x][z] = 't'; + } + else + { + object[x][z] = 'n'; + } + } + } + for(x = 0;x < MAP;x++) + for(z = 0;z < MAP;z++) + if(y[x][z] > 8) + { + n = y[x][z]; + y[x][z] *= n; + y[x][z] /= 256.0f; + } + for(x = 0;x <= MAP;x++) + { + for(z = 0;z <= MAP;z++) + { + gradient = ((float)(y[x][z] - y[x + 1][z])) / 100.0f; + if(y[x][z] > 64) + { + if((y[x][z] - y[x][z + 1]) < 8 && (y[x][z] - y[x][z + 1]) > -8 && (y[x][z] - y[x + 1][z]) < 8 && (y[x][z] - y[x + 1][z]) > -8) + { + c[x][z].g = gradient + 0.75f; + c[x][z].r = c[x][z].g; + c[x][z].b = c[x][z].g; + } + else + { + c[x][z].r = gradient + 0.75f; + c[x][z].g = c[x][z].r * 0.8f; + c[x][z].b = c[x][z].r * 0.5f; + } + } + else + if(y[x][z] > 0) + { + c[x][z].g = gradient + 0.75f; + c[x][z].r = c[x][z].g * 0.6f; + c[x][z].b = 0.0f; + } + else + { + c[x][z].r = gradient + 1.0f; + c[x][z].g = c[x][z].r * 0.75f; + c[x][z].b = c[x][z].r * 0.5f; + } + } + } + for(x = 0;x <= MAP;x++) + for(z = 0;z <= MAP;z++) + { + if(y[x][z] < 0) + y[x][z] /= 4.0f; + } + + } + + void makeTexture() + { + int i, j, h, c; + for(i = 0;i < WIDTH;i++) + { + for(j = 0;j < WIDTH;j++) + { + c = (int)(Math.random() * 15 + 240); + h = i * WIDTH * 4 + j * 4; + texImg[h + 0] = (byte)c; + texImg[h + 1] = (byte)c; + texImg[h + 2] = (byte)c; + texImg[h + 3] = (byte)255; + } + } + } + + void check_height() + { + float x0, x1, lx, lz, x, z, midpoint; + int fx, fz; + x = (posx / (comp * 1.0f)); + z = (posz / (comp * 1.0f)); + fx = (int)(x); + fz = (int)(z); + lx = x - fx; + lz = z - fz; + if(fx >= MAP + 2 || fz >= MAP + 2 || fx < 0 || fz < 0) + { + init_pos(); + return; + } + x0 = y[fx][fz] + (y[fx][fz + 1] - y[fx][fz]) * lz; + x1 = y[fx + 1][fz] + (y[fx + 1][fz + 1] - y[fx + 1][fz]) * lz; + midpoint = x0 + (x1 - x0) * lx; + posy = midpoint + 16.0f; + } + + /* Function that moves the eye / turns the angle of sight. */ + /* Updates scene if update. */ + void myMove(int dir, float amount, boolean update, boolean fetchGLContext) + { + float diff = (float)Math.sqrt(lookx * lookx + lookz * lookz); + /* + float alpha = (float) + Math.atan(Math.abs(lookz)/Math.abs(lookx)); + if(lookx<0&&lookz>=0) + alpha+=(float)(Math.PI/2.0); + else if(lookx>=0&&lookz>=0) + alpha+=0; + else if(lookx<0&&lookz<0) + alpha+=(float)Math.PI; + else if(lookx>=0&&lookz<0) + alpha+=(float)((3.0*Math.PI)/2.0); + float _alpha = (float) (alpha*180f/Math.PI ); + */ + boolean do_repaint = false; + lookx /= diff; + lookz /= diff; + //myDir=dir; + switch(dir) + { + case FORWARD: + posx += lookx * amount; + posz += lookz * amount; + break; + case TURNLEFT: + lookx = lookx * (float)Math.cos(amount) + lookz * (float)Math.sin(amount); + lookz = lookz * (float)Math.cos(amount) - lookx * (float)Math.sin(amount); + // lookx^2 + lookz^2 != 1 for some reason. Fix. + lookx /= diff; + lookz /= diff; + do_repaint = true; + break; + case STRAFELEFT: + posx += lookz * amount; + posz -= lookx * amount; + break; + case UP: + posy += amount; + do_repaint = true; + break; + case LOOKUP: + looky += amount; + do_repaint = true; + break; + case LOOKSET: + looky = amount; + do_repaint = true; + break; + } + int x = (int)(posx / (comp * 1.0f)); + int z = (int)(posz / (comp * 1.0f)); + if(x > MAP) + posx = 0; + if(z > MAP) + posz = 0; + if(posx < 0) + posx = MAP * comp; + if(posz < 0) + posz = MAP * comp; + if (update) + { + if(fetchGLContext && glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); + glu.gluLookAt(posx,posy,posz, + posx+lookx, posy+looky, + posz+lookz, 0.0f,1.0f,0.0f); + + if(fetchGLContext) + glj.gljFree(); + + if( do_repaint ) + repaint(); + } + } + + void draw_tree(int x, int z) + { + int x1, y1, z1; + y1 = (int)y[x][z]; + x1 = x * comp; + z1 = z * comp; + gl.glBegin(GL_POLYGON); + gl.glColor3f(0.6f,0.4f,0.0f); + gl.glVertex3f(x1 - 2,y1 + 5,z1); + gl.glVertex3f(x1 + 2,y1 + 5,z1); + gl.glVertex3f(x1 + 2,y1,z1); + gl.glVertex3f(x1 - 2,y1,z1); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glVertex3f(x1,y1 + 5,z1 - 2); + gl.glVertex3f(x1,y1 + 5,z1 + 2); + gl.glVertex3f(x1,y1,z1 + 2); + gl.glVertex3f(x1,y1,z1 - 2); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glColor3f(0.35f,0.7f,0.0f); + gl.glTexCoord2f(0.0f,0.0f); + gl.glVertex3f(x1 - 10,y1 + 5,z1); + gl.glTexCoord2f(0.5f,1.0f); + gl.glVertex3f(x1,y1 + 25,z1); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x1 + 10,y1 + 5,z1); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glColor3f(0.4f,0.8f,0.0f); + gl.glTexCoord2f(0.0f,0.0f); + gl.glVertex3f(x1,y1 + 5,z1 - 10); + gl.glTexCoord2f(0.5f,1.0f); + gl.glVertex3f(x1,y1 + 25,z1); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x1,y1 + 5,z1 + 10); + gl.glEnd(); + } + + void genLand() + { + int x, z, position_x, position_z; + float x1, x2, z1, z2; + + theLand = gl.glGenLists(1); + gl.glNewList(theLand, GL_COMPILE); + + position_x = (int)(posx / comp); + position_z = (int)(posz / comp); + for(x = position_x - 16;x < position_x + 17;x++) + for(z = position_z - 16;z < position_z + 17;z++) + { + if(x > 0 && x < MAP && z > 0 && z < MAP) + { + x1 = x * comp; + x2 = x * comp + comp; + z1 = z * comp; + z2 = z * comp + comp; + gl.glBegin(GL_POLYGON); + gl.glColor3f(c[x][z].r,c[x][z].g,c[x][z].b); + gl.glTexCoord2f(0.0f,0.0f); + gl.glVertex3f(x1,y[x][z],z1); + gl.glColor3f(c[x + 1][z].r,c[x + 1][z].g,c[x + 1][z].b); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x2,y[x + 1][z],z1); + gl.glColor3f(c[x][z + 1].r,c[x][z + 1].g,c[x][z + 1].b); + gl.glTexCoord2f(0.0f,1.0f); + gl.glVertex3f(x1,y[x][z + 1],z2); + gl.glEnd(); + gl.glBegin(GL_POLYGON); + gl.glColor3f(c[x + 1][z + 1].r,c[x + 1][z + 1].g,c[x + 1][z + 1].b); + gl.glTexCoord2f(1.0f,1.0f); + gl.glVertex3f(x2,y[x + 1][z + 1],z2); + gl.glColor3f(c[x][z + 1].r,c[x][z + 1].g,c[x][z + 1].b); + gl.glTexCoord2f(0.0f,1.0f); + gl.glVertex3f(x1,y[x][z + 1],z2); + gl.glColor3f(c[x + 1][z].r,c[x + 1][z].g,c[x + 1][z].b); + gl.glTexCoord2f(1.0f,0.0f); + gl.glVertex3f(x2,y[x + 1][z],z1); + gl.glEnd(); + if(object[x][z] == 't') + draw_tree(x,z); + } + } + gl.glEndList(); + glj.gljCheckGL(); + } + + public void reshape(int w, int h) + { + glj.gljResize(w,h); + gl.glViewport(0,0,w,h); + gl.glMatrixMode(GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluPerspective(60.0,(double)w / (double)h,1.0,1000.0); + gl.glMatrixMode(GL_MODELVIEW); + gl.glLoadIdentity(); + glu.gluLookAt(posx,posy,posz,posx + lookx,posy + looky,posz + lookz,0.0,1.0,0.0); + } + + public float getMySpeed() + { + return mySpeed; + } + + public void setMySpeed(float s) + { + mySpeed = s; + } + + public boolean getTextureState() + { + return texture_mapping == TRUE; + } + + public void setTexture(boolean t) + { + if(t) + { + if(texture_mapping == FALSE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glEnable(GL_TEXTURE_2D); + texture_mapping = TRUE; + glj.gljCheckGL(); + repaint(); + } + } + } + else + { + if(texture_mapping == TRUE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glDisable(GL_TEXTURE_2D); + texture_mapping = FALSE; + glj.gljCheckGL(); + repaint(); + } + } + } + setSuspended(false); + } + + public boolean getFogState() + { + return land_fogging == TRUE; + } + + public void setFog(boolean t) + { + if(t) + { + if(land_fogging == FALSE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glEnable(GL_FOG); + land_fogging = TRUE; + glj.gljCheckGL(); + repaint(); + } + } + } + else + { + if(land_fogging == TRUE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glDisable(GL_FOG); + land_fogging = FALSE; + glj.gljCheckGL(); + repaint(); + } + } + } + setSuspended(false); + } + + public boolean getFlatShadeState() + { + return flat_shading == TRUE; + } + + public void setFlatShading(boolean t) + { + if(t) + { + if(flat_shading == FALSE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glShadeModel(GL_FLAT); + flat_shading = TRUE; + glj.gljCheckGL(); + repaint(); + } + } + } + else + { + if(flat_shading == TRUE) + { + if(glj!=null) + { + if(glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glShadeModel(GL_SMOOTH); + flat_shading = FALSE; + glj.gljCheckGL(); + repaint(); + } + } + } + setSuspended(false); + } + + public void newFractal() + { + create_fractal(); + if(!cvsIsInit() || glj.gljMakeCurrent() == false) + { + System.out.println("problem in use() method"); + return; + } + gl.glFinish(); + gl.glDeleteLists(theLand, 1); + genLand(); + check_height(); + repaint(); + setSuspended(false); + } + +} + diff --git a/demos/GLLandScape/GLLandScape1w1Applet$SpeedTimer b/demos/GLLandScape/GLLandScape1w1Applet$SpeedTimer Binary files differnew file mode 100644 index 0000000..81e347a --- /dev/null +++ b/demos/GLLandScape/GLLandScape1w1Applet$SpeedTimer diff --git a/demos/GLLandScape/GLLandScape1w1Applet.java b/demos/GLLandScape/GLLandScape1w1Applet.java new file mode 100755 index 0000000..90da5f3 --- /dev/null +++ b/demos/GLLandScape/GLLandScape1w1Applet.java @@ -0,0 +1,416 @@ + +import gl4java.GLContext; +import java.awt.*; +import java.applet.*; +import java.awt.event.*; + +public class GLLandScape1w1Applet extends Applet + implements MouseListener, KeyListener, ActionListener +{ + GLLandScape1w1 landScape = null; + + Button bAddPlane = null; + Button bRemPlane = null; + Button bTexture = null; + Button bShading = null; + Button bFog = null; + Button bNewFractal = null; + Button bInfo = null; + + Button bFps; TextField tFps; + + boolean gameOn = true; + + SpeedTimer tMySpeed = null; + + public void init() + { + init(0,0); + } + + public void init(int w, int h) + { + super.init(); + + setLayout(new BorderLayout()); + + Panel glFeatures = new Panel(); + glFeatures.setLayout(new GridLayout(6,1)); + glFeatures.add(bAddPlane =new Button("+ Plane")); + glFeatures.add(bRemPlane =new Button("- Plane")); + glFeatures.add(bTexture =new Button("Texture")); + glFeatures.add(bShading =new Button("Shading")); + glFeatures.add(bFog =new Button("Fogging")); + glFeatures.add(bNewFractal =new Button("Fractal")); + bAddPlane.addMouseListener(this); + bRemPlane.addMouseListener(this); + bTexture.addMouseListener(this); + bShading.addMouseListener(this); + bFog.addMouseListener(this); + bNewFractal.addMouseListener(this); + add("East", glFeatures); + + Panel pFps = new Panel(); + pFps.setLayout(new GridLayout(1,3)); + pFps.add(bInfo =new Button("info")); + pFps.add(bFps =new Button("get fps")); + pFps.add(tFps =new TextField()); + bInfo.addMouseListener(this); + bFps.addMouseListener(this); + tFps.addActionListener(this); + add("South", pFps); + + if(w==0 && h==0) + { + Dimension d = getSize(); + landScape= new GLLandScape1w1(d.width, d.height); + } else { + landScape= new GLLandScape1w1(w, h); + } + landScape.setAnimateFps(30.0); + landScape.addMouseListener(this); + landScape.addKeyListener(this); + + tMySpeed = new SpeedTimer(landScape, 200); + + landScape.requestFocus(); + landScape.setMySpeed(0); + + add("Center", landScape); + } + + public void destroy() + { + landScape.stop(); + landScape.cvsDispose(); + landScape.removeMouseListener(this); + landScape.removeKeyListener(this); + } + + public void start() + { + landScape.start(); + } + + public void stop() + { + landScape.stop(); + } + + public static void main( String args[] ) { + String gljLib=null; + String glLib=null; + String gluLib=null; + + if(args.length>0) + gljLib = args[0]; + if(args.length>1) + glLib = args[1]; + if(args.length>2) + gluLib = args[2]; + + if(GLContext.loadNativeLibraries(gljLib, glLib, gluLib)==false) + System.out.println("GLCanvasV2 could not load native libs:"+ + gljLib + ", " + glLib + ", " + gluLib); + + GLContext.gljNativeDebug = false; + GLContext.gljClassDebug = false; + + GLLandScape1w1Applet window = + new GLLandScape1w1Applet(); + + Frame f = new Frame(); + + f.addWindowListener( new WindowAdapter() + { + public void windowClosed(WindowEvent e) + { + System.exit(0); + } + public void windowClosing(WindowEvent e) + { + windowClosed(e); + } + } + ); + + f.setLayout(new BorderLayout()); + f.add("Center", window); + window.init(500,300); + window.start(); + Dimension ps = window.getPreferredSize(); + f.setBounds(-100,-100,99,99); + f.setVisible(true); + f.setVisible(false); + Insets i = f.getInsets(); + f.setBounds(0,0, + ps.width+i.left+i.right, + ps.height+i.top+i.bottom); + f.setVisible(true); + } + + // Methods required for the implementation of MouseListener + public void mouseEntered( MouseEvent evt ) + { + Component comp = evt.getComponent(); + if( comp.equals(landScape ) ) + { + landScape.requestFocus(); + } + } + + public void mouseExited( MouseEvent evt ) + { + } + + public void mousePressed( MouseEvent evt ) + { + } + public void mouseReleased( MouseEvent evt ) { + } + + public void mouseClicked( MouseEvent evt ) + { + Component comp = evt.getComponent(); + + if( comp.equals(bAddPlane ) ) + landScape.addPlane(); + else if( comp.equals(bRemPlane ) ) + landScape.removePlane(); + else if( comp.equals(bTexture ) ) + landScape.setTexture( ! landScape.getTextureState()); + else if( comp.equals(bNewFractal ) ) + landScape.newFractal(); + else if( comp.equals(bShading ) ) + landScape.setFlatShading(!landScape.getFlatShadeState()); + else if( comp.equals(bFog ) ) + landScape.setFog( ! landScape.getFogState()); + else if( comp.equals(landScape) ) + landScape.setSuspended(false); + else if( comp.equals(bFps) ) + { + double fps = 0; + + landScape.stopFpsCounter(); + fps=landScape.getFps(); + tFps.setText(String.valueOf(fps)); + landScape.resetFpsCounter(); + } + else if( comp.equals(bInfo) ) + { + InfoWin iw = new InfoWin(); + } + } + + + public void keyTyped(KeyEvent e) + { + } + + public void keyPressed(KeyEvent e) + { + int key = e.getKeyCode(); + + if( gameOn==true ) + { + if ( key==KeyEvent.VK_LEFT ) + { + landScape.myMove(landScape.TURNLEFT, 0.1f, true, true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_RIGHT ) + { + landScape.myMove(landScape.TURNLEFT, -0.1f, true, true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_UP ) + { + float v = tMySpeed.getSpeed(); + + if ( e.isShiftDown() ) + { + tMySpeed.setSpeed(v+2.0f); + } + else { + tMySpeed.setSpeed(v+1.0f); + } + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_DOWN ) + { + float v = tMySpeed.getSpeed(); + + if ( e.isShiftDown() ) + tMySpeed.setSpeed(v/2.0f); + else + tMySpeed.setSpeed(v-1.0f); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_PAGE_UP ) + { + landScape.myMove(landScape.LOOKUP, 0.1f, true,true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_PAGE_DOWN ) + { + landScape.myMove(landScape.LOOKUP, -0.1f, true,true); + tMySpeed.start(); + } + else if ( key==KeyEvent.VK_END ) + { + landScape.myMove(landScape.LOOKSET, 0f, true,true); + tMySpeed.start(); + } + } + } + + public void keyReleased(KeyEvent e) + { + int key = e.getKeyCode(); + + if( gameOn==true && + ( key==KeyEvent.VK_UP || + key==KeyEvent.VK_DOWN + ) + ) + { + //ts.start(); + } + else if( gameOn==true && + ( key==KeyEvent.VK_LEFT || + key==KeyEvent.VK_RIGHT + ) + ) + { + //landScape.noMySpeed(); + } + } + + public void actionPerformed(ActionEvent event) + { + Object source = event.getSource(); + + if ( source == tFps ) + { + try { + double FramesPerSec= + Double.valueOf(tFps.getText()).doubleValue(); + landScape.setAnimateFps(FramesPerSec); + landScape.setSuspended(false); + } catch (NumberFormatException s) { + System.out.println("wrong fps format, use float .."); + } + + } + } + + class SpeedTimer implements Runnable { + protected Thread me = null; + protected boolean to=false, started=false; + protected int _t; + + protected float speed = 0.0f; + protected GLLandScape1w1 _ls; + + public SpeedTimer(GLLandScape1w1 ls, int t) + { _ls=ls; _t=t; } + + public void start() + { + if(me!=null) stop(); + to=false; + started=true; + + me = new Thread(this); + me.start(); + } + + public void stop() { + if(me!=null) + { + me.stop(); + me=null; + started=false; + to=false; + } + } + + public void run() { + if(me!=null) + { + try {me.sleep(_t,0);} catch (InterruptedException e){} + to=true; + while(speed>1.0f) + { + speed/=2.0f; + _ls.setMySpeed(speed); + try {me.sleep(_t,0);} catch (InterruptedException e){} + } + speed = 0.0f; + _ls.setMySpeed(0f); + } + } + + public boolean isActive() { return to; } + public boolean isStarted() { return started; } + + public float getSpeed() { return speed; } + public void setSpeed(float v) + { speed=v; + _ls.setMySpeed(speed); + } + + } + + class InfoWin extends Frame + implements ActionListener + { + protected Button DismissButton; + + String text = + "GLLandScape1w1 V 1.0\n"+ + "by Sven Goethel\n"+ + "\thttp://www.jausoft.com/gl4java.html\n"+ + "\tmailto:[email protected]\n\n"+ + "The original sources for the lanscape algorythms,\n"+ + "are taken from Nicholas Anderson's Landscape V1.0 !\n"+ + "\thttp://www.fortunecity.com/skyscraper/online/263\n"+ + "\tmailto:[email protected]\n\n"+ + "usage:\n"+ + "\t ARROW-UP : accelerate\n"+ + "\t ARROW-UP + SHIFT : accelerate fast \n"+ + "\t ARROW-DOWN : de-accelerate\n"+ + "\t ARROW-DOWN + SHIFT : de-accelerate fast\n"+ + "\t ARROW-LEFT : turn left\n"+ + "\t ARROW-right : turn right\n"+ + "\t PAGE-UP : look-up\n"+ + "\t PAGE-DOWN : look-down\n"+ + "\t END : look normal\n\n"+ + "Have a lot of fun - Sven Goethel\n"; + + public InfoWin() + { + setTitle("INFO"); + setName("INFO"); + + setLayout(new BorderLayout()); + add("Center", new TextArea(text, 25, 50)); + + add("South", DismissButton = new Button("dismiss")); + DismissButton.addActionListener(this); + + pack(); + setVisible(true); + + toFront(); + } + + public void actionPerformed(ActionEvent event) { + if ( event.getSource() == DismissButton) + { + setVisible(false); + dispose(); + } + } + } +} diff --git a/demos/GLLandScape/GLLandScape1w1_plugin13.html b/demos/GLLandScape/GLLandScape1w1_plugin13.html new file mode 100644 index 0000000..32ab0bf --- /dev/null +++ b/demos/GLLandScape/GLLandScape1w1_plugin13.html @@ -0,0 +1,46 @@ +<HTML>
+<HEAD>
+<TITLE>Göthel Hard- und Software Entwicklungen</TITLE>
+</HEAD>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<hr>
+<!--"CONVERTED_APPLET"-->
+<!-- CONVERTER VERSION 1.3 --> +<SCRIPT LANGUAGE="JavaScript"><!-- + var _info = navigator.userAgent; var _ns = false; + var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0); +//--></SCRIPT> +<COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!-- + var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0))); +//--></SCRIPT></COMMENT> + +<SCRIPT LANGUAGE="JavaScript"><!-- + if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 500 HEIGHT = 300 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"><NOEMBED><XMP>'); + else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.3" CODE = "GLLandScape1w1Applet.class" WIDTH = 500 HEIGHT = 300 frames = "55" scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html"><NOEMBED><XMP>'); +//--></SCRIPT> +<APPLET CODE = "GLLandScape1w1Applet.class" WIDTH = 500 HEIGHT = 300></XMP> +<PARAM NAME = CODE VALUE = "GLLandScape1w1Applet.class" >
+ +<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3"> +<PARAM NAME="scriptable" VALUE="false"> +<PARAM NAME = frames VALUE ="55">
+ +</APPLET> + +</NOEMBED></EMBED></OBJECT> + + +<!-- +<APPLET CODE = "GLLandScape1w1Applet.class" WIDTH = 500 HEIGHT = 300>
+<PARAM NAME = frames VALUE ="55">
+
+
+</APPLET> +--> +<!--"END_CONVERTED_APPLET"-->
+
+<hr>
+</BODY>
+</HTML>
+
+
diff --git a/demos/GLLandScape/GlutPlaneObj.java b/demos/GLLandScape/GlutPlaneObj.java new file mode 100644 index 0000000..3b449a7 --- /dev/null +++ b/demos/GLLandScape/GlutPlaneObj.java @@ -0,0 +1,112 @@ +/**
+ * @(#) glutplane.java
+ * @(#) author: Mark J. Kilgard (converted to Java by Ron Cemer)
+ */
+
+/* This program is freely distributable without licensing fees
+ and is provided without guarantee or warrantee expressed or
+ implied. This program is -not- in the public domain. */
+
+import java.applet.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.*;
+import java.util.*;
+import java.io.*;
+import java.util.*;
+import gl4java.GLContext;
+import gl4java.GLFunc;
+import gl4java.GLUFunc;
+import gl4java.GLEnum;
+import gl4java.GLUEnum;
+import gl4java.awt.GLAnimCanvas;
+import gl4java.applet.SimpleGLAnimApplet1;
+
+public class GlutPlaneObj
+ implements GLEnum, GLUEnum
+{
+ float speed = 0.0f; /* zero speed means not flying */
+ float red = 0.0f, green = 0.0f, blue = 0.0f;
+ float theta = 0.0f;
+ public float x = 0.0f, y = 0.0f, z = 0.0f, angle = 0.0f;
+
+ public void setPosition(float x, float y, float z)
+ {
+ this.x=x;
+ this.y=y;
+ this.z=z;
+ }
+
+
+ public void setColor(float r, float g, float b)
+ {
+ red = r;
+ green = g;
+ blue = b;
+ }
+
+
+ private final double M_PI = 3.14159265;
+ private final double M_PI_2 = 1.57079632;
+
+ GLFunc gl;
+ GLUFunc glu;
+
+ public GlutPlaneObj(GLFunc gl, GLUFunc glu)
+ {
+ this.gl=gl;
+ this.glu=glu;
+ }
+
+ public void display()
+ {
+
+ if (speed != 0.0f)
+ {
+ tick();
+ // System.out.println("plane: ("+x+"/"+y+"/"+z+")");
+ gl.glPushMatrix();
+ gl.glTranslatef(x, y, z);
+ gl.glRotatef(290.0f, 1.0f, 0.0f, 0.0f);
+ gl.glRotatef(angle, 0.0f, 0.0f, 1.0f);
+ // gl.glScalef(1.0f / 3.0f, 1.0f / 4.0f, 1.0f / 4.0f);
+ gl.glScalef(5.0f, 5.0f, 5.0f);
+ gl.glTranslatef(0.0f, -4.0f, -1.5f);
+ gl.glBegin(GL_TRIANGLE_STRIP);
+ /* left wing */
+ gl.glVertex3f(-7.0f, 0.0f, 2.0f);
+ gl.glVertex3f(-1.0f, 0.0f, 3.0f);
+ gl.glColor3f(red,green,blue);
+ gl.glVertex3f(-1.0f, 7.0f, 3.0f);
+ /* left side */
+ gl.glColor3f(0.6f * red, 0.6f * green, 0.6f * blue);
+ gl.glVertex3f(0.0f, 0.0f, 0.0f);
+ gl.glVertex3f(0.0f, 8.0f, 0.0f);
+ /* right side */
+ gl.glVertex3f(1.0f, 0.0f, 3.0f);
+ gl.glVertex3f(1.0f, 7.0f, 3.0f);
+ /* final tip of right wing */
+ gl.glColor3f(red, green, blue);
+ gl.glVertex3f(7.0f, 0.0f, 2.0f);
+ gl.glEnd();
+ gl.glPopMatrix();
+ }
+ }
+
+ public void tick()
+ {
+ /*
+ posx = 4500.0f;
+ posy = 256.0f;
+ posz = 4500.0f;
+ */
+ theta += speed;
+ z = 4500.0f + 600.0f * (float)Math.cos(theta);
+ x = 4500.0f + 600.0f * (float)Math.sin(2.0f * theta);
+ y = 280.0f + (float)Math.sin(theta / 3.4f) * 20.0f;
+ angle = (float)
+ (((Math.atan(2.0) + M_PI_2) * Math.sin(theta) - M_PI_2) *
+ 180.0 / M_PI);
+ if (speed < 0.0f) angle += 180.0f;
+ }
+}
diff --git a/demos/GLLandScape/LICENSE.txt b/demos/GLLandScape/LICENSE.txt new file mode 100644 index 0000000..9611410 --- /dev/null +++ b/demos/GLLandScape/LICENSE.txt @@ -0,0 +1,36 @@ +GLLandScape - A landscape generator, where you can walk through - uses GL4Java + +Copyright (C) 1999 Sven Goethel + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this library; if not, write to the +Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. + +You can also check the GNU Library General Public License +in the internet at http://www.gnu.org/copyleft/lgpl.html ! + +If you like to contact the author use: + +Sven Goethel, Elpke 5, 33605 Bielefeld, Germany +email: [email protected] +web : http://www.jausoft.com +voice: +49-521-2399440 +fax : +49-521-2399442 + +The landscape algorythms are taken from Nicholas Anderson's Landscape V1.0 ! + http://www.fortunecity.com/skyscraper/online/263 + mailto:[email protected] +Those parts are still under the Copyright (C) of Nicholas Anderson ! + +Sven Goethel, 15 January 1999 diff --git a/demos/GLLandScape/index.html b/demos/GLLandScape/index.html new file mode 100644 index 0000000..2efada2 --- /dev/null +++ b/demos/GLLandScape/index.html @@ -0,0 +1,52 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="Author" content="Ron Cemer & Sven Goethel">
+ <meta name="GENERATOR" content="Mozilla/4.61 [en] (Win98; U) [Netscape]">
+ <title>GL4Java Landscape World</title>
+</head>
+<BODY LINK="#0000ff" VLINK="#800080" BGCOLOR="#e6e6ff">
+<p>The GLLandScape World</p><BR>
+Paperplanes are flying arround a landscape !<br>
+<I>Thanxs to </I>
+<A HREF="http://pages.eidosnet.co.uk/~n.anderson/index.html">
+<I>Nicholas Anderson</I></A>
+<I> for ANSI-C sources of Landscape V1.0</I>
+<br>
+<br>
+Use the keybord's cursor keys to move arround.<br>
+The page up and down keys are used to look up and down.<br>
+This all is done to move like in Quake.<br>
+<br>
+<p> <a href="GLLandScape1.html">GLLandScape</a>
+: a LandScape V1 at 500x300
+<p> <a href="GLLandScape1-big.html">GLLandScape BIG</a>
+: a LandScape V1 at 800x600
+<p> <a href="GLLandScape1w1.html">GLLandScape-World</a>
+: a LandScape World V1 at 500x300
+<p> <a href="GLLandScape1w1-big.html">GLLandScape-World BIG</a>
+: a LandScape World V1 at 800x600
+<br>
+<br>
+<hr>
+<P ALIGN=CENTER><SPAN STYLE="text-decoration: none"><I>For use with
+the Java2-Plug-In: Tested with Win32,Netscape,Java2 <A HREF="Java2.txt">(see
+Installation-instructions Java2)</A> ! </I></SPAN><br>
+<br>
+<a href="../../Installer/java.policy">The Java2 (sdk, jre, plugin 1.3) policy file example to give GL4Java the necessary permissions (Click here) !</a>
+<br>
+</P>
+<p> <a href="GLLandScape1_plugin13.html">GLLandScape</a>
+: a LandScape V1 at 500x300
+<p> <a href="GLLandScape1-big_plugin13.html">GLLandScape BIG</a>
+: a LandScape V1 at 800x600
+<p> <a href="GLLandScape1w1_plugin13.html">GLLandScape-World</a>
+: a LandScape World V1 at 500x300
+<p> <a href="GLLandScape1w1-big_plugin13.html">GLLandScape-World BIG</a>
+: a LandScape World V1 at 800x600
+<br>
+<br>
+<hr>
+</body>
+</html>
|