From a simple 3D Sphere to a real-size Planet. Need help!

Posted By: joao13pt

From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 01:52

The title says it all, but i will show you this video just to completelly understand what i want to do with 3D GameStudio
here

I'm working on a space simulation, and i've learned quite a bit about programming in Lite-C in the process. I actually got the idea from the game shown in the video, it has amazing graphics and scenery
But THAT one thing that i just can't understand is how game developers do this: While in space, the planet looks like a simple 3D Sphere, but the closer you get, the more detail it has. Then, at a point, it goes from a round model to a "flat" terrain surface. And then you can go back in space and watch it lose detail, and start to appear round again, etc...
I hope you understand my question

Thank you very much, im really enjoying my experience with GameStudio
Posted By: PadMalcom

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 06:48

Hey, this technique is called LoD or Level of Detail. Models gain more and more dedails the closer you get and in contrast they loose details if you the distance between the camera and the model gets bigger.
Posted By: sivan

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 08:38

hi

I think they used a much more complex thing than simple LOD, like a spherical chunked terrain that looks like : http://imageshack.us/a/img202/3064/62479621.png and http://imageshack.us/a/img717/541/35220357.png , but it is not supported by any game engine natively, I'm afraid you have to write your own mesh generain and texturing, if you want both good performance and high terrain detail. or maybe by setting a couple of planet and terrain entities invisible/visible can do the trick in 3DGS too, to simulate a planet from any distance. anyway, it is an interesting topic in game creation.
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 14:38

I really needded to know how this is done, so thank you both for your replys, i really apreciate it laugh
I had heard about LODs, in some games it's very easilly noticiable when LODs are changing, like in Oblivion, for example, or any of these space games
I've been thinking alot about this, and with your replys, i think i have an ideia on how to do it: in space i'll just use the Sphere model, and when entering the planet's atmosphere, previously made terrains will start to be generated in their exact positions. So, at a distance but already in the planet's atmosphere, the terrains will be connected to each other by curving their edges, and this curve will start to be less and less noticiable when aproching the ground
I'll keep on researching, now that i actually know the techniques used.
Thanks again for those replys!
Posted By: sivan

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 14:49

sounds easy but will be hard to make it smooth laugh
Posted By: Det

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 18:59

It looks great very realistic the space and the Asteroids and the Mother Ship.Great Work. What Gamestudio Version you use for this ?
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 19:51

I didn't create what is shown in the video x) I'm hopping to learn how to create something close to it
Now im stuck in the "procedural planet generation" part, and this sucks because i don't even know where to start..
Posted By: Det

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/25/13 20:27

Ok then you have to learn to make it like this.Maybe some one in this Forum can give you some Tips to learn it.It loos not so easy to do this.
Posted By: sivan

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/27/13 10:27

I would use a sphere model for water (if needed) and another for ground, and a generated heighmap for the latter, to modify its vertices or use a shader to do it. based on the heightmap you could blend surface textures too. just as a first thought, but there should be some articles with ideas of it.
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/30/13 13:53

So far im stuck, i can't find a decent mathematical algorithm to transform the terrain, vertex by vertex, into a sphere
i've been googling this, non stop
"how transform 2d plane to sphere" "mapping terrain on a sphere"(...) i've searched in many different ways and i can't get anywhere. Im stuck now and if anyone here could help me with this algorithm i'd appreciate it a lot
i don't want to work with those shader techniques, for now i want only to use ent_getvertex and ent_setvertex to change each vertex's position
now, how do i turn a "flat" terrain, into a round sphere, vertice by vertice?
thanks in advance
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/30/13 15:54

just take spherical coordinates(x=alpha, y=beta) and convert them via sin and cos to 3d space (vec_rotate((1, 0, 0), (alpha, beta, 0)))
this won't give you a uniform distribution, but a spherical shape
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/30/13 19:38

Originally Posted By: MasterQ32
just take spherical coordinates(x=alpha, y=beta) and convert them via sin and cos to 3d space (vec_rotate((1, 0, 0), (alpha, beta, 0)))
this won't give you a uniform distribution, but a spherical shape

Being said like that i don't really know what to do xD sorry
i understand a thing or two about trigonometry, so maths isn't a problem for me, i just need "exact guidance" if you understand what i mean
im using the c.x,y,z (not the DX coordinates, but actual world coords) now i'd like to transform my "flat" terrain into a round, sphere-like mesh
would you be so kind as to explain a little better your idea please? x)
thanks for your help
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/30/13 20:59

your terrain is a flat surface, so you only have xz-coordinates, y is constant
you can now transform every vertex by taking the xz-coordinates and map them to a range of 360 degrees and then convert those two angles to the 3d spherical space.
i cannot draw an example right now but in about two days
Posted By: ryanhagz

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/31/13 05:43

Originally Posted By: MasterQ32
your terrain is a flat surface, so you only have xz-coordinates, y is constant
you can now transform every vertex by taking the xz-coordinates and map them to a range of 360 degrees and then convert those two angles to the 3d spherical space.
i cannot draw an example right now but in about two days


I'm looking for something very similar to what joao is looking for, I'd love to see your example drawn out. I'm a better visual learner. grin
Posted By: Ascalon

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 03/31/13 11:17

maybe this could help you, dont know http://www.gameprogrammer.com/fractal.html
Posted By: ryanhagz

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/01/13 03:52

Originally Posted By: Ascalon
maybe this could help you, dont know http://www.gameprogrammer.com/fractal.html


Thanks for that Ascalon! While it wasn't quite what i was looking for, it was still very helpful. I found the concept of storing the algorithms to make the image instead of the image itself interesting especially since I know the racing game "Fuel" used this same concept to develop their terrain (which happens to be the biggest map on any console; 14,000Km^2). While the game itself was kind of lame, it's interesting how they did the terrain. This video kind of talks about how they did it using procedural generation.

He starts off by comparing othe well known open world games with huge maps. If you'd like to see the bit about Fuel skip to around 1:00.

http://www.youtube.com/watch?v=HhyyUiYQolA
Posted By: BoH_Havoc

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/05/13 11:17

Some stuff to get you started:

basic introduction on mapping a cube to a sphere:
http://mathproofs.blogspot.de/2005/07/mapping-cube-to-sphere.html

what you want:
http://acko.net/blog/making-worlds-1-of-spheres-and-cubes/
http://www.nullpointer.co.uk/content/?p=393

Make sure you understand how a "basic" heightfield terrain works before attempting to create a spherical terrain. Basically a spherical terrain can be created out of 6 heightfield terrains, so it's really a good idea to start with them first laugh

[edit] Also, if you want to create MASSIVE scale spherical worlds, you should have a look at how octrees work.
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/05/13 21:15

Im sorry, i've been a little distant from both lite-c and pc's. My hard drive had some mechanical issues and wasn't allotwing me to log into windows, so i won't have it fixed for a couple of weeks. Using a crappy laptop at the moment, it has an integrated graphics card which can't even render more than 5000 polys without making the FPS decrease to about 5
So i won't be visiting this forum for some time.
Thanks to all who have helped me so far
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/06/13 02:19

I'm doing some research right now, my current progress:


Improvements:

Posted By: Superku

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/06/13 04:53

Very cool!
Posted By: alibaba

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/06/13 05:55

Indeed!
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/06/13 07:48

I have problems with selection the right LOD stages for the terrain (something with distance calculation and stuff...)
but i could do a 2D terrain system for sure with this technique (but i don't know what's about collision)
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 04/28/13 22:54

Hi! Im back and happy smile
You guys have been helping me a real lot with this! And i thank you all!
Some questions still remain in my head:
-Where to start?
-About the cube to sphere conversion, love the idea! But wait, using a cube model would't seem right. That leaves me with terrains. So, how do i rotate 6 terrains in order to produce a flawless cube? I've been trying some "homemade" algorithms, but none have worked..
-I love math, so, please, give me mathematic algorithms! I've red a lot both on perlin noise and on procedural planets, but it's mostly just blogs of people telling what they've done. I don't want just to know what they've done, i want to know HOW they've done it. What algorithms, what procedures, i want to actually know they path they used in the programming language, so that i myself can get a clue on what i should do get the same result in Lite-C
So, once again, help me

thanks
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/07/13 19:50

Really loved it if someone could continue answering to this topic, pleeeeeease smile
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/07/13 20:00

create a cube out of 6 "models"

each of those models gets transformed via shader to build a sphere (just normalize each vector to 1)

each of those models is made out of a quad tree which subdivides the surface of the model into more polygons if necessary (just a distance check for camera will do it in most of the cases)

i've made a quick test with a plane mdl which is in the range of [-1,0.5,-1] to [1, 0.5, 1]

you need to set the scale and position for each entity representing a part of quadatree manual, but it works pretty good if work with XNA tutorials as a template
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/08/13 17:53

Ok, so i work with GameStudio and im not doing this out of actual models, but out terrains. So, to build a cube i'll need 6 faces, that is, 6 different terrains. 1 will remain normal, the other 5 will have to rotated to get the cubic shape. This is one of my first obstacles, because transforming a cube to a sphere, the part about subdivision, all of those things i can manage to get there with a little research, i've actually red a lot of things by now. But this is my first "pain in the ass" obstacle, and i can't get past this because, in GameStudio it's said that terrains cant be moved and/or rotated, this really screws this whole project for me because it wouldn't make sense to use an actual model. Yes, those can be moved and rotated, but it just doesn't make sense to use a sphere model as an earth-like terrain
Are you understanding my problem? It's this one problem that just won't let me keep going with this project, i don't know how people do it, something is missing in my way of thinking
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/08/13 18:35

please don't use terrains!
you can't rotate them (because of LOD reasons and terrain chunk clipping)

just use models, in your case they aren't a bit faster than normal models
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/11/13 14:45

Thanks! Finally i know where and how to start
but to make an earth-like model i'd have to create a HUGE cube, to later transform it into a sphere (or could i make a sphere model right away?)
Will it still be possible to use subdivion algorithms with 3d models? I got the ideia that in GameStudio those would only work with terrains
But in the end, to simulate an actual universe where you could get lots of detail and actual terrain variations when close to each planet, wouldn't be possible with gamestudio's terrains because these can't moved and/or rotated, therefore my universe would be completely static
you have helped me alot! thank you! laugh
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/11/13 14:47

the problem with a sphere model is that you cannot do math that easy as with a cube.
just use a shader which normalizes each vertex position before modifying it with matView and matProjection.
Then you will get a sphere. The subdivision is made with models you don't subdivide the models. Gamestudio also cannot subdivide terrains
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/12/13 12:36

When i have enough time i'll try some stuff with GameStudio and eventually will post the results here
Procedural Planets are really hard but the motivation is greater than the dificulty
thank you!
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/24/13 19:18

I've been checking this website that shows how to convert a cube to a sphere, and, the result was this algorithm:

Code:
function cube_to_sphere(ENTITY* model) 
{
	
  int i = ent_status(model,0); 
  for (; i>0; i--) 
  {    														 
  	CONTACT* c = ent_getvertex(model,NULL,i);   
  	c.x = (c.x * (sqrt(1 - ((c.y^2)/2) - ((c.z^2)/2) + (((c.y^2)*(c.z^2))/3))));
  	wait(2);
  	c.y = (c.y * (sqrt(1 - ((c.x^2)/2) - ((c.z^2)/2) + (((c.x^2)*(c.z^2))/3))));
  	wait(2);
  	c.z = (c.z * (sqrt(1 - ((c.x^2)/2) - ((c.y^2)/2) + (((c.x^2)*(c.y^2))/3))));
  	wait(2);
  	c.v = NULL;   // set c.v to NULL to change c.x,y,z 
  	ent_setvertex(model,c,i); 
  	wait(4); 						 
  	}


}



The math in c.x, c.y and c.z comes from this image found in the website previously mentioned, and the result was waaaaay to horrific for me to post pics here, basically, each of the cube's 768 vertices were scattered around the level
I even added some wait() functions to slow the process down, thinking it could be the math "happenning" too fast, but the result was still awfull
Im a little tired to think where i made the mistake, i've been failling this algorithm for transforming a cube to a sphere for about a month, and now i really think i need extra help
Thanks in advance!
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/24/13 19:54

you have a little problem here with math:
c = c with normalized x
c = c with normalized y
c = c with normalized z
so you don't normalize the vector itself but each of the components. this results in a weird shape. just use vec_normalize(c.x, 1); here instead of the whole normalization code
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/25/13 13:18

Didn't work aswell..
i don't think you understand what im trying to achieve
So, i have an actuall cube model, it has 768 faces in total
I want to convert each of it's vertices's (x,y,z) values that make it have the shape of a cube, into values that form a sphere
basically i want to wrap this cube into a sphere
Thus that whole complicated math
using vec_normalize(c.x, 1) and doing the same for c.y and c.z isn't helping, because im not actually telling the program to turn it into a sphere, im just reducing it's size
Please explain the whole process to me, i'd be very gratefull, something is missing in my way of thinking and it's driving me crazy
Thank you


----------------------------- EDIT -------------------------
Exactly 10 seconds after writing the above post, i decided to try just changing the c.x, then just the c.y and then just the c.z
just to watch it fail again
and it work right away with the c.x
thank you so very much! I've been waiting for ever to have this result! thank you thank you thank you man!
Aparently i was confusing c.x,y,z with actual x,y,z values
was i thinking right or wrong? Because i just changed the vertice's X (c.x) value and the cube turned into a sphere shocked
I was not expecting it, but it worked out and THANK YOU!
here's the inicial cube


And the final sphere
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/25/13 15:32

Quote:
i don't think you understand what im trying to achieve

Really?

And congrats that it works now
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 05/25/13 19:08

Sorry about that, i really wans't thinking in what i was saying frown
It only works because of your help! thank you again!
Now i'll continue to create my virtual universe
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/04/13 19:59

Hello!
When moving or rotating the sphere that used to be a cube, it wont update it's shadow
But when i do the same with a sphere model from MED, it does update it's shadow without any issues
What's wrong?
Posted By: MasterQ32

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/04/13 20:01

how do you transform your cube?
Posted By: HeelX

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/04/13 21:35

Originally Posted By: joao13pt
it wont update it's shadow


I guess you mean the shading? When you just move the vertices around, the normals won't be updated. Try ent_fixnormals.
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/04/13 22:16

Originally Posted By: MasterQ32
just use vec_normalize(c.x, 1); here instead of the whole normalization code

I transform it into a sphere like you told me to, using this:

Code:
function cube_to_sphere(ENTITY* model) 
{
	
  int i = ent_status(model,0); 
  for (; i>0; i--) 
  {    														 
  	CONTACT* c = ent_getvertex(model,NULL,i);   
  	vec_normalize(c.x, 112);
  	c.v = NULL;   // set c.v to NULL	to change c.x,y,z 
  	ent_setvertex(model,c,i);
  	wait(5); 					 
  	}
  	
	ent_fixnormals(model, 0); // THIS PART OF THE CODE WAS ADDED AFTER READING THE PREVIOUS REPLY

}



The ent_fixnormals() worked out! thank you again for all your help fellow programmers!
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/08/13 23:15

Im sorry if i'm being annoying, i keep coming here with problems and questions and doubts
But now i need guidance to achieve my next goal, the one i was fearing most from the start, the part where i make my "procedural" planet, procedural: tessellation, face subdivision algorithms (this last one, im sure i could handle, i just can't freaking find any algorithm online nor any explanation of how to do it) and all of those things
I need advice on where to start
By now i've researched ALOT actually about procedural planets and all that stuff, and i've come to a (possibly wrong?) conclusion that real-time face subdivision is made through shaders, is it?
I really don't have the smallest clue on where to start, so any help from this community will be kindly apreciated
Thank you! smile
Posted By: Anonymous

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/08/13 23:30

Quote:
tessellation


I didn't think that was possible with the engine/dx9..? Adding removing vertices at runtime. This can be done?
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/08/13 23:43

From what i've read, i think it's possible in DX9 shocked
I sure hope to be right, because i have Win XP and therefore, DX9
Posted By: Anonymous

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/09/13 00:58

This says it's not part of dx9.

http://en.wikipedia.org/wiki/Microsoft_Direct3D#Direct3D_11
Posted By: Kartoffel

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/09/13 08:46

Do you need collisions? -> you can't use tesselation and have to do the vertex-transformations on the cpu.
Posted By: joao13pt

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/09/13 13:37

You're right, it can't be done in DX9, i apologize, but it CAN be done with the GameStudio engine
If you go to page 2 of this Thread, you'll see MasterQ32 has done exatcly what i want to achieve, with the 3DGS A8 engine
He shows exatcly what i want to do, i just don't know where and how to start frown

@Kartoffel - So how will i be able to do these vertex transformations in order to subdivide (or undo subdivision) the mesh's faces, with the 3DGS engine? I can't find anything in the manual nor online regarding this subject. I've found lots of tutorials with C++ but i can't "convert it" to Lite-C, i just don't know where to find the necessary functions/commands and information about them.
Posted By: Anonymous

Re: From a simple 3D Sphere to a real-size Planet. Need help! - 06/09/13 18:40

Quote:
If you go to page 2 of this Thread, you'll see MasterQ32 has done exactly what i want to achieve, with the 3DGS A8 engine


Yeah sorry about that - Note-to-self: Actually read the thread before jumping in on it.
© 2024 lite-C Forums