Conceptual difficulties

First time poster, so first and foremost. . .Hi all.



I’ve been playing with JME lately just trying to get my head around it, as it were. I’m having a concept problem that I really feel a little silly to ask, but can’t seem to find anything by searching or other means, probably because it’s common sense and I’m just making it harder than it is ; ) Just for background: I’m a 15 year professional software engineer, have a few cheesy 2D game-ish things behind me, and am just starting to look at 3D. Have a pretty good grasp of J3D and because of that went on to look at Xith and JME. . .no contest there.



The question is. . . How does one build a universe (scene) that is BIG, ie. Solar System sized? I understand the coordinate system, and as I understand it, that’s to represent a meter, more or less. What is the common way of translating that? Do we just consider a meter a kilometer? What then do I do with ships, just use the hi-res numbers (ie. 5.2323232234)? I guess what I’m looking for is kind of the best practice. . or any practice really ; )



Does anybody have any experience with this that has the patience to answer a stupid question?



Thanks all! Triple thanks to the JME crew. . .so far OUTSTANDING.

gander



P.S. Just for a bit more detail. Play like we’re modelling the Sol system, 1 sun, 9 planets, moons, etc. Maybe an asteroid belt for flair. I would guess that I would probably scale it down by, maybe 10X, but shrug.

"gander" wrote:
I'm a 15 year professional software engineer, have a few cheesy 2D game-ish things behind me, and am just starting to look at 3D. Have a pretty good grasp of J3D and because of that went on to look at Xith and JME. . .no contest there.
Must be my twin then ;)

Concerning your question: I don't know whether you have already taken a closer look at games like Freelancer. They definitely scale everything down way more than 1:10. Since most of the coordinate values currently are floats, big numbers may introduce precision problems if calculated frequently - which quite often happens when translating/rotating/scaling.

Apart from that: if you scale by 1:10, how fast will your ships move in order to make progress in a decent amount of time? In the solar system, the light needs somewhere about 20 hours to reach Pluto IIRC, so moving at light speed in a system scaled down by 10 will still leave 2 hours of constant movement...

If you want to see the entire sole system at one time then you need to scale the size down. To do this you change the 3d units to a larger size. For example you can make 1 unit = .1AU and then just zoom out to the proper distance and it would look fine. You can use any schall you want as long as you use the same one the hole time. (You need to use it in models and speed also). There is no started scale.



If you want to fly through the system with extreme precision then you can divide the system into sectors and only render one to three at a time. When you get to the edge of a sector then You would move into the next. Each sectors can have it’s one root node.

Thanks a ton guys for the reply. So yeah, I’ll have to scale it significantly just for “playability”. So that leaves the question. . .is there a programatic way to change (as Badmi said) 1 meter to .1AU? Or is it just simply a convention I apply mentally? Also, if I were to try and model this in 3DS Max or somesuch, is there a consideration there?



Thanks again,



gander

jME does not have the Universe (I believe that’s what Java3D called it, it’s been awhile) concept. It will not handle scale changes automatically for you. So, yes, you’ll have to handle switching scales in your own code. Typically, for example, you’d use one scale while doing interplanatary travel, than when you are at a specific planet. The scale swapping is necessary to make up for precision loss of floats. So, in summary, I would create a utility class that maintains scale levels and switches based on where you are in the solar system.

Hi gander :slight_smile:



I guess Badmi and the others are referring to Spatial.setLocalScale(…) here so you can set the scale for an entire node or subnode at once.

your problem lies in:



cam.setFrustumFar(100000000000f);

cam.setFrustumNear(.1f);



OpenGL defines a depth buffer that has limited precision, and having a difference of that size has gone beyond the precision limits.



From: http://www.opengl.org/resources/faq/technical/depthbuffer.htm


12.080 There is no way that a standard-sized depth buffer will have enough precision for my astronomically large scene. What are my options?

The typical approach is to use a multipass technique. The application might divide the geometry database into regions that don't interfere with each other in Z. The geometry in each region is then rendered, starting at the furthest region, with a clear of the depth buffer before each region is rendered. This way the precision of the entire depth buffer is made available to each region.


Hope that helps.
"winkman" wrote:
Hi gander :)

I guess Badmi and the others are referring to Spatial.setLocalScale(...) here so you can set the scale for an entire node or subnode at once.

Nope. I am referring to changing what the size of a unit. For example making 1 unit=.01AU so you can see the entire seen. You should not need to use setLocalScale if you make the models to scale.

Wow, again thanks for the help. So. . .if that’s my problem, I should be able to, say, make all 1 unit = 1000, or maybe 10000 km, that would solve the problem (ie, make the sun radius 695.2 and the earth dist 149600)? That would put my frustum far at, 150000. Is that still a bit far? What would the practical limit be? Any guess Mojo? Cause after that I’ll have to go out to pluto which will make the earth a very small number (for radius) indeed. Is that a valid technique? Of course, I could also learn how to do that multipass stuff.



sincerely appreciate it again guys.

glad to help. :smiley:

Hello gander



i’am currently working on a game in space whith jme and i had the same consideration (the space is SO big :wink: )



for the moment my parameter is set to cam.setFrustumFar(300000); and it works perfectly.



However, these kind of scales solve your problem of planet size but not the problem of distance between planet (or even greater your distance with the star of your system). Since i don’t know what is your project i can’t help you much but say to you what i have chosen : since my project is a game, my goal is playability, not realism, so i don’t keep real distance (even with a little scale, when you want the player to travel between planet with real distance just scaled it becomes a headache), so distance between planet won’t be real in my game and there will be means to travel very fast between planet (i will use ‘sector’ of universe).



Of course if your project is more a simulation, you must use a very accurate scale system, if this is the case, you can use a scaled time system with your scaled universe to permit the user to ‘accelerate time’





Hope this help,



Adenthar.

Adenthar,



It’s a game idea I’m working on. My plan was to keep the RATIOs somewhat accurate on the distance and radius numbers and then scaling that down dramatically for playability. But I’m not sure if that’s going to be practical at this point. Could you give me some examples of some of the numbers your using where your seeing everything as alright, and frustum settings? I pulled everything WAY down yesterday and was still having a lot of the same problems. . . .



// All values km
    float sunRadius = 695200f / 10000f;
    Vector3f sunLoc = new Vector3f(0,0,0);

    float earthRadius = 6378f / 10000f;
    float earthDist = 149600000f / 10000f;

    Renderer renderer;

    public static void main(String[] args)
    {
        GOne app = new GOne();
        app.setDialogBehaviour(SimpleGame.FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
        app.start();
    }

    protected void simpleInitGame()
    {
        renderer = display.getRenderer();

        System.out.println("sunRadius is " + sunRadius +
                           " earthRadius is " + earthRadius +
                           " earthDist = " + earthDist);


        cam.setFrustumFar(earthDist + earthRadius);
        cam.setLocation(new Vector3f(0f,0f, (earthDist + earthRadius)));
        cam.onFrameChange();
        cam.update();

        Sphere sun = new Sphere("Sun", 20, 20, (sunRadius));
        sun.setModelBound(new BoundingSphere());
        sun.updateModelBound();
        sun.setLocalTranslation(sunLoc);

        Sphere earth = new Sphere("Earth", 40,40, (earthRadius));
        earth.setModelBound(new BoundingSphere());
        earth.updateModelBound();
        earth.setLocalTranslation(new Vector3f(0f,0f, (earthDist)));


        cam.lookAt(earth.getCenter());
        cam.onFrameChange();



With the results of the println being

sunRadius is 69.52 earthRadius is 0.6378 earthDist = 14960.0


Have to admit, so far this has worked as a fair piece of humble pie. . .but the challenge is terrific!

Thanks,
G

Hi Gander,



Well i think my solution will not satisfy you, because it’s over simple, anyway :



my game is divided into ‘sector’ of universe (roughly a sector = 1 planet and its moon, spacebase and so on)



the player will ‘teleport’ himself from sector to sector



the sun (forgive me the star :slight_smile: ) is only decorative there’s no ‘sector’ with the real star of a system

no ship can survive near a star so i think it’s not necessary for the player to fly near the star.



In my game i use 1 jme unit = 1 km



So if you take the earth it would be earthRadius = 6378f; (well earth is not in my game but that’s not the problem :wink: )



I dont use a sphere for the star i use only lensflare, the optical effect is far better. Since the player teleport from sector to sector the lensflare is put arbitrary on the limit of the cube of the sector i know it isn’t realistic at all but the visual effect is correct.



as for the distance :



as i said the frustrum is set to 300000f

a planet has a radius of 6000f and is in a cube (sector) of 150000f size long (‘a sector’) the lensflare (the sun) is on coordinates near 145000, 145000, 145000 (near the border of the cube) for example.



As you can see my solution is simple and there’s no realism anywhere in my game.

But it’s playable and that’s my goal.



If you want to be more realistic, you can calculate the position of the sun relative to the position of the sector in the unverse but i think it’s not important in a game (i prefer to use my time to make more ships in my game than to make mathematical simulation :slight_smile: )



Bye,



Adenthar.

Adenthar,



Some good points, definitely stuff to mull over as I’m also a playability freak. Now though, I have a personal vengence thing going on with this stupiid test code : ) (this isn’t game yet, just learning)



Also, I found out why I was having trouble even after I scaled everything down. Either I’m misunderstanding it’s use, or there is a problem with Camera.lookAt(). As soon as I removed lookAt everything performed as I expected. Anybody know of a bug with that?



Thanks again!



G