Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Questionably effective terrain generator  (Read 3578 times)
0 Members and 1 Guest are viewing this topic.
Offline silverklyph

Senior Newbie




Java games rock!


« Posted 2004-01-28 19:32:00 »

Here's the code that I wrote/stole from other programs, to randomly generate 3d terrain.  When I run it however, the screen appears to have nothing.  Any ideas what's going wrong?  (Basic summary @ bottom)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
import javax.vecmath.*;
import com.xith3d.scenegraph.*;

import com.xith3d.render.*;
import com.xith3d.render.jogl.*;

public class LandTest {

  private Square[][] tiles;
  private Point3f[][] vertices;
  private final int NUM = 32;
  public static int counter = 0;

  public static void main(String[] args){
    new LandTest();
  }

  public LandTest(){
    initVerts();
    initSquares();

    VirtualUniverse universe = new VirtualUniverse();
    Locale l = new Locale(NUM/2f, 0, NUM/2f);
    View v = new View();
    universe.addLocale(l);
    universe.addView(v);

    BranchGroup scene = new BranchGroup();
    l.addBranchGraph(scene);

    Transform3D rotate = new Transform3D();
    rotate.rotXYZ(0,0,0);
    TransformGroup objRotate = new TransformGroup(rotate);
    scene.addChild(objRotate);

    for(int x = 0; x < NUM; x++){
      for(int y = 0; y < NUM; y++){
        objRotate.addChild(new Shape3D(tiles[x][y].getGeometry(), new Appearance()));
      }
    }

    scene.compile();

    RenderPeer rp = new RenderPeerImpl();
    CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);

    Canvas3D canvas = new Canvas3D();
    canvas.set3DPeer(cp);

    v.addCanvas3D(canvas);
    v.setFrontClipDistance(.5f);
    v.setBackClipDistance(20f);

    Transform3D t = new Transform3D();
    t.lookAt(new Vector3f(0, 5f, 10f),
             new Vector3f(NUM/2f, 0, NUM/2f),
             new Vector3f(0, 1f, 0));
    v.setTransform(t);

    for(int i = 0; i > -1; i++){
      v.renderOnce();
    }

  }

  private void initVerts(){
    vertices = new Point3f[NUM+1][NUM+1];
    for(int x = 0; x <= NUM; x++){
      for(int y = 0; y <= NUM; y++){
        vertices[x][y] = new Point3f(x, (float)(20*Math.random()-10), y);
      }
    }
  }

  private void initSquares(){

    tiles = new Square[NUM][NUM];
    for(int x = 0; x < NUM; x++){
      for(int y = 0; y < NUM; y++){
        tiles[x][y] = new Square( vertices[x][y],
                                  vertices[x+1][y],
                                  vertices[x][y+1],
                                  vertices[x+1][y+1]);
      }
    }
  }
}

class Square {

  private Geometry shape;

  Square(Point3f v1, Point3f v2, Point3f v3, Point3f v4){
    Point3f[] coords = new Point3f[] {
        v1, v2, v3,
        v1, v4, v3
    };
    Color3f[] colors = new Color3f[] {
        new Color3f(0, 1f, 0),
        new Color3f(0, 1f, 0),
        new Color3f(0, 1f, 0),
        new Color3f(0, 1f, 0),
        new Color3f(0, 1f, 0),
        new Color3f(0, 1f, 0)
    };

    TriangleArray array = new TriangleArray(coords.length, GeometryArray.COORDINATES|GeometryArray.COLOR_3);
    array.setCoordinates(0, coords);
    array.setColors(0, colors);
  }

  public Geometry getGeometry(){
    return shape;
  }
}



 Ok, so first thing it does: creates a 2^5 +1 x 2^5 + 1 array of Point3fs with definite x and z values.  The height of that point is determined randomly at runtime.  Then, Square objects are created from those points, constructing a 2^5 x 2^5 array of tiles.  Each Square has its own Geometry which is used to create Shape3Ds and they are stored in an unrotated TransformGroup.  If anything is rendered, however, I can't see it at runtime.  (The window with its trademark Xith Brown/Black bg appears, but nothing is in it).
Offline tomcat

Senior Newbie




Java games rock!


« Reply #1 - Posted 2004-01-29 15:49:26 »

I have had problems creating terrains with and without texture Sad. Judging by the low responses to this problem, I am getting the feeling that may be there is not an efficient or working way in xith to do this :-/. hope i am wrong.
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #2 - Posted 2004-01-29 15:56:12 »

/me has a heightmap terrain generation demo, not sure if it's of any help though
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tomcat

Senior Newbie




Java games rock!


« Reply #3 - Posted 2004-01-29 18:57:56 »

JCD, might be worth looking at this demo as I am not getting anywhere fast. Where can i find the demo?
Offline silverklyph

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-01-29 19:10:32 »

Hmm... it works better if I use a QuadArray instead of a TriangleArray.  Now I can actually see something rendered.  I'll show it once I get something concrete.
Offline Java Cool Dude

Senior Devvie




Java forever


« Reply #5 - Posted 2004-01-29 19:54:05 »

Quote
JCD, might be worth looking at this demo as I am not getting anywhere fast. Where can i find the demo?


Lemmie tweak it and hopefully release it tonight
Offline silverklyph

Senior Newbie




Java games rock!


« Reply #6 - Posted 2004-01-30 16:59:25 »

w00t!!

http://www.geocities.com/silver_klyph/demos.html
Offline silverklyph

Senior Newbie




Java games rock!


« Reply #7 - Posted 2004-01-31 13:16:08 »

Could someone help me in jar'ing a program in Xith3d?  The GSG isn't very helpful, no offense to whoever wrote it, I just have never jar'ed up a program before and Sun's guide isn't that great either.  Just listing the files that need to be loaded would be very helpful.  I can only provide screenshots of my programs now, but I'd like to eventually webstart something non-trivial.
Offline Jens

Senior Devvie




Java for games!


« Reply #8 - Posted 2004-01-31 15:52:49 »

The GSG isn't about jar packaging, that's why it can't help you in this case. What is so bad about the Sun tutorial? You can use "jar cf yourjar.jar file1.class file2.class dir1 dir2" to create a jar file with the name "yourjar.jar" including the files "file1.class", "file2.class" and the directories "dir1" and "dir2". Most IDEs can handle this automatically for you.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline silverklyph

Senior Newbie




Java games rock!


« Reply #9 - Posted 2004-01-31 16:36:56 »

I meant neither was helpful because I wasn't sure what files to JAR up.  Even after I put all the xith .jar files into my own jar file, it can't find com.xith3d.scenegraph.Node, do I have to jar the entire src directory and subdirectories?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline whome

Junior Devvie




Carte Noir Java


« Reply #10 - Posted 2004-01-31 18:37:53 »

Here is my plain project example. Create the following files and folders. This will apply to linux, just edit .bat files to linux scripts.

And modify a reference to your jdk path in script files. I always prefer an explicit reference so that know for sure what version is being used.

You always can unzip xith3d.jar file to classes folder and then jar it with your own files. Result is a single .jar file with all necessary files. I would prefer to use a separate xith3d.jar file however, just reference it with -classpath argument in a runner script.

c:\myapp\compile.bat
c:\myapp\jar.bat
c:\myapp\go.bat
c:\myapp\classes\
c:\myapp\lib\
c:\myapp\src\<all .java files with appropriate package subfolders>
c:\myapp\src\META-INF\MANIFEST.MF

MANIFEST.MF
1  
2  
3  
4  
Implementation-Title: MyAppTitle
Implementation-Version: 1.0.0 (2003-01-01)
Implementation-Vendor: MyCompany Ltd.
Implementation-URL: http://www.myserver.com


compile.bat
1  
2  
3  
c:\j2sdk1.4.2\bin\javac.exe -sourcepath ./src -d ./classes ./src/*.java
xcopy /Y .\src\META-INF\*.* .\classes\META-INF\
pause


jar.bat
1  
2  
3  
SET MF=./classes/META-INF/MANIFEST.MF
c:\j2sdk1.4.2\bin\jar.exe cvfm ./lib/myjar.jar %MF% -C ./classes .
pause


go.bat
1  
2  
3  
SET CP=./lib/myjar.jar;<put here other .jar references>
c:\j2sdk1.4.2\bin\java.exe -cp %CP% MyMainClass
pause
Offline Jens

Senior Devvie




Java for games!


« Reply #11 - Posted 2004-01-31 18:59:22 »

Quote
I meant neither was helpful because I wasn't sure what files to JAR up.  Even after I put all the xith .jar files into my own jar file, it can't find com.xith3d.scenegraph.Node, do I have to jar the entire src directory and subdirectories?


Creating a Webstart app:

First you have to package the files you created (without the libs you need!). After that you have to wrap the native libs in jars (because Webstart needs them as jars) as shown in the GSG. You have to reference all the jars you need in the Webstart jnlp file and specify a main class. If you look close at the jnlp example in the GSG, you can see the directory structure in which all the jars are placed. Next step is to sign the files and you are ready to go.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline William Denniss

JGO Coder


Projects: 2


Fire at will


« Reply #12 - Posted 2004-02-02 01:07:17 »

Quote
Could someone help me in jar'ing a program in Xith3d?  The GSG isn't very helpful, no offense to whoever wrote it, I just have never jar'ed up a program before and Sun's guide isn't that great either.  Just listing the files that need to be loaded would be very helpful.  I can only provide screenshots of my programs now, but I'd like to eventually webstart something non-trivial.


If it is the JWS tutorial you are referring to then I wrote it.  Can you elaborate on what isn't helpful?  Using that guide I've made some non-trivial JWS Xith3D apps.

I trust you are aware that a jar file is simply a zip file?  Just create a zip file and rename the extension to .jar - or as Jens suggested use sun's handy "jar" tool.

EDIT:  Oh, and the best way to do it (that I have found) is use an Ant build script, an example of which is in the GSG CVS.  This has the advantages in that it's platform independant, IDE independant and dead simple.

Will.

Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (45 views)
2018-11-16 13:46:03

hadezbladez (49 views)
2018-11-16 13:41:33

hadezbladez (26 views)
2018-11-16 13:35:35

hadezbladez (20 views)
2018-11-16 13:32:03

EgonOlsen (1897 views)
2018-06-10 19:43:48

EgonOlsen (1936 views)
2018-06-10 19:43:44

EgonOlsen (1286 views)
2018-06-10 19:43:20

DesertCoockie (1717 views)
2018-05-13 18:23:11

nelsongames (1411 views)
2018-04-24 18:15:36

nelsongames (2041 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!