Should be basic trigonometry or am I doing this the wrong way?

I’m trying to move the cube so that when it exceeds an x value -6 or +6 (just doing + at the moment), to get it to appear the other side but at the correct z value. I’ve tried soh cah toa but just not getting it…

https://playground.babylonjs.com/#T1SX13#9
Left click and drag right to angle the camera above 180 (debug on right will show you Y rotation). Only after 180 deg will the code kick in to try and adjust the cube’s re-entry point on the other side.

Lines: 149 to 154

or is there a better way of doing this? I need to do this for 200 to 300 planes.

Would it be better to fix the camera and move the 200 to 300 planes? But then look direction becomes an issue…

And ideas?

1 Like

Your PG does not work:(

Fixed :wink:

Thanbks :wink: may I ask you to set it up so we can see the problem immediately? I’m unsure about what you expect

I think I am begining to understand. You have a finite plane and a finite number of objects that you want to act as an infinite plane and an infinite number of objects. Within the viewport of the camera you see some objects. When an object moves outside the viewport you reuse it by positioning it at the opposite side of the viewport in a symmetric position. By using a symmetric position you can give a consistency to object positioning. For example if the camera is moving left and the object disappears to the right then it is set to appear in a symmetric position on the left, if you then immediately change the direction of the camera to the right the use of symmetric positioning will place the object back to where is was before disappearing.

Currently you are moving the camera and so have to work out the relative position of an object to the camera and hence the relative symmetric position.

This needs some deep thinking about.

You got it, I’ve done this a 100 times with 2D stuff, but the 3D version is proving tricky… Especial since the viewport / camera is moving… I done some basic pythag on it but what should be correct is not correct…

The playground already does… You need to rotate the scene slightly and then the cube leaving the right side is not at the same Y in 2D view that it started from due to camera rotation and I need it to come back into play on the opposite side at that Y.

Camera will wander through the planes and they will recycle for re-use via symetrical position re-use. Open world game tricks, an infinite road is not created and destroyed all the time it’s re-used just it’s position is changed.

Now this is an example of what I want in 2D, this is easy to work out but it’s the 3D method of this I can’t work out.

JohnK gave it another description above.

Almost but not quite right… Still using 2D concept… But illustrates things much better:

https://playground.babylonjs.com/#T1SX13#28

1 Like

As your problem seems to be related to the screen space (how to recycle/relocate something getting out of the screen space back to somewhere else in this screen space), if I were you, I would :

  • project the mesh positions to the screen space with the ViewMatrix
  • apply my recycling logic : here, it’s just a 2D AABB intersection test in the screen space, then a computation of the new location on the screen if any intersection
  • unprojected the newly computed location to the 3D plane, knowing that the mesh final altitude is fixed
  • position the recycled mesh to this new location

Hope it makes sense

Not quite, could you cook up a playground…?

The thing that is is moving is the camera, in the real application you are / the camera is where the yellow cone is.

The cone/camera is you locked to a Y = 0 but you have free rain to move around the scene on X and Z.

Got it…

https://playground.babylonjs.com/#T1SX13#30

2 Likes