[Solved] How to check if an object is in the view?

Hello!
I’m trying to find out how to detect if an object (like a TCastleScene or any TCastleTranform) is in field of vision of the viewport (TCastleViewport or its TCastleCamera).
How do I do that?

PS: Maybe this solution is already described in the documentation, examples or on the forum, but I didn’t find it, sorry in advance

See Castle Game Engine: CastleScene: Class TCastleScene
If you want a more powerful version that accounts for objects behind other objects, then see Castle Game Engine: CastleScene: Class TCastleScene

1 Like

Thanks for help!
Second method working for me


Looks like I misread the documentation, the first one is actually for something else…

After reading the description, I also thought that it should work. But maybe it is only for the described specific case.
¯\_(ツ)_/¯

The TCastleScene.WasVisible ( Castle Game Engine: CastleScene: Class TCastleScene ) is indeed the exact solution to this.

Other things determine how do we detect this visibility.

1 Like

Sudden addition :roll_eyes:
So what if I want to determine the visibility of the area or point where the object should appear, but it hasn’t appeared yet? What can I do then?

If you only want to detect “visibility, according to whether it is in frustum” then you can check “frustum vs box / sphere” collision yourself using routines like

To get TFrustum, you can just look at MyViewport.Camera.Frustum. It’s automatically updated.

( To get “visibility, accounting for the fact that object may be obscured by another object” is harder – our Occlusion Culling | Manual | Castle Game Engine doesn’t expose facility to check arbitrary things (not yet in world) now. You’d have to use the respective OpenGL/OpenGLES/WebGL API directly. See how castleinternalocclusionculling.pas is implemented. )

1 Like