How do I create a loop-around world?

Blitz3D Forums/Blitz3D Programming/How do I create a loop-around world?

Sokurah(Posted 2007) [#1]
I can't figure out how to do this and haven't been able to find anything among the sample programs.

Normally, like the castle demo, you have a landscape and some objects on it. When you move away from the objects you get further and further away, but it's not what I'd like to do.

I'd like a landscape that wraps around, so when you exit at one edge you'll appear at the oposite edge, but it should also be possible to SEE past the edge.

Imagine a small square landscape with 4 buildings positioned like this

AB
CD

- but with a little room inbetween.

What I'd like to achieve is to (example);
(a) walk right between buildings B & D and appear on the left between buildings A & C.
(b) also SEE buildings A & C when standing between buildings B & D (view could be FPS or viewed from above).

The only way I can think of would be to place a copy of the landscape at the 8 positions around the "real" landscape, and then move the player when he reaches the edge.
Unfortunately that would make things very complicated regarding objects. There must be an easier way.

The landscape would be an .X file (no, not one of those) :)

Can someone help me out with a simple solution?


Rob Farley(Posted 2007) [#2]
You wouldn't need 9 copies, you'd only need 4 copies in total.

Using your diagram:
AB
CD

If you're moving to the right you'd have you character in either A or C, moving left would be in B or D, moving up would be in C or D and moving down would be in A or B. As you change direction you'd have to shift all the objects / characters into the appropiate zone, or just create copies of everything and only check collisions on the objects in one zone.

As far as a simple way of doing it, I can't think of one either.


b32(Posted 2007) [#3]
Maybe you could use multiple cameras or render the scene a few times ?



Rob Farley(Posted 2007) [#4]
Hmmm the multiple render thing sounds like a really good solution.

You would have to set the cameraclsmode so it doesn't render over the last one and make sure you only render your skybox (if you have one) first and once.

If your landscape was 10x10 for example, if you were moving forwards (ie z+) you'd need to first render your terrain from zpos-10 then render your normal view with a cameraclsmode set to off. This would mean you'd first render the distant view followed by the close view.

Likewise if you're moving right (x+) you'd first render at xpos - 10 then the normal view (you'd had to render the distant views too).

Therefore you'll need to do 4 renders per frame but theres not really a big hit doing multiple renders. Certainly less that duplicating all your objects and managing what's going on.

On top of this if you're rotating the cam you'll need to do something a bit clever to know what to render but certainly shouldn't be too much of a hassle to manage.

Might have to have a play with this tonight when I've got blitz infront of me. Like the idea of that tough.


JoeGr(Posted 2007) [#5]
Here's a simple method which I think might work. You could have nine of your 'tiles' laid out like this:

ABABAB
CDCDCD
ABABAB
CDCDCD
ABABAB
CDCDCD

Let's assume that the player starts at the very centre (world 0,0,0) and that each tile is 10 units across, then just use something like this in your main loop:

If EntityX#(player)<-5 Then TranslateEntity player,10,0,0
If EntityX#(player)>5 Then TranslateEntity player,-10,0,0
If EntityZ#(player)<-5 Then TranslateEntity player,0,0,10
If EntityZ#(player)>5 Then TranslateEntity player,0,0,-10

EDIT - I've just realised this is exactly what you described in your first post! What's the problem with this method again?


Stevie G(Posted 2007) [#6]
I honestly think you're better sticking with your first suggestion. The multipass camera rendering idea could involved alot of unecessary entity management whether it actually works or not.

Use only 4 copies of the same level and simply wrap the player position coords so that they don't excede the dc/ba square in the center.

ABAB
CdcD
AbaB
CDCD

Remember that specific entities parented to each copy of the level will be culled individually if not in view so this will be plenty fast enough.

Stevie


Rob Farley(Posted 2007) [#7]
Joe, the problem is duplication and managment.

I was thinking about the multiple camera thing and thought the easy solution would be to parent the additional cameras to the main cam.

Graphics3D 1024,768,32,2

camera = CreatePivot()

Dim cam(8)
For n=0 To 8
	cam(n) = CreateCamera(camera)
	If n=1 Then PositionEntity cam(n),-20,0,20
	If n=2 Then PositionEntity cam(n),0,0,20
	If n=3 Then PositionEntity cam(n),20,0,20
	If n=4 Then PositionEntity cam(n),-20,0,0
	If n=5 Then PositionEntity cam(n),20,0,0
	If n=6 Then PositionEntity cam(n),-20,0,-20
	If n=7 Then PositionEntity cam(n),0,0,-20
	If n=8 Then PositionEntity cam(n),20,0,-20
	CameraClsMode cam(n),0,1
Next

PositionEntity camera,0,5,0

light = CreateLight()
TurnEntity light,45,45,0

For x=-5 To 5
For y=-5 To 5
	cc = CreateCube()
	PositionEntity cc,x*2,0,y*2
	EntityColor cc,Rand(50,255),Rand(50,255),Rand(50,255)
	ScaleEntity cc,1,.001,1
Next
Next

Repeat
	Cls
	
	If KeyDown(200) Then MoveEntity camera,0,0,.1
	If KeyDown(203) Then MoveEntity camera,-.1,0,0
	If KeyDown(208) Then MoveEntity camera,0,0,-.1
	If KeyDown(205) Then MoveEntity camera,.1,0,0
	
	If EntityX(camera) > 10 Then TranslateEntity camera,-20,0,0
	If EntityX(camera) < -10 Then TranslateEntity camera,20,0,0
	If EntityZ(camera) > 10 Then TranslateEntity camera,0,0,-20
	If EntityZ(camera) < -10 Then TranslateEntity camera,0,0,20
	
	RenderWorld
	
	Text 0,0,EntityX(camera)
	Text 0,10,EntityZ(camera)
	Flip
Until KeyHit(1)


Obviously in this example the landscape is so small you see the repeats, however you would have the landscape larger than the camera view distance and you won't get the flick.

Something's not quite right with that example though as there seems to be a band of colours that changes when the cam gets moved, this it's probably a positioning problem.

On top of this if you use 3D objects you will have to manage the order of which camera gets rendered otherwise you'll get 'strange' results if stuff at the back is rendered after stuff at the front.


Sokurah(Posted 2007) [#8]
The multiple render way seems like the way to do it, but also a bit complicated though.

Heh, I was kinda hoping for a simpler solution, but the important thing now is knowing that I wouldn't be trying to do something the difficult way, when there was an easier way that I just didn't think about.

Thanks for the answers guys. It's given me a lot to think about and some different ideas to try out.

...still, if some of you comes up with a brilliant idea, I'd still like to hear it though. ;)