g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.74k stars 292 forks source link

Camera Scale Barriers #260

Closed c4lliope closed 2 years ago

c4lliope commented 2 years ago

Hello, I am curious if g3n's camera can handle really large scenes; imagine Kerbal Space Program. I am making a scene using a scale-model Earth and space ship. I make the globe based on the shaders.earth demo:

    geom := geometry.NewSphere(6357000, 32, 16)
    t.sphere = graphic.NewMesh(geom, matEarth)
    a.Scene().Add(t.sphere)

...and I'm unsure how to place or configure my camera in the scene to be able to see this globe. I imagine some combination of SetNear, SetFar, and maybe ViewMatrix. My code is here: https://github.com/assembleco/debris-space.0; I'm glad for any help.

c4lliope commented 2 years ago

I had no luck with either:

    a.camera.ViewMatrix(math32.NewMatrix4().MakeTranslation(-18, 0, 0))
    a.camera.SetPosition(-18, 0, 0)

Using a sphere radius of 4.

danaugrs commented 2 years ago

Hi @c4lliope ! Thanks for you interest in G3N. I can't access the repo you linked. If the camera is facing the sphere then I you'd probably only need to modify the near and far planes to make sure the center of the sphere lies inside the camera frustum.