Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Hyperspherical universe

Author
Message
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 24th Mar 2009 04:32 Edited at: 24th Mar 2009 04:36
I've been thinking about this for a couple of days. Coded this tonight. Quite a lot of educated guesswork, but it seems to work OK! It's a "universe" "on" a 4d hypersphere - ie the surface (or volume) or a shape where w^2 + x^2 + y^2 + z^2 = 1, represented by a 3d world view in DBP.

Basically if you flight straight in any direction, you wind up where you started. It's like a 2d world on the surface of a sphere, but in 3d, or something. It's quite hard to get your head around. Quite wierd too- when things get halfway to the other side of the "world" from you, they start looking bigger! - theoretically you should be able to see yourself! (you can't in this prog at the moment)

Anyway check it out. Here are the codez so far.


Next thing to do is to try and simplify the trig expressions (think i did a trick with similar functions for the spherical camera thing)

Then a hard task will be to get the 3d world rotations from the 4x4 matrices for each object. I'm expecting this to be a massive pain in the bum. Hopefully can get my head around it.

I could reposition individual vertices and do save the trouble. Would also allow seing yourself from all the way around the world i think, which the method of using scaled models wouldn't really.

Not sure what of game this could be used for. Has the benefit that you can have a finite "endless" universe, without cheaty boxiness. Downside is that it bakes your head. Also, point lights and that you'd have to code separately.

Have a plan for how to do space gridding - similar to planet - instead of a projected cube with 6 gridded sides, used a projected hypercube with 8 gridded volumes. Pretty sure it'd work but a big job.

Basically it's overcomplicated but cool.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 24th Mar 2009 04:33
Oh bum can a mod please put [DBP] in my title? I am stupid.

lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 24th Mar 2009 04:50
very cool, but i dont see much use for it yet...
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 24th Mar 2009 05:06
Thanks dude.

It is largely pointless.

The plus is that you could make a space game where you could fly in any direction as far as you wanted, and not require an infinite amount of data.

The downside is that it's difficult to make "maps" for, the actual coding is not that simple - you'd need custom collision stuff for example. Same kind of ups and downs as with putting a 2d game on a sphere (like i did with "asteroid worlds").

I might make this into a simple game- like 3d asteroids or something. 3d Asteroids isn't a great concept anyway, because you can't see what's behind you, but we'll see how it goes.

lucifer 1101
15
Years of Service
User Offline
Joined: 26th Jan 2009
Location: Melbourne, Australia
Posted: 24th Mar 2009 05:22
you could just use some rearview cameras LOL!
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 26th Mar 2009 05:10 Edited at: 27th Mar 2009 22:19
LOL indeed. Seriously though, it would be pretty unplayable. And you'd need more than two cameras anyway, unless you do some kind of trick (like the spherical camera thing for instance). Maybe i'll make this just a pretty explore-em-up type thing.

So, i've made some progress on this! After days of getting nowhere and pretty much half a pad of A4 lined paper later i've now got somewhere. Feeling kind of elated but tired. Basically i should now be able to extract 3d rotation matrices from the 4d ones. From these i can hopefully extract Euler angles (DBP doesn't make this easy. I may power up to a plugin).

Anyway i should stop talking and start sleeping. Hopefully will post new version tomorrow.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 26th Mar 2009 23:39 Edited at: 27th Mar 2009 04:14
So i've extracted the 3x3 rotation matrix OK. Now trying to extract the Euler angles, so DBP can internally convert them back to the rotation matrix. This is proving incredibly difficult, which is all the more vexing because there is no reason for it! Aaaargh. I should have a cup of tea and see if that gives me any bright ideas.

Edit: Sorted! Now i just need to tidy up the code. After i've watched Newswipe of course.

Edit2: i needed code to make random rotation matrices (4d) - now it's done! pretty sweet- works for any number of dimensions! Maybe i'll post up another snippet. Now to put some randomly oriented objects into this demo....

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 27th Mar 2009 21:54 Edited at: 27th Mar 2009 22:18
New version! Check it out!

Controls:

Mouse to turn and pitch
<,> to roll
mouseclick to fly forwards and back (left, right mouse buttons)
arrow keys to move up/down/left/right

What to do/ What's the point?:

If you fly straight forward, you will eventually end up where you started, in both position and orientation. This is like what happens if you go in one direction around a spherical world.

It's true that in 2 or 3 dimensions, if you travel in a constant curve, you will also end up where you started (and the same holds true here). The difference is that, in this universe, when you go straight, you also end up where you came from!

The jury is out as to whether our actual universe behaves like this. But if it is finite, it's still very very big.

I think i'll leave this as it is for now. I could add some "icing" on the cake but it's pretty pointless. If anyone has any bright ideas speak up.



BTW Thanks very much to the mod who added [DBP] to the start of the topic title.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 29th Mar 2009 21:22 Edited at: 29th Mar 2009 21:25
I thought i could simplify the code before. Comes out quite nicely! Previous version was hella overcomplicated. Here's a more efficient version. The bit changed is after the lines :
for n=1 to numboxes
a#=1.0 + posw#(n, 0)



I could make dist# and scale# the same and just make the objects different sizes. Also loads of unnecessary recalculations here and there. I might make this a bit faster still, for what it's worth.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 30th Mar 2009 05:09 Edited at: 30th Mar 2009 05:10
Some more optimisations. Also i increased the draw distance so that the effect is more noticable- fly forward and distant things appear to get smaller before they get bigger. I'm pondering whether i can use something like quaterions for this. At the moment i'm just rotating the matrices and hoping for the best - really i should be renormalising them, making sure they're orthogonal etc. I should look into that. Also that might speed up the movement and rotation code- instead of doing 6 degrees of freedom separately (movement fwd/left/up, roll,pitch,turn)- rotate once about a 4-vector axis. I really need to learn more about quaternions!

Enough talk.


I'm also pondering what kind of game i could make. I thought maybe a no gravity cling to the surface of objects and jump from one to the other game. With this hyperspherical geometry, if you jump and miss all the other floating platforms, you'll come back the the one you jumped from! This is all pie in the sky and i'm not doing it soon.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 30th Mar 2009 23:11
Small update- i changed it so there are now "lines" of boxes moving up/down. left/right and forward/back from the start point. You'll need to move the camera to get out in the open to see things. It should be clearer now from looking at the lines how the geometry is warped. There are two points where all 3 lines cross - analagous to the poles on a globe.

It's also apparent that the approximation of scaling and rotating objects is not really too great for objects this big relative to the "universe" - the ends of adjacent boxes in the lines are obviously "stepped". To make a proper game engine, i'd recommend using this technique for small objects (like characters), and for the large level objects position each vertex using vertexdata commands.



Monk
15
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 1st Apr 2009 22:44
Sounds good Mr tank, cept I keep getting errors, saying that the command is in the wrong place. Possibly the ide getting confused with so many different for next loops...

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 1st Apr 2009 23:16
Thanks for looking. I tried cutting and posting the latest version into my editor and it works OK for me. What editor are you using?

I remember someone saying once (of my code) that it didn't work because i use ... (three full stops together) in my comments a lot, which is used by some editors to mean something else. Here is a version with those taken out:



Monk
15
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 2nd Apr 2009 22:28
Whatever you changed, it works =)

I use the default editor, and have never had any problems with ... before now...

I gotta say that is amongst the coolest things I ve seen, but then again, I cant thing of many uses for it.

Is it me, or does the sphere wrap around you once you reach the edge?
If not, it sure looks like that =)

I might have a deeper look into this soon, if you dont mind...

Nice work, I hate to see good work going to waste with only one person posting... =)

Dr Tank
14
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 4th Apr 2009 00:51
Thanks dude.

Of course i don't mind if you look at or use this. That's why i posted.

I can't really think of much use for it either. If you wanted to make a finite world where you could travel forever, but without having to have an infinite amount data, there are a number of solutions. The simplest would be to make the world in a cube. That would require no "bending" or space, and getting relative positions would be very easy. This method is more symmetric, but quite complicated!

Another solution would be to have nothingness around your universe, but numbers wrap around eventually, and having nothing isn't very cool.

In a way you are right that the sphere "wraps around". You could map all of the space into the volume of a 3d sphere. However, in this case, the outside area of the sphere would be equivalent to the point in the centre.

The way i convert from positions of the surface of the hypersphere in 4 dimensions (which i think is called a 3-sphere, confusingly) into 3d coordinates is like a sterographic projection.

In a sterographic projection, you place the sphere you want to make a map of onto a flat surface. Imagine the south pole is on the surface. Then project points onto the sphere onto the 2d plane from the point on top of the sphere- in this case the north pole. This is how angle preserving maps of the world are made. On the map described the south pole sits in the middle, and the north pole is at infinity in any direction. Because of the angle preserving property, small features on the surface of the 3d sphere appear as scaled but undistorted (ie not sheared) features on the 2d map. They get larger the further from the centre of the map they are.

Similarly, This angle preserving property is how is managed to use 3d models that are scaled but not sheared in this program.

http://www.youtube.com/watch?v=6JgGKViQzbc

Note that for things quite big relative to the size of the sphere, distortions are apparent. That's why stepped features in the axes lines appear, like i mentioned in the last post.
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st May 2009 07:11
I had a project on spherical geometry at school. After i was finished, and was waling home from school, i started thinking about multi-dimensional "spherical" geometry. I was thinking about the circumference of a circle, surface area of a sphere, aaand surface volume of a hypersphere. Then i remembered this program! I just looked at it a bit to see what calculations were involved and... wow... I think i need a bit more than algebra 2 to figure this out
Dr Tank
14
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 31st May 2009 18:37
Cool to know you're doing this kind of stuff at school! When i was at school, the most advanced thing we did was probably differentiation. And they say standards are slipping.

It does hurt your head. Once you strip away the object generation, random rotation matrix generation, conversion from rotation matrices to euler angles etc, the actual code that does the "main" part of the program - moving the objects constrained to the surface of the 4d sphere, and converting to 3d, is quite short. Particularly when formulated in matrix notation.

Perhaps the easiest way to understand is by considering the lower dimensional problem of presenting things on the surface of an ordinary sphere in flat 2d - a stereographic projection. Then up the dimensions by one.

I found this quite challenging to do though.

Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 1st Jun 2009 00:16 Edited at: 1st Jun 2009 00:49
I never thought about using the 2d surface of a 3d sphere as a stepping stone to using the 3d surface of a 4d sphere. But besides that, i need to at least learn about matrices before i start tackling this...

Actually, i have an algebra 2 book upstairs, i think i'll go learn about that now

Also, I forget where i read this, but isn't the universe hypothesised to be in the shape of the surface of a hypertorus? I could only imagine how much of a pain using that would be.

the above text is subject to the words "Probably", "Kinda", and "Not".*
Dr Tank
14
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 1st Jun 2009 17:31
You should learn about rotation matrices for sure. Useful things in game dev.

Read a book recently about the shape of the universe. Basically, it's pretty flat - we can't see any curvature outside of our margin for error. So it could be a really big hypersphere, or torus, klein bottle or whatever and we wouldn't know. BTW isn't a hypertorus basically a posh name for a wrapping cuboid? Like Asteroids but in 3d? Same topography.

Valle
18
Years of Service
User Offline
Joined: 10th Mar 2006
Location: in your girlfriends bed
Posted: 2nd Jun 2009 01:02 Edited at: 2nd Jun 2009 01:02
wow, the last code really has hard sex with your brain
This looks incredibly complicated and i bet you had fun and a sense of achievement while doing this
Awesome work Mister Tank!


AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 3rd Jun 2009 04:12
Quote: "wow, the last code really has hard sex with your brain"


I've never heard that expression before...

i like orange
Dr Tank
14
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 13th Jun 2009 05:28
Thanks. Yes, my mind felt pleasantly violated after this. I was well chuffed it worked.

Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Jul 2009 16:24
Since when did you become Dr Tank?
This sounds weird, I hope it works in DBC.

TGC Forum - converting error messages into sarcasm since 2002.
RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th Jul 2009 08:26
This is freaking awesome! Wow!

Quote: "wow, the last code really has hard sex with your brain"

Never heard that one before either; but... yes.

3D PacMan? Asteroids? Epsilon?


Open MMORPG: It's your game!
NeX the Fairly Fast Ferret
18
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 10th Aug 2009 19:42
I tried to understand what this is meant to represent and had a spontaneous cranial explosion!

Good work!

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Aug 2009 04:03
The coolest thing about this is that, somehow, I do really feel like there is no 'up'. I can't put my finger on why; it's a more realistic feeling than just flying around in a finite world. Totally awesome, gotta say.

Login to post a reply

Server time is: 2024-03-29 11:08:37
Your offset time is: 2024-03-29 11:08:37