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.

DarkBASIC Professional Discussion / Sectors in 3d space

Author
Message
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 2nd Jul 2013 00:22 Edited at: 2nd Jul 2013 00:26
Hey everybody,

I've got a multiplayer 'game' (well basically moving cameras and a quake style console) and hoping to turn it into a space shooter. I've been experimenting with procedurally generated data and wish to continue with that.

Now I have the idea to work with sectors. Sectors occupying each client/players and sectors within a (variable) range around the player. All other sectors (outside the range) are unloaded.

Now my problem is, how to get the sector, based on player location in the form of X,Y,Z and those sectors in range?

I know this must be simple but I got nothing...

Any help is much appreciated!

Regards Sph!nx
www.mental-image.net
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 2nd Jul 2013 01:27
Just a distance formula should do. You can switch objects for any X/Y/Z position.



Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 2nd Jul 2013 02:56
The current sector is the position divided with the total size of the sector universe (ie. sectorWidth * sectorsAcross x sectorDepth * dectorsDown) + any offset (for exampla half the total universe size if the middle is at (0, 0) rather than the bottom left corner).
The easiest solution is to always show the sector the player is currently in + x sectors to the left / right / up / down of it. In that way you won't have to check for distances. It looks best if this is combined with some distance culling of the objects actually in the sectors based on their average size, otherwise large parts of the scene (the individual sectors) will jump in and out of sight as some particular line (between sectors) is crossed.


"Why do programmers get Halloween and Christmas mixed up?"
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 2nd Jul 2013 14:53 Edited at: 2nd Jul 2013 15:34
Hey, thanks for the quick response guys. I'll take a good look at both your solutions and will let you know how things turn out!

Edit
Ok, still in theory. Each client has data of the sector that should be active for him/her (example: 1,-7,4. This data represent 1 * sector size X, etc.). With this, I can do a search on disk for a file named 1,-7,4 and load it, or generate a new sector. I got this covered.

What still puzzles me is how to get all sectors within a range around that active sector.

Regards Sph!nx
www.mental-image.net
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 3rd Jul 2013 15:30 Edited at: 3rd Jul 2013 15:30
Ok, I'm getting confused reading my own previous posts. Sorry. Let me clear it up.

I now know how to get a sector, that a client is occupying in the form of x,y,z.

example: -1,5,4 (meaning -1 * sector size, 5 * sector size and 4 * sector size. This form will keep the full string small, that will act as ID (for files names, etc.) and indicated the position in space.) I got this covered.

The problem I have is that I don't know the correct process/calculation to get all sectors within a range of that sector. Anyone got some ideas?

This is all to make a list that is used to load/generate or unload the actual sectors.

Any help is greatly appreciated!

Regards Sph!nx
www.mental-image.net
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 3rd Jul 2013 18:57 Edited at: 3rd Jul 2013 18:57
If you store your sectors in an array and know the centre sector it would be as simple as something along these lines:



"Why do programmers get Halloween and Christmas mixed up?"
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 4th Jul 2013 00:14
Thanks, Rudolpho. I'm really sorry and I cannot understand why something like this confuses me but I still don't understand. Could you please elaborate?

I have this data:
Sector_size# = 1024
Sector_range# = 6

Sector the player is occupying (example) = sec_id$ = "15,7,-19"

I store the list in an array like so:


I've added the sector the client is occupying like so:


Could you please show I could add all sectors in the range of the first one to that list?

Regards Sph!nx
www.mental-image.net
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 4th Jul 2013 15:36
I think you would have to show some more code.
How do you store all of your sector data? What is the "id string"; 'x, y, z'? If you store all your sectors in an array at all times (or at least their id's / filenames / what have you) you could step through the surrounding sectors as I did in my last snippet. If you want to add them to a list, that's what you would do on the line with the comment "Process sector(tx, ty)". If you have a 3-dimensional sector system you would have to add a z-component as well.


"Why do programmers get Halloween and Christmas mixed up?"
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 4th Jul 2013 18:48
Thanks so far mate,

The ID String is a string in the form of this (example: -1,4,15 can be anything). This ID is used to ID each sector in the array, as saved file on disc and for multiplayer communication.

This ID based on the position of the sector. From the example above: -1 * sector_size#, 4 * sector_size#, 15 * sector_size#.

Some globals:


The first part of the sector function. It shows how I started the listing of sectors by getting the client positions, turning it into a string label and adding it to the array:


I hope this makes it it clear of what I mean.

Regards Sph!nx
www.mental-image.net
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 5th Jul 2013 02:31 Edited at: 5th Jul 2013 02:32
Ah... that's a fairly odd sector identifying system but I'm sure you have your reasons :p

Everything would get clearer if you just actually stored the sector as a position (think of it as sector[x, y[, z - if you use that, as it seems you are]]).

Then you could determine the sector as the integer part of your new_-variables, just like you're doing when creating those ID strings.
An easier way to write it would be something like:




"Why do programmers get Halloween and Christmas mixed up?"
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 5th Jul 2013 14:12 Edited at: 5th Jul 2013 14:13
Thank you very much, Rudolpho!

It has become much clearer on how this process can be done. I should be able to implement this without problems.

I have the sector ID like this, so it can be easily used for several purposes. One of them is to use it as file name to save the sector when it's unloaded to disc. It keep the strings as small as possible.

Regards Sph!nx
www.mental-image.net

Login to post a reply

Server time is: 2026-07-06 18:37:51
Your offset time is: 2026-07-06 18:37:51