I've got some problems with checking the visibility of a mesh in my application. Here is a video showing the problems:
">Youtube.com
Now the code is use looks like the following:
public bool IsCameraVisible { get { foreach (Adt.ADTChunk c in Chunks) { Vector3 pos = new Vector3(c.XBase + Utils.Metrics.Chunksize / 2.0f, c.YBase, c.ZBase + Utils.Metrics.Chunksize / 2.0f); Vector3 dir = Mgr.Camera.Target - Mgr.Camera.Position; float midX = pos.X; float midZ = pos.Z; Vector3 destV = new Vector3(midX - Mgr.Camera.Position.X, pos.Y - Mgr.Camera.Position.Y, midZ - Mgr.Camera.Position.Z); Vector2 dir2 = new Vector2(dir.X, dir.Z); Vector2 destV2 = new Vector2(destV.X, destV.Z); float lengths = destV2.Length() * dir2.Length(); float skalar = dir2.X * destV2.X + /*dir.Y * destV.Y + */dir2.Y * destV2.Y; float cos = skalar / lengths; float angle = (float)Math.Acos((double)cos); float angleD = (angle * 180) / (float)Math.PI; if (angleD > 60 || (destV.Length() > 1.4f * Utils.Metrics.Tilesize)) continue; return true; } return false; } } }
Some explanation:
I use atlases of textures to reduce render calls. To determine if a certain atlas (that is made up of 16 chunks) is visible to the camera the above code looks if any of the chunks is visible and returns it. The code basically works well if i don't render the atlases but every chunks as an own mesh. But in the atlas the strange behavior shown in the video comes up! Im clueless why this happens...
Greetings
Plerion